2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <sys/resource.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
29 #include <libubox/md5.h>
38 INSTANCE_ATTR_COMMAND,
43 INSTANCE_ATTR_TRIGGER,
44 INSTANCE_ATTR_RESPAWN,
54 INSTANCE_ATTR_SECCOMP,
58 static const struct blobmsg_policy instance_attr[__INSTANCE_ATTR_MAX] = {
59 [INSTANCE_ATTR_COMMAND] = { "command", BLOBMSG_TYPE_ARRAY },
60 [INSTANCE_ATTR_ENV] = { "env", BLOBMSG_TYPE_TABLE },
61 [INSTANCE_ATTR_DATA] = { "data", BLOBMSG_TYPE_TABLE },
62 [INSTANCE_ATTR_NETDEV] = { "netdev", BLOBMSG_TYPE_ARRAY },
63 [INSTANCE_ATTR_FILE] = { "file", BLOBMSG_TYPE_ARRAY },
64 [INSTANCE_ATTR_TRIGGER] = { "triggers", BLOBMSG_TYPE_ARRAY },
65 [INSTANCE_ATTR_RESPAWN] = { "respawn", BLOBMSG_TYPE_ARRAY },
66 [INSTANCE_ATTR_NICE] = { "nice", BLOBMSG_TYPE_INT32 },
67 [INSTANCE_ATTR_LIMITS] = { "limits", BLOBMSG_TYPE_TABLE },
68 [INSTANCE_ATTR_WATCH] = { "watch", BLOBMSG_TYPE_ARRAY },
69 [INSTANCE_ATTR_ERROR] = { "error", BLOBMSG_TYPE_ARRAY },
70 [INSTANCE_ATTR_USER] = { "user", BLOBMSG_TYPE_STRING },
71 [INSTANCE_ATTR_STDOUT] = { "stdout", BLOBMSG_TYPE_BOOL },
72 [INSTANCE_ATTR_STDERR] = { "stderr", BLOBMSG_TYPE_BOOL },
73 [INSTANCE_ATTR_JAIL] = { "jail", BLOBMSG_TYPE_TABLE },
74 [INSTANCE_ATTR_TRACE] = { "trace", BLOBMSG_TYPE_BOOL },
75 [INSTANCE_ATTR_SECCOMP] = { "seccomp", BLOBMSG_TYPE_STRING },
89 static const struct blobmsg_policy jail_attr[__JAIL_ATTR_MAX] = {
90 [JAIL_ATTR_NAME] = { "name", BLOBMSG_TYPE_STRING },
91 [JAIL_ATTR_ROOT] = { "root", BLOBMSG_TYPE_STRING },
92 [JAIL_ATTR_PROCFS] = { "procfs", BLOBMSG_TYPE_BOOL },
93 [JAIL_ATTR_SYSFS] = { "sysfs", BLOBMSG_TYPE_BOOL },
94 [JAIL_ATTR_UBUS] = { "ubus", BLOBMSG_TYPE_BOOL },
95 [JAIL_ATTR_LOG] = { "log", BLOBMSG_TYPE_BOOL },
96 [JAIL_ATTR_MOUNT] = { "mount", BLOBMSG_TYPE_TABLE },
99 struct instance_netdev {
100 struct blobmsg_list_node node;
104 struct instance_file {
105 struct blobmsg_list_node node;
114 static const struct rlimit_name rlimit_names[] = {
116 { "core", RLIMIT_CORE },
117 { "cpu", RLIMIT_CPU },
118 { "data", RLIMIT_DATA },
119 { "fsize", RLIMIT_FSIZE },
120 { "memlock", RLIMIT_MEMLOCK },
121 { "msgqueue", RLIMIT_MSGQUEUE },
122 { "nice", RLIMIT_NICE },
123 { "nofile", RLIMIT_NOFILE },
124 { "nproc", RLIMIT_NPROC },
125 { "rss", RLIMIT_RSS },
126 { "rtprio", RLIMIT_RTPRIO },
127 { "sigpending", RLIMIT_SIGPENDING },
128 { "stack", RLIMIT_STACK },
132 static char trace[] = "/sbin/utrace";
134 static void closefd(int fd)
136 if (fd > STDERR_FILENO)
141 instance_limits(const char *limit, const char *value)
145 unsigned long cur, max;
147 for (i = 0; rlimit_names[i].name != NULL; i++) {
148 if (strcmp(rlimit_names[i].name, limit))
150 if (!strcmp(value, "unlimited")) {
151 rlim.rlim_cur = RLIM_INFINITY;
152 rlim.rlim_max = RLIM_INFINITY;
154 if (getrlimit(rlimit_names[i].resource, &rlim))
160 if (sscanf(value, "%lu %lu", &cur, &max) < 1)
167 setrlimit(rlimit_names[i].resource, &rlim);
173 jail_run(struct service_instance *in, char **argv)
175 struct blobmsg_list_node *var;
176 struct jail *jail = &in->jail;
179 argv[argc++] = "/sbin/ujail";
183 argv[argc++] = jail->name;
188 argv[argc++] = jail->root;
193 argv[argc++] = in->seccomp;
208 blobmsg_list_for_each(&jail->mount, var) {
209 const char *type = blobmsg_data(var->data);
215 argv[argc++] = (char *) blobmsg_name(var->data);
224 instance_run(struct service_instance *in, int _stdout, int _stderr)
226 struct blobmsg_list_node *var;
227 struct blob_attr *cur;
230 int argc = 1; /* NULL terminated */
232 bool seccomp = !in->trace && !in->has_jail && in->seccomp;
233 bool setlbf = _stdout >= 0;
236 setpriority(PRIO_PROCESS, 0, in->nice);
238 blobmsg_for_each_attr(cur, in->command, rem)
241 blobmsg_list_for_each(&in->env, var)
242 setenv(blobmsg_name(var->data), blobmsg_data(var->data), 1);
245 setenv("SECCOMP_FILE", in->seccomp, 1);
247 if ((seccomp || setlbf) && asprintf(&ld_preload, "LD_PRELOAD=%s%s%s",
248 seccomp ? "/lib/libpreload-seccomp.so" : "",
249 seccomp && setlbf ? ":" : "",
250 setlbf ? "/lib/libsetlbf.so" : "") > 0)
253 blobmsg_list_for_each(&in->limits, var)
254 instance_limits(blobmsg_name(var->data), blobmsg_data(var->data));
259 argv = alloca(sizeof(char *) * (argc + in->jail.argc));
263 argv[argc++] = trace;
266 argc = jail_run(in, argv);
268 blobmsg_for_each_attr(cur, in->command, rem)
269 argv[argc++] = blobmsg_data(cur);
273 _stdin = open("/dev/null", O_RDONLY);
276 _stdout = open("/dev/null", O_WRONLY);
279 _stderr = open("/dev/null", O_WRONLY);
282 dup2(_stdin, STDIN_FILENO);
286 dup2(_stdout, STDOUT_FILENO);
290 dup2(_stderr, STDERR_FILENO);
294 if (in->gid && setgid(in->gid)) {
295 ERROR("failed to set group id %d: %d (%s)\n", in->gid, errno, strerror(errno));
298 if (in->uid && setuid(in->uid)) {
299 ERROR("failed to set user id %d: %d (%s)\n", in->uid, errno, strerror(errno));
303 execvp(argv[0], argv);
308 instance_free_stdio(struct service_instance *in)
310 if (in->_stdout.fd.fd > -1) {
311 ustream_free(&in->_stdout.stream);
312 close(in->_stdout.fd.fd);
313 in->_stdout.fd.fd = -1;
316 if (in->_stderr.fd.fd > -1) {
317 ustream_free(&in->_stderr.stream);
318 close(in->_stderr.fd.fd);
319 in->_stderr.fd.fd = -1;
324 instance_start(struct service_instance *in)
327 int opipe[2] = { -1, -1 };
328 int epipe[2] = { -1, -1 };
330 if (!avl_is_empty(&in->errors.avl)) {
331 LOG("Not starting instance %s::%s, an error was indicated\n", in->srv->name, in->name);
335 if (in->proc.pending)
338 instance_free_stdio(in);
339 if (in->_stdout.fd.fd > -2) {
341 ULOG_WARN("pipe() failed: %d (%s)\n", errno, strerror(errno));
342 opipe[0] = opipe[1] = -1;
346 if (in->_stderr.fd.fd > -2) {
348 ULOG_WARN("pipe() failed: %d (%s)\n", errno, strerror(errno));
349 epipe[0] = epipe[1] = -1;
354 in->halt = !in->respawn;
367 instance_run(in, opipe[1], epipe[1]);
371 DEBUG(2, "Started instance %s::%s\n", in->srv->name, in->name);
373 clock_gettime(CLOCK_MONOTONIC, &in->start);
374 uloop_process_add(&in->proc);
377 ustream_fd_init(&in->_stdout, opipe[0]);
382 ustream_fd_init(&in->_stderr, epipe[0]);
386 service_event("instance.start", in->srv->name, in->name);
390 instance_stdio(struct ustream *s, int prio, struct service_instance *in)
392 char *newline, *str, *arg0, ident[32];
395 arg0 = basename(blobmsg_data(blobmsg_data(in->command)));
396 snprintf(ident, sizeof(ident), "%s[%d]", arg0, in->proc.pid);
397 ulog_open(ULOG_SYSLOG, LOG_DAEMON, ident);
400 str = ustream_get_read_buf(s, NULL);
404 newline = strchr(str, '\n');
409 ulog(prio, "%s\n", str);
411 len = newline + 1 - str;
412 ustream_consume(s, len);
415 ulog_open(ULOG_SYSLOG, LOG_DAEMON, "procd");
419 instance_stdout(struct ustream *s, int bytes)
421 instance_stdio(s, LOG_INFO,
422 container_of(s, struct service_instance, _stdout.stream));
426 instance_stderr(struct ustream *s, int bytes)
428 instance_stdio(s, LOG_ERR,
429 container_of(s, struct service_instance, _stderr.stream));
433 instance_timeout(struct uloop_timeout *t)
435 struct service_instance *in;
437 in = container_of(t, struct service_instance, timeout);
439 if (!in->halt && (in->restart || in->respawn))
444 instance_exit(struct uloop_process *p, int ret)
446 struct service_instance *in;
450 in = container_of(p, struct service_instance, proc);
452 clock_gettime(CLOCK_MONOTONIC, &tp);
453 runtime = tp.tv_sec - in->start.tv_sec;
455 DEBUG(2, "Instance %s::%s exit with error code %d after %ld seconds\n", in->srv->name, in->name, ret, runtime);
459 uloop_timeout_cancel(&in->timeout);
462 } else if (in->restart) {
464 } else if (in->respawn) {
465 if (runtime < in->respawn_threshold)
468 in->respawn_count = 0;
469 if (in->respawn_count > in->respawn_retry && in->respawn_retry > 0 ) {
470 LOG("Instance %s::%s s in a crash loop %d crashes, %ld seconds since last crash\n",
471 in->srv->name, in->name, in->respawn_count, runtime);
472 in->restart = in->respawn = 0;
475 uloop_timeout_set(&in->timeout, in->respawn_timeout * 1000);
478 service_event("instance.stop", in->srv->name, in->name);
482 instance_stop(struct service_instance *in)
484 if (!in->proc.pending)
487 in->restart = in->respawn = false;
488 kill(in->proc.pid, SIGTERM);
492 instance_restart(struct service_instance *in)
494 if (!in->proc.pending)
498 kill(in->proc.pid, SIGTERM);
502 instance_config_changed(struct service_instance *in, struct service_instance *in_new)
507 if (!blob_attr_equal(in->command, in_new->command))
510 if (!blobmsg_list_equal(&in->env, &in_new->env))
513 if (!blobmsg_list_equal(&in->data, &in_new->data))
516 if (!blobmsg_list_equal(&in->netdev, &in_new->netdev))
519 if (!blobmsg_list_equal(&in->file, &in_new->file))
522 if (in->nice != in_new->nice)
525 if (in->uid != in_new->uid)
528 if (in->gid != in_new->gid)
531 if (!blobmsg_list_equal(&in->limits, &in_new->limits))
534 if (!blobmsg_list_equal(&in->jail.mount, &in_new->jail.mount))
537 if (!blobmsg_list_equal(&in->errors, &in_new->errors))
544 instance_netdev_cmp(struct blobmsg_list_node *l1, struct blobmsg_list_node *l2)
546 struct instance_netdev *n1 = container_of(l1, struct instance_netdev, node);
547 struct instance_netdev *n2 = container_of(l2, struct instance_netdev, node);
549 return n1->ifindex == n2->ifindex;
553 instance_netdev_update(struct blobmsg_list_node *l)
555 struct instance_netdev *n = container_of(l, struct instance_netdev, node);
557 n->ifindex = if_nametoindex(n->node.avl.key);
561 instance_file_cmp(struct blobmsg_list_node *l1, struct blobmsg_list_node *l2)
563 struct instance_file *f1 = container_of(l1, struct instance_file, node);
564 struct instance_file *f2 = container_of(l2, struct instance_file, node);
566 return !memcmp(f1->md5, f2->md5, sizeof(f1->md5));
570 instance_file_update(struct blobmsg_list_node *l)
572 struct instance_file *f = container_of(l, struct instance_file, node);
577 memset(f->md5, 0, sizeof(f->md5));
579 fd = open(l->avl.key, O_RDONLY);
585 len = read(fd, buf, sizeof(buf));
595 md5_hash(buf, len, &md5);
598 md5_end(f->md5, &md5);
603 instance_fill_any(struct blobmsg_list *l, struct blob_attr *cur)
608 blobmsg_list_fill(l, blobmsg_data(cur), blobmsg_data_len(cur), false);
612 instance_fill_array(struct blobmsg_list *l, struct blob_attr *cur, blobmsg_update_cb cb, bool array)
614 struct blobmsg_list_node *node;
619 if (!blobmsg_check_attr_list(cur, BLOBMSG_TYPE_STRING))
622 blobmsg_list_fill(l, blobmsg_data(cur), blobmsg_data_len(cur), array);
624 blobmsg_list_for_each(l, node)
631 instance_jail_parse(struct service_instance *in, struct blob_attr *attr)
633 struct blob_attr *tb[__JAIL_ATTR_MAX];
634 struct jail *jail = &in->jail;
637 if (stat("/sbin/ujail", &s))
640 blobmsg_parse(jail_attr, __JAIL_ATTR_MAX, tb,
641 blobmsg_data(attr), blobmsg_data_len(attr));
645 if (tb[JAIL_ATTR_NAME]) {
646 jail->name = blobmsg_get_string(tb[JAIL_ATTR_NAME]);
649 if (tb[JAIL_ATTR_ROOT]) {
650 jail->root = blobmsg_get_string(tb[JAIL_ATTR_ROOT]);
653 if (tb[JAIL_ATTR_PROCFS]) {
654 jail->procfs = blobmsg_get_bool(tb[JAIL_ATTR_PROCFS]);
657 if (tb[JAIL_ATTR_SYSFS]) {
658 jail->sysfs = blobmsg_get_bool(tb[JAIL_ATTR_SYSFS]);
661 if (tb[JAIL_ATTR_UBUS]) {
662 jail->ubus = blobmsg_get_bool(tb[JAIL_ATTR_UBUS]);
665 if (tb[JAIL_ATTR_LOG]) {
666 jail->log = blobmsg_get_bool(tb[JAIL_ATTR_LOG]);
669 if (tb[JAIL_ATTR_MOUNT]) {
670 struct blob_attr *cur;
673 blobmsg_for_each_attr(cur, tb[JAIL_ATTR_MOUNT], rem)
675 instance_fill_array(&jail->mount, tb[JAIL_ATTR_MOUNT], NULL, false);
684 instance_config_parse(struct service_instance *in)
686 struct blob_attr *tb[__INSTANCE_ATTR_MAX];
687 struct blob_attr *cur, *cur2;
691 blobmsg_parse(instance_attr, __INSTANCE_ATTR_MAX, tb,
692 blobmsg_data(in->config), blobmsg_data_len(in->config));
694 cur = tb[INSTANCE_ATTR_COMMAND];
698 if (!blobmsg_check_attr_list(cur, BLOBMSG_TYPE_STRING))
701 blobmsg_for_each_attr(cur2, cur, rem) {
710 if (tb[INSTANCE_ATTR_RESPAWN]) {
712 uint32_t vals[3] = { 3600, 5, 5};
714 blobmsg_for_each_attr(cur2, tb[INSTANCE_ATTR_RESPAWN], rem) {
715 if ((i >= 3) && (blobmsg_type(cur2) == BLOBMSG_TYPE_STRING))
717 vals[i] = atoi(blobmsg_get_string(cur2));
721 in->respawn_count = 0;
722 in->respawn_threshold = vals[0];
723 in->respawn_timeout = vals[1];
724 in->respawn_retry = vals[2];
726 if (tb[INSTANCE_ATTR_TRIGGER]) {
727 in->trigger = tb[INSTANCE_ATTR_TRIGGER];
728 trigger_add(in->trigger, in);
731 if (tb[INSTANCE_ATTR_WATCH]) {
732 blobmsg_for_each_attr(cur2, tb[INSTANCE_ATTR_WATCH], rem) {
733 if (blobmsg_type(cur2) != BLOBMSG_TYPE_STRING)
735 DEBUG(3, "watch for %s\n", blobmsg_get_string(cur2));
736 watch_add(blobmsg_get_string(cur2), in);
740 if ((cur = tb[INSTANCE_ATTR_NICE])) {
741 in->nice = (int8_t) blobmsg_get_u32(cur);
742 if (in->nice < -20 || in->nice > 20)
746 if (tb[INSTANCE_ATTR_USER]) {
747 struct passwd *p = getpwnam(blobmsg_get_string(tb[INSTANCE_ATTR_USER]));
754 if (tb[INSTANCE_ATTR_TRACE])
755 in->trace = blobmsg_get_bool(tb[INSTANCE_ATTR_TRACE]);
757 if (!in->trace && tb[INSTANCE_ATTR_SECCOMP]) {
758 char *seccomp = blobmsg_get_string(tb[INSTANCE_ATTR_SECCOMP]);
761 if (stat(seccomp, &s))
762 ERROR("%s: not starting seccomp as %s is missing\n", in->name, seccomp);
764 in->seccomp = seccomp;
766 if (!in->trace && tb[INSTANCE_ATTR_JAIL])
767 in->has_jail = instance_jail_parse(in, tb[INSTANCE_ATTR_JAIL]);
769 if (tb[INSTANCE_ATTR_STDOUT] && blobmsg_get_bool(tb[INSTANCE_ATTR_STDOUT]))
770 in->_stdout.fd.fd = -1;
772 if (tb[INSTANCE_ATTR_STDERR] && blobmsg_get_bool(tb[INSTANCE_ATTR_STDERR]))
773 in->_stderr.fd.fd = -1;
775 instance_fill_any(&in->data, tb[INSTANCE_ATTR_DATA]);
777 if (!instance_fill_array(&in->env, tb[INSTANCE_ATTR_ENV], NULL, false))
780 if (!instance_fill_array(&in->netdev, tb[INSTANCE_ATTR_NETDEV], instance_netdev_update, true))
783 if (!instance_fill_array(&in->file, tb[INSTANCE_ATTR_FILE], instance_file_update, true))
786 if (!instance_fill_array(&in->limits, tb[INSTANCE_ATTR_LIMITS], NULL, false))
789 if (!instance_fill_array(&in->errors, tb[INSTANCE_ATTR_ERROR], NULL, true))
796 instance_config_cleanup(struct service_instance *in)
798 blobmsg_list_free(&in->env);
799 blobmsg_list_free(&in->data);
800 blobmsg_list_free(&in->netdev);
801 blobmsg_list_free(&in->file);
802 blobmsg_list_free(&in->limits);
803 blobmsg_list_free(&in->errors);
804 blobmsg_list_free(&in->jail.mount);
808 instance_config_move(struct service_instance *in, struct service_instance *in_src)
810 instance_config_cleanup(in);
811 blobmsg_list_move(&in->env, &in_src->env);
812 blobmsg_list_move(&in->data, &in_src->data);
813 blobmsg_list_move(&in->netdev, &in_src->netdev);
814 blobmsg_list_move(&in->file, &in_src->file);
815 blobmsg_list_move(&in->limits, &in_src->limits);
816 blobmsg_list_move(&in->errors, &in_src->errors);
817 blobmsg_list_move(&in->jail.mount, &in_src->jail.mount);
818 in->trigger = in_src->trigger;
819 in->command = in_src->command;
820 in->name = in_src->name;
821 in->node.avl.key = in_src->node.avl.key;
824 in->config = in_src->config;
825 in_src->config = NULL;
829 instance_update(struct service_instance *in, struct service_instance *in_new)
831 bool changed = instance_config_changed(in, in_new);
832 bool running = in->proc.pending;
834 if (!changed && running)
839 instance_config_move(in, in_new);
842 instance_restart(in);
843 instance_config_move(in, in_new);
844 /* restart happens in the child callback handler */
850 instance_free(struct service_instance *in)
852 instance_free_stdio(in);
853 uloop_process_delete(&in->proc);
854 uloop_timeout_cancel(&in->timeout);
857 instance_config_cleanup(in);
863 instance_init(struct service_instance *in, struct service *s, struct blob_attr *config)
865 config = blob_memdup(config);
867 in->name = blobmsg_name(config);
869 in->timeout.cb = instance_timeout;
870 in->proc.cb = instance_exit;
872 in->_stdout.fd.fd = -2;
873 in->_stdout.stream.string_data = true;
874 in->_stdout.stream.notify_read = instance_stdout;
876 in->_stderr.fd.fd = -2;
877 in->_stderr.stream.string_data = true;
878 in->_stderr.stream.notify_read = instance_stderr;
880 blobmsg_list_init(&in->netdev, struct instance_netdev, node, instance_netdev_cmp);
881 blobmsg_list_init(&in->file, struct instance_file, node, instance_file_cmp);
882 blobmsg_list_simple_init(&in->env);
883 blobmsg_list_simple_init(&in->data);
884 blobmsg_list_simple_init(&in->limits);
885 blobmsg_list_simple_init(&in->errors);
886 blobmsg_list_simple_init(&in->jail.mount);
887 in->valid = instance_config_parse(in);
890 void instance_dump(struct blob_buf *b, struct service_instance *in, int verbose)
897 i = blobmsg_open_table(b, in->name);
898 blobmsg_add_u8(b, "running", in->proc.pending);
899 if (in->proc.pending)
900 blobmsg_add_u32(b, "pid", in->proc.pid);
901 blobmsg_add_blob(b, in->command);
903 if (!avl_is_empty(&in->errors.avl)) {
904 struct blobmsg_list_node *var;
905 void *e = blobmsg_open_array(b, "errors");
906 blobmsg_list_for_each(&in->errors, var)
907 blobmsg_add_string(b, NULL, blobmsg_data(var->data));
908 blobmsg_close_table(b, e);
911 if (!avl_is_empty(&in->env.avl)) {
912 struct blobmsg_list_node *var;
913 void *e = blobmsg_open_table(b, "env");
914 blobmsg_list_for_each(&in->env, var)
915 blobmsg_add_string(b, blobmsg_name(var->data), blobmsg_data(var->data));
916 blobmsg_close_table(b, e);
919 if (!avl_is_empty(&in->data.avl)) {
920 struct blobmsg_list_node *var;
921 void *e = blobmsg_open_table(b, "data");
922 blobmsg_list_for_each(&in->data, var)
923 blobmsg_add_blob(b, var->data);
924 blobmsg_close_table(b, e);
927 if (!avl_is_empty(&in->limits.avl)) {
928 struct blobmsg_list_node *var;
929 void *e = blobmsg_open_table(b, "limits");
930 blobmsg_list_for_each(&in->limits, var)
931 blobmsg_add_string(b, blobmsg_name(var->data), blobmsg_data(var->data));
932 blobmsg_close_table(b, e);
936 void *r = blobmsg_open_table(b, "respawn");
937 blobmsg_add_u32(b, "threshold", in->respawn_threshold);
938 blobmsg_add_u32(b, "timeout", in->respawn_timeout);
939 blobmsg_add_u32(b, "retry", in->respawn_retry);
940 blobmsg_close_table(b, r);
944 blobmsg_add_u8(b, "trace", true);
947 blobmsg_add_string(b, "seccomp", in->seccomp);
950 void *r = blobmsg_open_table(b, "jail");
952 blobmsg_add_string(b, "name", in->jail.name);
954 blobmsg_add_string(b, "root", in->jail.root);
955 blobmsg_add_u8(b, "procfs", in->jail.procfs);
956 blobmsg_add_u8(b, "sysfs", in->jail.sysfs);
957 blobmsg_add_u8(b, "ubus", in->jail.ubus);
958 blobmsg_add_u8(b, "log", in->jail.log);
959 blobmsg_close_table(b, r);
960 if (!avl_is_empty(&in->jail.mount.avl)) {
961 struct blobmsg_list_node *var;
962 void *e = blobmsg_open_table(b, "mount");
963 blobmsg_list_for_each(&in->jail.mount, var)
964 blobmsg_add_string(b, blobmsg_name(var->data), blobmsg_data(var->data));
965 blobmsg_close_table(b, e);
969 if (verbose && in->trigger)
970 blobmsg_add_blob(b, in->trigger);
972 blobmsg_close_table(b, i);