mirror of
https://github.com/troglobit/finit.git
synced 2026-10-11 17:02:42 +07:00
Follow-up to issue #81: remove SysV shared memory IPC altogether
This change removes a long standing kernel requirement and architectural mishap in the design of Finit v1. It is no longer necessary to include CONFIG_SYSVIPC in the kernel to use Finit and its command line tool initctl. It is also no longer possible to connect to the internals of PID 1 using shmat(), the initctl tool has already been updated to use the domain socket API. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -21,9 +21,6 @@ can also be used.
|
||||
General
|
||||
-------
|
||||
|
||||
* Remove shm, let `initctl` call `api.c` for each `svc_t` instead of
|
||||
opening up the inner parts of PID 1 to other processes. Also, this
|
||||
would prevent issues like #81 from happening.
|
||||
* Add support for timed shutdown in Finit, including cancelled shutdown.
|
||||
* SysV init and systemd use SIGUSR1 to restart their FIFO/D-Bus. Add
|
||||
API restart to SIGHUP callback for the same functionality in Finit.
|
||||
|
||||
@@ -378,10 +378,6 @@ int main(int argc, char* argv[])
|
||||
makedir("/dev/pts", 0755);
|
||||
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620");
|
||||
|
||||
makedir("/dev/shm", 0755);
|
||||
if (!fismnt("/dev/shm"))
|
||||
mount("shm", "/dev/shm", "tmpfs", 0, NULL);
|
||||
|
||||
/*
|
||||
* New tmpfs based /run for volatile runtime data
|
||||
* For details, see http://lwn.net/Articles/436012/
|
||||
|
||||
@@ -35,37 +35,20 @@
|
||||
|
||||
/* Each svc_t needs a unique job# */
|
||||
static int jobcounter = 1;
|
||||
static svc_t *workaround = NULL;
|
||||
static svc_t *svc_list = NULL;
|
||||
|
||||
static svc_t *__connect_shm(void)
|
||||
{
|
||||
svc_t *list;
|
||||
if (svc_list)
|
||||
return svc_list;
|
||||
|
||||
list = finit_svc_connect();
|
||||
if (!list) {
|
||||
if (workaround)
|
||||
return workaround;
|
||||
|
||||
/* Linux not built with CONFIG_SYSVIPC, or libc does not support shmat()/shmget() */
|
||||
if (ENOSYS == errno)
|
||||
warn("Kernel does support SYSV shmat() IPC, error %d", errno);
|
||||
|
||||
/* Try to prevent PID 1 from aborting, issue #81 */
|
||||
if (getpid() == 1) {
|
||||
warnx("Implementing PID 1 workaround, initctl tool will not work ...");
|
||||
if (!workaround)
|
||||
workaround = calloc(MAX_NUM_SVC, sizeof(svc_t));
|
||||
|
||||
list = workaround;
|
||||
}
|
||||
}
|
||||
|
||||
if (!list) {
|
||||
warn("Failed connecting to shared memory, error %d", errno);
|
||||
svc_list = calloc(MAX_NUM_SVC, sizeof(svc_t));
|
||||
if (!svc_list) {
|
||||
warn("Failed allocating static list of services, error %d", errno);
|
||||
abort();
|
||||
}
|
||||
|
||||
return list;
|
||||
return svc_list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
#include <sys/ipc.h> /* IPC_CREAT */
|
||||
#include <sys/resource.h>
|
||||
#include <sys/shm.h> /* shmat() */
|
||||
#include <sys/types.h> /* pid_t */
|
||||
#include <lite/lite.h>
|
||||
|
||||
@@ -66,7 +65,6 @@ typedef enum {
|
||||
SVC_BLOCK_RESTARTING,
|
||||
} svc_block_t;
|
||||
|
||||
#define FINIT_SHM_ID 0x494E4954 /* "INIT", see ascii(7) */
|
||||
#define MAX_ARG_LEN 64
|
||||
#define MAX_STR_LEN 64
|
||||
#define MAX_COND_LEN (MAX_ARG_LEN * 3)
|
||||
@@ -129,23 +127,6 @@ typedef struct svc {
|
||||
void (*timer_cb)(struct svc *svc);
|
||||
} svc_t;
|
||||
|
||||
typedef struct svc_map svc_map_t;
|
||||
|
||||
/* Put services array in shm */
|
||||
static inline svc_t *finit_svc_connect(void)
|
||||
{
|
||||
static void *ptr = (void *)-1;
|
||||
|
||||
if ((void *)-1 == ptr) {
|
||||
ptr = shmat(shmget(FINIT_SHM_ID, sizeof(svc_t) * MAX_NUM_SVC,
|
||||
0600 | IPC_CREAT), NULL, 0);
|
||||
if ((void *)-1 == ptr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (svc_t *)ptr;
|
||||
}
|
||||
|
||||
svc_t *svc_new (char *cmd, int id, int type);
|
||||
int svc_del (svc_t *svc);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user