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>
32 #include <libubox/md5.h>
39 #define UJAIL_BIN_PATH "/sbin/ujail"
42 INSTANCE_ATTR_COMMAND
,
47 INSTANCE_ATTR_TRIGGER
,
48 INSTANCE_ATTR_RESPAWN
,
57 INSTANCE_ATTR_NO_NEW_PRIVS
,
60 INSTANCE_ATTR_SECCOMP
,
61 INSTANCE_ATTR_PIDFILE
,
62 INSTANCE_ATTR_RELOADSIG
,
63 INSTANCE_ATTR_TERMTIMEOUT
,
64 INSTANCE_ATTR_FACILITY
,
65 INSTANCE_ATTR_EXTROOT
,
66 INSTANCE_ATTR_OVERLAYDIR
,
67 INSTANCE_ATTR_TMPOVERLAYSIZE
,
69 INSTANCE_ATTR_WATCHDOG
,
73 static const struct blobmsg_policy instance_attr
[__INSTANCE_ATTR_MAX
] = {
74 [INSTANCE_ATTR_COMMAND
] = { "command", BLOBMSG_TYPE_ARRAY
},
75 [INSTANCE_ATTR_ENV
] = { "env", BLOBMSG_TYPE_TABLE
},
76 [INSTANCE_ATTR_DATA
] = { "data", BLOBMSG_TYPE_TABLE
},
77 [INSTANCE_ATTR_NETDEV
] = { "netdev", BLOBMSG_TYPE_ARRAY
},
78 [INSTANCE_ATTR_FILE
] = { "file", BLOBMSG_TYPE_ARRAY
},
79 [INSTANCE_ATTR_TRIGGER
] = { "triggers", BLOBMSG_TYPE_ARRAY
},
80 [INSTANCE_ATTR_RESPAWN
] = { "respawn", BLOBMSG_TYPE_ARRAY
},
81 [INSTANCE_ATTR_NICE
] = { "nice", BLOBMSG_TYPE_INT32
},
82 [INSTANCE_ATTR_LIMITS
] = { "limits", BLOBMSG_TYPE_TABLE
},
83 [INSTANCE_ATTR_WATCH
] = { "watch", BLOBMSG_TYPE_ARRAY
},
84 [INSTANCE_ATTR_ERROR
] = { "error", BLOBMSG_TYPE_ARRAY
},
85 [INSTANCE_ATTR_USER
] = { "user", BLOBMSG_TYPE_STRING
},
86 [INSTANCE_ATTR_GROUP
] = { "group", BLOBMSG_TYPE_STRING
},
87 [INSTANCE_ATTR_STDOUT
] = { "stdout", BLOBMSG_TYPE_BOOL
},
88 [INSTANCE_ATTR_STDERR
] = { "stderr", BLOBMSG_TYPE_BOOL
},
89 [INSTANCE_ATTR_NO_NEW_PRIVS
] = { "no_new_privs", BLOBMSG_TYPE_BOOL
},
90 [INSTANCE_ATTR_JAIL
] = { "jail", BLOBMSG_TYPE_TABLE
},
91 [INSTANCE_ATTR_TRACE
] = { "trace", BLOBMSG_TYPE_BOOL
},
92 [INSTANCE_ATTR_SECCOMP
] = { "seccomp", BLOBMSG_TYPE_STRING
},
93 [INSTANCE_ATTR_PIDFILE
] = { "pidfile", BLOBMSG_TYPE_STRING
},
94 [INSTANCE_ATTR_RELOADSIG
] = { "reload_signal", BLOBMSG_TYPE_INT32
},
95 [INSTANCE_ATTR_TERMTIMEOUT
] = { "term_timeout", BLOBMSG_TYPE_INT32
},
96 [INSTANCE_ATTR_FACILITY
] = { "facility", BLOBMSG_TYPE_STRING
},
97 [INSTANCE_ATTR_EXTROOT
] = { "extroot", BLOBMSG_TYPE_STRING
},
98 [INSTANCE_ATTR_OVERLAYDIR
] = { "overlaydir", BLOBMSG_TYPE_STRING
},
99 [INSTANCE_ATTR_TMPOVERLAYSIZE
] = { "tmpoverlaysize", BLOBMSG_TYPE_STRING
},
100 [INSTANCE_ATTR_BUNDLE
] = { "bundle", BLOBMSG_TYPE_STRING
},
101 [INSTANCE_ATTR_WATCHDOG
] = { "watchdog", BLOBMSG_TYPE_ARRAY
},
117 JAIL_ATTR_REQUIREJAIL
,
118 JAIL_ATTR_IMMEDIATELY
,
122 static const struct blobmsg_policy jail_attr
[__JAIL_ATTR_MAX
] = {
123 [JAIL_ATTR_NAME
] = { "name", BLOBMSG_TYPE_STRING
},
124 [JAIL_ATTR_HOSTNAME
] = { "hostname", BLOBMSG_TYPE_STRING
},
125 [JAIL_ATTR_PROCFS
] = { "procfs", BLOBMSG_TYPE_BOOL
},
126 [JAIL_ATTR_SYSFS
] = { "sysfs", BLOBMSG_TYPE_BOOL
},
127 [JAIL_ATTR_UBUS
] = { "ubus", BLOBMSG_TYPE_BOOL
},
128 [JAIL_ATTR_LOG
] = { "log", BLOBMSG_TYPE_BOOL
},
129 [JAIL_ATTR_RONLY
] = { "ronly", BLOBMSG_TYPE_BOOL
},
130 [JAIL_ATTR_MOUNT
] = { "mount", BLOBMSG_TYPE_TABLE
},
131 [JAIL_ATTR_NETNS
] = { "netns", BLOBMSG_TYPE_BOOL
},
132 [JAIL_ATTR_USERNS
] = { "userns", BLOBMSG_TYPE_BOOL
},
133 [JAIL_ATTR_CGROUPSNS
] = { "cgroupsns", BLOBMSG_TYPE_BOOL
},
134 [JAIL_ATTR_CONSOLE
] = { "console", BLOBMSG_TYPE_BOOL
},
135 [JAIL_ATTR_REQUIREJAIL
] = { "requirejail", BLOBMSG_TYPE_BOOL
},
136 [JAIL_ATTR_IMMEDIATELY
] = { "immediately", BLOBMSG_TYPE_BOOL
},
139 struct instance_netdev
{
140 struct blobmsg_list_node node
;
144 struct instance_file
{
145 struct blobmsg_list_node node
;
154 static const struct rlimit_name rlimit_names
[] = {
156 { "core", RLIMIT_CORE
},
157 { "cpu", RLIMIT_CPU
},
158 { "data", RLIMIT_DATA
},
159 { "fsize", RLIMIT_FSIZE
},
160 { "memlock", RLIMIT_MEMLOCK
},
161 { "nofile", RLIMIT_NOFILE
},
162 { "nproc", RLIMIT_NPROC
},
163 { "rss", RLIMIT_RSS
},
164 { "stack", RLIMIT_STACK
},
166 { "nice", RLIMIT_NICE
},
167 { "rtprio", RLIMIT_RTPRIO
},
168 { "msgqueue", RLIMIT_MSGQUEUE
},
169 { "sigpending", RLIMIT_SIGPENDING
},
174 static void closefd(int fd
)
176 if (fd
> STDERR_FILENO
)
180 /* convert a string into numeric syslog facility or return -1 if no match found */
182 syslog_facility_str_to_int(const char *facility
)
184 CODE
*p
= facilitynames
;
186 while (p
->c_name
&& strcasecmp(p
->c_name
, facility
))
193 instance_limits(const char *limit
, const char *value
)
197 unsigned long cur
, max
;
199 for (i
= 0; rlimit_names
[i
].name
!= NULL
; i
++) {
200 if (strcmp(rlimit_names
[i
].name
, limit
))
202 if (!strcmp(value
, "unlimited")) {
203 rlim
.rlim_cur
= RLIM_INFINITY
;
204 rlim
.rlim_max
= RLIM_INFINITY
;
206 if (getrlimit(rlimit_names
[i
].resource
, &rlim
))
212 if (sscanf(value
, "%lu %lu", &cur
, &max
) < 1)
219 setrlimit(rlimit_names
[i
].resource
, &rlim
);
225 jail_run(struct service_instance
*in
, char **argv
)
227 struct blobmsg_list_node
*var
;
228 struct jail
*jail
= &in
->jail
;
231 argv
[argc
++] = UJAIL_BIN_PATH
;
235 argv
[argc
++] = jail
->name
;
238 if (jail
->hostname
) {
240 argv
[argc
++] = jail
->hostname
;
245 argv
[argc
++] = in
->seccomp
;
250 argv
[argc
++] = in
->user
;
255 argv
[argc
++] = in
->group
;
258 if (in
->no_new_privs
)
290 argv
[argc
++] = in
->extroot
;
293 if (in
->overlaydir
) {
295 argv
[argc
++] = in
->overlaydir
;
298 if (in
->tmpoverlaysize
) {
300 argv
[argc
++] = in
->tmpoverlaysize
;
308 argv
[argc
++] = in
->bundle
;
311 if (in
->require_jail
)
314 blobmsg_list_for_each(&jail
->mount
, var
) {
315 const char *type
= blobmsg_data(var
->data
);
321 argv
[argc
++] = (char *) blobmsg_name(var
->data
);
330 instance_removepid(struct service_instance
*in
) {
333 if (unlink(in
->pidfile
)) {
334 ERROR("Failed to remove pidfile: %s: %m\n", in
->pidfile
);
341 instance_writepid(struct service_instance
*in
)
348 _pidfile
= fopen(in
->pidfile
, "w");
349 if (_pidfile
== NULL
) {
350 ERROR("failed to open pidfile for writing: %s: %m", in
->pidfile
);
353 if (fprintf(_pidfile
, "%d\n", in
->proc
.pid
) < 0) {
354 ERROR("failed to write pidfile: %s: %m", in
->pidfile
);
358 if (fclose(_pidfile
)) {
359 ERROR("failed to close pidfile: %s: %m", in
->pidfile
);
367 instance_run(struct service_instance
*in
, int _stdout
, int _stderr
)
369 struct blobmsg_list_node
*var
;
370 struct blob_attr
*cur
;
372 int argc
= 1; /* NULL terminated */
374 bool seccomp
= !in
->trace
&& !in
->has_jail
&& in
->seccomp
;
375 bool setlbf
= _stdout
>= 0;
378 setpriority(PRIO_PROCESS
, 0, in
->nice
);
380 blobmsg_for_each_attr(cur
, in
->command
, rem
)
383 blobmsg_list_for_each(&in
->env
, var
)
384 setenv(blobmsg_name(var
->data
), blobmsg_data(var
->data
), 1);
387 setenv("SECCOMP_FILE", in
->seccomp
, 1);
390 setenv("LD_PRELOAD", "/lib/libsetlbf.so", 1);
392 blobmsg_list_for_each(&in
->limits
, var
)
393 instance_limits(blobmsg_name(var
->data
), blobmsg_data(var
->data
));
395 if (in
->trace
|| seccomp
)
398 argv
= alloca(sizeof(char *) * (argc
+ in
->jail
.argc
));
401 #ifdef SECCOMP_SUPPORT
403 argv
[argc
++] = "/sbin/utrace";
405 argv
[argc
++] = "/sbin/seccomp-trace";
407 if (in
->trace
|| seccomp
)
408 ULOG_WARN("Seccomp support for %s::%s not available\n", in
->srv
->name
, in
->name
);
412 argc
= jail_run(in
, argv
);
413 if (argc
!= in
->jail
.argc
)
414 ULOG_WARN("expected %i jail params, used %i for %s::%s\n",
415 in
->jail
.argc
, argc
, in
->srv
->name
, in
->name
);
418 blobmsg_for_each_attr(cur
, in
->command
, rem
)
419 argv
[argc
++] = blobmsg_data(cur
);
423 _stdin
= open("/dev/null", O_RDONLY
);
426 _stdout
= open("/dev/null", O_WRONLY
);
429 _stderr
= open("/dev/null", O_WRONLY
);
432 dup2(_stdin
, STDIN_FILENO
);
436 dup2(_stdout
, STDOUT_FILENO
);
440 dup2(_stderr
, STDERR_FILENO
);
444 if (!in
->has_jail
&& in
->user
&& in
->pw_gid
&& initgroups(in
->user
, in
->pw_gid
)) {
445 ERROR("failed to initgroups() for user %s: %m\n", in
->user
);
448 if (!in
->has_jail
&& in
->gr_gid
&& setgid(in
->gr_gid
)) {
449 ERROR("failed to set group id %d: %m\n", in
->gr_gid
);
452 if (!in
->has_jail
&& in
->uid
&& setuid(in
->uid
)) {
453 ERROR("failed to set user id %d: %m\n", in
->uid
);
457 execvp(argv
[0], argv
);
462 instance_free_stdio(struct service_instance
*in
)
464 if (in
->_stdout
.fd
.fd
> -1) {
465 ustream_free(&in
->_stdout
.stream
);
466 close(in
->_stdout
.fd
.fd
);
467 in
->_stdout
.fd
.fd
= -1;
470 if (in
->_stderr
.fd
.fd
> -1) {
471 ustream_free(&in
->_stderr
.stream
);
472 close(in
->_stderr
.fd
.fd
);
473 in
->_stderr
.fd
.fd
= -1;
476 if (in
->console
.fd
.fd
> -1) {
477 ustream_free(&in
->console
.stream
);
478 close(in
->console
.fd
.fd
);
479 in
->console
.fd
.fd
= -1;
482 if (in
->console_client
.fd
.fd
> -1) {
483 ustream_free(&in
->console_client
.stream
);
484 close(in
->console_client
.fd
.fd
);
485 in
->console_client
.fd
.fd
= -1;
490 instance_start(struct service_instance
*in
)
493 int opipe
[2] = { -1, -1 };
494 int epipe
[2] = { -1, -1 };
496 if (!avl_is_empty(&in
->errors
.avl
)) {
497 LOG("Not starting instance %s::%s, an error was indicated\n", in
->srv
->name
, in
->name
);
501 if (!in
->bundle
&& !in
->command
) {
502 LOG("Not starting instance %s::%s, command not set\n", in
->srv
->name
, in
->name
);
506 if (in
->proc
.pending
) {
512 instance_free_stdio(in
);
513 if (in
->_stdout
.fd
.fd
> -2) {
515 ULOG_WARN("pipe() failed: %m\n");
516 opipe
[0] = opipe
[1] = -1;
520 if (in
->_stderr
.fd
.fd
> -2) {
522 ULOG_WARN("pipe() failed: %m\n");
523 epipe
[0] = epipe
[1] = -1;
541 instance_run(in
, opipe
[1], epipe
[1]);
545 DEBUG(2, "Started instance %s::%s[%d]\n", in
->srv
->name
, in
->name
, pid
);
547 instance_writepid(in
);
548 clock_gettime(CLOCK_MONOTONIC
, &in
->start
);
549 uloop_process_add(&in
->proc
);
552 ustream_fd_init(&in
->_stdout
, opipe
[0]);
554 fcntl(opipe
[0], F_SETFD
, FD_CLOEXEC
);
558 ustream_fd_init(&in
->_stderr
, epipe
[0]);
560 fcntl(epipe
[0], F_SETFD
, FD_CLOEXEC
);
563 if (in
->watchdog
.mode
!= INSTANCE_WATCHDOG_MODE_DISABLED
) {
564 uloop_timeout_set(&in
->watchdog
.timeout
, in
->watchdog
.freq
* 1000);
565 DEBUG(2, "Started instance %s::%s watchdog timer : timeout = %d\n", in
->srv
->name
, in
->name
, in
->watchdog
.freq
);
568 service_event("instance.start", in
->srv
->name
, in
->name
);
572 instance_stdio(struct ustream
*s
, int prio
, struct service_instance
*in
)
574 char *newline
, *str
, *arg0
, ident
[32];
577 arg0
= basename(blobmsg_data(blobmsg_data(in
->command
)));
578 snprintf(ident
, sizeof(ident
), "%s[%d]", arg0
, in
->proc
.pid
);
579 ulog_open(ULOG_SYSLOG
, in
->syslog_facility
, ident
);
582 str
= ustream_get_read_buf(s
, &len
);
586 newline
= memchr(str
, '\n', len
);
587 if (!newline
&& (s
->r
.buffer_len
!= len
))
592 len
= newline
+ 1 - str
;
594 ulog(prio
, "%s\n", str
);
596 ustream_consume(s
, len
);
599 ulog_open(ULOG_SYSLOG
, LOG_DAEMON
, "procd");
603 instance_stdout(struct ustream
*s
, int bytes
)
605 instance_stdio(s
, LOG_INFO
,
606 container_of(s
, struct service_instance
, _stdout
.stream
));
610 instance_console(struct ustream
*s
, int bytes
)
612 struct service_instance
*in
= container_of(s
, struct service_instance
, console
.stream
);
617 buf
= ustream_get_read_buf(s
, &len
);
621 ulog(LOG_INFO
, "out: %s\n", buf
);
623 /* test if console client is attached */
624 if (in
->console_client
.fd
.fd
> -1)
625 ustream_write(&in
->console_client
.stream
, buf
, len
, false);
627 ustream_consume(s
, len
);
632 instance_console_client(struct ustream
*s
, int bytes
)
634 struct service_instance
*in
= container_of(s
, struct service_instance
, console_client
.stream
);
639 buf
= ustream_get_read_buf(s
, &len
);
643 ulog(LOG_INFO
, "in: %s\n", buf
);
644 ustream_write(&in
->console
.stream
, buf
, len
, false);
645 ustream_consume(s
, len
);
650 instance_stderr(struct ustream
*s
, int bytes
)
652 instance_stdio(s
, LOG_ERR
,
653 container_of(s
, struct service_instance
, _stderr
.stream
));
657 instance_timeout(struct uloop_timeout
*t
)
659 struct service_instance
*in
;
661 in
= container_of(t
, struct service_instance
, timeout
);
664 LOG("Instance %s::%s pid %d not stopped on SIGTERM, sending SIGKILL instead\n",
665 in
->srv
->name
, in
->name
, in
->proc
.pid
);
666 kill(in
->proc
.pid
, SIGKILL
);
667 } else if (in
->restart
|| in
->respawn
)
672 instance_delete(struct service_instance
*in
)
674 struct service
*s
= in
->srv
;
676 avl_delete(&s
->instances
.avl
, &in
->node
.avl
);
682 instance_exit_code(int ret
)
684 if (WIFEXITED(ret
)) {
685 return WEXITSTATUS(ret
);
688 if (WIFSIGNALED(ret
)) {
689 return SIGNALLED_OFFSET
+ WTERMSIG(ret
);
692 if (WIFSTOPPED(ret
)) {
693 return WSTOPSIG(ret
);
700 instance_exit(struct uloop_process
*p
, int ret
)
702 struct service_instance
*in
;
706 in
= container_of(p
, struct service_instance
, proc
);
708 clock_gettime(CLOCK_MONOTONIC
, &tp
);
709 runtime
= tp
.tv_sec
- in
->start
.tv_sec
;
711 DEBUG(2, "Instance %s::%s exit with error code %d after %ld seconds\n", in
->srv
->name
, in
->name
, ret
, runtime
);
713 in
->exit_code
= instance_exit_code(ret
);
714 uloop_timeout_cancel(&in
->timeout
);
715 uloop_timeout_cancel(&in
->watchdog
.timeout
);
716 service_event("instance.stop", in
->srv
->name
, in
->name
);
719 instance_removepid(in
);
724 } else if (in
->restart
) {
726 } else if (in
->respawn
) {
727 if (runtime
< in
->respawn_threshold
)
730 in
->respawn_count
= 0;
731 if (in
->respawn_count
> in
->respawn_retry
&& in
->respawn_retry
> 0 ) {
732 LOG("Instance %s::%s s in a crash loop %d crashes, %ld seconds since last crash\n",
733 in
->srv
->name
, in
->name
, in
->respawn_count
, runtime
);
734 in
->restart
= in
->respawn
= 0;
736 service_event("instance.fail", in
->srv
->name
, in
->name
);
738 service_event("instance.respawn", in
->srv
->name
, in
->name
);
739 uloop_timeout_set(&in
->timeout
, in
->respawn_timeout
* 1000);
745 instance_stop(struct service_instance
*in
, bool halt
)
747 if (!in
->proc
.pending
) {
753 in
->restart
= in
->respawn
= false;
754 kill(in
->proc
.pid
, SIGTERM
);
755 uloop_timeout_set(&in
->timeout
, in
->term_timeout
* 1000);
759 instance_restart(struct service_instance
*in
)
761 if (!in
->proc
.pending
)
764 if (in
->reload_signal
) {
765 kill(in
->proc
.pid
, in
->reload_signal
);
771 kill(in
->proc
.pid
, SIGTERM
);
772 uloop_timeout_set(&in
->timeout
, in
->term_timeout
* 1000);
776 instance_watchdog(struct uloop_timeout
*t
)
778 struct service_instance
*in
= container_of(t
, struct service_instance
, watchdog
.timeout
);
780 DEBUG(3, "instance %s::%s watchdog timer expired\n", in
->srv
->name
, in
->name
);
783 instance_restart(in
);
785 instance_stop(in
, true);
788 static bool string_changed(const char *a
, const char *b
)
790 return !((!a
&& !b
) || (a
&& b
&& !strcmp(a
, b
)));
794 instance_config_changed(struct service_instance
*in
, struct service_instance
*in_new
)
799 if (!blob_attr_equal(in
->command
, in_new
->command
))
802 if (string_changed(in
->bundle
, in_new
->bundle
))
805 if (string_changed(in
->extroot
, in_new
->extroot
))
808 if (string_changed(in
->overlaydir
, in_new
->overlaydir
))
811 if (string_changed(in
->tmpoverlaysize
, in_new
->tmpoverlaysize
))
814 if (!blobmsg_list_equal(&in
->env
, &in_new
->env
))
817 if (!blobmsg_list_equal(&in
->netdev
, &in_new
->netdev
))
820 if (!blobmsg_list_equal(&in
->file
, &in_new
->file
))
823 if (in
->nice
!= in_new
->nice
)
826 if (in
->syslog_facility
!= in_new
->syslog_facility
)
829 if (string_changed(in
->user
, in_new
->user
))
832 if (string_changed(in
->group
, in_new
->group
))
835 if (in
->uid
!= in_new
->uid
)
838 if (in
->pw_gid
!= in_new
->pw_gid
)
841 if (in
->gr_gid
!= in_new
->gr_gid
)
844 if (string_changed(in
->pidfile
, in_new
->pidfile
))
847 if (in
->respawn_retry
!= in_new
->respawn_retry
)
849 if (in
->respawn_threshold
!= in_new
->respawn_threshold
)
851 if (in
->respawn_timeout
!= in_new
->respawn_timeout
)
854 if (in
->reload_signal
!= in_new
->reload_signal
)
857 if (in
->term_timeout
!= in_new
->term_timeout
)
860 if (string_changed(in
->seccomp
, in_new
->seccomp
))
863 if (!blobmsg_list_equal(&in
->limits
, &in_new
->limits
))
866 if (!blobmsg_list_equal(&in
->jail
.mount
, &in_new
->jail
.mount
))
869 if (!blobmsg_list_equal(&in
->errors
, &in_new
->errors
))
872 if (in
->has_jail
!= in_new
->has_jail
)
875 if (in
->trace
!= in_new
->trace
)
878 if (in
->require_jail
!= in_new
->require_jail
)
881 if (in
->immediately
!= in_new
->immediately
)
884 if (in
->no_new_privs
!= in_new
->no_new_privs
)
887 if (string_changed(in
->jail
.name
, in_new
->jail
.name
))
890 if (string_changed(in
->jail
.hostname
, in_new
->jail
.hostname
))
893 if (in
->jail
.procfs
!= in_new
->jail
.procfs
)
896 if (in
->jail
.sysfs
!= in_new
->jail
.sysfs
)
899 if (in
->jail
.ubus
!= in_new
->jail
.ubus
)
902 if (in
->jail
.log
!= in_new
->jail
.log
)
905 if (in
->jail
.ronly
!= in_new
->jail
.ronly
)
908 if (in
->jail
.netns
!= in_new
->jail
.netns
)
911 if (in
->jail
.userns
!= in_new
->jail
.userns
)
914 if (in
->jail
.cgroupsns
!= in_new
->jail
.cgroupsns
)
917 if (in
->jail
.console
!= in_new
->jail
.console
)
920 if (!blobmsg_list_equal(&in
->jail
.mount
, &in_new
->jail
.mount
))
923 if (in
->watchdog
.mode
!= in_new
->watchdog
.mode
)
926 if (in
->watchdog
.freq
!= in_new
->watchdog
.freq
)
933 instance_netdev_cmp(struct blobmsg_list_node
*l1
, struct blobmsg_list_node
*l2
)
935 struct instance_netdev
*n1
= container_of(l1
, struct instance_netdev
, node
);
936 struct instance_netdev
*n2
= container_of(l2
, struct instance_netdev
, node
);
938 return n1
->ifindex
== n2
->ifindex
;
942 instance_netdev_update(struct blobmsg_list_node
*l
)
944 struct instance_netdev
*n
= container_of(l
, struct instance_netdev
, node
);
946 n
->ifindex
= if_nametoindex(n
->node
.avl
.key
);
950 instance_file_cmp(struct blobmsg_list_node
*l1
, struct blobmsg_list_node
*l2
)
952 struct instance_file
*f1
= container_of(l1
, struct instance_file
, node
);
953 struct instance_file
*f2
= container_of(l2
, struct instance_file
, node
);
955 return !memcmp(f1
->md5
, f2
->md5
, sizeof(f1
->md5
));
959 instance_file_update(struct blobmsg_list_node
*l
)
961 struct instance_file
*f
= container_of(l
, struct instance_file
, node
);
966 memset(f
->md5
, 0, sizeof(f
->md5
));
968 fd
= open(l
->avl
.key
, O_RDONLY
);
974 len
= read(fd
, buf
, sizeof(buf
));
984 md5_hash(buf
, len
, &md5
);
987 md5_end(f
->md5
, &md5
);
992 instance_fill_any(struct blobmsg_list
*l
, struct blob_attr
*cur
)
997 blobmsg_list_fill(l
, blobmsg_data(cur
), blobmsg_data_len(cur
), false);
1001 instance_fill_array(struct blobmsg_list
*l
, struct blob_attr
*cur
, blobmsg_update_cb cb
, bool array
)
1003 struct blobmsg_list_node
*node
;
1008 if (!blobmsg_check_attr_list(cur
, BLOBMSG_TYPE_STRING
))
1011 blobmsg_list_fill(l
, blobmsg_data(cur
), blobmsg_data_len(cur
), array
);
1013 blobmsg_list_for_each(l
, node
)
1020 instance_jail_parse(struct service_instance
*in
, struct blob_attr
*attr
)
1022 struct blob_attr
*tb
[__JAIL_ATTR_MAX
];
1023 struct jail
*jail
= &in
->jail
;
1025 blobmsg_parse(jail_attr
, __JAIL_ATTR_MAX
, tb
,
1026 blobmsg_data(attr
), blobmsg_data_len(attr
));
1030 if (tb
[JAIL_ATTR_REQUIREJAIL
] && blobmsg_get_bool(tb
[JAIL_ATTR_REQUIREJAIL
])) {
1031 in
->require_jail
= true;
1034 if (tb
[JAIL_ATTR_IMMEDIATELY
] && blobmsg_get_bool(tb
[JAIL_ATTR_IMMEDIATELY
])) {
1035 in
->immediately
= true;
1038 if (tb
[JAIL_ATTR_NAME
]) {
1039 jail
->name
= strdup(blobmsg_get_string(tb
[JAIL_ATTR_NAME
]));
1042 if (tb
[JAIL_ATTR_HOSTNAME
]) {
1043 jail
->hostname
= strdup(blobmsg_get_string(tb
[JAIL_ATTR_HOSTNAME
]));
1046 if (tb
[JAIL_ATTR_PROCFS
] && blobmsg_get_bool(tb
[JAIL_ATTR_PROCFS
])) {
1047 jail
->procfs
= true;
1050 if (tb
[JAIL_ATTR_SYSFS
] && blobmsg_get_bool(tb
[JAIL_ATTR_SYSFS
])) {
1054 if (tb
[JAIL_ATTR_UBUS
] && blobmsg_get_bool(tb
[JAIL_ATTR_UBUS
])) {
1058 if (tb
[JAIL_ATTR_LOG
] && blobmsg_get_bool(tb
[JAIL_ATTR_LOG
])) {
1062 if (tb
[JAIL_ATTR_RONLY
] && blobmsg_get_bool(tb
[JAIL_ATTR_RONLY
])) {
1066 if (tb
[JAIL_ATTR_NETNS
] && blobmsg_get_bool(tb
[JAIL_ATTR_NETNS
])) {
1070 if (tb
[JAIL_ATTR_USERNS
] && blobmsg_get_bool(tb
[JAIL_ATTR_USERNS
])) {
1071 jail
->userns
= true;
1074 if (tb
[JAIL_ATTR_CGROUPSNS
] && blobmsg_get_bool(tb
[JAIL_ATTR_CGROUPSNS
])) {
1075 jail
->cgroupsns
= true;
1078 if (tb
[JAIL_ATTR_CONSOLE
] && blobmsg_get_bool(tb
[JAIL_ATTR_CONSOLE
])) {
1079 jail
->console
= true;
1083 if (tb
[JAIL_ATTR_MOUNT
]) {
1084 struct blob_attr
*cur
;
1087 blobmsg_for_each_attr(cur
, tb
[JAIL_ATTR_MOUNT
], rem
)
1089 instance_fill_array(&jail
->mount
, tb
[JAIL_ATTR_MOUNT
], NULL
, false);
1106 if (in
->tmpoverlaysize
)
1109 if (in
->no_new_privs
)
1119 instance_config_parse_command(struct service_instance
*in
, struct blob_attr
**tb
)
1121 struct blob_attr
*cur
, *cur2
;
1125 cur
= tb
[INSTANCE_ATTR_COMMAND
];
1131 if (!blobmsg_check_attr_list(cur
, BLOBMSG_TYPE_STRING
))
1134 blobmsg_for_each_attr(cur2
, cur
, rem
) {
1144 instance_config_parse(struct service_instance
*in
)
1146 struct blob_attr
*tb
[__INSTANCE_ATTR_MAX
];
1147 struct blob_attr
*cur
, *cur2
;
1151 blobmsg_parse(instance_attr
, __INSTANCE_ATTR_MAX
, tb
,
1152 blobmsg_data(in
->config
), blobmsg_data_len(in
->config
));
1154 if (!tb
[INSTANCE_ATTR_BUNDLE
] && !instance_config_parse_command(in
, tb
))
1157 if (tb
[INSTANCE_ATTR_TERMTIMEOUT
])
1158 in
->term_timeout
= blobmsg_get_u32(tb
[INSTANCE_ATTR_TERMTIMEOUT
]);
1159 if (tb
[INSTANCE_ATTR_RESPAWN
]) {
1161 uint32_t vals
[3] = { 3600, 5, 5};
1163 blobmsg_for_each_attr(cur2
, tb
[INSTANCE_ATTR_RESPAWN
], rem
) {
1164 if ((i
>= 3) && (blobmsg_type(cur2
) == BLOBMSG_TYPE_STRING
))
1166 vals
[i
] = atoi(blobmsg_get_string(cur2
));
1170 in
->respawn_count
= 0;
1171 in
->respawn_threshold
= vals
[0];
1172 in
->respawn_timeout
= vals
[1];
1173 in
->respawn_retry
= vals
[2];
1175 if (tb
[INSTANCE_ATTR_TRIGGER
]) {
1176 in
->trigger
= tb
[INSTANCE_ATTR_TRIGGER
];
1177 trigger_add(in
->trigger
, in
);
1180 if (tb
[INSTANCE_ATTR_WATCH
]) {
1181 blobmsg_for_each_attr(cur2
, tb
[INSTANCE_ATTR_WATCH
], rem
) {
1182 if (blobmsg_type(cur2
) != BLOBMSG_TYPE_STRING
)
1184 DEBUG(3, "watch for %s\n", blobmsg_get_string(cur2
));
1185 watch_add(blobmsg_get_string(cur2
), in
);
1189 if ((cur
= tb
[INSTANCE_ATTR_NICE
])) {
1190 in
->nice
= (int8_t) blobmsg_get_u32(cur
);
1191 if (in
->nice
< -20 || in
->nice
> 20)
1195 if (tb
[INSTANCE_ATTR_USER
]) {
1196 const char *user
= blobmsg_get_string(tb
[INSTANCE_ATTR_USER
]);
1197 struct passwd
*p
= getpwnam(user
);
1199 in
->user
= strdup(user
);
1200 in
->uid
= p
->pw_uid
;
1201 in
->gr_gid
= in
->pw_gid
= p
->pw_gid
;
1205 if (tb
[INSTANCE_ATTR_GROUP
]) {
1206 const char *group
= blobmsg_get_string(tb
[INSTANCE_ATTR_GROUP
]);
1207 struct group
*p
= getgrnam(group
);
1209 in
->group
= strdup(group
);
1210 in
->gr_gid
= p
->gr_gid
;
1214 if (tb
[INSTANCE_ATTR_TRACE
])
1215 in
->trace
= blobmsg_get_bool(tb
[INSTANCE_ATTR_TRACE
]);
1217 if (tb
[INSTANCE_ATTR_NO_NEW_PRIVS
])
1218 in
->no_new_privs
= blobmsg_get_bool(tb
[INSTANCE_ATTR_NO_NEW_PRIVS
]);
1220 if (!in
->trace
&& tb
[INSTANCE_ATTR_SECCOMP
])
1221 in
->seccomp
= strdup(blobmsg_get_string(tb
[INSTANCE_ATTR_SECCOMP
]));
1223 if (tb
[INSTANCE_ATTR_EXTROOT
])
1224 in
->extroot
= strdup(blobmsg_get_string(tb
[INSTANCE_ATTR_EXTROOT
]));
1226 if (tb
[INSTANCE_ATTR_OVERLAYDIR
])
1227 in
->overlaydir
= strdup(blobmsg_get_string(tb
[INSTANCE_ATTR_OVERLAYDIR
]));
1229 if (tb
[INSTANCE_ATTR_TMPOVERLAYSIZE
])
1230 in
->tmpoverlaysize
= strdup(blobmsg_get_string(tb
[INSTANCE_ATTR_TMPOVERLAYSIZE
]));
1232 if (tb
[INSTANCE_ATTR_BUNDLE
])
1233 in
->bundle
= strdup(blobmsg_get_string(tb
[INSTANCE_ATTR_BUNDLE
]));
1235 if (tb
[INSTANCE_ATTR_PIDFILE
]) {
1236 char *pidfile
= blobmsg_get_string(tb
[INSTANCE_ATTR_PIDFILE
]);
1238 in
->pidfile
= strdup(pidfile
);
1241 if (tb
[INSTANCE_ATTR_RELOADSIG
])
1242 in
->reload_signal
= blobmsg_get_u32(tb
[INSTANCE_ATTR_RELOADSIG
]);
1244 if (!in
->trace
&& tb
[INSTANCE_ATTR_JAIL
])
1245 in
->has_jail
= instance_jail_parse(in
, tb
[INSTANCE_ATTR_JAIL
]);
1248 r
= stat(UJAIL_BIN_PATH
, &s
);
1250 if (in
->require_jail
) {
1251 ERROR("Cannot jail service %s::%s. %s: %m (%d)\n",
1252 in
->srv
->name
, in
->name
, UJAIL_BIN_PATH
, r
);
1255 DEBUG(2, "unable to find %s: %m (%d)\n", UJAIL_BIN_PATH
, r
);
1256 in
->has_jail
= false;
1260 if (tb
[INSTANCE_ATTR_STDOUT
] && blobmsg_get_bool(tb
[INSTANCE_ATTR_STDOUT
]))
1261 in
->_stdout
.fd
.fd
= -1;
1263 if (tb
[INSTANCE_ATTR_STDERR
] && blobmsg_get_bool(tb
[INSTANCE_ATTR_STDERR
]))
1264 in
->_stderr
.fd
.fd
= -1;
1266 instance_fill_any(&in
->data
, tb
[INSTANCE_ATTR_DATA
]);
1268 if (!instance_fill_array(&in
->env
, tb
[INSTANCE_ATTR_ENV
], NULL
, false))
1271 if (!instance_fill_array(&in
->netdev
, tb
[INSTANCE_ATTR_NETDEV
], instance_netdev_update
, true))
1274 if (!instance_fill_array(&in
->file
, tb
[INSTANCE_ATTR_FILE
], instance_file_update
, true))
1277 if (!instance_fill_array(&in
->limits
, tb
[INSTANCE_ATTR_LIMITS
], NULL
, false))
1280 if (!instance_fill_array(&in
->errors
, tb
[INSTANCE_ATTR_ERROR
], NULL
, true))
1283 if (tb
[INSTANCE_ATTR_FACILITY
]) {
1284 int facility
= syslog_facility_str_to_int(blobmsg_get_string(tb
[INSTANCE_ATTR_FACILITY
]));
1285 if (facility
!= -1) {
1286 in
->syslog_facility
= facility
;
1287 DEBUG(3, "setting facility '%s'\n", blobmsg_get_string(tb
[INSTANCE_ATTR_FACILITY
]));
1289 DEBUG(3, "unknown syslog facility '%s' given, using default (LOG_DAEMON)\n", blobmsg_get_string(tb
[INSTANCE_ATTR_FACILITY
]));
1292 if (tb
[INSTANCE_ATTR_WATCHDOG
]) {
1294 uint32_t vals
[2] = { 0, 30 };
1296 blobmsg_for_each_attr(cur2
, tb
[INSTANCE_ATTR_WATCHDOG
], rem
) {
1300 vals
[i
] = atoi(blobmsg_get_string(cur2
));
1304 if (vals
[0] >= 0 && vals
[0] < __INSTANCE_WATCHDOG_MODE_MAX
) {
1305 in
->watchdog
.mode
= vals
[0];
1306 DEBUG(3, "setting watchdog mode (%d)\n", vals
[0]);
1308 in
->watchdog
.mode
= 0;
1309 DEBUG(3, "unknown watchdog mode (%d) given, using default (0)\n", vals
[0]);
1313 in
->watchdog
.freq
= vals
[1];
1314 DEBUG(3, "setting watchdog timeout (%d)\n", vals
[0]);
1316 in
->watchdog
.freq
= 30;
1317 DEBUG(3, "invalid watchdog timeout (%d) given, using default (30)\n", vals
[1]);
1325 instance_config_cleanup(struct service_instance
*in
)
1327 blobmsg_list_free(&in
->env
);
1328 blobmsg_list_free(&in
->data
);
1329 blobmsg_list_free(&in
->netdev
);
1330 blobmsg_list_free(&in
->file
);
1331 blobmsg_list_free(&in
->limits
);
1332 blobmsg_list_free(&in
->errors
);
1333 blobmsg_list_free(&in
->jail
.mount
);
1337 instance_config_move_strdup(char **dst
, char *src
)
1351 instance_config_move(struct service_instance
*in
, struct service_instance
*in_src
)
1353 instance_config_cleanup(in
);
1354 blobmsg_list_move(&in
->env
, &in_src
->env
);
1355 blobmsg_list_move(&in
->data
, &in_src
->data
);
1356 blobmsg_list_move(&in
->netdev
, &in_src
->netdev
);
1357 blobmsg_list_move(&in
->file
, &in_src
->file
);
1358 blobmsg_list_move(&in
->limits
, &in_src
->limits
);
1359 blobmsg_list_move(&in
->errors
, &in_src
->errors
);
1360 blobmsg_list_move(&in
->jail
.mount
, &in_src
->jail
.mount
);
1361 in
->trigger
= in_src
->trigger
;
1362 in
->command
= in_src
->command
;
1363 in
->respawn
= in_src
->respawn
;
1364 in
->respawn_retry
= in_src
->respawn_retry
;
1365 in
->respawn_threshold
= in_src
->respawn_threshold
;
1366 in
->respawn_timeout
= in_src
->respawn_timeout
;
1367 in
->reload_signal
= in_src
->reload_signal
;
1368 in
->term_timeout
= in_src
->term_timeout
;
1369 in
->watchdog
.mode
= in_src
->watchdog
.mode
;
1370 in
->watchdog
.freq
= in_src
->watchdog
.freq
;
1371 in
->watchdog
.timeout
= in_src
->watchdog
.timeout
;
1372 in
->name
= in_src
->name
;
1373 in
->nice
= in_src
->nice
;
1374 in
->trace
= in_src
->trace
;
1375 in
->node
.avl
.key
= in_src
->node
.avl
.key
;
1376 in
->syslog_facility
= in_src
->syslog_facility
;
1377 in
->require_jail
= in_src
->require_jail
;
1378 in
->no_new_privs
= in_src
->no_new_privs
;
1379 in
->immediately
= in_src
->immediately
;
1380 in
->uid
= in_src
->uid
;
1381 in
->pw_gid
= in_src
->pw_gid
;
1382 in
->gr_gid
= in_src
->gr_gid
;
1384 in
->has_jail
= in_src
->has_jail
;
1385 in
->jail
.procfs
= in_src
->jail
.procfs
;
1386 in
->jail
.sysfs
= in_src
->jail
.sysfs
;
1387 in
->jail
.ubus
= in_src
->jail
.ubus
;
1388 in
->jail
.log
= in_src
->jail
.log
;
1389 in
->jail
.ronly
= in_src
->jail
.ronly
;
1390 in
->jail
.netns
= in_src
->jail
.netns
;
1391 in
->jail
.cgroupsns
= in_src
->jail
.cgroupsns
;
1392 in
->jail
.console
= in_src
->jail
.console
;
1393 in
->jail
.argc
= in_src
->jail
.argc
;
1395 instance_config_move_strdup(&in
->pidfile
, in_src
->pidfile
);
1396 instance_config_move_strdup(&in
->seccomp
, in_src
->seccomp
);
1397 instance_config_move_strdup(&in
->bundle
, in_src
->bundle
);
1398 instance_config_move_strdup(&in
->extroot
, in_src
->extroot
);
1399 instance_config_move_strdup(&in
->overlaydir
, in_src
->overlaydir
);
1400 instance_config_move_strdup(&in
->tmpoverlaysize
, in_src
->tmpoverlaysize
);
1401 instance_config_move_strdup(&in
->user
, in_src
->user
);
1402 instance_config_move_strdup(&in
->group
, in_src
->group
);
1403 instance_config_move_strdup(&in
->jail
.name
, in_src
->jail
.name
);
1404 instance_config_move_strdup(&in
->jail
.hostname
, in_src
->jail
.hostname
);
1407 in
->config
= in_src
->config
;
1408 in_src
->config
= NULL
;
1412 instance_update(struct service_instance
*in
, struct service_instance
*in_new
)
1414 bool changed
= instance_config_changed(in
, in_new
);
1415 bool running
= in
->proc
.pending
;
1416 bool stopping
= in
->halt
;
1418 if (!running
|| stopping
) {
1419 instance_config_move(in
, in_new
);
1423 instance_restart(in
);
1424 instance_config_move(in
, in_new
);
1425 /* restart happens in the child callback handler */
1430 instance_free(struct service_instance
*in
)
1432 instance_free_stdio(in
);
1433 uloop_process_delete(&in
->proc
);
1434 uloop_timeout_cancel(&in
->timeout
);
1435 uloop_timeout_cancel(&in
->watchdog
.timeout
);
1438 instance_config_cleanup(in
);
1443 free(in
->overlaydir
);
1444 free(in
->tmpoverlaysize
);
1446 free(in
->jail
.name
);
1447 free(in
->jail
.hostname
);
1454 instance_init(struct service_instance
*in
, struct service
*s
, struct blob_attr
*config
)
1456 config
= blob_memdup(config
);
1458 in
->name
= blobmsg_name(config
);
1459 in
->config
= config
;
1460 in
->timeout
.cb
= instance_timeout
;
1461 in
->proc
.cb
= instance_exit
;
1462 in
->term_timeout
= 5;
1463 in
->syslog_facility
= LOG_DAEMON
;
1465 in
->require_jail
= false;
1466 in
->immediately
= false;
1468 in
->_stdout
.fd
.fd
= -2;
1469 in
->_stdout
.stream
.string_data
= true;
1470 in
->_stdout
.stream
.notify_read
= instance_stdout
;
1472 in
->_stderr
.fd
.fd
= -2;
1473 in
->_stderr
.stream
.string_data
= true;
1474 in
->_stderr
.stream
.notify_read
= instance_stderr
;
1476 in
->console
.fd
.fd
= -2;
1477 in
->console
.stream
.string_data
= true;
1478 in
->console
.stream
.notify_read
= instance_console
;
1480 in
->console_client
.fd
.fd
= -2;
1481 in
->console_client
.stream
.string_data
= true;
1482 in
->console_client
.stream
.notify_read
= instance_console_client
;
1484 blobmsg_list_init(&in
->netdev
, struct instance_netdev
, node
, instance_netdev_cmp
);
1485 blobmsg_list_init(&in
->file
, struct instance_file
, node
, instance_file_cmp
);
1486 blobmsg_list_simple_init(&in
->env
);
1487 blobmsg_list_simple_init(&in
->data
);
1488 blobmsg_list_simple_init(&in
->limits
);
1489 blobmsg_list_simple_init(&in
->errors
);
1490 blobmsg_list_simple_init(&in
->jail
.mount
);
1492 in
->watchdog
.timeout
.cb
= instance_watchdog
;
1494 in
->valid
= instance_config_parse(in
);
1497 void instance_dump(struct blob_buf
*b
, struct service_instance
*in
, int verbose
)
1504 i
= blobmsg_open_table(b
, in
->name
);
1505 blobmsg_add_u8(b
, "running", in
->proc
.pending
);
1506 if (in
->proc
.pending
)
1507 blobmsg_add_u32(b
, "pid", in
->proc
.pid
);
1509 blobmsg_add_blob(b
, in
->command
);
1511 blobmsg_add_string(b
, "bundle", in
->bundle
);
1512 blobmsg_add_u32(b
, "term_timeout", in
->term_timeout
);
1513 if (!in
->proc
.pending
)
1514 blobmsg_add_u32(b
, "exit_code", in
->exit_code
);
1516 if (!avl_is_empty(&in
->errors
.avl
)) {
1517 struct blobmsg_list_node
*var
;
1518 void *e
= blobmsg_open_array(b
, "errors");
1519 blobmsg_list_for_each(&in
->errors
, var
)
1520 blobmsg_add_string(b
, NULL
, blobmsg_data(var
->data
));
1521 blobmsg_close_table(b
, e
);
1524 if (!avl_is_empty(&in
->env
.avl
)) {
1525 struct blobmsg_list_node
*var
;
1526 void *e
= blobmsg_open_table(b
, "env");
1527 blobmsg_list_for_each(&in
->env
, var
)
1528 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
1529 blobmsg_close_table(b
, e
);
1532 if (!avl_is_empty(&in
->data
.avl
)) {
1533 struct blobmsg_list_node
*var
;
1534 void *e
= blobmsg_open_table(b
, "data");
1535 blobmsg_list_for_each(&in
->data
, var
)
1536 blobmsg_add_blob(b
, var
->data
);
1537 blobmsg_close_table(b
, e
);
1540 if (!avl_is_empty(&in
->limits
.avl
)) {
1541 struct blobmsg_list_node
*var
;
1542 void *e
= blobmsg_open_table(b
, "limits");
1543 blobmsg_list_for_each(&in
->limits
, var
)
1544 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
1545 blobmsg_close_table(b
, e
);
1548 if (in
->reload_signal
)
1549 blobmsg_add_u32(b
, "reload_signal", in
->reload_signal
);
1552 void *r
= blobmsg_open_table(b
, "respawn");
1553 blobmsg_add_u32(b
, "threshold", in
->respawn_threshold
);
1554 blobmsg_add_u32(b
, "timeout", in
->respawn_timeout
);
1555 blobmsg_add_u32(b
, "retry", in
->respawn_retry
);
1556 blobmsg_close_table(b
, r
);
1560 blobmsg_add_u8(b
, "trace", true);
1562 if (in
->no_new_privs
)
1563 blobmsg_add_u8(b
, "no_new_privs", true);
1566 blobmsg_add_string(b
, "seccomp", in
->seccomp
);
1569 blobmsg_add_string(b
, "pidfile", in
->pidfile
);
1572 blobmsg_add_string(b
, "user", in
->user
);
1575 blobmsg_add_string(b
, "group", in
->group
);
1578 void *r
= blobmsg_open_table(b
, "jail");
1580 blobmsg_add_string(b
, "name", in
->jail
.name
);
1582 if (in
->jail
.hostname
)
1583 blobmsg_add_string(b
, "hostname", in
->jail
.hostname
);
1585 blobmsg_add_u8(b
, "procfs", in
->jail
.procfs
);
1586 blobmsg_add_u8(b
, "sysfs", in
->jail
.sysfs
);
1587 blobmsg_add_u8(b
, "ubus", in
->jail
.ubus
);
1588 blobmsg_add_u8(b
, "log", in
->jail
.log
);
1589 blobmsg_add_u8(b
, "ronly", in
->jail
.ronly
);
1590 blobmsg_add_u8(b
, "netns", in
->jail
.netns
);
1591 blobmsg_add_u8(b
, "userns", in
->jail
.userns
);
1592 blobmsg_add_u8(b
, "cgroupsns", in
->jail
.cgroupsns
);
1594 blobmsg_add_u8(b
, "immediately", in
->immediately
);
1596 blobmsg_add_u8(b
, "console", (in
->console
.fd
.fd
> -1));
1597 blobmsg_close_table(b
, r
);
1598 if (!avl_is_empty(&in
->jail
.mount
.avl
)) {
1599 struct blobmsg_list_node
*var
;
1600 void *e
= blobmsg_open_table(b
, "mount");
1601 blobmsg_list_for_each(&in
->jail
.mount
, var
)
1602 blobmsg_add_string(b
, blobmsg_name(var
->data
), blobmsg_data(var
->data
));
1603 blobmsg_close_table(b
, e
);
1608 blobmsg_add_string(b
, "extroot", in
->extroot
);
1610 blobmsg_add_string(b
, "overlaydir", in
->overlaydir
);
1611 if (in
->tmpoverlaysize
)
1612 blobmsg_add_string(b
, "tmpoverlaysize", in
->tmpoverlaysize
);
1614 if (verbose
&& in
->trigger
)
1615 blobmsg_add_blob(b
, in
->trigger
);
1617 if (in
->watchdog
.mode
!= INSTANCE_WATCHDOG_MODE_DISABLED
) {
1618 void *r
= blobmsg_open_table(b
, "watchdog");
1619 blobmsg_add_u32(b
, "mode", in
->watchdog
.mode
);
1620 blobmsg_add_u32(b
, "timeout", in
->watchdog
.freq
);
1621 blobmsg_close_table(b
, r
);
1624 blobmsg_close_table(b
, i
);