service: move jail parsing to end of instance parser
authorDaniel Golle <daniel@makrotopia.org>
Sat, 20 Nov 2021 16:13:23 +0000 (16:13 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 23 Nov 2021 13:56:41 +0000 (13:56 +0000)
Generating parameters for ujail assumes that other instance attributes
such as 'env' have already been populated.
Move parsing jail to end of the instance parser to make that assumption
hold true.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
service/instance.c

index 8cabedb8b0fd789fb0686c7b4a9f35ec3abfd441..748c1e51eb0db0631a03c2f119372c226ab12340 100644 (file)
@@ -1387,22 +1387,6 @@ instance_config_parse(struct service_instance *in)
        if (tb[INSTANCE_ATTR_RELOADSIG])
                in->reload_signal = blobmsg_get_u32(tb[INSTANCE_ATTR_RELOADSIG]);
 
-       if (!in->trace && tb[INSTANCE_ATTR_JAIL])
-               in->has_jail = instance_jail_parse(in, tb[INSTANCE_ATTR_JAIL]);
-
-       if (in->has_jail) {
-               r = stat(UJAIL_BIN_PATH, &s);
-               if (r < 0) {
-                       if (in->require_jail) {
-                               ERROR("Cannot jail service %s::%s. %s: %m (%d)\n",
-                                               in->srv->name, in->name, UJAIL_BIN_PATH, r);
-                               return false;
-                       }
-                       DEBUG(2, "unable to find %s: %m (%d)\n", UJAIL_BIN_PATH, r);
-                       in->has_jail = false;
-               }
-       }
-
        if (tb[INSTANCE_ATTR_STDOUT] && blobmsg_get_bool(tb[INSTANCE_ATTR_STDOUT]))
                in->_stdout.fd.fd = -1;
 
@@ -1464,6 +1448,22 @@ instance_config_parse(struct service_instance *in)
                }
        }
 
+       if (!in->trace && tb[INSTANCE_ATTR_JAIL])
+               in->has_jail = instance_jail_parse(in, tb[INSTANCE_ATTR_JAIL]);
+
+       if (in->has_jail) {
+               r = stat(UJAIL_BIN_PATH, &s);
+               if (r < 0) {
+                       if (in->require_jail) {
+                               ERROR("Cannot jail service %s::%s. %s: %m (%d)\n",
+                                               in->srv->name, in->name, UJAIL_BIN_PATH, r);
+                               return false;
+                       }
+                       DEBUG(2, "unable to find %s: %m (%d)\n", UJAIL_BIN_PATH, r);
+                       in->has_jail = false;
+               }
+       }
+
        return true;
 }