summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-21 09:53:48 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-21 13:55:40 -0400
commit12bf0ae4c6c338603bd11bac9002d73339aedae4 (patch)
tree113d8c3f7c837a86bf9dbd396c817925723a03b3
parent9a7c402b2a30dbe759f839b8ad88f57f9e74a105 (diff)
shared/install: rewrite unit_file_changes_add()
path_kill_slashes was applied to the wrong arg...
-rw-r--r--src/shared/install.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 7a98c2d298..63cb76f21b 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -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);