From: Andre Noll Date: Thu, 16 Jun 2016 21:06:29 +0000 (+0200) Subject: ipc: Make pid pointer optional. X-Git-Tag: v0.1.7~7 X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=commitdiff_plain;h=81d9c8b0e49a12f7b726b06e2df48c2c3314bbcb 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.. --- 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;