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
;
64 mounts
= fopen(proc_mounts
, "r");
68 while ((nread
= getline(&mountstr
, &len
, mounts
)) != -1) {
71 pos
= strchr(mountstr
, ' ');
76 pos
= strchr(tmp
, ' ');
85 pos
= strchr(tmp
, ' ');
91 if (!strcmp(tmp
, "overlay")) {
93 * there is no point in parsing overlay option string for
94 * lowerdir, as that can point to "/" being a previous
95 * overlay mount (after firstboot or sysuprade config
96 * restore). Hence just assume the lowerdir is "/rom" and
97 * restart searching for that instead.
100 fseek(mounts
, 0, SEEK_SET
);
109 strncpy(fstype
, tmp
, sizeof(fstype
) - 1);
111 fstype
[sizeof(fstype
) - 1]= '\0';
121 static int system_board(struct ubus_context
*ctx
, struct ubus_object
*obj
,
122 struct ubus_request_data
*req
, const char *method
,
123 struct blob_attr
*msg
)
127 char *key
, *val
, *next
;
128 const char *rootfs_type
= system_rootfs_type();
129 struct utsname utsname
;
132 blob_buf_init(&b
, 0);
134 if (uname(&utsname
) >= 0)
136 blobmsg_add_string(&b
, "kernel", utsname
.release
);
137 blobmsg_add_string(&b
, "hostname", utsname
.nodename
);
140 if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
142 while(fgets(line
, sizeof(line
), f
))
144 key
= strtok(line
, "\t:");
145 val
= strtok(NULL
, "\t\n");
151 if (!strcasecmp(key
, "CPU revision")) {
152 snprintf(line
, sizeof(line
), "ARMv8 Processor rev %lu", strtoul(val
+ 2, NULL
, 16));
153 blobmsg_add_string(&b
, "system", line
);
157 if (!strcasecmp(key
, "system type") ||
158 !strcasecmp(key
, "processor") ||
159 !strcasecmp(key
, "cpu") ||
160 !strcasecmp(key
, "model name"))
162 strtoul(val
+ 2, &key
, 0);
164 if (key
== (val
+ 2) || *key
!= 0)
166 blobmsg_add_string(&b
, "system", val
+ 2);
176 if ((f
= fopen("/tmp/sysinfo/model", "r")) != NULL
||
177 (f
= fopen("/proc/device-tree/model", "r")) != NULL
)
179 if (fgets(line
, sizeof(line
), f
))
181 val
= strtok(line
, "\t\n");
184 blobmsg_add_string(&b
, "model", val
);
189 else if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
191 while(fgets(line
, sizeof(line
), f
))
193 key
= strtok(line
, "\t:");
194 val
= strtok(NULL
, "\t\n");
199 if (!strcasecmp(key
, "machine") ||
200 !strcasecmp(key
, "hardware"))
202 blobmsg_add_string(&b
, "model", val
+ 2);
210 if ((f
= fopen("/tmp/sysinfo/board_name", "r")) != NULL
)
212 if (fgets(line
, sizeof(line
), f
))
214 val
= strtok(line
, "\t\n");
217 blobmsg_add_string(&b
, "board_name", val
);
222 else if ((f
= fopen("/proc/device-tree/compatible", "r")) != NULL
)
224 if (fgets(line
, sizeof(line
), f
))
226 val
= strtok(line
, "\t\n");
231 while ((next
= strchr(next
, ',')) != NULL
)
237 blobmsg_add_string(&b
, "board_name", val
);
245 blobmsg_add_string(&b
, "rootfs_type", rootfs_type
);
247 if ((f
= fopen("/etc/openwrt_release", "r")) != NULL
)
249 c
= blobmsg_open_table(&b
, "release");
251 while (fgets(line
, sizeof(line
), f
))
257 val
= strchr(line
, '=');
263 if (!strcasecmp(key
, "DISTRIB_ID"))
264 key
= "distribution";
265 else if (!strcasecmp(key
, "DISTRIB_RELEASE"))
267 else if (!strcasecmp(key
, "DISTRIB_REVISION"))
269 else if (!strcasecmp(key
, "DISTRIB_CODENAME"))
271 else if (!strcasecmp(key
, "DISTRIB_TARGET"))
273 else if (!strcasecmp(key
, "DISTRIB_DESCRIPTION"))
278 dest
= blobmsg_alloc_string_buffer(&b
, key
, strlen(val
));
280 ERROR("Failed to allocate blob.\n");
284 while (val
&& (ch
= *(val
++)) != 0) {
288 next
= strchr(val
, ch
);
297 dest
+= strlen(dest
);
300 *(dest
++) = *(val
++);
304 blobmsg_add_string_buffer(&b
);
307 blobmsg_close_array(&b
, c
);
312 ubus_send_reply(ctx
, req
, b
.head
);
314 return UBUS_STATUS_OK
;
318 kscale(unsigned long b
, unsigned long bs
)
320 return (b
* (unsigned long long) bs
+ 1024/2) / 1024;
323 static int system_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
324 struct ubus_request_data
*req
, const char *method
,
325 struct blob_attr
*msg
)
334 unsigned long long available
, cached
;
338 const char *fslist
[] = {
344 return UBUS_STATUS_UNKNOWN_ERROR
;
346 if ((f
= fopen("/proc/meminfo", "r")) == NULL
)
347 return UBUS_STATUS_UNKNOWN_ERROR
;
349 /* if linux < 3.14 MemAvailable is not in meminfo */
353 while (fgets(line
, sizeof(line
), f
))
355 key
= strtok(line
, " :");
356 val
= strtok(NULL
, " ");
361 if (!strcasecmp(key
, "MemAvailable"))
362 available
= 1024 * atoll(val
);
363 else if (!strcasecmp(key
, "Cached"))
364 cached
= 1024 * atoll(val
);
372 if (!(tm
= localtime(&now
)))
373 return UBUS_STATUS_UNKNOWN_ERROR
;
375 blob_buf_init(&b
, 0);
377 blobmsg_add_u32(&b
, "localtime", now
+ tm
->tm_gmtoff
);
380 blobmsg_add_u32(&b
, "uptime", info
.uptime
);
382 c
= blobmsg_open_array(&b
, "load");
383 blobmsg_add_u32(&b
, NULL
, info
.loads
[0]);
384 blobmsg_add_u32(&b
, NULL
, info
.loads
[1]);
385 blobmsg_add_u32(&b
, NULL
, info
.loads
[2]);
386 blobmsg_close_array(&b
, c
);
388 c
= blobmsg_open_table(&b
, "memory");
389 blobmsg_add_u64(&b
, "total",
390 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalram
);
391 blobmsg_add_u64(&b
, "free",
392 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeram
);
393 blobmsg_add_u64(&b
, "shared",
394 (uint64_t)info
.mem_unit
* (uint64_t)info
.sharedram
);
395 blobmsg_add_u64(&b
, "buffered",
396 (uint64_t)info
.mem_unit
* (uint64_t)info
.bufferram
);
397 blobmsg_add_u64(&b
, "available", available
);
398 blobmsg_add_u64(&b
, "cached", cached
);
399 blobmsg_close_table(&b
, c
);
401 for (i
= 0; i
< sizeof(fslist
) / sizeof(fslist
[0]); i
+= 2) {
402 if (statvfs(fslist
[i
], &s
))
405 c
= blobmsg_open_table(&b
, fslist
[i
+1]);
408 s
.f_frsize
= s
.f_bsize
;
410 blobmsg_add_u64(&b
, "total", kscale(s
.f_blocks
, s
.f_frsize
));
411 blobmsg_add_u64(&b
, "free", kscale(s
.f_bfree
, s
.f_frsize
));
412 blobmsg_add_u64(&b
, "used", kscale(s
.f_blocks
- s
.f_bfree
, s
.f_frsize
));
413 blobmsg_add_u64(&b
, "avail", kscale(s
.f_bavail
, s
.f_frsize
));
415 blobmsg_close_table(&b
, c
);
418 c
= blobmsg_open_table(&b
, "swap");
419 blobmsg_add_u64(&b
, "total",
420 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalswap
);
421 blobmsg_add_u64(&b
, "free",
422 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeswap
);
423 blobmsg_close_table(&b
, c
);
426 ubus_send_reply(ctx
, req
, b
.head
);
428 return UBUS_STATUS_OK
;
431 static int system_reboot(struct ubus_context
*ctx
, struct ubus_object
*obj
,
432 struct ubus_request_data
*req
, const char *method
,
433 struct blob_attr
*msg
)
435 procd_shutdown(RB_AUTOBOOT
);
447 static const struct blobmsg_policy watchdog_policy
[__WDT_MAX
] = {
448 [WDT_FREQUENCY
] = { .name
= "frequency", .type
= BLOBMSG_TYPE_INT32
},
449 [WDT_TIMEOUT
] = { .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
},
450 [WDT_MAGICCLOSE
] = { .name
= "magicclose", .type
= BLOBMSG_TYPE_BOOL
},
451 [WDT_STOP
] = { .name
= "stop", .type
= BLOBMSG_TYPE_BOOL
},
454 static int watchdog_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
455 struct ubus_request_data
*req
, const char *method
,
456 struct blob_attr
*msg
)
458 struct blob_attr
*tb
[__WDT_MAX
];
462 return UBUS_STATUS_INVALID_ARGUMENT
;
464 blobmsg_parse(watchdog_policy
, __WDT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
465 if (tb
[WDT_FREQUENCY
]) {
466 unsigned int timeout
= tb
[WDT_TIMEOUT
] ? blobmsg_get_u32(tb
[WDT_TIMEOUT
]) :
468 unsigned int freq
= blobmsg_get_u32(tb
[WDT_FREQUENCY
]);
471 if (freq
> timeout
/ 2)
473 watchdog_frequency(freq
);
477 if (tb
[WDT_TIMEOUT
]) {
478 unsigned int timeout
= blobmsg_get_u32(tb
[WDT_TIMEOUT
]);
479 unsigned int frequency
= watchdog_frequency(0);
481 if (timeout
<= frequency
)
482 timeout
= frequency
* 2;
483 watchdog_timeout(timeout
);
486 if (tb
[WDT_MAGICCLOSE
])
487 watchdog_set_magicclose(blobmsg_get_bool(tb
[WDT_MAGICCLOSE
]));
490 watchdog_set_stopped(blobmsg_get_bool(tb
[WDT_STOP
]));
492 if (watchdog_fd() == NULL
)
494 else if (watchdog_get_stopped())
499 blob_buf_init(&b
, 0);
500 blobmsg_add_string(&b
, "status", status
);
501 blobmsg_add_u32(&b
, "timeout", watchdog_timeout(0));
502 blobmsg_add_u32(&b
, "frequency", watchdog_frequency(0));
503 blobmsg_add_u8(&b
, "magicclose", watchdog_get_magicclose());
504 ubus_send_reply(ctx
, req
, b
.head
);
515 static const struct blobmsg_policy signal_policy
[__SIGNAL_MAX
] = {
516 [SIGNAL_PID
] = { .name
= "pid", .type
= BLOBMSG_TYPE_INT32
},
517 [SIGNAL_NUM
] = { .name
= "signum", .type
= BLOBMSG_TYPE_INT32
},
520 static int proc_signal(struct ubus_context
*ctx
, struct ubus_object
*obj
,
521 struct ubus_request_data
*req
, const char *method
,
522 struct blob_attr
*msg
)
524 struct blob_attr
*tb
[__SIGNAL_MAX
];
527 return UBUS_STATUS_INVALID_ARGUMENT
;
529 blobmsg_parse(signal_policy
, __SIGNAL_MAX
, tb
, blob_data(msg
), blob_len(msg
));
530 if (!tb
[SIGNAL_PID
|| !tb
[SIGNAL_NUM
]])
531 return UBUS_STATUS_INVALID_ARGUMENT
;
533 kill(blobmsg_get_u32(tb
[SIGNAL_PID
]), blobmsg_get_u32(tb
[SIGNAL_NUM
]));
538 __attribute__((format (printf
, 2, 3)))
539 static enum vjson_state
vjson_error(char **b
, const char *fmt
, ...)
541 static char buf
[256] = { 0 };
542 const char *pfx
= "Firmware image couldn't be validated: ";
546 r
= snprintf(buf
, sizeof(buf
), "%s", pfx
);
548 *b
= "vjson_error() snprintf failed";
553 r
= vsnprintf(buf
+r
, sizeof(buf
)-r
, fmt
, va
);
555 *b
= "vjson_error() vsnprintf failed";
564 static enum vjson_state
vjson_parse_token(json_tokener
*tok
, char *buf
, ssize_t len
, char **err
)
566 json_object
*jsobj
= NULL
;
568 jsobj
= json_tokener_parse_ex(tok
, buf
, len
);
569 if (json_tokener_get_error(tok
) == json_tokener_continue
)
570 return VJSON_CONTINUE
;
572 if (json_tokener_get_error(tok
) == json_tokener_success
) {
573 if (json_object_get_type(jsobj
) != json_type_object
) {
574 json_object_put(jsobj
);
575 return vjson_error(err
, "result is not an JSON object");
578 blobmsg_add_object(&b
, jsobj
);
579 json_object_put(jsobj
);
580 return VJSON_SUCCESS
;
583 return vjson_error(err
, "failed to parse JSON: %s (%d)",
584 json_tokener_error_desc(json_tokener_get_error(tok
)),
585 json_tokener_get_error(tok
));
588 static enum vjson_state
vjson_parse(int fd
, char **err
)
590 enum vjson_state r
= VJSON_ERROR
;
591 size_t read_count
= 0;
592 char buf
[64] = { 0 };
597 tok
= json_tokener_new();
599 return vjson_error(err
, "json_tokener_new() failed");
601 vjson_error(err
, "incomplete JSON input");
603 while ((len
= read(fd
, buf
, sizeof(buf
)))) {
604 if (len
< 0 && errno
== EINTR
)
609 json_tokener_free(tok
);
610 return vjson_error(err
, "read() failed: %s (%d)",
611 strerror(_errno
), _errno
);
615 r
= vjson_parse_token(tok
, buf
, len
, err
);
616 if (r
!= VJSON_CONTINUE
)
619 memset(buf
, 0, sizeof(buf
));
623 vjson_error(err
, "no JSON input");
625 json_tokener_free(tok
);
630 * validate_firmware_image_call - perform validation & store result in global b
632 * @file: firmware image path
634 static enum vjson_state
validate_firmware_image_call(const char *file
, char **err
)
636 const char *path
= "/usr/libexec/validate_firmware_image";
637 enum vjson_state ret
= VJSON_ERROR
;
642 blob_buf_init(&b
, 0);
643 vjson_error(err
, "unhandled error");
647 return vjson_error(err
, "pipe() failed: %s (%d)",
648 strerror(_errno
), _errno
);
658 return vjson_error(err
, "fork() failed: %s (%d)",
659 strerror(_errno
), _errno
);
661 /* Set stdin & stderr to /dev/null */
662 fd
= open("/dev/null", O_RDWR
);
669 /* Set stdout to the shared pipe */
674 execl(path
, path
, file
, NULL
);
681 ret
= vjson_parse(fds
[0], err
);
688 VALIDATE_FIRMWARE_IMAGE_PATH
,
689 __VALIDATE_FIRMWARE_IMAGE_MAX
,
692 static const struct blobmsg_policy validate_firmware_image_policy
[__VALIDATE_FIRMWARE_IMAGE_MAX
] = {
693 [VALIDATE_FIRMWARE_IMAGE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
696 static int validate_firmware_image(struct ubus_context
*ctx
,
697 struct ubus_object
*obj
,
698 struct ubus_request_data
*req
,
699 const char *method
, struct blob_attr
*msg
)
701 struct blob_attr
*tb
[__VALIDATE_FIRMWARE_IMAGE_MAX
];
702 enum vjson_state ret
= VJSON_ERROR
;
706 return UBUS_STATUS_INVALID_ARGUMENT
;
708 blobmsg_parse(validate_firmware_image_policy
, __VALIDATE_FIRMWARE_IMAGE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
709 if (!tb
[VALIDATE_FIRMWARE_IMAGE_PATH
])
710 return UBUS_STATUS_INVALID_ARGUMENT
;
712 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[VALIDATE_FIRMWARE_IMAGE_PATH
]), &err
);
713 if (ret
!= VJSON_SUCCESS
)
714 return UBUS_STATUS_UNKNOWN_ERROR
;
716 ubus_send_reply(ctx
, req
, b
.head
);
718 return UBUS_STATUS_OK
;
731 static const struct blobmsg_policy sysupgrade_policy
[__SYSUPGRADE_MAX
] = {
732 [SYSUPGRADE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
733 [SYSUPGRADE_FORCE
] = { .name
= "force", .type
= BLOBMSG_TYPE_BOOL
},
734 [SYSUPGRADE_BACKUP
] = { .name
= "backup", .type
= BLOBMSG_TYPE_STRING
},
735 [SYSUPGRADE_PREFIX
] = { .name
= "prefix", .type
= BLOBMSG_TYPE_STRING
},
736 [SYSUPGRADE_COMMAND
] = { .name
= "command", .type
= BLOBMSG_TYPE_STRING
},
737 [SYSUPGRADE_OPTIONS
] = { .name
= "options", .type
= BLOBMSG_TYPE_TABLE
},
740 static void sysupgrade_error(struct ubus_context
*ctx
,
741 struct ubus_request_data
*req
,
746 blob_buf_init(&b
, 0);
748 c
= blobmsg_open_table(&b
, "error");
749 blobmsg_add_string(&b
, "message", message
);
750 blobmsg_close_table(&b
, c
);
752 ubus_send_reply(ctx
, req
, b
.head
);
755 static int sysupgrade(struct ubus_context
*ctx
, struct ubus_object
*obj
,
756 struct ubus_request_data
*req
, const char *method
,
757 struct blob_attr
*msg
)
761 VALIDATION_FORCEABLE
,
762 VALIDATION_ALLOW_BACKUP
,
765 static const struct blobmsg_policy validation_policy
[__VALIDATION_MAX
] = {
766 [VALIDATION_VALID
] = { .name
= "valid", .type
= BLOBMSG_TYPE_BOOL
},
767 [VALIDATION_FORCEABLE
] = { .name
= "forceable", .type
= BLOBMSG_TYPE_BOOL
},
768 [VALIDATION_ALLOW_BACKUP
] = { .name
= "allow_backup", .type
= BLOBMSG_TYPE_BOOL
},
770 struct blob_attr
*validation
[__VALIDATION_MAX
];
771 struct blob_attr
*tb
[__SYSUPGRADE_MAX
];
772 bool valid
, forceable
, allow_backup
;
773 enum vjson_state ret
= VJSON_ERROR
;
777 return UBUS_STATUS_INVALID_ARGUMENT
;
779 blobmsg_parse(sysupgrade_policy
, __SYSUPGRADE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
780 if (!tb
[SYSUPGRADE_PATH
] || !tb
[SYSUPGRADE_PREFIX
])
781 return UBUS_STATUS_INVALID_ARGUMENT
;
783 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[SYSUPGRADE_PATH
]), &err
);
784 if (ret
!= VJSON_SUCCESS
) {
785 sysupgrade_error(ctx
, req
, err
);
786 return UBUS_STATUS_UNKNOWN_ERROR
;
789 blobmsg_parse(validation_policy
, __VALIDATION_MAX
, validation
, blob_data(b
.head
), blob_len(b
.head
));
791 if (!validation
[VALIDATION_VALID
] || !validation
[VALIDATION_FORCEABLE
] ||
792 !validation
[VALIDATION_ALLOW_BACKUP
]) {
793 sysupgrade_error(ctx
, req
, "Validation script provided invalid input");
794 return UBUS_STATUS_INVALID_ARGUMENT
;
797 valid
= validation
[VALIDATION_VALID
] && blobmsg_get_bool(validation
[VALIDATION_VALID
]);
798 forceable
= validation
[VALIDATION_FORCEABLE
] && blobmsg_get_bool(validation
[VALIDATION_FORCEABLE
]);
799 allow_backup
= validation
[VALIDATION_ALLOW_BACKUP
] && blobmsg_get_bool(validation
[VALIDATION_ALLOW_BACKUP
]);
803 sysupgrade_error(ctx
, req
, "Firmware image is broken and cannot be installed");
804 return UBUS_STATUS_NOT_SUPPORTED
;
805 } else if (!tb
[SYSUPGRADE_FORCE
] || !blobmsg_get_bool(tb
[SYSUPGRADE_FORCE
])) {
806 sysupgrade_error(ctx
, req
, "Firmware image is invalid");
807 return UBUS_STATUS_NOT_SUPPORTED
;
809 } else if (!allow_backup
&& tb
[SYSUPGRADE_BACKUP
]) {
810 sysupgrade_error(ctx
, req
, "Firmware image doesn't allow preserving a backup");
811 return UBUS_STATUS_NOT_SUPPORTED
;
816 sysupgrade_exec_upgraded(blobmsg_get_string(tb
[SYSUPGRADE_PREFIX
]),
817 blobmsg_get_string(tb
[SYSUPGRADE_PATH
]),
818 tb
[SYSUPGRADE_BACKUP
] ? blobmsg_get_string(tb
[SYSUPGRADE_BACKUP
]) : NULL
,
819 tb
[SYSUPGRADE_COMMAND
] ? blobmsg_get_string(tb
[SYSUPGRADE_COMMAND
]) : NULL
,
820 tb
[SYSUPGRADE_OPTIONS
]);
822 /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
823 return UBUS_STATUS_UNKNOWN_ERROR
;
827 procd_subscribe_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
)
829 notify
= obj
->has_subscribers
;
833 static const struct ubus_method system_methods
[] = {
834 UBUS_METHOD_NOARG("board", system_board
),
835 UBUS_METHOD_NOARG("info", system_info
),
836 UBUS_METHOD_NOARG("reboot", system_reboot
),
837 UBUS_METHOD("watchdog", watchdog_set
, watchdog_policy
),
838 UBUS_METHOD("signal", proc_signal
, signal_policy
),
839 UBUS_METHOD("validate_firmware_image", validate_firmware_image
, validate_firmware_image_policy
),
840 UBUS_METHOD("sysupgrade", sysupgrade
, sysupgrade_policy
),
843 static struct ubus_object_type system_object_type
=
844 UBUS_OBJECT_TYPE("system", system_methods
);
846 static struct ubus_object system_object
= {
848 .type
= &system_object_type
,
849 .methods
= system_methods
,
850 .n_methods
= ARRAY_SIZE(system_methods
),
851 .subscribe_cb
= procd_subscribe_cb
,
855 procd_bcast_event(char *event
, struct blob_attr
*msg
)
862 ret
= ubus_notify(_ctx
, &system_object
, event
, msg
, -1);
864 fprintf(stderr
, "Failed to notify log: %s\n", ubus_strerror(ret
));
867 void ubus_init_system(struct ubus_context
*ctx
)
873 initramfs
= !!getenv("INITRAMFS");
875 unsetenv("INITRAMFS");
877 ret
= ubus_add_object(ctx
, &system_object
);
879 ERROR("Failed to add object: %s\n", ubus_strerror(ret
));