]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
parse-util: allow parse_pid() to work with NULL return parameter
authorLennart Poettering <lennart@poettering.net>
Thu, 20 Apr 2023 16:46:55 +0000 (18:46 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 24 Apr 2023 19:16:33 +0000 (03:16 +0800)
That way the function becomes useful for validating pids formatted as
strings.

src/basic/parse-util.c

index 3445d3130761c708c595cc8ec242b8af7e62080d..a53cbc73b89e12f3774456d4b93bd6429e99dddd 100644 (file)
@@ -50,7 +50,6 @@ int parse_pid(const char *s, pid_t* ret_pid) {
         int r;
 
         assert(s);
-        assert(ret_pid);
 
         r = safe_atolu(s, &ul);
         if (r < 0)
@@ -64,7 +63,8 @@ int parse_pid(const char *s, pid_t* ret_pid) {
         if (!pid_is_valid(pid))
                 return -ERANGE;
 
-        *ret_pid = pid;
+        if (ret_pid)
+                *ret_pid = pid;
         return 0;
 }