]> git.tuebingen.mpg.de Git - dss.git/commitdiff
ipc: Make pid pointer optional.
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 16 Jun 2016 21:06:29 +0000 (23:06 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 21 Aug 2016 19:13:25 +0000 (21:13 +0200)
This changes get_dss_pid() to handle the case where the caller passed
a NULL pid pointer. Conversely, if pid is not NULL, we now make sure
to initialize the given address in all cases.

The single caller currently never passes NULL, so this change is just
defensive programming, protecting against future users. Be liberal
in what you accept, be strict in what you return..

ipc.c

diff --git a/ipc.c b/ipc.c
index 65ef20049d26748ef54b6fd60068e7492b159beb..478d307e37e4d7f3179596e1b23358cd2528cb77 100644 (file)
--- a/ipc.c
+++ b/ipc.c
@@ -345,6 +345,8 @@ int get_dss_pid(char *config_file, pid_t *pid)
 {
        int ret, semid, key = get_key_or_die(config_file);
 
+       if (pid)
+               *pid = 0;
        ret = mutex_get(key, 0);
        if (ret < 0)
                return ret;
@@ -352,7 +354,8 @@ int get_dss_pid(char *config_file, pid_t *pid)
        ret = semctl(semid, 1, GETPID);
        if (ret < 0)
                return -E_NOT_RUNNING;
-       *pid = ret;
+       if (pid)
+               *pid = ret;
        ret = mutex_try_lock(semid);
        if (ret >= 0)
                return -E_NOT_RUNNING;