chiark / gitweb /
build-sys: use -Og instead of -O0 to catch warnings
[elogind.git] / src / core / manager.c
index 58dacdc8b5d7e894d909eb5cc60e66a3018ae75f..60c22e31d7caa61807e71d562502aed2931690ad 100644 (file)
@@ -236,7 +236,7 @@ static void draw_cylon(char buffer[], size_t buflen, unsigned width, unsigned po
                 *p++ = '*';
                 if (pos < width-1)
                         p = mempset(p, ' ', width-1-pos);
-                p = stpcpy(p, ANSI_HIGHLIGHT_OFF);
+                strcpy(p, ANSI_HIGHLIGHT_OFF);
         }
 }
 
@@ -257,6 +257,7 @@ static void manager_print_jobs_in_progress(Manager *m) {
         /* m->n_running_jobs must be consistent with the contents of m->jobs,
          * so the above loop must have succeeded in finding j. */
         assert(counter == print_nr + 1);
+        assert(j);
 
         cylon_pos = m->jobs_in_progress_iteration % 14;
         if (cylon_pos >= 8)
@@ -485,6 +486,7 @@ static int manager_default_environment(Manager *m) {
 int manager_new(SystemdRunningAs running_as, bool reexecuting, Manager **_m) {
         Manager *m;
         int r = -ENOMEM;
+        bool try_bus_connect = false;
 
         assert(_m);
         assert(running_as >= 0);
@@ -556,15 +558,18 @@ int manager_new(SystemdRunningAs running_as, bool reexecuting, Manager **_m) {
         if (r < 0)
                 goto fail;
 
-        /* Try to connect to the busses, if possible. */
-        if ((running_as == SYSTEMD_USER && getenv("DBUS_SESSION_BUS_ADDRESS")) ||
-            running_as == SYSTEMD_SYSTEM) {
-                r = bus_init(m, reexecuting || running_as != SYSTEMD_SYSTEM);
-                if (r < 0)
-                        goto fail;
-        } else
+        if (running_as == SYSTEMD_SYSTEM)
+                try_bus_connect = reexecuting;
+        else if (getenv("DBUS_SESSION_BUS_ADDRESS"))
+                try_bus_connect = true;
+        else
                 log_debug("Skipping DBus session bus connection attempt - no DBUS_SESSION_BUS_ADDRESS set...");
 
+        /* Try to connect to the busses, if possible. */
+        r = bus_init(m, try_bus_connect);
+        if (r < 0)
+                goto fail;
+
         m->taint_usr = dir_is_empty("/usr") > 0;
 
         *_m = m;
@@ -671,7 +676,7 @@ static unsigned manager_dispatch_gc_queue(Manager *m) {
 
                 unit_gc_sweep(u, gc_marker);
 
-                LIST_REMOVE(Unit, gc_queue, m->gc_queue, u);
+                LIST_REMOVE(gc_queue, m->gc_queue, u);
                 u->in_gc_queue = false;
 
                 n++;
@@ -2057,7 +2062,7 @@ void manager_dispatch_bus_query_pid_done(
 
 int manager_open_serialization(Manager *m, FILE **_f) {
         char *path = NULL;
-        int fd;
+        int fd = -1;
         FILE *f;
 
         assert(_f);
@@ -2317,8 +2322,8 @@ int manager_distribute_fds(Manager *m, FDSet *fds) {
 
 int manager_reload(Manager *m) {
         int r, q;
-        FILE *f;
-        FDSet *fds;
+        _cleanup_fclose_ FILE *f = NULL;
+        _cleanup_fdset_free_ FDSet *fds = NULL;
 
         assert(m);
 
@@ -2332,20 +2337,18 @@ int manager_reload(Manager *m) {
         fds = fdset_new();
         if (!fds) {
                 m->n_reloading --;
-                r = -ENOMEM;
-                goto finish;
+                return -ENOMEM;
         }
 
         r = manager_serialize(m, f, fds, false);
         if (r < 0) {
                 m->n_reloading --;
-                goto finish;
+                return r;
         }
 
         if (fseeko(f, 0, SEEK_SET) < 0) {
                 m->n_reloading --;
-                r = -errno;
-                goto finish;
+                return -errno;
         }
 
         /* From here on there is no way back. */
@@ -2389,13 +2392,6 @@ int manager_reload(Manager *m) {
 
         m->send_reloading_done = true;
 
-finish:
-        if (f)
-                fclose(f);
-
-        if (fds)
-                fdset_free(fds);
-
         return r;
 }