instance, ujail: wire hostname (-h) option
authorEtienne CHAMPETIER <champetier.etienne@gmail.com>
Mon, 30 Nov 2015 23:09:27 +0000 (23:09 +0000)
committerJohn Crispin <blogic@openwrt.org>
Fri, 11 Dec 2015 11:05:45 +0000 (12:05 +0100)
Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
service/instance.c
service/instance.h

index 52f5cf29bb38a19387e9f8f5d90673f97664e079..b8602b8c49d0b0bf720def627865ad773f30e20d 100644 (file)
@@ -79,6 +79,7 @@ static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = {
 
 enum {
        JAIL_ATTR_NAME,
+       JAIL_ATTR_HOSTNAME,
        JAIL_ATTR_PROCFS,
        JAIL_ATTR_SYSFS,
        JAIL_ATTR_UBUS,
@@ -90,6 +91,7 @@ enum {
 
 static const struct blobmsg_policy jail_attr[__JAIL_ATTR_MAX] = {
        [JAIL_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING },
+       [JAIL_ATTR_HOSTNAME] = { "hostname", BLOBMSG_TYPE_STRING },
        [JAIL_ATTR_PROCFS] = { "procfs", BLOBMSG_TYPE_BOOL },
        [JAIL_ATTR_SYSFS] = { "sysfs", BLOBMSG_TYPE_BOOL },
        [JAIL_ATTR_UBUS] = { "ubus", BLOBMSG_TYPE_BOOL },
@@ -185,6 +187,11 @@ jail_run(struct service_instance *in, char **argv)
                argv[argc++] = jail->name;
        }
 
+       if (jail->hostname) {
+               argv[argc++] = "-h";
+               argv[argc++] = jail->hostname;
+       }
+
        if (in->seccomp) {
                argv[argc++] = "-S";
                argv[argc++] = in->seccomp;
@@ -649,6 +656,10 @@ instance_jail_parse(struct service_instance *in, struct blob_attr *attr)
                jail->name = blobmsg_get_string(tb[JAIL_ATTR_NAME]);
                jail->argc += 2;
        }
+       if (tb[JAIL_ATTR_HOSTNAME]) {
+               jail->hostname = blobmsg_get_string(tb[JAIL_ATTR_HOSTNAME]);
+               jail->argc += 2;
+       }
        if (tb[JAIL_ATTR_PROCFS]) {
                jail->procfs = blobmsg_get_bool(tb[JAIL_ATTR_PROCFS]);
                jail->argc++;
@@ -959,6 +970,8 @@ void instance_dump(struct blob_buf *b, struct service_instance *in, int verbose)
                void *r = blobmsg_open_table(b, "jail");
                if (in->jail.name)
                        blobmsg_add_string(b, "name", in->jail.name);
+               if (in->jail.hostname)
+                       blobmsg_add_string(b, "hostname", in->jail.hostname);
                blobmsg_add_u8(b, "procfs", in->jail.procfs);
                blobmsg_add_u8(b, "sysfs", in->jail.sysfs);
                blobmsg_add_u8(b, "ubus", in->jail.ubus);
index 770000001b62c993d5a6902bbe685d127d0df5ca..7490462cfae81a9d4e262839b44eb0b1bc305d8b 100644 (file)
@@ -29,6 +29,7 @@ struct jail {
        bool log;
        bool ronly;
        char *name;
+       char *hostname;
        struct blobmsg_list mount;
        int argc;
 };