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"
37 static struct blob_buf b
;
39 static struct ubus_context
*_ctx
;
48 static const char *system_rootfs_type(void) {
49 const char proc_mounts
[] = "/proc/self/mounts";
50 static char fstype
[16] = { 0 };
51 char *mountstr
= NULL
, *mp
= "/", *pos
, *tmp
;
63 mounts
= fopen(proc_mounts
, "r");
67 while ((nread
= getline(&mountstr
, &len
, mounts
)) != -1) {
70 pos
= strchr(mountstr
, ' ');
75 pos
= strchr(tmp
, ' ');
84 pos
= strchr(tmp
, ' ');
90 if (!strcmp(tmp
, "overlay")) {
92 * there is no point in parsing overlay option string for
93 * lowerdir, as that can point to "/" being a previous
94 * overlay mount (after firstboot or sysuprade config
95 * restore). Hence just assume the lowerdir is "/rom" and
96 * restart searching for that instead.
99 fseek(mounts
, 0, SEEK_SET
);
108 strncpy(fstype
, tmp
, sizeof(fstype
) - 1);
110 fstype
[sizeof(fstype
) - 1]= '\0';
120 static int system_board(struct ubus_context
*ctx
, struct ubus_object
*obj
,
121 struct ubus_request_data
*req
, const char *method
,
122 struct blob_attr
*msg
)
126 char *key
, *val
, *next
;
127 const char *rootfs_type
= system_rootfs_type();
128 struct utsname utsname
;
131 blob_buf_init(&b
, 0);
133 if (uname(&utsname
) >= 0)
135 blobmsg_add_string(&b
, "kernel", utsname
.release
);
136 blobmsg_add_string(&b
, "hostname", utsname
.nodename
);
139 if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
141 while(fgets(line
, sizeof(line
), f
))
143 key
= strtok(line
, "\t:");
144 val
= strtok(NULL
, "\t\n");
150 if (!strcasecmp(key
, "CPU revision")) {
151 snprintf(line
, sizeof(line
), "ARMv8 Processor rev %lu", strtoul(val
+ 2, NULL
, 16));
152 blobmsg_add_string(&b
, "system", line
);
156 if (!strcasecmp(key
, "system type") ||
157 !strcasecmp(key
, "processor") ||
158 !strcasecmp(key
, "cpu") ||
159 !strcasecmp(key
, "model name"))
161 strtoul(val
+ 2, &key
, 0);
163 if (key
== (val
+ 2) || *key
!= 0)
165 blobmsg_add_string(&b
, "system", val
+ 2);
175 if ((f
= fopen("/tmp/sysinfo/model", "r")) != NULL
||
176 (f
= fopen("/proc/device-tree/model", "r")) != NULL
)
178 if (fgets(line
, sizeof(line
), f
))
180 val
= strtok(line
, "\t\n");
183 blobmsg_add_string(&b
, "model", val
);
188 else if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
190 while(fgets(line
, sizeof(line
), f
))
192 key
= strtok(line
, "\t:");
193 val
= strtok(NULL
, "\t\n");
198 if (!strcasecmp(key
, "machine") ||
199 !strcasecmp(key
, "hardware"))
201 blobmsg_add_string(&b
, "model", val
+ 2);
209 if ((f
= fopen("/tmp/sysinfo/board_name", "r")) != NULL
)
211 if (fgets(line
, sizeof(line
), f
))
213 val
= strtok(line
, "\t\n");
216 blobmsg_add_string(&b
, "board_name", val
);
221 else if ((f
= fopen("/proc/device-tree/compatible", "r")) != NULL
)
223 if (fgets(line
, sizeof(line
), f
))
225 val
= strtok(line
, "\t\n");
230 while ((next
= strchr(next
, ',')) != NULL
)
236 blobmsg_add_string(&b
, "board_name", val
);
244 blobmsg_add_string(&b
, "rootfs_type", rootfs_type
);
246 if ((f
= fopen("/etc/openwrt_release", "r")) != NULL
)
248 c
= blobmsg_open_table(&b
, "release");
250 while (fgets(line
, sizeof(line
), f
))
256 val
= strchr(line
, '=');
262 if (!strcasecmp(key
, "DISTRIB_ID"))
263 key
= "distribution";
264 else if (!strcasecmp(key
, "DISTRIB_RELEASE"))
266 else if (!strcasecmp(key
, "DISTRIB_REVISION"))
268 else if (!strcasecmp(key
, "DISTRIB_CODENAME"))
270 else if (!strcasecmp(key
, "DISTRIB_TARGET"))
272 else if (!strcasecmp(key
, "DISTRIB_DESCRIPTION"))
277 dest
= blobmsg_alloc_string_buffer(&b
, key
, strlen(val
));
279 ERROR("Failed to allocate blob.\n");
283 while (val
&& (ch
= *(val
++)) != 0) {
287 next
= strchr(val
, ch
);
296 dest
+= strlen(dest
);
299 *(dest
++) = *(val
++);
303 blobmsg_add_string_buffer(&b
);
306 blobmsg_close_array(&b
, c
);
311 ubus_send_reply(ctx
, req
, b
.head
);
313 return UBUS_STATUS_OK
;
317 kscale(unsigned long b
, unsigned long bs
)
319 return (b
* (unsigned long long) bs
+ 1024/2) / 1024;
322 static int system_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
323 struct ubus_request_data
*req
, const char *method
,
324 struct blob_attr
*msg
)
333 unsigned long long available
, cached
;
337 const char *fslist
[] = {
343 return UBUS_STATUS_UNKNOWN_ERROR
;
345 if ((f
= fopen("/proc/meminfo", "r")) == NULL
)
346 return UBUS_STATUS_UNKNOWN_ERROR
;
348 /* if linux < 3.14 MemAvailable is not in meminfo */
352 while (fgets(line
, sizeof(line
), f
))
354 key
= strtok(line
, " :");
355 val
= strtok(NULL
, " ");
360 if (!strcasecmp(key
, "MemAvailable"))
361 available
= 1024 * atoll(val
);
362 else if (!strcasecmp(key
, "Cached"))
363 cached
= 1024 * atoll(val
);
371 if (!(tm
= localtime(&now
)))
372 return UBUS_STATUS_UNKNOWN_ERROR
;
374 blob_buf_init(&b
, 0);
376 blobmsg_add_u32(&b
, "localtime", now
+ tm
->tm_gmtoff
);
379 blobmsg_add_u32(&b
, "uptime", info
.uptime
);
381 c
= blobmsg_open_array(&b
, "load");
382 blobmsg_add_u32(&b
, NULL
, info
.loads
[0]);
383 blobmsg_add_u32(&b
, NULL
, info
.loads
[1]);
384 blobmsg_add_u32(&b
, NULL
, info
.loads
[2]);
385 blobmsg_close_array(&b
, c
);
387 c
= blobmsg_open_table(&b
, "memory");
388 blobmsg_add_u64(&b
, "total",
389 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalram
);
390 blobmsg_add_u64(&b
, "free",
391 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeram
);
392 blobmsg_add_u64(&b
, "shared",
393 (uint64_t)info
.mem_unit
* (uint64_t)info
.sharedram
);
394 blobmsg_add_u64(&b
, "buffered",
395 (uint64_t)info
.mem_unit
* (uint64_t)info
.bufferram
);
396 blobmsg_add_u64(&b
, "available", available
);
397 blobmsg_add_u64(&b
, "cached", cached
);
398 blobmsg_close_table(&b
, c
);
400 for (i
= 0; i
< sizeof(fslist
) / sizeof(fslist
[0]); i
+= 2) {
401 if (statvfs(fslist
[i
], &s
))
404 c
= blobmsg_open_table(&b
, fslist
[i
+1]);
407 s
.f_frsize
= s
.f_bsize
;
409 blobmsg_add_u64(&b
, "total", kscale(s
.f_blocks
, s
.f_frsize
));
410 blobmsg_add_u64(&b
, "free", kscale(s
.f_bfree
, s
.f_frsize
));
411 blobmsg_add_u64(&b
, "used", kscale(s
.f_blocks
- s
.f_bfree
, s
.f_frsize
));
412 blobmsg_add_u64(&b
, "avail", kscale(s
.f_bavail
, s
.f_frsize
));
414 blobmsg_close_table(&b
, c
);
417 c
= blobmsg_open_table(&b
, "swap");
418 blobmsg_add_u64(&b
, "total",
419 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalswap
);
420 blobmsg_add_u64(&b
, "free",
421 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeswap
);
422 blobmsg_close_table(&b
, c
);
425 ubus_send_reply(ctx
, req
, b
.head
);
427 return UBUS_STATUS_OK
;
430 static int system_reboot(struct ubus_context
*ctx
, struct ubus_object
*obj
,
431 struct ubus_request_data
*req
, const char *method
,
432 struct blob_attr
*msg
)
434 procd_shutdown(RB_AUTOBOOT
);
446 static const struct blobmsg_policy watchdog_policy
[__WDT_MAX
] = {
447 [WDT_FREQUENCY
] = { .name
= "frequency", .type
= BLOBMSG_TYPE_INT32
},
448 [WDT_TIMEOUT
] = { .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
},
449 [WDT_MAGICCLOSE
] = { .name
= "magicclose", .type
= BLOBMSG_TYPE_BOOL
},
450 [WDT_STOP
] = { .name
= "stop", .type
= BLOBMSG_TYPE_BOOL
},
453 static int watchdog_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
454 struct ubus_request_data
*req
, const char *method
,
455 struct blob_attr
*msg
)
457 struct blob_attr
*tb
[__WDT_MAX
];
461 return UBUS_STATUS_INVALID_ARGUMENT
;
463 blobmsg_parse(watchdog_policy
, __WDT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
464 if (tb
[WDT_FREQUENCY
]) {
465 unsigned int timeout
= tb
[WDT_TIMEOUT
] ? blobmsg_get_u32(tb
[WDT_TIMEOUT
]) :
467 unsigned int freq
= blobmsg_get_u32(tb
[WDT_FREQUENCY
]);
470 if (freq
> timeout
/ 2)
472 watchdog_frequency(freq
);
476 if (tb
[WDT_TIMEOUT
]) {
477 unsigned int timeout
= blobmsg_get_u32(tb
[WDT_TIMEOUT
]);
478 unsigned int frequency
= watchdog_frequency(0);
480 if (timeout
<= frequency
)
481 timeout
= frequency
* 2;
482 watchdog_timeout(timeout
);
485 if (tb
[WDT_MAGICCLOSE
])
486 watchdog_set_magicclose(blobmsg_get_bool(tb
[WDT_MAGICCLOSE
]));
489 watchdog_set_stopped(blobmsg_get_bool(tb
[WDT_STOP
]));
491 if (watchdog_fd() == NULL
)
493 else if (watchdog_get_stopped())
498 blob_buf_init(&b
, 0);
499 blobmsg_add_string(&b
, "status", status
);
500 blobmsg_add_u32(&b
, "timeout", watchdog_timeout(0));
501 blobmsg_add_u32(&b
, "frequency", watchdog_frequency(0));
502 blobmsg_add_u8(&b
, "magicclose", watchdog_get_magicclose());
503 ubus_send_reply(ctx
, req
, b
.head
);
514 static const struct blobmsg_policy signal_policy
[__SIGNAL_MAX
] = {
515 [SIGNAL_PID
] = { .name
= "pid", .type
= BLOBMSG_TYPE_INT32
},
516 [SIGNAL_NUM
] = { .name
= "signum", .type
= BLOBMSG_TYPE_INT32
},
519 static int proc_signal(struct ubus_context
*ctx
, struct ubus_object
*obj
,
520 struct ubus_request_data
*req
, const char *method
,
521 struct blob_attr
*msg
)
523 struct blob_attr
*tb
[__SIGNAL_MAX
];
526 return UBUS_STATUS_INVALID_ARGUMENT
;
528 blobmsg_parse(signal_policy
, __SIGNAL_MAX
, tb
, blob_data(msg
), blob_len(msg
));
529 if (!tb
[SIGNAL_PID
|| !tb
[SIGNAL_NUM
]])
530 return UBUS_STATUS_INVALID_ARGUMENT
;
532 kill(blobmsg_get_u32(tb
[SIGNAL_PID
]), blobmsg_get_u32(tb
[SIGNAL_NUM
]));
537 __attribute__((format (printf
, 2, 3)))
538 static enum vjson_state
vjson_error(char **b
, const char *fmt
, ...)
540 static char buf
[256] = { 0 };
541 const char *pfx
= "Firmware image couldn't be validated: ";
545 r
= snprintf(buf
, sizeof(buf
), "%s", pfx
);
547 *b
= "vjson_error() snprintf failed";
552 r
= vsnprintf(buf
+r
, sizeof(buf
)-r
, fmt
, va
);
554 *b
= "vjson_error() vsnprintf failed";
563 static enum vjson_state
vjson_parse_token(json_tokener
*tok
, char *buf
, ssize_t len
, char **err
)
565 json_object
*jsobj
= NULL
;
567 jsobj
= json_tokener_parse_ex(tok
, buf
, len
);
568 if (json_tokener_get_error(tok
) == json_tokener_continue
)
569 return VJSON_CONTINUE
;
571 if (json_tokener_get_error(tok
) == json_tokener_success
) {
572 if (json_object_get_type(jsobj
) != json_type_object
) {
573 json_object_put(jsobj
);
574 return vjson_error(err
, "result is not an JSON object");
577 blobmsg_add_object(&b
, jsobj
);
578 json_object_put(jsobj
);
579 return VJSON_SUCCESS
;
582 return vjson_error(err
, "failed to parse JSON: %s (%d)",
583 json_tokener_error_desc(json_tokener_get_error(tok
)),
584 json_tokener_get_error(tok
));
587 static enum vjson_state
vjson_parse(int fd
, char **err
)
589 enum vjson_state r
= VJSON_ERROR
;
590 size_t read_count
= 0;
591 char buf
[64] = { 0 };
596 tok
= json_tokener_new();
598 return vjson_error(err
, "json_tokener_new() failed");
600 vjson_error(err
, "incomplete JSON input");
602 while ((len
= read(fd
, buf
, sizeof(buf
)))) {
603 if (len
< 0 && errno
== EINTR
)
608 json_tokener_free(tok
);
609 return vjson_error(err
, "read() failed: %s (%d)",
610 strerror(_errno
), _errno
);
614 r
= vjson_parse_token(tok
, buf
, len
, err
);
615 if (r
!= VJSON_CONTINUE
)
618 memset(buf
, 0, sizeof(buf
));
622 vjson_error(err
, "no JSON input");
624 json_tokener_free(tok
);
629 * validate_firmware_image_call - perform validation & store result in global b
631 * @file: firmware image path
633 static enum vjson_state
validate_firmware_image_call(const char *file
, char **err
)
635 const char *path
= "/usr/libexec/validate_firmware_image";
636 enum vjson_state ret
= VJSON_ERROR
;
641 blob_buf_init(&b
, 0);
642 vjson_error(err
, "unhandled error");
646 return vjson_error(err
, "pipe() failed: %s (%d)",
647 strerror(_errno
), _errno
);
657 return vjson_error(err
, "fork() failed: %s (%d)",
658 strerror(_errno
), _errno
);
660 /* Set stdin & stderr to /dev/null */
661 fd
= open("/dev/null", O_RDWR
);
668 /* Set stdout to the shared pipe */
673 execl(path
, path
, file
, NULL
);
680 ret
= vjson_parse(fds
[0], err
);
687 VALIDATE_FIRMWARE_IMAGE_PATH
,
688 __VALIDATE_FIRMWARE_IMAGE_MAX
,
691 static const struct blobmsg_policy validate_firmware_image_policy
[__VALIDATE_FIRMWARE_IMAGE_MAX
] = {
692 [VALIDATE_FIRMWARE_IMAGE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
695 static int validate_firmware_image(struct ubus_context
*ctx
,
696 struct ubus_object
*obj
,
697 struct ubus_request_data
*req
,
698 const char *method
, struct blob_attr
*msg
)
700 struct blob_attr
*tb
[__VALIDATE_FIRMWARE_IMAGE_MAX
];
701 enum vjson_state ret
= VJSON_ERROR
;
705 return UBUS_STATUS_INVALID_ARGUMENT
;
707 blobmsg_parse(validate_firmware_image_policy
, __VALIDATE_FIRMWARE_IMAGE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
708 if (!tb
[VALIDATE_FIRMWARE_IMAGE_PATH
])
709 return UBUS_STATUS_INVALID_ARGUMENT
;
711 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[VALIDATE_FIRMWARE_IMAGE_PATH
]), &err
);
712 if (ret
!= VJSON_SUCCESS
)
713 return UBUS_STATUS_UNKNOWN_ERROR
;
715 ubus_send_reply(ctx
, req
, b
.head
);
717 return UBUS_STATUS_OK
;
730 static const struct blobmsg_policy sysupgrade_policy
[__SYSUPGRADE_MAX
] = {
731 [SYSUPGRADE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
732 [SYSUPGRADE_FORCE
] = { .name
= "force", .type
= BLOBMSG_TYPE_BOOL
},
733 [SYSUPGRADE_BACKUP
] = { .name
= "backup", .type
= BLOBMSG_TYPE_STRING
},
734 [SYSUPGRADE_PREFIX
] = { .name
= "prefix", .type
= BLOBMSG_TYPE_STRING
},
735 [SYSUPGRADE_COMMAND
] = { .name
= "command", .type
= BLOBMSG_TYPE_STRING
},
736 [SYSUPGRADE_OPTIONS
] = { .name
= "options", .type
= BLOBMSG_TYPE_TABLE
},
739 static void sysupgrade_error(struct ubus_context
*ctx
,
740 struct ubus_request_data
*req
,
745 blob_buf_init(&b
, 0);
747 c
= blobmsg_open_table(&b
, "error");
748 blobmsg_add_string(&b
, "message", message
);
749 blobmsg_close_table(&b
, c
);
751 ubus_send_reply(ctx
, req
, b
.head
);
754 static int sysupgrade(struct ubus_context
*ctx
, struct ubus_object
*obj
,
755 struct ubus_request_data
*req
, const char *method
,
756 struct blob_attr
*msg
)
760 VALIDATION_FORCEABLE
,
761 VALIDATION_ALLOW_BACKUP
,
764 static const struct blobmsg_policy validation_policy
[__VALIDATION_MAX
] = {
765 [VALIDATION_VALID
] = { .name
= "valid", .type
= BLOBMSG_TYPE_BOOL
},
766 [VALIDATION_FORCEABLE
] = { .name
= "forceable", .type
= BLOBMSG_TYPE_BOOL
},
767 [VALIDATION_ALLOW_BACKUP
] = { .name
= "allow_backup", .type
= BLOBMSG_TYPE_BOOL
},
769 struct blob_attr
*validation
[__VALIDATION_MAX
];
770 struct blob_attr
*tb
[__SYSUPGRADE_MAX
];
771 bool valid
, forceable
, allow_backup
;
772 enum vjson_state ret
= VJSON_ERROR
;
776 return UBUS_STATUS_INVALID_ARGUMENT
;
778 blobmsg_parse(sysupgrade_policy
, __SYSUPGRADE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
779 if (!tb
[SYSUPGRADE_PATH
] || !tb
[SYSUPGRADE_PREFIX
])
780 return UBUS_STATUS_INVALID_ARGUMENT
;
782 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[SYSUPGRADE_PATH
]), &err
);
783 if (ret
!= VJSON_SUCCESS
) {
784 sysupgrade_error(ctx
, req
, err
);
785 return UBUS_STATUS_UNKNOWN_ERROR
;
788 blobmsg_parse(validation_policy
, __VALIDATION_MAX
, validation
, blob_data(b
.head
), blob_len(b
.head
));
790 if (!validation
[VALIDATION_VALID
] || !validation
[VALIDATION_FORCEABLE
] ||
791 !validation
[VALIDATION_ALLOW_BACKUP
]) {
792 sysupgrade_error(ctx
, req
, "Validation script provided invalid input");
793 return UBUS_STATUS_INVALID_ARGUMENT
;
796 valid
= validation
[VALIDATION_VALID
] && blobmsg_get_bool(validation
[VALIDATION_VALID
]);
797 forceable
= validation
[VALIDATION_FORCEABLE
] && blobmsg_get_bool(validation
[VALIDATION_FORCEABLE
]);
798 allow_backup
= validation
[VALIDATION_ALLOW_BACKUP
] && blobmsg_get_bool(validation
[VALIDATION_ALLOW_BACKUP
]);
802 sysupgrade_error(ctx
, req
, "Firmware image is broken and cannot be installed");
803 return UBUS_STATUS_NOT_SUPPORTED
;
804 } else if (!tb
[SYSUPGRADE_FORCE
] || !blobmsg_get_bool(tb
[SYSUPGRADE_FORCE
])) {
805 sysupgrade_error(ctx
, req
, "Firmware image is invalid");
806 return UBUS_STATUS_NOT_SUPPORTED
;
808 } else if (!allow_backup
&& tb
[SYSUPGRADE_BACKUP
]) {
809 sysupgrade_error(ctx
, req
, "Firmware image doesn't allow preserving a backup");
810 return UBUS_STATUS_NOT_SUPPORTED
;
813 sysupgrade_exec_upgraded(blobmsg_get_string(tb
[SYSUPGRADE_PREFIX
]),
814 blobmsg_get_string(tb
[SYSUPGRADE_PATH
]),
815 tb
[SYSUPGRADE_BACKUP
] ? blobmsg_get_string(tb
[SYSUPGRADE_BACKUP
]) : NULL
,
816 tb
[SYSUPGRADE_COMMAND
] ? blobmsg_get_string(tb
[SYSUPGRADE_COMMAND
]) : NULL
,
817 tb
[SYSUPGRADE_OPTIONS
]);
819 /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
820 return UBUS_STATUS_UNKNOWN_ERROR
;
824 procd_subscribe_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
)
826 notify
= obj
->has_subscribers
;
830 static const struct ubus_method system_methods
[] = {
831 UBUS_METHOD_NOARG("board", system_board
),
832 UBUS_METHOD_NOARG("info", system_info
),
833 UBUS_METHOD_NOARG("reboot", system_reboot
),
834 UBUS_METHOD("watchdog", watchdog_set
, watchdog_policy
),
835 UBUS_METHOD("signal", proc_signal
, signal_policy
),
836 UBUS_METHOD("validate_firmware_image", validate_firmware_image
, validate_firmware_image_policy
),
837 UBUS_METHOD("sysupgrade", sysupgrade
, sysupgrade_policy
),
840 static struct ubus_object_type system_object_type
=
841 UBUS_OBJECT_TYPE("system", system_methods
);
843 static struct ubus_object system_object
= {
845 .type
= &system_object_type
,
846 .methods
= system_methods
,
847 .n_methods
= ARRAY_SIZE(system_methods
),
848 .subscribe_cb
= procd_subscribe_cb
,
852 procd_bcast_event(char *event
, struct blob_attr
*msg
)
859 ret
= ubus_notify(_ctx
, &system_object
, event
, msg
, -1);
861 fprintf(stderr
, "Failed to notify log: %s\n", ubus_strerror(ret
));
864 void ubus_init_system(struct ubus_context
*ctx
)
870 initramfs
= !!getenv("INITRAMFS");
872 unsetenv("INITRAMFS");
874 ret
= ubus_add_object(ctx
, &system_object
);
876 ERROR("Failed to add object: %s\n", ubus_strerror(ret
));