From: Andre Noll Date: Sun, 11 Sep 2011 02:21:40 +0000 (+0200) Subject: afs: Write 'afs' to argv[0]. X-Git-Tag: v0.4.9~14^2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=96dc6e5b66b37d3bd0e0e4d35e39825f374b8b40;p=paraslash.git afs: Write 'afs' to argv[0]. This allows to distinguish the afs process from the main server process by looking at the ps output. Although there are less hacky ways to achieve this (prctl(PR_SET_NAME, ...), setproctitle()), the argv approach has the advantage of working on all supported operating systems except FreeBSD. We have been doing the argv mangling for a long time now in the command handlers and it has never caused any problems, so it should be safe. --- diff --git a/server.c b/server.c index 15ae5c9a..120fea25 100644 --- a/server.c +++ b/server.c @@ -434,7 +434,7 @@ err: exit(EXIT_FAILURE); } -static int init_afs(void) +static int init_afs(int argc, char **argv) { int ret, afs_server_socket[2]; pid_t afs_pid; @@ -448,6 +448,10 @@ static int init_afs(void) if (afs_pid < 0) exit(EXIT_FAILURE); if (afs_pid == 0) { /* child (afs) */ + int i; + for (i = argc - 1; i >= 0; i--) + memset(argv[i], 0, strlen(argv[i])); + sprintf(argv[0], "para_server (afs)"); close(afs_server_socket[0]); afs_init(afs_socket_cookie, afs_server_socket[1]); } @@ -514,7 +518,7 @@ static void server_init(int argc, char **argv) */ para_sigaction(SIGCHLD, tmp_sigchld_handler); PARA_NOTICE_LOG("initializing the audio file selector\n"); - afs_socket = init_afs(); + afs_socket = init_afs(argc, argv); init_signal_task(); PARA_NOTICE_LOG("initializing virtual streaming system\n"); init_vss_task(afs_socket);