diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-07-27 20:59:28 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-07-27 20:59:28 +0200 |
commit | 0676bd67c6ef5367c96d1e19d731340826abebd4 (patch) | |
tree | d591ffd6e35dbb1ee754c882fe1bdb184fc8ada6 /src | |
parent | fix multiple clients bug: minor bug in linked_list caused removal of old clients + add dump method for linked list (diff) | |
download | mds-0676bd67c6ef5367c96d1e19d731340826abebd4.tar.gz mds-0676bd67c6ef5367c96d1e19d731340826abebd4.tar.bz2 mds-0676bd67c6ef5367c96d1e19d731340826abebd4.tar.xz |
mds-base: add server_initialised
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/mds-base.c | 30 | ||||
-rw-r--r-- | src/mds-base.h | 19 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/mds-base.c b/src/mds-base.c index 12eac19..1b2e767 100644 --- a/src/mds-base.c +++ b/src/mds-base.c @@ -42,6 +42,8 @@ int argc = 0; char** argv = NULL; int is_respawn = -1; int is_reexec = 0; +int on_init_fork = 0; +char* on_init_sh = NULL; pthread_t master_thread; volatile sig_atomic_t terminating = 0; @@ -82,6 +84,10 @@ int __attribute__((weak)) parse_cmdline(void) is_reexec = 1; else if (startswith(arg, "--alarm=")) /* Schedule an alarm signal for forced abort. */ alarm((unsigned)min(atoi(arg + strlen("--alarm=")), 60)); /* At most 1 minute. */ + else if (strequals(arg, "--on-init-fork")) /* Fork process when initialised. */ + on_init_fork = 1; + else if (startswith(arg, "--on-init-sh=")) /* Run a command when initialised. */ + on_init_sh = arg + strlen("--on-init-sh="); } if (is_reexec) { @@ -131,6 +137,30 @@ int __attribute__((weak)) connect_to_display(void) return 1; } +/** + * This function should be called when the server has + * been properly initialised but before initialisation + * of anything that is removed at forking is initialised + */ +void __attribute__((weak)) server_initialised(void) +{ + pid_t r; + if (on_init_fork && (r = fork())) + { + if (r == (pid_t)-1) + { + perror(*argv); + eprint("while forking at completed initialisation"); + exit(1); + } + else + exit(0); + } + + if (on_init_sh != NULL) + system(on_init_sh); +} + /** * This function is called when a signal that diff --git a/src/mds-base.h b/src/mds-base.h index a4298da..c8666a1 100644 --- a/src/mds-base.h +++ b/src/mds-base.h @@ -91,6 +91,18 @@ extern int is_respawn; extern int is_reexec; /** + * Whether to fork the process when the + * server has been properly initialised + */ +extern int on_init_fork; + +/** + * Command the run (`NULL` for none) when + * the server has been properly initialised + */ +extern char* on_init_sh; + +/** * The thread that runs the master loop */ extern pthread_t master_thread; @@ -138,6 +150,13 @@ int parse_cmdline(void); /* __attribute__((weak)) */ */ int connect_to_display(void); /* __attribute__((weak)) */ +/** + * This function should be called when the server has + * been properly initialised but before initialisation + * of anything that is removed at forking is initialised + */ +void server_initialised(void); /* __attribute__((weak)) */ + /** * This function should be implemented by the actual server implementation |