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/utsname.h>
17 #include <sys/sysinfo.h>
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
21 #include <sys/reboot.h>
23 #include <sys/statvfs.h>
29 #include <json-c/json_tokener.h>
30 #include <libubox/blobmsg_json.h>
31 #include <libubox/uloop.h>
34 #include "sysupgrade.h"
36 #include "service/service.h"
38 static struct blob_buf b
;
40 static struct ubus_context
*_ctx
;
49 static const char *system_rootfs_type(void) {
50 const char proc_mounts
[] = "/proc/self/mounts";
51 static char fstype
[16] = { 0 };
52 char *mountstr
= NULL
, *mp
= "/", *pos
, *tmp
;
63 mounts
= fopen(proc_mounts
, "r");
67 while (getline(&mountstr
, &len
, mounts
) != -1) {
68 pos
= strchr(mountstr
, ' ');
73 pos
= strchr(tmp
, ' ');
82 pos
= strchr(tmp
, ' ');
88 if (!strcmp(tmp
, "overlay")) {
90 * there is no point in parsing overlay option string for
91 * lowerdir, as that can point to "/" being a previous
92 * overlay mount (after firstboot or sysuprade config
93 * restore). Hence just assume the lowerdir is "/rom" and
94 * restart searching for that instead if that's not
97 if (!strcmp(mp
, "/rom"))
101 fseek(mounts
, 0, SEEK_SET
);
110 strncpy(fstype
, tmp
, sizeof(fstype
) - 1);
112 fstype
[sizeof(fstype
) - 1]= '\0';
122 static int system_board(struct ubus_context
*ctx
, struct ubus_object
*obj
,
123 struct ubus_request_data
*req
, const char *method
,
124 struct blob_attr
*msg
)
128 char *key
, *val
, *next
;
129 const char *rootfs_type
= system_rootfs_type();
130 struct utsname utsname
;
133 blob_buf_init(&b
, 0);
135 if (uname(&utsname
) >= 0)
137 blobmsg_add_string(&b
, "kernel", utsname
.release
);
138 blobmsg_add_string(&b
, "hostname", utsname
.nodename
);
141 if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
143 while(fgets(line
, sizeof(line
), f
))
145 key
= strtok(line
, "\t:");
146 val
= strtok(NULL
, "\t\n");
152 if (!strcasecmp(key
, "CPU revision")) {
153 snprintf(line
, sizeof(line
), "ARMv8 Processor rev %lu", strtoul(val
+ 2, NULL
, 16));
154 blobmsg_add_string(&b
, "system", line
);
158 if (!strcasecmp(key
, "isa")) {
159 snprintf(line
, sizeof(line
), "RISC-V (%s)", val
+ 2);
160 blobmsg_add_string(&b
, "system", line
);
164 if (!strcasecmp(key
, "system type") ||
165 !strcasecmp(key
, "processor") ||
166 !strcasecmp(key
, "cpu") ||
167 !strcasecmp(key
, "model name"))
169 strtoul(val
+ 2, &key
, 0);
171 if (key
== (val
+ 2) || *key
!= 0)
173 blobmsg_add_string(&b
, "system", val
+ 2);
183 if ((f
= fopen("/tmp/sysinfo/model", "r")) != NULL
||
184 (f
= fopen("/proc/device-tree/model", "r")) != NULL
)
186 if (fgets(line
, sizeof(line
), f
))
188 val
= strtok(line
, "\t\n");
191 blobmsg_add_string(&b
, "model", val
);
196 else if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
198 while(fgets(line
, sizeof(line
), f
))
200 key
= strtok(line
, "\t:");
201 val
= strtok(NULL
, "\t\n");
206 if (!strcasecmp(key
, "machine") ||
207 !strcasecmp(key
, "hardware"))
209 blobmsg_add_string(&b
, "model", val
+ 2);
217 if ((f
= fopen("/tmp/sysinfo/board_name", "r")) != NULL
)
219 if (fgets(line
, sizeof(line
), f
))
221 val
= strtok(line
, "\t\n");
224 blobmsg_add_string(&b
, "board_name", val
);
229 else if ((f
= fopen("/proc/device-tree/compatible", "r")) != NULL
)
231 if (fgets(line
, sizeof(line
), f
))
233 val
= strtok(line
, "\t\n");
238 while ((next
= strchr(next
, ',')) != NULL
)
244 blobmsg_add_string(&b
, "board_name", val
);
252 blobmsg_add_string(&b
, "rootfs_type", rootfs_type
);
254 if ((f
= fopen("/etc/openwrt_release", "r")) != NULL
)
256 c
= blobmsg_open_table(&b
, "release");
258 while (fgets(line
, sizeof(line
), f
))
264 val
= strchr(line
, '=');
270 if (!strcasecmp(key
, "DISTRIB_ID"))
271 key
= "distribution";
272 else if (!strcasecmp(key
, "DISTRIB_RELEASE"))
274 else if (!strcasecmp(key
, "DISTRIB_REVISION"))
276 else if (!strcasecmp(key
, "DISTRIB_CODENAME"))
278 else if (!strcasecmp(key
, "DISTRIB_TARGET"))
280 else if (!strcasecmp(key
, "DISTRIB_DESCRIPTION"))
285 dest
= blobmsg_alloc_string_buffer(&b
, key
, strlen(val
));
287 ERROR("Failed to allocate blob.\n");
291 while (val
&& (ch
= *(val
++)) != 0) {
295 next
= strchr(val
, ch
);
304 dest
+= strlen(dest
);
307 *(dest
++) = *(val
++);
311 blobmsg_add_string_buffer(&b
);
314 blobmsg_close_array(&b
, c
);
319 ubus_send_reply(ctx
, req
, b
.head
);
321 return UBUS_STATUS_OK
;
325 kscale(unsigned long b
, unsigned long bs
)
327 return (b
* (unsigned long long) bs
+ 1024/2) / 1024;
330 static int system_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
331 struct ubus_request_data
*req
, const char *method
,
332 struct blob_attr
*msg
)
341 unsigned long long available
, cached
;
345 const char *fslist
[] = {
351 return UBUS_STATUS_UNKNOWN_ERROR
;
353 if ((f
= fopen("/proc/meminfo", "r")) == NULL
)
354 return UBUS_STATUS_UNKNOWN_ERROR
;
356 /* if linux < 3.14 MemAvailable is not in meminfo */
360 while (fgets(line
, sizeof(line
), f
))
362 key
= strtok(line
, " :");
363 val
= strtok(NULL
, " ");
368 if (!strcasecmp(key
, "MemAvailable"))
369 available
= 1024 * atoll(val
);
370 else if (!strcasecmp(key
, "Cached"))
371 cached
= 1024 * atoll(val
);
379 if (!(tm
= localtime(&now
)))
380 return UBUS_STATUS_UNKNOWN_ERROR
;
382 blob_buf_init(&b
, 0);
384 blobmsg_add_u32(&b
, "localtime", now
+ tm
->tm_gmtoff
);
387 blobmsg_add_u32(&b
, "uptime", info
.uptime
);
389 c
= blobmsg_open_array(&b
, "load");
390 blobmsg_add_u32(&b
, NULL
, info
.loads
[0]);
391 blobmsg_add_u32(&b
, NULL
, info
.loads
[1]);
392 blobmsg_add_u32(&b
, NULL
, info
.loads
[2]);
393 blobmsg_close_array(&b
, c
);
395 c
= blobmsg_open_table(&b
, "memory");
396 blobmsg_add_u64(&b
, "total",
397 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalram
);
398 blobmsg_add_u64(&b
, "free",
399 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeram
);
400 blobmsg_add_u64(&b
, "shared",
401 (uint64_t)info
.mem_unit
* (uint64_t)info
.sharedram
);
402 blobmsg_add_u64(&b
, "buffered",
403 (uint64_t)info
.mem_unit
* (uint64_t)info
.bufferram
);
404 blobmsg_add_u64(&b
, "available", available
);
405 blobmsg_add_u64(&b
, "cached", cached
);
406 blobmsg_close_table(&b
, c
);
408 for (i
= 0; i
< sizeof(fslist
) / sizeof(fslist
[0]); i
+= 2) {
409 if (statvfs(fslist
[i
], &s
))
412 c
= blobmsg_open_table(&b
, fslist
[i
+1]);
415 s
.f_frsize
= s
.f_bsize
;
417 blobmsg_add_u64(&b
, "total", kscale(s
.f_blocks
, s
.f_frsize
));
418 blobmsg_add_u64(&b
, "free", kscale(s
.f_bfree
, s
.f_frsize
));
419 blobmsg_add_u64(&b
, "used", kscale(s
.f_blocks
- s
.f_bfree
, s
.f_frsize
));
420 blobmsg_add_u64(&b
, "avail", kscale(s
.f_bavail
, s
.f_frsize
));
422 blobmsg_close_table(&b
, c
);
425 c
= blobmsg_open_table(&b
, "swap");
426 blobmsg_add_u64(&b
, "total",
427 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalswap
);
428 blobmsg_add_u64(&b
, "free",
429 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeswap
);
430 blobmsg_close_table(&b
, c
);
433 ubus_send_reply(ctx
, req
, b
.head
);
435 return UBUS_STATUS_OK
;
438 static int system_reboot(struct ubus_context
*ctx
, struct ubus_object
*obj
,
439 struct ubus_request_data
*req
, const char *method
,
440 struct blob_attr
*msg
)
442 procd_shutdown(RB_AUTOBOOT
);
454 static const struct blobmsg_policy watchdog_policy
[__WDT_MAX
] = {
455 [WDT_FREQUENCY
] = { .name
= "frequency", .type
= BLOBMSG_TYPE_INT32
},
456 [WDT_TIMEOUT
] = { .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
},
457 [WDT_MAGICCLOSE
] = { .name
= "magicclose", .type
= BLOBMSG_TYPE_BOOL
},
458 [WDT_STOP
] = { .name
= "stop", .type
= BLOBMSG_TYPE_BOOL
},
461 static int watchdog_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
462 struct ubus_request_data
*req
, const char *method
,
463 struct blob_attr
*msg
)
465 struct blob_attr
*tb
[__WDT_MAX
];
469 return UBUS_STATUS_INVALID_ARGUMENT
;
471 blobmsg_parse(watchdog_policy
, __WDT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
472 if (tb
[WDT_FREQUENCY
]) {
473 unsigned int timeout
= tb
[WDT_TIMEOUT
] ? blobmsg_get_u32(tb
[WDT_TIMEOUT
]) :
475 unsigned int freq
= blobmsg_get_u32(tb
[WDT_FREQUENCY
]);
478 if (freq
> timeout
/ 2)
480 watchdog_frequency(freq
);
484 if (tb
[WDT_TIMEOUT
]) {
485 unsigned int timeout
= blobmsg_get_u32(tb
[WDT_TIMEOUT
]);
486 unsigned int frequency
= watchdog_frequency(0);
488 if (timeout
<= frequency
)
489 timeout
= frequency
* 2;
490 watchdog_timeout(timeout
);
493 if (tb
[WDT_MAGICCLOSE
])
494 watchdog_set_magicclose(blobmsg_get_bool(tb
[WDT_MAGICCLOSE
]));
497 watchdog_set_stopped(blobmsg_get_bool(tb
[WDT_STOP
]));
499 if (watchdog_fd() == NULL
)
501 else if (watchdog_get_stopped())
506 blob_buf_init(&b
, 0);
507 blobmsg_add_string(&b
, "status", status
);
508 blobmsg_add_u32(&b
, "timeout", watchdog_timeout(0));
509 blobmsg_add_u32(&b
, "frequency", watchdog_frequency(0));
510 blobmsg_add_u8(&b
, "magicclose", watchdog_get_magicclose());
511 ubus_send_reply(ctx
, req
, b
.head
);
522 static const struct blobmsg_policy signal_policy
[__SIGNAL_MAX
] = {
523 [SIGNAL_PID
] = { .name
= "pid", .type
= BLOBMSG_TYPE_INT32
},
524 [SIGNAL_NUM
] = { .name
= "signum", .type
= BLOBMSG_TYPE_INT32
},
527 static int proc_signal(struct ubus_context
*ctx
, struct ubus_object
*obj
,
528 struct ubus_request_data
*req
, const char *method
,
529 struct blob_attr
*msg
)
531 struct blob_attr
*tb
[__SIGNAL_MAX
];
534 return UBUS_STATUS_INVALID_ARGUMENT
;
536 blobmsg_parse(signal_policy
, __SIGNAL_MAX
, tb
, blob_data(msg
), blob_len(msg
));
537 if (!tb
[SIGNAL_PID
|| !tb
[SIGNAL_NUM
]])
538 return UBUS_STATUS_INVALID_ARGUMENT
;
540 kill(blobmsg_get_u32(tb
[SIGNAL_PID
]), blobmsg_get_u32(tb
[SIGNAL_NUM
]));
545 __attribute__((format (printf
, 2, 3)))
546 static enum vjson_state
vjson_error(char **b
, const char *fmt
, ...)
548 static char buf
[256] = { 0 };
549 const char *pfx
= "Firmware image couldn't be validated: ";
553 r
= snprintf(buf
, sizeof(buf
), "%s", pfx
);
555 *b
= "vjson_error() snprintf failed";
560 r
= vsnprintf(buf
+r
, sizeof(buf
)-r
, fmt
, va
);
562 *b
= "vjson_error() vsnprintf failed";
571 static enum vjson_state
vjson_parse_token(json_tokener
*tok
, char *buf
, ssize_t len
, char **err
)
573 json_object
*jsobj
= NULL
;
575 jsobj
= json_tokener_parse_ex(tok
, buf
, len
);
576 if (json_tokener_get_error(tok
) == json_tokener_continue
)
577 return VJSON_CONTINUE
;
579 if (json_tokener_get_error(tok
) == json_tokener_success
) {
580 if (json_object_get_type(jsobj
) != json_type_object
) {
581 json_object_put(jsobj
);
582 return vjson_error(err
, "result is not an JSON object");
585 blobmsg_add_object(&b
, jsobj
);
586 json_object_put(jsobj
);
587 return VJSON_SUCCESS
;
590 return vjson_error(err
, "failed to parse JSON: %s (%d)",
591 json_tokener_error_desc(json_tokener_get_error(tok
)),
592 json_tokener_get_error(tok
));
595 static enum vjson_state
vjson_parse(int fd
, char **err
)
597 enum vjson_state r
= VJSON_ERROR
;
598 size_t read_count
= 0;
599 char buf
[64] = { 0 };
604 tok
= json_tokener_new();
606 return vjson_error(err
, "json_tokener_new() failed");
608 vjson_error(err
, "incomplete JSON input");
610 while ((len
= read(fd
, buf
, sizeof(buf
)))) {
611 if (len
< 0 && errno
== EINTR
)
616 json_tokener_free(tok
);
617 return vjson_error(err
, "read() failed: %s (%d)",
618 strerror(_errno
), _errno
);
622 r
= vjson_parse_token(tok
, buf
, len
, err
);
623 if (r
!= VJSON_CONTINUE
)
626 memset(buf
, 0, sizeof(buf
));
630 vjson_error(err
, "no JSON input");
632 json_tokener_free(tok
);
637 * validate_firmware_image_call - perform validation & store result in global b
639 * @file: firmware image path
641 static enum vjson_state
validate_firmware_image_call(const char *file
, char **err
)
643 const char *path
= "/usr/libexec/validate_firmware_image";
644 enum vjson_state ret
= VJSON_ERROR
;
649 blob_buf_init(&b
, 0);
650 vjson_error(err
, "unhandled error");
654 return vjson_error(err
, "pipe() failed: %s (%d)",
655 strerror(_errno
), _errno
);
665 return vjson_error(err
, "fork() failed: %s (%d)",
666 strerror(_errno
), _errno
);
668 /* Set stdin & stderr to /dev/null */
669 fd
= open("/dev/null", O_RDWR
);
676 /* Set stdout to the shared pipe */
681 execl(path
, path
, file
, NULL
);
688 ret
= vjson_parse(fds
[0], err
);
695 VALIDATE_FIRMWARE_IMAGE_PATH
,
696 __VALIDATE_FIRMWARE_IMAGE_MAX
,
699 static const struct blobmsg_policy validate_firmware_image_policy
[__VALIDATE_FIRMWARE_IMAGE_MAX
] = {
700 [VALIDATE_FIRMWARE_IMAGE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
703 static int validate_firmware_image(struct ubus_context
*ctx
,
704 struct ubus_object
*obj
,
705 struct ubus_request_data
*req
,
706 const char *method
, struct blob_attr
*msg
)
708 struct blob_attr
*tb
[__VALIDATE_FIRMWARE_IMAGE_MAX
];
709 enum vjson_state ret
= VJSON_ERROR
;
713 return UBUS_STATUS_INVALID_ARGUMENT
;
715 blobmsg_parse(validate_firmware_image_policy
, __VALIDATE_FIRMWARE_IMAGE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
716 if (!tb
[VALIDATE_FIRMWARE_IMAGE_PATH
])
717 return UBUS_STATUS_INVALID_ARGUMENT
;
719 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[VALIDATE_FIRMWARE_IMAGE_PATH
]), &err
);
720 if (ret
!= VJSON_SUCCESS
)
721 return UBUS_STATUS_UNKNOWN_ERROR
;
723 ubus_send_reply(ctx
, req
, b
.head
);
725 return UBUS_STATUS_OK
;
738 static const struct blobmsg_policy sysupgrade_policy
[__SYSUPGRADE_MAX
] = {
739 [SYSUPGRADE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
740 [SYSUPGRADE_FORCE
] = { .name
= "force", .type
= BLOBMSG_TYPE_BOOL
},
741 [SYSUPGRADE_BACKUP
] = { .name
= "backup", .type
= BLOBMSG_TYPE_STRING
},
742 [SYSUPGRADE_PREFIX
] = { .name
= "prefix", .type
= BLOBMSG_TYPE_STRING
},
743 [SYSUPGRADE_COMMAND
] = { .name
= "command", .type
= BLOBMSG_TYPE_STRING
},
744 [SYSUPGRADE_OPTIONS
] = { .name
= "options", .type
= BLOBMSG_TYPE_TABLE
},
747 static void sysupgrade_error(struct ubus_context
*ctx
,
748 struct ubus_request_data
*req
,
753 blob_buf_init(&b
, 0);
755 c
= blobmsg_open_table(&b
, "error");
756 blobmsg_add_string(&b
, "message", message
);
757 blobmsg_close_table(&b
, c
);
759 ubus_send_reply(ctx
, req
, b
.head
);
762 static int sysupgrade(struct ubus_context
*ctx
, struct ubus_object
*obj
,
763 struct ubus_request_data
*req
, const char *method
,
764 struct blob_attr
*msg
)
768 VALIDATION_FORCEABLE
,
769 VALIDATION_ALLOW_BACKUP
,
772 static const struct blobmsg_policy validation_policy
[__VALIDATION_MAX
] = {
773 [VALIDATION_VALID
] = { .name
= "valid", .type
= BLOBMSG_TYPE_BOOL
},
774 [VALIDATION_FORCEABLE
] = { .name
= "forceable", .type
= BLOBMSG_TYPE_BOOL
},
775 [VALIDATION_ALLOW_BACKUP
] = { .name
= "allow_backup", .type
= BLOBMSG_TYPE_BOOL
},
777 struct blob_attr
*validation
[__VALIDATION_MAX
];
778 struct blob_attr
*tb
[__SYSUPGRADE_MAX
];
779 bool valid
, forceable
, allow_backup
;
780 enum vjson_state ret
= VJSON_ERROR
;
784 return UBUS_STATUS_INVALID_ARGUMENT
;
786 blobmsg_parse(sysupgrade_policy
, __SYSUPGRADE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
787 if (!tb
[SYSUPGRADE_PATH
] || !tb
[SYSUPGRADE_PREFIX
])
788 return UBUS_STATUS_INVALID_ARGUMENT
;
790 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[SYSUPGRADE_PATH
]), &err
);
791 if (ret
!= VJSON_SUCCESS
) {
792 sysupgrade_error(ctx
, req
, err
);
793 return UBUS_STATUS_UNKNOWN_ERROR
;
796 blobmsg_parse(validation_policy
, __VALIDATION_MAX
, validation
, blob_data(b
.head
), blob_len(b
.head
));
798 if (!validation
[VALIDATION_VALID
] || !validation
[VALIDATION_FORCEABLE
] ||
799 !validation
[VALIDATION_ALLOW_BACKUP
]) {
800 sysupgrade_error(ctx
, req
, "Validation script provided invalid input");
801 return UBUS_STATUS_INVALID_ARGUMENT
;
804 valid
= validation
[VALIDATION_VALID
] && blobmsg_get_bool(validation
[VALIDATION_VALID
]);
805 forceable
= validation
[VALIDATION_FORCEABLE
] && blobmsg_get_bool(validation
[VALIDATION_FORCEABLE
]);
806 allow_backup
= validation
[VALIDATION_ALLOW_BACKUP
] && blobmsg_get_bool(validation
[VALIDATION_ALLOW_BACKUP
]);
810 sysupgrade_error(ctx
, req
, "Firmware image is broken and cannot be installed");
811 return UBUS_STATUS_NOT_SUPPORTED
;
812 } else if (!tb
[SYSUPGRADE_FORCE
] || !blobmsg_get_bool(tb
[SYSUPGRADE_FORCE
])) {
813 sysupgrade_error(ctx
, req
, "Firmware image is invalid");
814 return UBUS_STATUS_NOT_SUPPORTED
;
816 } else if (!allow_backup
&& tb
[SYSUPGRADE_BACKUP
]) {
817 sysupgrade_error(ctx
, req
, "Firmware image doesn't allow preserving a backup");
818 return UBUS_STATUS_NOT_SUPPORTED
;
823 sysupgrade_exec_upgraded(blobmsg_get_string(tb
[SYSUPGRADE_PREFIX
]),
824 blobmsg_get_string(tb
[SYSUPGRADE_PATH
]),
825 tb
[SYSUPGRADE_BACKUP
] ? blobmsg_get_string(tb
[SYSUPGRADE_BACKUP
]) : NULL
,
826 tb
[SYSUPGRADE_COMMAND
] ? blobmsg_get_string(tb
[SYSUPGRADE_COMMAND
]) : NULL
,
827 tb
[SYSUPGRADE_OPTIONS
]);
829 /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
830 return UBUS_STATUS_UNKNOWN_ERROR
;
834 procd_subscribe_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
)
836 notify
= obj
->has_subscribers
;
840 static const struct ubus_method system_methods
[] = {
841 UBUS_METHOD_NOARG("board", system_board
),
842 UBUS_METHOD_NOARG("info", system_info
),
843 UBUS_METHOD_NOARG("reboot", system_reboot
),
844 UBUS_METHOD("watchdog", watchdog_set
, watchdog_policy
),
845 UBUS_METHOD("signal", proc_signal
, signal_policy
),
846 UBUS_METHOD("validate_firmware_image", validate_firmware_image
, validate_firmware_image_policy
),
847 UBUS_METHOD("sysupgrade", sysupgrade
, sysupgrade_policy
),
850 static struct ubus_object_type system_object_type
=
851 UBUS_OBJECT_TYPE("system", system_methods
);
853 static struct ubus_object system_object
= {
855 .type
= &system_object_type
,
856 .methods
= system_methods
,
857 .n_methods
= ARRAY_SIZE(system_methods
),
858 .subscribe_cb
= procd_subscribe_cb
,
862 procd_bcast_event(char *event
, struct blob_attr
*msg
)
869 ret
= ubus_notify(_ctx
, &system_object
, event
, msg
, -1);
871 fprintf(stderr
, "Failed to notify log: %s\n", ubus_strerror(ret
));
874 void ubus_init_system(struct ubus_context
*ctx
)
880 initramfs
= !!getenv("INITRAMFS");
882 unsetenv("INITRAMFS");
884 ret
= ubus_add_object(ctx
, &system_object
);
886 ERROR("Failed to add object: %s\n", ubus_strerror(ret
));