]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd/sd-bus/bus-creds.c
tree-wide: drop {} from one-line if blocks
[thirdparty/systemd.git] / src / libsystemd / sd-bus / bus-creds.c
index fed66823c7a9071d5afc0fa3bb949711fc3b7584..6826e2166545afc59e1977e686ade02b27d845aa 100644 (file)
@@ -107,8 +107,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) {
                         free(c->cgroup_root);
                         free(c->description);
 
-                        free(c->supplementary_gids);
-                        c->supplementary_gids = NULL;
+                        c->supplementary_gids = mfree(c->supplementary_gids);
 
                         strv_free(c->well_known_names);
                         c->well_known_names = NULL;
@@ -303,7 +302,7 @@ _public_ int sd_bus_creds_get_ppid(sd_bus_creds *c, pid_t *ppid) {
         if (!(c->mask & SD_BUS_CREDS_PPID))
                 return -ENODATA;
 
-        /* PID 1 has no parent process. Let's distuingish the case of
+        /* PID 1 has no parent process. Let's distinguish the case of
          * not knowing and not having a parent process by the returned
          * error code. */
         if (c->ppid == 0)
@@ -773,11 +772,13 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
                 return 0;
 
         /* Try to retrieve PID from creds if it wasn't passed to us */
-        if (pid <= 0 && (c->mask & SD_BUS_CREDS_PID))
+        if (pid > 0) {
+                c->pid = pid;
+                c->mask |= SD_BUS_CREDS_PID;
+        } else if (c->mask & SD_BUS_CREDS_PID)
                 pid = c->pid;
-
-        /* Without pid we cannot do much... */
-        if (pid <= 0)
+        else
+                /* Without pid we cannot do much... */
                 return 0;
 
         /* Try to retrieve TID from creds if it wasn't passed to us */
@@ -789,9 +790,6 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
         if (missing == 0)
                 return 0;
 
-        c->pid = pid;
-        c->mask |= SD_BUS_CREDS_PID;
-
         if (tid > 0) {
                 c->tid = tid;
                 c->mask |= SD_BUS_CREDS_TID;
@@ -989,7 +987,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
         if (missing & SD_BUS_CREDS_EXE) {
                 r = get_process_exe(pid, &c->exe);
                 if (r == -ESRCH) {
-                        /* Unfortunately we cannot really distuingish
+                        /* Unfortunately we cannot really distinguish
                          * the case here where the process does not
                          * exist, and /proc/$PID/exe being unreadable
                          * because $PID is a kernel thread. Hence,
@@ -1016,10 +1014,8 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
                         if (r != -EPERM && r != -EACCES)
                                 return r;
                 } else {
-                        if (c->cmdline_size == 0) {
-                                free(c->cmdline);
-                                c->cmdline = NULL;
-                        }
+                        if (c->cmdline_size == 0)
+                                c->cmdline = mfree(c->cmdline);
 
                         c->mask |= SD_BUS_CREDS_CMDLINE;
                 }
@@ -1063,8 +1059,8 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
 
         if (missing & SD_BUS_CREDS_AUDIT_SESSION_ID) {
                 r = audit_session_from_pid(pid, &c->audit_session_id);
-                if (r == -ENXIO) {
-                        /* ENXIO means: no audit session id assigned */
+                if (r == -ENODATA) {
+                        /* ENODATA means: no audit session id assigned */
                         c->audit_session_id = AUDIT_SESSION_INVALID;
                         c->mask |= SD_BUS_CREDS_AUDIT_SESSION_ID;
                 } else if (r < 0) {
@@ -1076,8 +1072,8 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
 
         if (missing & SD_BUS_CREDS_AUDIT_LOGIN_UID) {
                 r = audit_loginuid_from_pid(pid, &c->audit_login_uid);
-                if (r == -ENXIO) {
-                        /* ENXIO means: no audit login uid assigned */
+                if (r == -ENODATA) {
+                        /* ENODATA means: no audit login uid assigned */
                         c->audit_login_uid = UID_INVALID;
                         c->mask |= SD_BUS_CREDS_AUDIT_LOGIN_UID;
                 } else if (r < 0) {
@@ -1101,7 +1097,7 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
         }
 
         /* In case only the exe path was to be read we cannot
-         * distuingish the case where the exe path was unreadable
+         * distinguish the case where the exe path was unreadable
          * because the process was a kernel thread, or when the
          * process didn't exist at all. Hence, let's do a final check,
          * to be sure. */