From 81d9c8b0e49a12f7b726b06e2df48c2c3314bbcb Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 16 Jun 2016 23:06:29 +0200 Subject: [PATCH] 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.. --- ipc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; -- 2.39.2