]> err.no Git - systemd/commitdiff
clang: fix numerous little issues found with clang-analyzer
authorLennart Poettering <lennart@poettering.net>
Wed, 11 Aug 2010 20:04:22 +0000 (22:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 11 Aug 2010 20:04:25 +0000 (22:04 +0200)
18 files changed:
src/automount.c
src/cgroup-show.c
src/cgroup-util.c
src/cgroup.c
src/dbus-execute.c
src/execute.c
src/initctl.c
src/logger.c
src/main.c
src/manager.c
src/mount.c
src/namespace.c
src/path.c
src/service.c
src/socket.c
src/systemctl.c
src/timer.c
src/unit.c

index 9843481a61c231b4783b61d0ac58238c4587974b..047af7759bbd3f706bf7a15a5bdb6f1498c8a9fd 100644 (file)
@@ -444,6 +444,8 @@ int automount_send_ready(Automount *a, int status) {
         else
                 log_debug("Sending success.");
 
+        r = 0;
+
         /* Autofs thankfully does not hand out 0 as a token */
         while ((token = PTR_TO_UINT(set_steal_first(a->tokens)))) {
                 int k;
@@ -460,8 +462,6 @@ int automount_send_ready(Automount *a, int status) {
                         r = k;
         }
 
-        r = 0;
-
 fail:
         if (ioctl_fd >= 0)
                 close_nointr_nofail(ioctl_fd);
index 24d2ba398d671389ae0f08c3cd53c67ec4d8dcfd..af44729a51ae61e729c4d783ddfe8848121ca91d 100644 (file)
@@ -138,7 +138,7 @@ static int show_cgroup_one_by_path(const char *path, const char *prefix, unsigne
                         printf("%s%s %*lu %s\n",
                                prefix,
                                (more || i < n-1) ? "\342\224\234" : "\342\224\224",
-                               ilog10(biggest),
+                               (int) ilog10(biggest),
                                (unsigned long) pids[i],
                                strna(t));
 
index 2f3fcb5981dac8a713bf5714992a285e608530bf..88adec0c9546a16b349af1dce5ab9875a06f9a0a 100644 (file)
@@ -737,10 +737,8 @@ int cg_install_release_agent(const char *controller, const char *agent) {
 
         free(fs);
         fs = NULL;
-        if ((r = cg_get_path(controller, NULL, "notify_on_release", &fs)) < 0) {
-                r = -ENOMEM;
+        if ((r = cg_get_path(controller, NULL, "notify_on_release", &fs)) < 0)
                 goto finish;
-        }
 
         free(contents);
         contents = NULL;
index 02c2919187dfcf842245e12d9d3ad4a66db384be..23ba5d86a9eb84d1278eff582eaf6a4889315986 100644 (file)
@@ -231,7 +231,7 @@ int manager_setup_cgroup(Manager *m) {
         } else {
                 /* We need a new root cgroup */
                 m->cgroup_hierarchy = NULL;
-                if ((r = asprintf(&m->cgroup_hierarchy, "%s%s", streq(current, "/") ? "" : current, suffix)) < 0) {
+                if (asprintf(&m->cgroup_hierarchy, "%s%s", streq(current, "/") ? "" : current, suffix) < 0) {
                         r = -ENOMEM;
                         goto finish;
                 }
@@ -325,14 +325,13 @@ int cgroup_notify_empty(Manager *m, const char *group) {
 Unit* cgroup_unit_by_pid(Manager *m, pid_t pid) {
         CGroupBonding *l, *b;
         char *group = NULL;
-        int r;
 
         assert(m);
 
         if (pid <= 1)
                 return NULL;
 
-        if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &group)))
+        if (cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &group) < 0)
                 return NULL;
 
         l = hashmap_get(m->cgroup_bondings, group);
index bb660b1853a19d375e2e537c15954c92f9b6c796..55c61e593fbf5c6a4caaeed454bc321f1e6617b5 100644 (file)
@@ -286,9 +286,9 @@ int bus_execute_append_command(Manager *m, DBusMessageIter *i, const char *prope
                     !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_BOOLEAN, &c->ignore) ||
                     !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.start_timestamp.realtime) ||
                     !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT64, &c->exec_status.exit_timestamp.realtime) ||
-                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &c->exec_status.pid) ||
-                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &c->exec_status.code) ||
-                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &c->exec_status.status))
+                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_UINT32, &pid) ||
+                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &code) ||
+                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_INT32, &status))
                         return -ENOMEM;
 
                 if (!dbus_message_iter_close_container(&sub, &sub2))
index 352def3cfaff28f8826a64c27a1c533471bbacfc..b34c052014d1523089103073d45646576078e9e1 100644 (file)
@@ -1055,7 +1055,7 @@ int exec_spawn(ExecCommand *command,
                 }
 
                 if (cgroup_bondings)
-                        if ((r = cgroup_bonding_install_list(cgroup_bondings, 0)) < 0) {
+                        if (cgroup_bonding_install_list(cgroup_bondings, 0) < 0) {
                                 r = EXIT_CGROUP;
                                 goto fail;
                         }
index 74eccac557c769ff0f3577033a75b02e5d8b94bc..a504c8f337c867f732bf947d06ba6b6d404b4c46 100644 (file)
@@ -387,7 +387,7 @@ int main(int argc, char *argv[]) {
                 if (k <= 0)
                         break;
 
-                if ((k = process_event(&server, &event)) < 0)
+                if (process_event(&server, &event) < 0)
                         goto fail;
         }
 
index 3d69fcf2cd6de49b809fda124e6dedf274f7c7d6..a9ac54b1149b70018d8d941fbecac3a3303a6f65 100644 (file)
@@ -585,7 +585,7 @@ int main(int argc, char *argv[]) {
                 if (k <= 0)
                         break;
 
-                if ((k = process_event(&server, &event)) < 0)
+                if (process_event(&server, &event) < 0)
                         goto fail;
         }
 
index 79a46b8cd50324f24fdd8e76231677ae0f38b074..3810033fb223ca5bf1586d71cd2894a35eb82528 100644 (file)
@@ -117,10 +117,10 @@ _noreturn_ static void crash(int sig) {
                         _exit(1);
 
                 } else {
-                        int status, r;
+                        int status;
 
                         /* Order things nicely. */
-                        if ((r = waitpid(pid, &status, 0)) < 0)
+                        if (waitpid(pid, &status, 0) < 0)
                                 log_error("Caught <%s>, waitpid() failed: %s", signal_to_string(sig), strerror(errno));
                         else if (!WCOREDUMP(status))
                                 log_error("Caught <%s>, core dump failed.", signal_to_string(sig));
@@ -540,7 +540,7 @@ static int parse_proc_cmdline(void) {
         char *state;
 
         if ((r = read_one_line_file("/proc/cmdline", &line)) < 0) {
-                log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(errno));
+                log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r));
                 return 0;
         }
 
index 18b014004f31ecb9376e8ae886c48844d5bb9cd0..9684efac8b1cc3c2e4baa98b4aed133fa8f8ce2b 100644 (file)
@@ -791,7 +791,8 @@ static int delete_one_unmergeable_job(Manager *m, Job *j) {
                                                 d = j;
                                         else
                                                 d = k;
-                                }
+                                } else
+                                        d = j;
 
                         } else if (!j->matters_to_anchor)
                                 d = j;
@@ -824,7 +825,7 @@ static int transaction_merge_jobs(Manager *m, DBusError *e) {
 
                 t = j->type;
                 LIST_FOREACH(transaction, k, j->transaction_next) {
-                        if ((r = job_type_merge(&t, k->type)) >= 0)
+                        if (job_type_merge(&t, k->type) >= 0)
                                 continue;
 
                         /* OK, we could not merge all jobs for this
@@ -1293,7 +1294,6 @@ rollback:
 
 static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool override, bool *is_new) {
         Job *j, *f;
-        int r;
 
         assert(m);
         assert(unit);
@@ -1326,7 +1326,7 @@ static Job* transaction_add_one_job(Manager *m, JobType type, Unit *unit, bool o
 
         LIST_PREPEND(Job, transaction, f, j);
 
-        if ((r = hashmap_replace(m->transaction_jobs, unit, f)) < 0) {
+        if (hashmap_replace(m->transaction_jobs, unit, f) < 0) {
                 job_free(j);
                 return NULL;
         }
index cf2355a3337bbf946bdec943c598ac5701f26bb2..9a201f33eda61990af100a41d0f935d48668713f 100644 (file)
@@ -789,6 +789,7 @@ static void mount_enter_remounting(Mount *m, bool success) {
         return;
 
 fail:
+        log_warning("%s failed to run 'remount' task: %s", m->meta.id, strerror(-r));
         mount_enter_mounted(m, false);
 }
 
@@ -876,7 +877,6 @@ static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
 
 static int mount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
         Mount *m = MOUNT(u);
-        int r;
 
         assert(u);
         assert(key);
@@ -901,7 +901,7 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
         } else if (streq(key, "control-pid")) {
                 pid_t pid;
 
-                if ((r = parse_pid(value, &pid)) < 0)
+                if (parse_pid(value, &pid) < 0)
                         log_debug("Failed to parse control-pid value %s", value);
                 else
                         m->control_pid = pid;
@@ -1422,7 +1422,7 @@ void mount_fd_event(Manager *m, int events) {
          * table changes */
 
         if ((r = mount_load_proc_self_mountinfo(m, true)) < 0) {
-                log_error("Failed to reread /proc/self/mountinfo: %s", strerror(errno));
+                log_error("Failed to reread /proc/self/mountinfo: %s", strerror(-r));
 
                 /* Reset flags, just in case, for later calls */
                 LIST_FOREACH(units_per_type, meta, m->units_per_type[UNIT_MOUNT]) {
index 09bcaff9684845ee121544f3ebd7151a503100e5..9e964c5b8f4348fa8b3cf905ae0e5d29e9dd410f 100644 (file)
@@ -151,6 +151,9 @@ static int apply_mount(Path *p, const char *root_dir, const char *inaccessible_d
         case PRIVATE:
                 what = private_dir;
                 break;
+
+        default:
+                assert_not_reached("Unknown mode");
         }
 
         if ((r = mount(what, where, NULL, MS_BIND|MS_REC, NULL)) >= 0) {
index 91de56f34ce44b5eff881a9428eedff1df9a20dd..2f1e0aea632631bc59bf11701cd64f3fcfde60e7 100644 (file)
@@ -145,12 +145,10 @@ static int path_load(Unit *u) {
 
 static void path_dump(Unit *u, FILE *f, const char *prefix) {
         Path *p = PATH(u);
-        const char *prefix2;
-        char *p2;
         PathSpec *s;
 
-        p2 = strappend(prefix, "\t");
-        prefix2 = p2 ? p2 : prefix;
+        assert(p);
+        assert(f);
 
         fprintf(f,
                 "%sPath State: %s\n"
@@ -164,8 +162,6 @@ static void path_dump(Unit *u, FILE *f, const char *prefix) {
                         prefix,
                         path_type_to_string(s->type),
                         s->path);
-
-        free(p2);
 }
 
 static void path_unwatch_one(Path *p, PathSpec *s) {
index 318d8a7dc4e558e2a43dcb68eb744994bac08ede..a3a23e327119f6a7b010b51874f334a51f67f052 100644 (file)
@@ -797,7 +797,7 @@ static int service_load_sysv(Service *s) {
                         if (t == s->meta.id)
                                 continue;
 
-                        if ((r == service_load_sysv_name(s, t)) < 0)
+                        if ((r = service_load_sysv_name(s, t)) < 0)
                                 return r;
 
                         if (s->meta.load_state != UNIT_STUB)
@@ -2063,7 +2063,6 @@ static int service_serialize(Unit *u, FILE *f, FDSet *fds) {
 
 static int service_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
         Service *s = SERVICE(u);
-        int r;
 
         assert(u);
         assert(key);
@@ -2087,14 +2086,14 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
         } else if (streq(key, "control-pid")) {
                 pid_t pid;
 
-                if ((r = parse_pid(value, &pid)) < 0)
+                if (parse_pid(value, &pid) < 0)
                         log_debug("Failed to parse control-pid value %s", value);
                 else
                         s->control_pid = pid;
         } else if (streq(key, "main-pid")) {
                 pid_t pid;
 
-                if ((r = parse_pid(value, &pid)) < 0)
+                if (parse_pid(value, &pid) < 0)
                         log_debug("Failed to parse main-pid value %s", value);
                 else
                         service_set_main_pid(s, (pid_t) pid);
@@ -2136,49 +2135,49 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
         } else if (streq(key, "main-exec-status-pid")) {
                 pid_t pid;
 
-                if ((r = parse_pid(value, &pid)) < 0)
+                if (parse_pid(value, &pid) < 0)
                         log_debug("Failed to parse main-exec-status-pid value %s", value);
                 else
                         s->main_exec_status.pid = pid;
         } else if (streq(key, "main-exec-status-code")) {
                 int i;
 
-                if ((r = safe_atoi(value, &i)) < 0)
+                if (safe_atoi(value, &i) < 0)
                         log_debug("Failed to parse main-exec-status-code value %s", value);
                 else
                         s->main_exec_status.code = i;
         } else if (streq(key, "main-exec-status-status")) {
                 int i;
 
-                if ((r = safe_atoi(value, &i)) < 0)
+                if (safe_atoi(value, &i) < 0)
                         log_debug("Failed to parse main-exec-status-status value %s", value);
                 else
                         s->main_exec_status.status = i;
         } else if (streq(key, "main-exec-status-start-realtime")) {
                 uint64_t k;
 
-                if ((r = safe_atou64(value, &k)) < 0)
+                if (safe_atou64(value, &k) < 0)
                         log_debug("Failed to parse main-exec-status-start-realtime value %s", value);
                 else
                         s->main_exec_status.start_timestamp.realtime = (usec_t) k;
         } else if (streq(key, "main-exec-status-start-monotonic")) {
                 uint64_t k;
 
-                if ((r = safe_atou64(value, &k)) < 0)
+                if (safe_atou64(value, &k) < 0)
                         log_debug("Failed to parse main-exec-status-start-monotonic value %s", value);
                 else
                         s->main_exec_status.start_timestamp.monotonic = (usec_t) k;
         } else if (streq(key, "main-exec-status-exit-realtime")) {
                 uint64_t k;
 
-                if ((r = safe_atou64(value, &k)) < 0)
+                if (safe_atou64(value, &k) < 0)
                         log_debug("Failed to parse main-exec-status-exit-realtime value %s", value);
                 else
                         s->main_exec_status.exit_timestamp.realtime = (usec_t) k;
         } else if (streq(key, "main-exec-status-exit-monotonic")) {
                 uint64_t k;
 
-                if ((r = safe_atou64(value, &k)) < 0)
+                if (safe_atou64(value, &k) < 0)
                         log_debug("Failed to parse main-exec-status-exit-monotonic value %s", value);
                 else
                         s->main_exec_status.exit_timestamp.monotonic = (usec_t) k;
index 23658ac274a2343e0bb6ed7455e9d9954022b18f..5132f8e7002abf34395bfeca0468293e793bc13b 100644 (file)
@@ -445,14 +445,14 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                 if (p->type == SOCKET_SOCKET) {
                         const char *t;
                         int r;
-                        char *k;
+                        char *k = NULL;
 
                         if ((r = socket_address_print(&p->address, &k)) < 0)
                                 t = strerror(-r);
                         else
                                 t = k;
 
-                        fprintf(f, "%s%s: %s\n", prefix, listen_lookup(p->address.type), k);
+                        fprintf(f, "%s%s: %s\n", prefix, listen_lookup(p->address.type), t);
                         free(k);
                 } else
                         fprintf(f, "%sListenFIFO: %s\n", prefix, p->path);
@@ -1374,7 +1374,6 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
 
 static int socket_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
         Socket *s = SOCKET(u);
-        int r;
 
         assert(u);
         assert(key);
@@ -1399,14 +1398,14 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
         } else if (streq(key, "n-accepted")) {
                 unsigned k;
 
-                if ((r = safe_atou(value, &k)) < 0)
+                if (safe_atou(value, &k) < 0)
                         log_debug("Failed to parse n-accepted value %s", value);
                 else
                         s->n_accepted += k;
         } else if (streq(key, "control-pid")) {
                 pid_t pid;
 
-                if ((r = parse_pid(value, &pid)) < 0)
+                if (parse_pid(value, &pid) < 0)
                         log_debug("Failed to parse control-pid value %s", value);
                 else
                         s->control_pid = pid;
@@ -1665,7 +1664,7 @@ int socket_collect_fds(Socket *s, int **fds, unsigned *n_fds) {
                 if (p->fd >= 0)
                         rn_fds++;
 
-        if (!(rfds = new(int, rn_fds)) < 0)
+        if (!(rfds = new(int, rn_fds)))
                 return -ENOMEM;
 
         k = 0;
index 8ef1adda5e3126bc1bc5f820b944c9a39836b21b..993e1d6557696f508ec7c49278aea7b8eae5a066 100644 (file)
@@ -457,6 +457,8 @@ static int dot_one(DBusConnection *bus, const char *name, const char *path) {
                 dbus_message_iter_next(&sub);
         }
 
+        r = 0;
+
 finish:
         if (m)
                 dbus_message_unref(m);
@@ -798,7 +800,7 @@ finish:
 }
 
 static bool need_daemon_reload(DBusConnection *bus, const char *unit) {
-        DBusMessage *m, *reply;
+        DBusMessage *m = NULL, *reply = NULL;
         dbus_bool_t b = FALSE;
         DBusMessageIter iter, sub;
         const char
@@ -3154,7 +3156,7 @@ static int remove_marked_symlinks_fd(int fd, const char *config_path, const char
                         free(p);
 
                         if (r == 0)
-                                q = r;
+                                r = q;
 
                 } else if (is_link) {
                         char *p, *dest, *c;
@@ -4530,11 +4532,10 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
 }
 
 static int reload_with_fallback(DBusConnection *bus) {
-        int r;
 
         if (bus) {
                 /* First, try systemd via D-Bus. */
-                if ((r = daemon_reload(bus, NULL, 0)) > 0)
+                if (daemon_reload(bus, NULL, 0) > 0)
                         return 0;
         }
 
@@ -4550,22 +4551,21 @@ static int reload_with_fallback(DBusConnection *bus) {
 }
 
 static int start_with_fallback(DBusConnection *bus) {
-        int r;
 
         if (bus) {
                 /* First, try systemd via D-Bus. */
-                if ((r = start_unit(bus, NULL, 0)) > 0)
+                if (start_unit(bus, NULL, 0) > 0)
                         goto done;
         }
 
         /* Hmm, talking to systemd via D-Bus didn't work. Then
          * let's try to talk to Upstart via D-Bus. */
-        if ((r = talk_upstart()) > 0)
+        if (talk_upstart() > 0)
                 goto done;
 
         /* Nothing else worked, so let's try
          * /dev/initctl */
-        if ((r = talk_initctl()) != 0)
+        if (talk_initctl() != 0)
                 goto done;
 
         log_error("Failed to talk to init daemon.");
index 2c21b49197978e41418463d5b327ac182e43f403..a63de9466eb2058542ebf595b102f7eed020416d 100644 (file)
@@ -114,15 +114,10 @@ static int timer_load(Unit *u) {
 
 static void timer_dump(Unit *u, FILE *f, const char *prefix) {
         Timer *t = TIMER(u);
-        const char *prefix2;
-        char *p2;
         TimerValue *v;
         char
                 timespan1[FORMAT_TIMESPAN_MAX];
 
-        p2 = strappend(prefix, "\t");
-        prefix2 = p2 ? p2 : prefix;
-
         fprintf(f,
                 "%sTimer State: %s\n"
                 "%sUnit: %s\n",
@@ -135,8 +130,6 @@ static void timer_dump(Unit *u, FILE *f, const char *prefix) {
                         prefix,
                         timer_base_to_string(v->base),
                         strna(format_timespan(timespan1, sizeof(timespan1), v->value)));
-
-        free(p2);
 }
 
 static void timer_set_state(Timer *t, TimerState state) {
index 59fc93a9ba3d74487f8c3a144bc49d3b6b25e071..3c2e974163e504c2617c5f3096cfa259ec8a3b50 100644 (file)
@@ -859,10 +859,10 @@ int unit_reload(Unit *u) {
                 return -EBADR;
 
         state = unit_active_state(u);
-        if (unit_active_state(u) == UNIT_RELOADING)
+        if (state == UNIT_RELOADING)
                 return -EALREADY;
 
-        if (unit_active_state(u) != UNIT_ACTIVE)
+        if (state != UNIT_ACTIVE)
                 return -ENOEXEC;
 
         unit_add_to_dbus_queue(u);