]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: exit with 1 if no unit files found 15191/head
authorGiedrius Statkevičius <giedriuswork@gmail.com>
Sun, 22 Mar 2020 13:49:55 +0000 (15:49 +0200)
committerGiedrius Statkevičius <giedriuswork@gmail.com>
Wed, 25 Mar 2020 20:20:58 +0000 (22:20 +0200)
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.

src/systemctl/systemctl.c

index f8b0adc3347b9d798b622da1fbd294af47a9dde7..58b0fd3688a7fe3ada5a93ec6fb336d7b58746df 100644 (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;
 }