Files
finit/plugin.h
T
Joachim Nilsson c49d89dfe0 Revert new experimental libev backend due to time constraints
Due to time constraints I had to revert the new libev backend to the
service, I/O and signals monitor.  Employed instead is the tried and
tested signals based service monitor, with a small extension for an
additional I/O monitor using poll() for the I/O plugins to use.

Tried restoring the startx finit.conf directive on top of the service
implementation. However, it's currently not usable to run /usr/bin/startx
for any other user than root. I recommend using the examples/finit.conf
and run /usr/sbin/gdm instead.

finit.c:
        New run_loop() function, replaces libev ev_run().

helpers.c:
        Refactor start_process() into svc_start().

plugin.c:
        Add fds[] array for use in the io_monitor() called by the
        new run_loop().

signal.c:
        Ignore SIGCHLD. Handled by waitpid() in svc_monitor() now,
        which is called by the new run_loop().

svc.c:
        svc_register(): Optional @username parsing for the command line.
        svc_monitor(): Replaced libev callback with waitpid()
        svc_start(): Refactored to use most of helpers.c:start_process()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
2012-09-26 12:18:54 +02:00

122 lines
4.0 KiB
C

/* Plugin based services architecture for finit
*
* Copyright (c) 2012 Joachim Nilsson <troglobit@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef FINIT_PLUGIN_H_
#define FINIT_PLUGIN_H_
#include <poll.h>
#include <sys/queue.h> /* BSD sys/queue.h API */
#define PLUGIN_IO_READ POLLIN
#define PLUGIN_IO_WRITE POLLOUT
#define PLUGIN_INIT(x) static void __attribute__ ((constructor)) x(void)
#define PLUGIN_EXIT(x) static void __attribute__ ((destructor)) x(void)
#define PLUGIN_ITERATOR(x) LIST_FOREACH(x, &plugins, link)
/*
* Predefined hook points for easier plugin debugging
*/
typedef enum {
HOOK_BASEFS_UP = 0,
HOOK_NETWORK_UP,
HOOK_SYSTEM_UP,
HOOK_SHUTDOWN,
HOOK_MAX_NUM
} hook_point_t;
/**
* plugin_t - Finit &plugin_t object
* @link: BSD sys/queue.h linked list node
* @name: Plugin name, or identifier to match against a &svc_t object
* @svc: Service callback for a loaded &svc_t object
* @hook: Hook callback definitions
* @io: I/O hook callback
*
* To setup an &svc_t object callback for a service monitor the @name
* must match the @svc_t @cmd exactly for them to "pair".
*
* A &plugin_t object may contain a service callback, several hooks
* and/or an I/O callback as well. This way all critical extensions
* to finit can fit in one single plugin, if needed.
*
* The "dynamic events" discussed in the svc callback is for external
* service plugins to implement. However, it can be anything that
* can cause a service to need to SIGHUP at runtime. E.g., acquiring
* a DHCP lease, or an interface going UP/DOWN.
*
* It is up to the external service plugin to track these events and
* relay them to each @dynamic service plugins' callback. I.e., to
* all those with the dynamic flag set.
*/
typedef struct plugin {
/* BSD sys/queue.h linked list node. */
LIST_ENTRY(plugin) link;
/* Plugin name, defaults to plugin path if unset.
* NOTE: Must be same as @cmd for service plugins! */
char *name;
/* Service callback to be called once per lap of runloop. */
struct plugin_svc {
/* Private */
int id; /* Service ID# to match this service plugin against, set on installation. */
/* Public */
void *arg; /* Optional argument to callback func, set by plugin. */
int dynamic; /* Reload (SIGHUP) on dynamic event? Set by plugin. */
int private; /* For callbacks to use freely, possibly to store "states", set by plugin. */
int (*cb)(void *arg, int event);
} svc;
/* List of hook callbacks. */
struct {
void *arg; /* Optional argument to callback func. */
void (*cb)(void *arg);
} hook[HOOK_MAX_NUM];
/* I/O Plugin */
struct {
int fd, flags; /* 1:READ, 2:WRITE */
void *arg;
void (*cb)(void *arg, int fd, int events);
} io;
} plugin_t;
/* Used by svc.h */
typedef struct plugin_svc plugin_svc_t;
/* Public plugin API */
int plugin_register (plugin_t *plugin);
int plugin_unregister (plugin_t *plugin);
#endif /* FINIT_PLUGIN_H_ */
/**
* Local Variables:
* version-control: t
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/