]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: rewrite unit_file_changes_add()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Apr 2016 13:53:48 +0000 (09:53 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 21 Apr 2016 17:55:40 +0000 (13:55 -0400)
path_kill_slashes was applied to the wrong arg...

src/shared/install.c

index 7a98c2d298e42737088fd7a571d9a58530cd21ca..63cb76f21b76d5037d31771849c01cae002eba6f 100644 (file)
@@ -222,8 +222,8 @@ int unit_file_changes_add(
                 const char *path,
                 const char *source) {
 
+        _cleanup_free_ char *p = NULL, *s = NULL;
         UnitFileChange *c;
-        unsigned i;
 
         assert(path);
         assert(!changes == !n_changes);
@@ -234,29 +234,22 @@ int unit_file_changes_add(
         c = realloc(*changes, (*n_changes + 1) * sizeof(UnitFileChange));
         if (!c)
                 return -ENOMEM;
-
         *changes = c;
-        i = *n_changes;
-
-        c[i].type = type;
-        c[i].path = strdup(path);
-        if (!c[i].path)
-                return -ENOMEM;
 
-        path_kill_slashes(c[i].path);
+        p = strdup(path);
+        if (source)
+                s = strdup(source);
 
-        if (source) {
-                c[i].source = strdup(source);
-                if (!c[i].source) {
-                        free(c[i].path);
-                        return -ENOMEM;
-                }
+        if (!p || (source && !s))
+                return -ENOMEM;
 
-                path_kill_slashes(c[i].path);
-        } else
-                c[i].source = NULL;
+        path_kill_slashes(p);
+        if (s)
+                path_kill_slashes(s);
 
-        *n_changes = i+1;
+        c[*n_changes] = (UnitFileChange) { type, p, s };
+        p = s = NULL;
+        (*n_changes) ++;
         return 0;
 }
 
@@ -265,9 +258,6 @@ void unit_file_changes_free(UnitFileChange *changes, unsigned n_changes) {
 
         assert(changes || n_changes == 0);
 
-        if (!changes)
-                return;
-
         for (i = 0; i < n_changes; i++) {
                 free(changes[i].path);
                 free(changes[i].source);
@@ -529,8 +519,8 @@ static int remove_marked_symlinks_fd(
 
                         unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, p, NULL);
 
-                        /* Now, remember the full path (but with the root prefix removed) of the symlink we just
-                         * removed, and remove any symlinks to it, too */
+                        /* Now, remember the full path (but with the root prefix removed) of
+                         * the symlink we just removed, and remove any symlinks to it, too. */
 
                         rp = skip_root(lp, p);
                         q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: p);