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.
15 #include <sys/resource.h>
16 #include <sys/types.h>
17 #include <sys/socket.h>
27 #include <libubox/md5.h>
36 INSTANCE_ATTR_COMMAND
,
41 INSTANCE_ATTR_TRIGGER
,
42 INSTANCE_ATTR_RESPAWN
,
52 INSTANCE_ATTR_SECCOMP
,
56 static const struct blobmsg_policy instance_attr
[__INSTANCE_ATTR_MAX
] = {
57 [INSTANCE_ATTR_COMMAND
] = { "command", BLOBMSG_TYPE_ARRAY
},
58 [INSTANCE_ATTR_ENV
] = { "env", BLOBMSG_TYPE_TABLE
},
59 [INSTANCE_ATTR_DATA
] = { "data", BLOBMSG_TYPE_TABLE
},
60 [INSTANCE_ATTR_NETDEV
] = { "netdev", BLOBMSG_TYPE_ARRAY
},
61 [INSTANCE_ATTR_FILE
] = { "file", BLOBMSG_TYPE_ARRAY
},
62 [INSTANCE_ATTR_TRIGGER
] = { "triggers", BLOBMSG_TYPE_ARRAY
},
63 [INSTANCE_ATTR_RESPAWN
] = { "respawn", BLOBMSG_TYPE_ARRAY
},
64 [INSTANCE_ATTR_NICE
] = { "nice", BLOBMSG_TYPE_INT32
},
65 [INSTANCE_ATTR_LIMITS
] = { "limits", BLOBMSG_TYPE_TABLE
},
66 [INSTANCE_ATTR_WATCH
] = { "watch", BLOBMSG_TYPE_ARRAY
},
67 [INSTANCE_ATTR_ERROR
] = { "error", BLOBMSG_TYPE_ARRAY
},
68 [INSTANCE_ATTR_USER
] = { "user", BLOBMSG_TYPE_STRING
},
69 [INSTANCE_ATTR_STDOUT
] = { "stdout", BLOBMSG_TYPE_BOOL
},
70 [INSTANCE_ATTR_STDERR
] = { "stderr", BLOBMSG_TYPE_BOOL
},
71 [INSTANCE_ATTR_JAIL
] = { "jail", BLOBMSG_TYPE_TABLE
},
72 [INSTANCE_ATTR_TRACE
] = { "trace", BLOBMSG_TYPE_BOOL
},
73 [INSTANCE_ATTR_SECCOMP
] = { "seccomp", BLOBMSG_TYPE_STRING
},
87 static const struct blobmsg_policy jail_attr
[__JAIL_ATTR_MAX
] = {
88 [JAIL_ATTR_NAME
] = { "name", BLOBMSG_TYPE_STRING
},
89 [JAIL_ATTR_ROOT
] = { "root", BLOBMSG_TYPE_STRING
},
90 [JAIL_ATTR_PROCFS
] = { "procfs", BLOBMSG_TYPE_BOOL
},
91 [JAIL_ATTR_SYSFS
] = { "sysfs", BLOBMSG_TYPE_BOOL
},
92 [JAIL_ATTR_UBUS
] = { "ubus", BLOBMSG_TYPE_BOOL
},
93 [JAIL_ATTR_LOG
] = { "log", BLOBMSG_TYPE_BOOL
},
94 [JAIL_ATTR_MOUNT
] = { "mount", BLOBMSG_TYPE_TABLE
},
97 struct instance_netdev
{
98 struct blobmsg_list_node node
;
102 struct instance_file
{
103 struct blobmsg_list_node node
;
112 static const struct rlimit_name rlimit_names
[] = {
114 { "core", RLIMIT_CORE
},
115 { "cpu", RLIMIT_CPU
},
116 { "data", RLIMIT_DATA
},
117 { "fsize", RLIMIT_FSIZE
},
118 { "memlock", RLIMIT_MEMLOCK
},
119 { "msgqueue", RLIMIT_MSGQUEUE
},
120 { "nice", RLIMIT_NICE
},
121 { "nofile", RLIMIT_NOFILE
},
122 { "nproc", RLIMIT_NPROC
},
123 { "rss", RLIMIT_RSS
},
124 { "rtprio", RLIMIT_RTPRIO
},
125 { "sigpending", RLIMIT_SIGPENDING
},
126 { "stack", RLIMIT_STACK
},
130 static char trace
[] = "/sbin/utrace";
132 static void closefd(int fd
)
134 if (fd
> STDERR_FILENO
)
139 instance_limits(const char *limit
, const char *value
)
143 unsigned long cur
, max
;
145 for (i
= 0; rlimit_names
[i
].name
!= NULL
; i
++) {
146 if (strcmp(rlimit_names
[i
].name
, limit
))
148 if (!strcmp(value
, "unlimited")) {
149 rlim
.rlim_cur
= RLIM_INFINITY
;
150 rlim
.rlim_max
= RLIM_INFINITY
;
152 if (getrlimit(rlimit_names
[i
].resource
, &rlim
))
158 if (sscanf(value
, "%lu %lu", &cur
, &max
) < 1)
165 setrlimit(rlimit_names
[i
].resource
, &rlim
);
171 jail_run(struct service_instance
*in
, char **argv
)
173 struct blobmsg_list_node
*var
;
174 struct jail
*jail
= &in
->jail
;
177 argv
[argc
++] = "/sbin/ujail";
181 argv
[argc
++] = jail
->name
;
186 argv
[argc
++] = jail
->root
;
191 argv
[argc
++] = in
->seccomp
;
206 blobmsg_list_for_each(&jail
->mount
, var
) {
207 const char *type
= blobmsg_data(var
->data
);
213 argv
[argc
++] = (char *) blobmsg_name(var
->data
);
222 instance_run(struct service_instance
*in
, int _stdout
, int _stderr
)
224 struct blobmsg_list_node
*var
;
225 struct blob_attr
*cur
;
227 int argc
= 1; /* NULL terminated */
231 setpriority(PRIO_PROCESS
, 0, in
->nice
);
233 blobmsg_for_each_attr(cur
, in
->command
, rem
)
236 blobmsg_list_for_each(&in
->env
, var
)
237 setenv(blobmsg_name(var
->data
), blobmsg_data(var
->data
), 1);
239 if (!in
->trace
&& !in
->has_jail
&& in
->seccomp
) {
240 setenv("SECCOMP_FILE", in
->seccomp
, 1);
241 setenv("LD_PRELOAD", "/lib/libpreload-seccomp.so", 1);
244 blobmsg_list_for_each(&in
->limits
, var
)
245 instance_limits(blobmsg_name(var
->data
), blobmsg_data(var
->data
));
250 argv
= alloca(sizeof(char *) * (argc
+ in
->jail
.argc
));
254 argv
[argc
++] = trace
;
257 argc
= jail_run(in
, argv
);
259 blobmsg_for_each_attr(cur
, in
->command
, rem
)
260 argv
[argc
++] = blobmsg_data(cur
);
264 _stdin
= open("/dev/null", O_RDONLY
);
267 _stdout
= open("/dev/null", O_WRONLY
);
270 _stderr
= open("/dev/null", O_WRONLY
);
273 dup2(_stdin
, STDIN_FILENO
);
277 dup2(_stdout
, STDOUT_FILENO
);
281 dup2(_stderr
, STDERR_FILENO
);
285 if (in
->gid
&& setgid(in
->gid
)) {
286 ERROR("failed to set group id %d: %d (%s)\n", in
->gid
, errno
, strerror(errno
));
289 if (in
->uid
&& setuid(in
->uid
)) {
290 ERROR("failed to set user id %d: %d (%s)\n", in
->uid
, errno
, strerror(errno
));
294 execvp(argv
[0], argv
);
299 instance_start(struct service_instance
*in
)
302 int opipe
[2] = { -1, -1 };
303 int epipe
[2] = { -1, -1 };
305 if (!avl_is_empty(&in
->errors
.avl
)) {
306 LOG("Not starting instance %s::%s, an error was indicated\n", in
->srv
->name
, in
->name
);
310 if (in
->proc
.pending
)
313 if (in
->_stdout
.fd
.fd
> -2) {
315 ULOG_WARN("pipe() failed: %d (%s)\n", errno
, strerror(errno
));
316 opipe
[0] = opipe
[1] = -1;
320 if (in
->_stderr
.fd
.fd
> -2) {
322 ULOG_WARN("pipe() failed: %d (%s)\n", errno
, strerror(errno
));
323 epipe
[0] = epipe
[1] = -1;
328 in
->halt
= !in
->respawn
;
341 instance_run(in
, opipe
[1], epipe
[1]);
345 DEBUG(2, "Started instance %s::%s\n", in
->srv
->name
, in
->name
);
347 clock_gettime(CLOCK_MONOTONIC
, &in
->start
);
348 uloop_process_add(&in
->proc
);
351 ustream_fd_init(&in
->_stdout
, opipe
[0]);
356 ustream_fd_init(&in
->_stderr
, epipe
[0]);
360 service_event("instance.start", in
->srv
->name
, in
->name
);
364 instance_stdio(struct ustream
*s
, int prio
, struct service_instance
*in
)
366 char *newline
, *str
, *arg0
, ident
[32];
369 arg0
= basename(blobmsg_data(blobmsg_data(in
->command
)));
370 snprintf(ident
, sizeof(ident
), "%s[%d]", arg0
, in
->proc
.pid
);
371 ulog_open(ULOG_SYSLOG
, LOG_DAEMON
, ident
);
374 str
= ustream_get_read_buf(s
, NULL
);
378 newline
= strchr(str
, '\n');
383 ulog(prio
, "%s\n", str
);
385 len
= newline
+ 1 - str
;
386 ustream_consume(s
, len
);
389 ulog_open(ULOG_SYSLOG
, LOG_DAEMON
, "procd");
393 instance_stdout(struct ustream
*s
, int bytes
)
395 instance_stdio(s
, LOG_INFO
,
396 container_of(s
, struct service_instance
, _stdout
.stream
));
400 instance_stderr(struct ustream
*s
, int bytes
)
402 instance_stdio(s
, LOG_ERR
,
403 container_of(s
, struct service_instance
, _stderr
.stream
));
407 instance_timeout(struct uloop_timeout
*t
)
409 struct service_instance
*in
;
411 in
= container_of(t
, struct service_instance
, timeout
);
413 if (!in
->halt
&& (in
->restart
|| in
->respawn
))
418 instance_exit(struct uloop_process
*p
, int ret
)
420 struct service_instance
*in
;
424 in
= container_of(p
, struct service_instance
, proc
);
426 clock_gettime(CLOCK_MONOTONIC
, &tp
);
427 runtime
= tp
.tv_sec
- in
->start
.tv_sec
;
429 DEBUG(2, "Instance %s::%s exit with error code %d after %ld seconds\n", in
->srv
->name
, in
->name
, ret
, runtime
);
433 uloop_timeout_cancel(&in
->timeout
);
436 } else if (in
->restart
) {
438 } else if (in
->respawn
) {
439 if (runtime
< in
->respawn_threshold
)
442 in
->respawn_count
= 0;
443 if (in
->respawn_count
> in
->respawn_retry
&& in
->respawn_retry
> 0 ) {
444 LOG("Instance %s::%s s in a crash loop %d crashes, %ld seconds since last crash\n",
445 in
->srv
->name
, in
->name
, in
->respawn_count
, runtime
);
446 in
->restart
= in
->respawn
= 0;
449 uloop_timeout_set(&in
->timeout
, in
->respawn_timeout
* 1000);
452 service_event("instance.stop", in
->srv
->name
, in
->name
);
456 instance_stop(struct service_instance
*in
)
458 if (!in
->proc
.pending
)
461 in
->restart
= in
->respawn
= false;
462 kill(in
->proc
.pid
, SIGTERM
);
466 instance_restart(struct service_instance
*in
)
468 if (!in
->proc
.pending
)
472 kill(in
->proc
.pid
, SIGTERM
);
476 instance_config_changed(struct service_instance
*in
, struct service_instance
*in_new
)
481 if (!blob_attr_equal(in
->command
, in_new
->command
))
484 if (!blobmsg_list_equal(&in
->env
, &in_new
->env
))
487 if (!blobmsg_list_equal(&in
->data
, &in_new
->data
))
490 if (!blobmsg_list_equal(&in
->netdev
, &in_new
->netdev
))
493 if (!blobmsg_list_equal(&in
->file
, &in_new
->file
))
496 if (in
->nice
!= in_new
->nice
)
499 if (in
->uid
!= in_new
->uid
)
502 if (in
->gid
!= in_new
->gid
)
505 if (!blobmsg_list_equal(&in
->limits
, &in_new
->limits
))
508 if (!blobmsg_list_equal(&in
->jail
.mount
, &in_new
->jail
.mount
))
511 if (!blobmsg_list_equal(&in
->errors
, &in_new
->errors
))
518 instance_netdev_cmp(struct blobmsg_list_node
*l1
, struct blobmsg_list_node
*l2
)
520 struct instance_netdev
*n1
= container_of(l1
, struct instance_netdev
, node
);
521 struct instance_netdev
*n2
= container_of(l2
, struct instance_netdev
, node
);
523 return n1
->ifindex
== n2
->ifindex
;
527 instance_netdev_update(struct blobmsg_list_node
*l
)
529 struct instance_netdev
*n
= container_of(l
, struct instance_netdev
, node
);
531 n
->ifindex
= if_nametoindex(n
->node
.avl
.key
);
535 instance_file_cmp(struct blobmsg_list_node
*l1
, struct blobmsg_list_node
*l2
)
537 struct instance_file
*f1
= container_of(l1
, struct instance_file
, node
);
538 struct instance_file
*f2
= container_of(l2
, struct instance_file
, node
);
540 return !memcmp(f1
->md5
, f2
->md5
, sizeof(f1
->md5
));
544 instance_file_update(struct blobmsg_list_node
*l
)
546 struct instance_file
*f
= container_of(l
, struct instance_file
, node
);
551 memset(f
->md5
, 0, sizeof(f
->md5
));
553 fd
= open(l
->avl
.key
, O_RDONLY
);
559 len
= read(fd
, buf
, sizeof(buf
));
569 md5_hash(buf
, len
, &md5
);
572 md5_end(f
->md5
, &md5
);
577 instance_fill_any(struct blobmsg_list
*l
, struct blob_attr
*cur
)
582 blobmsg_list_fill(l
, blobmsg_data(cur
), blobmsg_data_len(cur
), false);
586 instance_fill_array(struct blobmsg_list
*l
, struct blob_attr
*cur
, blobmsg_update_cb cb
, bool array
)
588 struct blobmsg_list_node
*node
;
593 if (!blobmsg_check_attr_list(cur
, BLOBMSG_TYPE_STRING
))
596 blobmsg_list_fill(l
, blobmsg_data(cur
), blobmsg_data_len(cur
), array
);
598 blobmsg_list_for_each(l
, node
)
605 instance_jail_parse(struct service_instance
*in
, struct blob_attr
*attr
)
607 struct blob_attr
*tb
[__JAIL_ATTR_MAX
];
608 struct jail
*jail
= &in
->jail
;
611 if (stat("/sbin/ujail", &s
))
614 blobmsg_parse(jail_attr
, __JAIL_ATTR_MAX
, tb
,
615 blobmsg_data(attr
), blobmsg_data_len(attr
));
619 if (tb
[JAIL_ATTR_NAME
]) {
620 jail
->name
= blobmsg_get_string(tb
[JAIL_ATTR_NAME
]);
623 if (tb
[JAIL_ATTR_ROOT
]) {
624 jail
->root
= blobmsg_get_string(tb
[JAIL_ATTR_ROOT
]);
627 if (tb
[JAIL_ATTR_PROCFS
]) {
628 jail
->procfs
= blobmsg_get_bool(tb
[JAIL_ATTR_PROCFS
]);
631 if (tb
[JAIL_ATTR_SYSFS
]) {
632 jail
->sysfs
= blobmsg_get_bool(tb
[JAIL_ATTR_SYSFS
]);
635 if (tb
[JAIL_ATTR_UBUS
]) {
636 jail
->ubus
= blobmsg_get_bool(tb
[JAIL_ATTR_UBUS
]);
639 if (tb
[JAIL_ATTR_LOG
]) {
640 jail
->log
= blobmsg_get_bool(tb
[JAIL_ATTR_LOG
]);
643 if (tb
[JAIL_ATTR_MOUNT
]) {
644 struct blob_attr
*cur
;
647 blobmsg_for_each_attr(cur
, tb
[JAIL_ATTR_MOUNT
], rem
)
649 instance_fill_array(&jail
->mount
, tb
[JAIL_ATTR_MOUNT
], NULL
, false);
658 instance_config_parse(struct service_instance
*in
)
660 struct blob_attr
*tb
[__INSTANCE_ATTR_MAX
];
661 struct blob_attr
*cur
, *cur2
;
665 blobmsg_parse(instance_attr
, __INSTANCE_ATTR_MAX
, tb
,
666 blobmsg_data(in
->config
), blobmsg_data_len(in
->config
));
668 cur
= tb
[INSTANCE_ATTR_COMMAND
];
672 if (!blobmsg_check_attr_list(cur
, BLOBMSG_TYPE_STRING
))
675 blobmsg_for_each_attr(cur2
, cur
, rem
) {
684 if (tb
[INSTANCE_ATTR_RESPAWN
]) {
686 uint32_t vals
[3] = { 3600, 5, 5};
688 blobmsg_for_each_attr(cur2
, tb
[INSTANCE_ATTR_RESPAWN
], rem
) {
689 if ((i
>= 3) && (blobmsg_type(cur2
) == BLOBMSG_TYPE_STRING
))
691 vals
[i
] = atoi(blobmsg_get_string(cur2
));
695 in
->respawn_count
= 0;
696 in
->respawn_threshold
= vals
[0];
697 in
->respawn_timeout
= vals
[1];
698 in
->respawn_retry
= vals
[2];
700 if (tb
[INSTANCE_ATTR_TRIGGER
]) {
701 in
->trigger
= tb
[INSTANCE_ATTR_TRIGGER
];
702 trigger_add(in
->trigger
, in
);
705 if (tb
[INSTANCE_ATTR_WATCH
]) {
706 blobmsg_for_each_attr(cur2
, tb
[INSTANCE_ATTR_WATCH
], rem
) {
707 if (blobmsg_type(cur2
) != BLOBMSG_TYPE_STRING
)
709 DEBUG(3, "watch for %s\n", blobmsg_get_string(cur2
));
710 watch_add(blobmsg_get_string(cur2
), in
);
714 if ((cur
= tb
[INSTANCE_ATTR_NICE
])) {
715 in
->nice
= (int8_t) blobmsg_get_u32(cur
);
716 if (in
->nice
< -20 || in
->nice
> 20)
720 if (tb
[INSTANCE_ATTR_USER
]) {
721 struct passwd
*p
= getpwnam(blobmsg_get_string(tb
[INSTANCE_ATTR_USER
]));
728 if (tb
[INSTANCE_ATTR_TRACE
])
729 in
->trace
= blobmsg_get_bool(tb
[INSTANCE_ATTR_TRACE
]);
731 if (!in
->trace
&& tb
[INSTANCE_ATTR_SECCOMP
]) {
732 char *seccomp
= blobmsg_get_string(tb
[INSTANCE_ATTR_SECCOMP
]);
735 if (stat(seccomp
, &s
))
736 ERROR("%s: not starting seccomp as %s is missing\n", in
->name
, seccomp
);
738 in
->seccomp
= seccomp
;
740 if (!in
->trace
&& tb
[INSTANCE_ATTR_JAIL
])
741 in
->has_jail
= instance_jail_parse(in
, tb
[INSTANCE_ATTR_JAIL
]);
743 if (tb
[INSTANCE_ATTR_STDOUT
] && blobmsg_get_bool(tb
[INSTANCE_ATTR_STDOUT
]))
744 in
->_stdout
.fd
.fd
= -1;
746 if (tb
[INSTANCE_ATTR_STDERR
] && blobmsg_get_bool(tb
[INSTANCE_ATTR_STDERR
]))
747 in
->_stderr
.fd
.fd
= -1;
749 instance_fill_any(&in
->data
, tb
[INSTANCE_ATTR_DATA
]);
751 if (!instance_fill_array(&in
->env
, tb
[INSTANCE_ATTR_ENV
], NULL
, false))
754 if (!instance_fill_array(&in
->netdev
, tb
[INSTANCE_ATTR_NETDEV
], instance_netdev_update
, true))
757 if (!instance_fill_array(&in
->file
, tb
[INSTANCE_ATTR_FILE
], instance_file_update
, true))
760 if (!instance_fill_array(&in
->limits
, tb
[INSTANCE_ATTR_LIMITS
], NULL
, false))
763 if (!instance_fill_array(&in
->errors
, tb
[INSTANCE_ATTR_ERROR
], NULL
, true))
770 instance_config_cleanup(struct service_instance
*in
)
772 blobmsg_list_free(&in
->env
);
773 blobmsg_list_free(&in
->data
);
774 blobmsg_list_free(&in
->netdev
);
775 blobmsg_list_free(&in
->file
);
776 blobmsg_list_free(&in
->limits
);
777 blobmsg_list_free(&in
->errors
);
778 blobmsg_list_free(&in
->jail
.mount
);
782 instance_config_move(struct service_instance
*in
, struct service_instance
*in_src
)
784 instance_config_cleanup(in
);
785 blobmsg_list_move(&in
->env
, &in_src
->env
);
786 blobmsg_list_move(&in
->data
, &in_src
->data
);
787 blobmsg_list_move(&in
->netdev
, &in_src
->netdev
);
788 blobmsg_list_move(&in
->file
, &in_src
->file
);
789 blobmsg_list_move(&in
->limits
, &in_src
->limits
);
790 blobmsg_list_move(&in
->errors
, &in_src
->errors
);
791 blobmsg_list_move(&in
->jail
.mount
, &in_src
->jail
.mount
);
792 in
->trigger
= in_src
->trigger
;
793 in
->command
= in_src
->command
;
794 in
->name
= in_src
->name
;
795 in
->node
.avl
.key
= in_src
->node
.avl
.key
;
798 in
->config
= in_src
->config
;
799 in_src
->config
= NULL
;
803 instance_update(struct service_instance
*in
, struct service_instance
*in_new
)
805 bool changed
= instance_config_changed(in
, in_new
);
806 bool running
= in
->proc
.pending
;
808 if (!changed
&& running
)
813 instance_config_move(in
, in_new
);
816 instance_restart(in
);
817 instance_config_move(in
, in_new
);
818 /* restart happens in the child callback handler */
824 instance_free(struct service_instance
*in
)
826 if (in
->_stdout
.fd
.fd
> -1) {
827 ustream_free(&in
->_stdout
.stream
);
828 close(in
->_stdout
.fd
.fd
);
831 if (in
->_stderr
.fd
.fd
> -1) {
832 ustream_free(&in
->_stderr
.stream
);
833 close(in
->_stderr
.fd
.fd
);
836 uloop_process_delete(&in
->proc
);
837 uloop_timeout_cancel(&in
->timeout
);
840 instance_config_cleanup(in
);
846 instance_init(struct service_instance
*in
, struct service
*s
, struct blob_attr
*config
)
848 config
= blob_memdup(config
);
850 in
->name
= blobmsg_name(config
);
852 in
->timeout
.cb
= instance_timeout
;
853 in
->proc
.cb
= instance_exit
;
855 in
->_stdout
.fd
.fd
= -2;
856 in
->_stdout
.stream
.string_data
= true;
857 in
->_stdout
.stream
.notify_read
= instance_stdout
;
859 in
->_stderr
.fd
.fd
= -2;
860 in
->_stderr
.stream
.string_data
= true;
861 in
->_stderr
.stream
.notify_read
= instance_stderr
;
863 blobmsg_list_init(&in
->netdev
, struct instance_netdev
, node
, instance_netdev_cmp
);
864 blobmsg_list_init(&in
->file
, struct instance_file
, node
, instance_file_cmp
);
865 blobmsg_list_simple_init(&in
->env
);
866 blobmsg_list_simple_init(&in
->data
);
867 blobmsg_list_simple_init(&in
->limits
);
868 blobmsg_list_simple_init(&in
->errors
);
869 blobmsg_list_simple_init(&in
->jail
.mount
);
870 in
->valid
= instance_config_parse(in
);
873 void instance_dump(struct blob_buf
*b
, struct service_instance
*in
, int verbose
)
880 i
= blobmsg_open_table(b
, in
->name
);
881 blobmsg_add_u8(b
, "running", in
->proc
.pending
);
882 if (in
->proc
.pending
)
883 blobmsg_add_u32(b
, "pid", in
->proc
.pid
);
884 blobmsg_add_blob(b
, in
->command
);
886 if (!avl_is_empty(&in
->errors
.avl
)) {
887 struct blobmsg_list_node
*var
;
888 void *e
= blobmsg_open_array(b
, "errors");
889 blobmsg_list_for_each(&in
->errors
, var
)
890 blobmsg_add_string(b
, NULL
, blobmsg_data(var
->data
));
891 blobmsg_close_table(b
, e
);
894 if (!avl_is_empty(&in
->env
.avl
)) {
895 struct blobmsg_list_node
*var
;
896 void *e
= blobmsg_open_table(b
, "env");
897 blobmsg_list_for_each(&in
->env
, var
)
898 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
899 blobmsg_close_table(b
, e
);
902 if (!avl_is_empty(&in
->data
.avl
)) {
903 struct blobmsg_list_node
*var
;
904 void *e
= blobmsg_open_table(b
, "data");
905 blobmsg_list_for_each(&in
->data
, var
)
906 blobmsg_add_blob(b
, var
->data
);
907 blobmsg_close_table(b
, e
);
910 if (!avl_is_empty(&in
->limits
.avl
)) {
911 struct blobmsg_list_node
*var
;
912 void *e
= blobmsg_open_table(b
, "limits");
913 blobmsg_list_for_each(&in
->limits
, var
)
914 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
915 blobmsg_close_table(b
, e
);
919 void *r
= blobmsg_open_table(b
, "respawn");
920 blobmsg_add_u32(b
, "threshold", in
->respawn_threshold
);
921 blobmsg_add_u32(b
, "timeout", in
->respawn_timeout
);
922 blobmsg_add_u32(b
, "retry", in
->respawn_retry
);
923 blobmsg_close_table(b
, r
);
927 blobmsg_add_u8(b
, "trace", true);
930 blobmsg_add_string(b
, "seccomp", in
->seccomp
);
933 void *r
= blobmsg_open_table(b
, "jail");
935 blobmsg_add_string(b
, "name", in
->jail
.name
);
937 blobmsg_add_string(b
, "root", in
->jail
.root
);
938 blobmsg_add_u8(b
, "procfs", in
->jail
.procfs
);
939 blobmsg_add_u8(b
, "sysfs", in
->jail
.sysfs
);
940 blobmsg_add_u8(b
, "ubus", in
->jail
.ubus
);
941 blobmsg_add_u8(b
, "log", in
->jail
.log
);
942 blobmsg_close_table(b
, r
);
943 if (!avl_is_empty(&in
->jail
.mount
.avl
)) {
944 struct blobmsg_list_node
*var
;
945 void *e
= blobmsg_open_table(b
, "mount");
946 blobmsg_list_for_each(&in
->jail
.mount
, var
)
947 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
948 blobmsg_close_table(b
, e
);
952 if (verbose
&& in
->trigger
)
953 blobmsg_add_blob(b
, in
->trigger
);
955 blobmsg_close_table(b
, i
);