Compare commits

...

2 Commits

Author SHA1 Message Date
Anita Zhang a22e8850a8
Merge pull request #15191 from GiedriusS/feature/list-unit-files-return-1
systemctl: exit with 1 if no unit files found
2020-03-25 16:50:30 -07:00
Giedrius Statkevičius eeb1542b5e systemctl: exit with 1 if no unit files found
Add a simple check on the number of unit files that were found: return
`-ENOENT` when none is found from the function and thus `systemctl`
consequently exits with `1` (`EXIT_FAILURE`) if none were found.

Verification:
```bash
root@image:~# systemctl list-unit-files dbus-nonexistant.service; echo
$?
UNIT FILE STATE VENDOR PRESET

0 unit files listed.
1
root@image:~# systemctl list-unit-files dbus.service; echo $?
UNIT FILE    STATE  VENDOR PRESET
dbus.service static enabled

1 unit files listed.
0
```

Fixes #15082.
2020-03-25 22:20:58 +02:00
1 changed files with 3 additions and 0 deletions

View File

@ -1659,6 +1659,9 @@ static int list_unit_files(int argc, char *argv[], void *userdata) {
for (unit = units; unit < units + c; unit++)
free(unit->path);
if (c == 0)
return -ENOENT;
return 0;
}