1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 10:25:37 +03:00

shared/install: rewrite unit_file_changes_add()

path_kill_slashes was applied to the wrong arg...
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-04-21 09:53:48 -04:00
parent 9a7c402b2a
commit 12bf0ae4c6

View 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)
p = strdup(path);
if (source)
s = strdup(source);
if (!p || (source && !s))
return -ENOMEM;
path_kill_slashes(c[i].path);
path_kill_slashes(p);
if (s)
path_kill_slashes(s);
if (source) {
c[i].source = strdup(source);
if (!c[i].source) {
free(c[i].path);
return -ENOMEM;
}
path_kill_slashes(c[i].path);
} else
c[i].source = NULL;
*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);