From 10c2b48b4f12e34a282b96ba1e1e899e0ced6d1e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 19 Apr 2014 19:36:50 +1000 Subject: [PATCH] Rename processes and change generator function to suit pi model --- configure.ac | 2 +- src/ckpool.c | 20 +++++++++++++++----- src/generator.c | 4 +++- src/generator.h | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 93ed7a61..3807ec59 100644 --- a/configure.ac +++ b/configure.ac @@ -37,7 +37,7 @@ AC_CHECK_LIB(jansson, json_loads, , AC_CHECK_HEADERS(stdio.h stdlib.h fcntl.h sys/time.h unistd.h) AC_CHECK_HEADERS(ctype.h errno.h byteswap.h string.h time.h) AC_CHECK_HEADERS(endian.h sys/endian.h arpa/inet.h syslog.h) -AC_CHECK_HEADERS(alloca.h pthread.h stdio.h math.h signal.h) +AC_CHECK_HEADERS(alloca.h pthread.h stdio.h math.h signal.h sys/prctl.h) AC_CHECK_HEADERS(sys/types.h sys/socket.h sys/stat.h linux/un.h netdb.h) AC_CHECK_HEADERS(stdint.h netinet/in.h netinet/tcp.h) AC_CHECK_HEADERS(jansson.h) diff --git a/src/ckpool.c b/src/ckpool.c index 09875673..84a40658 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -7,6 +7,7 @@ * any later version. See COPYING for more details. */ +#include #include #include #include @@ -20,12 +21,21 @@ #include "libckpool.h" #include "generator.h" +static void rename_proc(const char *name) +{ + char buf[16]; + + snprintf(buf, 16, "ckp@%s", name); + prctl(PR_SET_NAME, buf, 0, 0, 0); +} + static void *listener(void *arg) { proc_instance_t *pi = (proc_instance_t *)arg; unixsock_t *us = &pi->us; int sockd; + rename_proc(pi->sockname); retry: sockd = accept(us->sockd, NULL, NULL); if (sockd < 0) { @@ -89,7 +99,7 @@ static void create_process_unixsock(proc_instance_t *pi) quit(1, "Failed to open %s socket", pi->sockname); } -void write_namepid(proc_instance_t *pi) +static void write_namepid(proc_instance_t *pi) { int pid = getpid(); char s[1024]; @@ -99,7 +109,7 @@ void write_namepid(proc_instance_t *pi) quit(1, "Failed to write %s pid %d", pi->processname, pid); } -int launch_process(proc_instance_t *pi) +static void launch_process(proc_instance_t *pi) { pid_t pid; @@ -107,12 +117,11 @@ int launch_process(proc_instance_t *pi) if (pid < 0) quit(1, "Failed to fork %s in launch_process", pi->processname); if (!pid) { + rename_proc(pi->processname); write_namepid(pi); create_process_unixsock(pi); - pi->process(pi); + exit(pi->process(pi)); } - - return 0; } int main(int argc, char **argv) @@ -161,6 +170,7 @@ int main(int argc, char **argv) proc_generator.ckp = &ckp; proc_generator.processname = strdup("generator"); proc_generator.sockname = proc_generator.processname; + proc_generator.process = &generator; launch_process(&proc_generator); /* Shutdown from here */ diff --git a/src/generator.c b/src/generator.c index bd165977..cd77e3f5 100644 --- a/src/generator.c +++ b/src/generator.c @@ -11,7 +11,9 @@ #include "libckpool.h" #include "generator.h" -int generator(unixsock_t *us) +int generator(proc_instance_t *pi) { + LOGDEBUG("Process %s started", pi->processname); + return 0; } \ No newline at end of file diff --git a/src/generator.h b/src/generator.h index bc378fd2..8b7aa875 100644 --- a/src/generator.h +++ b/src/generator.h @@ -12,6 +12,6 @@ #include "config.h" -int generator(unixsock_t *us); +int generator(proc_instance_t *pi); #endif /* GENERATOR_H */