instance: provide error feedback if ujail binary is missing
authorPetr Štetiar <ynezz@true.cz>
Fri, 17 Jan 2020 15:21:51 +0000 (16:21 +0100)
committerPetr Štetiar <ynezz@true.cz>
Tue, 21 Jan 2020 14:41:46 +0000 (15:41 +0100)
Otherwise it's quite hard to track such issues.  While at it, be DRY and
use UJAIL_BIN_PATH constant for ujail binary.

Signed-off-by: Petr Štetiar <ynezz@true.cz>
service/instance.c

index 3b4e93a98ce17331d63df108a1948830f9340100..658c086121850ad4a7faa9c58dc64571369cd71e 100644 (file)
@@ -36,6 +36,7 @@
 #include "service.h"
 #include "instance.h"
 
+#define UJAIL_BIN_PATH "/sbin/ujail"
 
 enum {
        INSTANCE_ATTR_COMMAND,
@@ -207,7 +208,7 @@ jail_run(struct service_instance *in, char **argv)
        struct jail *jail = &in->jail;
        int argc = 0;
 
-       argv[argc++] = "/sbin/ujail";
+       argv[argc++] = UJAIL_BIN_PATH;
 
        if (jail->name) {
                argv[argc++] = "-n";
@@ -800,9 +801,13 @@ instance_jail_parse(struct service_instance *in, struct blob_attr *attr)
        struct blob_attr *tb[__JAIL_ATTR_MAX];
        struct jail *jail = &in->jail;
        struct stat s;
+       int r;
 
-       if (stat("/sbin/ujail", &s))
+       r = stat(UJAIL_BIN_PATH, &s);
+       if (r < 0) {
+               ERROR("unable to find %s: %m (%d)\n", UJAIL_BIN_PATH, r);
                return 0;
+       }
 
        blobmsg_parse(jail_attr, __JAIL_ATTR_MAX, tb,
                blobmsg_data(attr), blobmsg_data_len(attr));