summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Noll <maan@tuebingen.mpg.de>2016-06-16 23:06:29 +0200
committerAndre Noll <maan@tuebingen.mpg.de>2016-08-21 21:13:25 +0200
commit81d9c8b0e49a12f7b726b06e2df48c2c3314bbcb (patch)
tree0a922a1bf00bfd06b24458e846e934569ffe0513
parent7da9a331fbbfb10a35fd9d014c47edbad13ffed7 (diff)
ipc: Make pid pointer optional.
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..
-rw-r--r--ipc.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/ipc.c b/ipc.c
index 65ef200..478d307 100644
--- 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;