afs: Write 'afs' to argv[0].
authorAndre Noll <maan@systemlinux.org>
Sun, 11 Sep 2011 02:21:40 +0000 (04:21 +0200)
committerAndre Noll <maan@systemlinux.org>
Thu, 13 Oct 2011 08:48:12 +0000 (10:48 +0200)
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.

server.c

index 15ae5c9a296be654471fd1f95aa9395629fae097..120fea258a64fdd1bf91e1436f22ee5d7e00a7c0 100644 (file)
--- 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);