mirror of
https://github.com/troglobit/finit.git
synced 2026-11-06 15:51:03 +00:00
Convert finit to use libev and fix so plugin ctors runs on dlopen().
Lots of cleanup and simplification of the main code in this commit. Most notably libev has been added to take care of the main loop and monitor services. Still TODO is migrating to use the libev signal handling. Convert initctl.c:listen_initctl() to a plugin instead. This also meant introducing a new form of I/O plugin to finit, also handled by libev. Load plugins *after* we've setup the base filesystem (BASEFS) in case plugins reside on a filesystem not reachable before "mount -a" has run. This also has the side effect of lining up nicely with the first level plugin hooks. If a plugin wants to hook up with a loded service we connect them by their respective numeric IDs in plugin_register(). I.e., the service monitor checks if a service has a registered callback, which in turn decides if a service should be started, stopped or reloaded. Rip out old EeePC distribution defines from finit.h, none of it really applies anymore. If you need distribution specific settings this is the place to put them. Make hookpoint names (#defines) clearer: after BASEFS, after networking, after all setup, etc. Use #inlude_next <signal.h> in signal.h to include system header file! Simplify service monitor: move essential code to svc.c and rip out the TIPC dependency. Write your own service.so plugin, or wait for a more complete example of how to extend service monitoring using the primitives in svc.c Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
5dda9051ac
commit
0e02429e75
25 files changed
+620
-1073
No files matched your search
@@ -22,17 +22,86 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef FINIT_SVC_H__
|
||||
#define FINIT_SVC_H__
|
||||
#ifndef FINIT_SVC_H_
|
||||
#define FINIT_SVC_H_
|
||||
|
||||
#include "service.h"
|
||||
#include <errno.h>
|
||||
#include <sys/shm.h> /* shmat() */
|
||||
#include <sys/types.h> /* pid_t */
|
||||
|
||||
svc_t *svc_new_service (void);
|
||||
svc_t *svc_find_by_id (int id);
|
||||
svc_t *svc_find_by_name (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
#include "finit.h"
|
||||
|
||||
#endif /* FINIT_SVC_H__ */
|
||||
typedef enum {
|
||||
SVC_STOP = 0, /* Disabled */
|
||||
SVC_START, /* Enabled */
|
||||
SVC_RELOAD /* Enabled, needs restart */
|
||||
} svc_cmd_t;
|
||||
|
||||
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
|
||||
#define MAX_ARG_LEN 64
|
||||
#define MAX_STR_LEN 64
|
||||
#define MAX_NUM_SVC 64 /* Enough? */
|
||||
#define MAX_NUM_SVC_ARGS 16
|
||||
|
||||
/* Default enable for all services, can be stopped by means
|
||||
* of issuing an initctl call. E.g.
|
||||
* initctl <stop|start|restart> service */
|
||||
typedef struct svc {
|
||||
/* Private */
|
||||
int id; /* Service ID#, set by svc_new() */
|
||||
pid_t pid;
|
||||
char cmd[MAX_ARG_LEN];
|
||||
char args[MAX_NUM_SVC_ARGS][MAX_ARG_LEN];
|
||||
char descr[MAX_STR_LEN];
|
||||
/* Public */
|
||||
int delayed_reload; /* For external service plugin. */
|
||||
plugin_svc_t *plugin;
|
||||
} svc_t;
|
||||
|
||||
typedef struct svc_map svc_map_t;
|
||||
|
||||
/* Put services array in shm */
|
||||
static inline svc_t *finit_svc_connect(void)
|
||||
{
|
||||
const long ID = FINIT_SHM_ID;
|
||||
static void *ptr = (void *)-1;
|
||||
|
||||
if ((void *)-1 == ptr) {
|
||||
ptr = shmat (shmget (ID, sizeof(svc_t) * MAX_NUM_SVC, 0600 | IPC_CREAT), NULL, 0);
|
||||
if ((void *)-1 == ptr) {
|
||||
_d("Failed allocating shared memory, error %d: %s", errno, strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (svc_t *)ptr;
|
||||
}
|
||||
|
||||
static inline int svc_id(svc_t *svc)
|
||||
{
|
||||
if (!svc) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return svc->id;
|
||||
}
|
||||
|
||||
svc_t *svc_new (void);
|
||||
svc_t *svc_find_by_id (int id);
|
||||
svc_t *svc_find_by_name (char *name);
|
||||
svc_t *svc_iterator (int restart);
|
||||
|
||||
int svc_register (char *line);
|
||||
int svc_id_by_name (char *name);
|
||||
svc_cmd_t svc_enabled (svc_t *svc, int dynamic);
|
||||
int svc_start (svc_t *svc);
|
||||
int svc_start_by_name (char *name);
|
||||
int svc_stop (svc_t *svc);
|
||||
int svc_reload (svc_t *svc);
|
||||
void svc_start_all (void);
|
||||
|
||||
#endif /* FINIT_SVC_H_ */
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
|
||||
Reference in new issue
Block a user