Skip to content

Commit

Permalink
shared/install: avoid overwriting 'r' counter with a partial result
Browse files Browse the repository at this point in the history
We want to store either the first error or the total number of changes in 'r'.
Instead, we were overwriting this with the return value from
install_info_traverse().

LGTM complained later in the loop that:
> Comparison is always true because r >= 0.
  • Loading branch information
keszybz committed Oct 2, 2018
1 parent 0a58733 commit 459500a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/shared/install.c
Expand Up @@ -1896,10 +1896,10 @@ static int install_context_apply(
if (q < 0)
return q;

r = install_info_traverse(scope, c, paths, i, flags, NULL);
if (r < 0) {
q = install_info_traverse(scope, c, paths, i, flags, NULL);
if (q < 0) {
unit_file_changes_add(changes, n_changes, r, i->name, NULL);
return r;
return q;
}

/* We can attempt to process a masked unit when a different unit
Expand Down
2 changes: 1 addition & 1 deletion src/test/test-install-root.c
Expand Up @@ -862,7 +862,7 @@ static void test_with_dropin(const char *root) {
unit_file_changes_free(changes, n_changes);
changes = NULL; n_changes = 0;

assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 1);
assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("with-dropin-4a.service"), &changes, &n_changes) == 2);
assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "with-dropin-3.service", &state) >= 0 && state == UNIT_FILE_ENABLED);
assert_se(n_changes == 2);
assert_se(changes[0].type == UNIT_FILE_SYMLINK);
Expand Down

0 comments on commit 459500a

Please sign in to comment.