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
, "isa")) {
158 snprintf(line
, sizeof(line
), "RISC-V (%s)", val
+ 2);
159 blobmsg_add_string(&b
, "system", line
);
163 if (!strcasecmp(key
, "system type") ||
164 !strcasecmp(key
, "processor") ||
165 !strcasecmp(key
, "cpu") ||
166 !strcasecmp(key
, "model name"))
168 strtoul(val
+ 2, &key
, 0);
170 if (key
== (val
+ 2) || *key
!= 0)
172 blobmsg_add_string(&b
, "system", val
+ 2);
182 if ((f
= fopen("/tmp/sysinfo/model", "r")) != NULL
||
183 (f
= fopen("/proc/device-tree/model", "r")) != NULL
)
185 if (fgets(line
, sizeof(line
), f
))
187 val
= strtok(line
, "\t\n");
190 blobmsg_add_string(&b
, "model", val
);
195 else if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
197 while(fgets(line
, sizeof(line
), f
))
199 key
= strtok(line
, "\t:");
200 val
= strtok(NULL
, "\t\n");
205 if (!strcasecmp(key
, "machine") ||
206 !strcasecmp(key
, "hardware"))
208 blobmsg_add_string(&b
, "model", val
+ 2);
216 if ((f
= fopen("/tmp/sysinfo/board_name", "r")) != NULL
)
218 if (fgets(line
, sizeof(line
), f
))
220 val
= strtok(line
, "\t\n");
223 blobmsg_add_string(&b
, "board_name", val
);
228 else if ((f
= fopen("/proc/device-tree/compatible", "r")) != NULL
)
230 if (fgets(line
, sizeof(line
), f
))
232 val
= strtok(line
, "\t\n");
237 while ((next
= strchr(next
, ',')) != NULL
)
243 blobmsg_add_string(&b
, "board_name", val
);
251 blobmsg_add_string(&b
, "rootfs_type", rootfs_type
);
253 if ((f
= fopen("/etc/openwrt_release", "r")) != NULL
)
255 c
= blobmsg_open_table(&b
, "release");
257 while (fgets(line
, sizeof(line
), f
))
263 val
= strchr(line
, '=');
269 if (!strcasecmp(key
, "DISTRIB_ID"))
270 key
= "distribution";
271 else if (!strcasecmp(key
, "DISTRIB_RELEASE"))
273 else if (!strcasecmp(key
, "DISTRIB_REVISION"))
275 else if (!strcasecmp(key
, "DISTRIB_CODENAME"))
277 else if (!strcasecmp(key
, "DISTRIB_TARGET"))
279 else if (!strcasecmp(key
, "DISTRIB_DESCRIPTION"))
284 dest
= blobmsg_alloc_string_buffer(&b
, key
, strlen(val
));
286 ERROR("Failed to allocate blob.\n");
290 while (val
&& (ch
= *(val
++)) != 0) {
294 next
= strchr(val
, ch
);
303 dest
+= strlen(dest
);
306 *(dest
++) = *(val
++);
310 blobmsg_add_string_buffer(&b
);
313 blobmsg_close_array(&b
, c
);
318 ubus_send_reply(ctx
, req
, b
.head
);
320 return UBUS_STATUS_OK
;
324 kscale(unsigned long b
, unsigned long bs
)
326 return (b
* (unsigned long long) bs
+ 1024/2) / 1024;
329 static int system_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
330 struct ubus_request_data
*req
, const char *method
,
331 struct blob_attr
*msg
)
340 unsigned long long available
, cached
;
344 const char *fslist
[] = {
350 return UBUS_STATUS_UNKNOWN_ERROR
;
352 if ((f
= fopen("/proc/meminfo", "r")) == NULL
)
353 return UBUS_STATUS_UNKNOWN_ERROR
;
355 /* if linux < 3.14 MemAvailable is not in meminfo */
359 while (fgets(line
, sizeof(line
), f
))
361 key
= strtok(line
, " :");
362 val
= strtok(NULL
, " ");
367 if (!strcasecmp(key
, "MemAvailable"))
368 available
= 1024 * atoll(val
);
369 else if (!strcasecmp(key
, "Cached"))
370 cached
= 1024 * atoll(val
);
378 if (!(tm
= localtime(&now
)))
379 return UBUS_STATUS_UNKNOWN_ERROR
;
381 blob_buf_init(&b
, 0);
383 blobmsg_add_u32(&b
, "localtime", now
+ tm
->tm_gmtoff
);
386 blobmsg_add_u32(&b
, "uptime", info
.uptime
);
388 c
= blobmsg_open_array(&b
, "load");
389 blobmsg_add_u32(&b
, NULL
, info
.loads
[0]);
390 blobmsg_add_u32(&b
, NULL
, info
.loads
[1]);
391 blobmsg_add_u32(&b
, NULL
, info
.loads
[2]);
392 blobmsg_close_array(&b
, c
);
394 c
= blobmsg_open_table(&b
, "memory");
395 blobmsg_add_u64(&b
, "total",
396 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalram
);
397 blobmsg_add_u64(&b
, "free",
398 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeram
);
399 blobmsg_add_u64(&b
, "shared",
400 (uint64_t)info
.mem_unit
* (uint64_t)info
.sharedram
);
401 blobmsg_add_u64(&b
, "buffered",
402 (uint64_t)info
.mem_unit
* (uint64_t)info
.bufferram
);
403 blobmsg_add_u64(&b
, "available", available
);
404 blobmsg_add_u64(&b
, "cached", cached
);
405 blobmsg_close_table(&b
, c
);
407 for (i
= 0; i
< sizeof(fslist
) / sizeof(fslist
[0]); i
+= 2) {
408 if (statvfs(fslist
[i
], &s
))
411 c
= blobmsg_open_table(&b
, fslist
[i
+1]);
414 s
.f_frsize
= s
.f_bsize
;
416 blobmsg_add_u64(&b
, "total", kscale(s
.f_blocks
, s
.f_frsize
));
417 blobmsg_add_u64(&b
, "free", kscale(s
.f_bfree
, s
.f_frsize
));
418 blobmsg_add_u64(&b
, "used", kscale(s
.f_blocks
- s
.f_bfree
, s
.f_frsize
));
419 blobmsg_add_u64(&b
, "avail", kscale(s
.f_bavail
, s
.f_frsize
));
421 blobmsg_close_table(&b
, c
);
424 c
= blobmsg_open_table(&b
, "swap");
425 blobmsg_add_u64(&b
, "total",
426 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalswap
);
427 blobmsg_add_u64(&b
, "free",
428 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeswap
);
429 blobmsg_close_table(&b
, c
);
432 ubus_send_reply(ctx
, req
, b
.head
);
434 return UBUS_STATUS_OK
;
437 static int system_reboot(struct ubus_context
*ctx
, struct ubus_object
*obj
,
438 struct ubus_request_data
*req
, const char *method
,
439 struct blob_attr
*msg
)
441 procd_shutdown(RB_AUTOBOOT
);
453 static const struct blobmsg_policy watchdog_policy
[__WDT_MAX
] = {
454 [WDT_FREQUENCY
] = { .name
= "frequency", .type
= BLOBMSG_TYPE_INT32
},
455 [WDT_TIMEOUT
] = { .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
},
456 [WDT_MAGICCLOSE
] = { .name
= "magicclose", .type
= BLOBMSG_TYPE_BOOL
},
457 [WDT_STOP
] = { .name
= "stop", .type
= BLOBMSG_TYPE_BOOL
},
460 static int watchdog_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
461 struct ubus_request_data
*req
, const char *method
,
462 struct blob_attr
*msg
)
464 struct blob_attr
*tb
[__WDT_MAX
];
468 return UBUS_STATUS_INVALID_ARGUMENT
;
470 blobmsg_parse(watchdog_policy
, __WDT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
471 if (tb
[WDT_FREQUENCY
]) {
472 unsigned int timeout
= tb
[WDT_TIMEOUT
] ? blobmsg_get_u32(tb
[WDT_TIMEOUT
]) :
474 unsigned int freq
= blobmsg_get_u32(tb
[WDT_FREQUENCY
]);
477 if (freq
> timeout
/ 2)
479 watchdog_frequency(freq
);
483 if (tb
[WDT_TIMEOUT
]) {
484 unsigned int timeout
= blobmsg_get_u32(tb
[WDT_TIMEOUT
]);
485 unsigned int frequency
= watchdog_frequency(0);
487 if (timeout
<= frequency
)
488 timeout
= frequency
* 2;
489 watchdog_timeout(timeout
);
492 if (tb
[WDT_MAGICCLOSE
])
493 watchdog_set_magicclose(blobmsg_get_bool(tb
[WDT_MAGICCLOSE
]));
496 watchdog_set_stopped(blobmsg_get_bool(tb
[WDT_STOP
]));
498 if (watchdog_fd() == NULL
)
500 else if (watchdog_get_stopped())
505 blob_buf_init(&b
, 0);
506 blobmsg_add_string(&b
, "status", status
);
507 blobmsg_add_u32(&b
, "timeout", watchdog_timeout(0));
508 blobmsg_add_u32(&b
, "frequency", watchdog_frequency(0));
509 blobmsg_add_u8(&b
, "magicclose", watchdog_get_magicclose());
510 ubus_send_reply(ctx
, req
, b
.head
);
521 static const struct blobmsg_policy signal_policy
[__SIGNAL_MAX
] = {
522 [SIGNAL_PID
] = { .name
= "pid", .type
= BLOBMSG_TYPE_INT32
},
523 [SIGNAL_NUM
] = { .name
= "signum", .type
= BLOBMSG_TYPE_INT32
},
526 static int proc_signal(struct ubus_context
*ctx
, struct ubus_object
*obj
,
527 struct ubus_request_data
*req
, const char *method
,
528 struct blob_attr
*msg
)
530 struct blob_attr
*tb
[__SIGNAL_MAX
];
533 return UBUS_STATUS_INVALID_ARGUMENT
;
535 blobmsg_parse(signal_policy
, __SIGNAL_MAX
, tb
, blob_data(msg
), blob_len(msg
));
536 if (!tb
[SIGNAL_PID
|| !tb
[SIGNAL_NUM
]])
537 return UBUS_STATUS_INVALID_ARGUMENT
;
539 kill(blobmsg_get_u32(tb
[SIGNAL_PID
]), blobmsg_get_u32(tb
[SIGNAL_NUM
]));
544 __attribute__((format (printf
, 2, 3)))
545 static enum vjson_state
vjson_error(char **b
, const char *fmt
, ...)
547 static char buf
[256] = { 0 };
548 const char *pfx
= "Firmware image couldn't be validated: ";
552 r
= snprintf(buf
, sizeof(buf
), "%s", pfx
);
554 *b
= "vjson_error() snprintf failed";
559 r
= vsnprintf(buf
+r
, sizeof(buf
)-r
, fmt
, va
);
561 *b
= "vjson_error() vsnprintf failed";
570 static enum vjson_state
vjson_parse_token(json_tokener
*tok
, char *buf
, ssize_t len
, char **err
)
572 json_object
*jsobj
= NULL
;
574 jsobj
= json_tokener_parse_ex(tok
, buf
, len
);
575 if (json_tokener_get_error(tok
) == json_tokener_continue
)
576 return VJSON_CONTINUE
;
578 if (json_tokener_get_error(tok
) == json_tokener_success
) {
579 if (json_object_get_type(jsobj
) != json_type_object
) {
580 json_object_put(jsobj
);
581 return vjson_error(err
, "result is not an JSON object");
584 blobmsg_add_object(&b
, jsobj
);
585 json_object_put(jsobj
);
586 return VJSON_SUCCESS
;
589 return vjson_error(err
, "failed to parse JSON: %s (%d)",
590 json_tokener_error_desc(json_tokener_get_error(tok
)),
591 json_tokener_get_error(tok
));
594 static enum vjson_state
vjson_parse(int fd
, char **err
)
596 enum vjson_state r
= VJSON_ERROR
;
597 size_t read_count
= 0;
598 char buf
[64] = { 0 };
603 tok
= json_tokener_new();
605 return vjson_error(err
, "json_tokener_new() failed");
607 vjson_error(err
, "incomplete JSON input");
609 while ((len
= read(fd
, buf
, sizeof(buf
)))) {
610 if (len
< 0 && errno
== EINTR
)
615 json_tokener_free(tok
);
616 return vjson_error(err
, "read() failed: %s (%d)",
617 strerror(_errno
), _errno
);
621 r
= vjson_parse_token(tok
, buf
, len
, err
);
622 if (r
!= VJSON_CONTINUE
)
625 memset(buf
, 0, sizeof(buf
));
629 vjson_error(err
, "no JSON input");
631 json_tokener_free(tok
);
636 * validate_firmware_image_call - perform validation & store result in global b
638 * @file: firmware image path
640 static enum vjson_state
validate_firmware_image_call(const char *file
, char **err
)
642 const char *path
= "/usr/libexec/validate_firmware_image";
643 enum vjson_state ret
= VJSON_ERROR
;
648 blob_buf_init(&b
, 0);
649 vjson_error(err
, "unhandled error");
653 return vjson_error(err
, "pipe() failed: %s (%d)",
654 strerror(_errno
), _errno
);
664 return vjson_error(err
, "fork() failed: %s (%d)",
665 strerror(_errno
), _errno
);
667 /* Set stdin & stderr to /dev/null */
668 fd
= open("/dev/null", O_RDWR
);
675 /* Set stdout to the shared pipe */
680 execl(path
, path
, file
, NULL
);
687 ret
= vjson_parse(fds
[0], err
);
694 VALIDATE_FIRMWARE_IMAGE_PATH
,
695 __VALIDATE_FIRMWARE_IMAGE_MAX
,
698 static const struct blobmsg_policy validate_firmware_image_policy
[__VALIDATE_FIRMWARE_IMAGE_MAX
] = {
699 [VALIDATE_FIRMWARE_IMAGE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
702 static int validate_firmware_image(struct ubus_context
*ctx
,
703 struct ubus_object
*obj
,
704 struct ubus_request_data
*req
,
705 const char *method
, struct blob_attr
*msg
)
707 struct blob_attr
*tb
[__VALIDATE_FIRMWARE_IMAGE_MAX
];
708 enum vjson_state ret
= VJSON_ERROR
;
712 return UBUS_STATUS_INVALID_ARGUMENT
;
714 blobmsg_parse(validate_firmware_image_policy
, __VALIDATE_FIRMWARE_IMAGE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
715 if (!tb
[VALIDATE_FIRMWARE_IMAGE_PATH
])
716 return UBUS_STATUS_INVALID_ARGUMENT
;
718 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[VALIDATE_FIRMWARE_IMAGE_PATH
]), &err
);
719 if (ret
!= VJSON_SUCCESS
)
720 return UBUS_STATUS_UNKNOWN_ERROR
;
722 ubus_send_reply(ctx
, req
, b
.head
);
724 return UBUS_STATUS_OK
;
737 static const struct blobmsg_policy sysupgrade_policy
[__SYSUPGRADE_MAX
] = {
738 [SYSUPGRADE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
739 [SYSUPGRADE_FORCE
] = { .name
= "force", .type
= BLOBMSG_TYPE_BOOL
},
740 [SYSUPGRADE_BACKUP
] = { .name
= "backup", .type
= BLOBMSG_TYPE_STRING
},
741 [SYSUPGRADE_PREFIX
] = { .name
= "prefix", .type
= BLOBMSG_TYPE_STRING
},
742 [SYSUPGRADE_COMMAND
] = { .name
= "command", .type
= BLOBMSG_TYPE_STRING
},
743 [SYSUPGRADE_OPTIONS
] = { .name
= "options", .type
= BLOBMSG_TYPE_TABLE
},
746 static void sysupgrade_error(struct ubus_context
*ctx
,
747 struct ubus_request_data
*req
,
752 blob_buf_init(&b
, 0);
754 c
= blobmsg_open_table(&b
, "error");
755 blobmsg_add_string(&b
, "message", message
);
756 blobmsg_close_table(&b
, c
);
758 ubus_send_reply(ctx
, req
, b
.head
);
761 static int sysupgrade(struct ubus_context
*ctx
, struct ubus_object
*obj
,
762 struct ubus_request_data
*req
, const char *method
,
763 struct blob_attr
*msg
)
767 VALIDATION_FORCEABLE
,
768 VALIDATION_ALLOW_BACKUP
,
771 static const struct blobmsg_policy validation_policy
[__VALIDATION_MAX
] = {
772 [VALIDATION_VALID
] = { .name
= "valid", .type
= BLOBMSG_TYPE_BOOL
},
773 [VALIDATION_FORCEABLE
] = { .name
= "forceable", .type
= BLOBMSG_TYPE_BOOL
},
774 [VALIDATION_ALLOW_BACKUP
] = { .name
= "allow_backup", .type
= BLOBMSG_TYPE_BOOL
},
776 struct blob_attr
*validation
[__VALIDATION_MAX
];
777 struct blob_attr
*tb
[__SYSUPGRADE_MAX
];
778 bool valid
, forceable
, allow_backup
;
779 enum vjson_state ret
= VJSON_ERROR
;
783 return UBUS_STATUS_INVALID_ARGUMENT
;
785 blobmsg_parse(sysupgrade_policy
, __SYSUPGRADE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
786 if (!tb
[SYSUPGRADE_PATH
] || !tb
[SYSUPGRADE_PREFIX
])
787 return UBUS_STATUS_INVALID_ARGUMENT
;
789 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[SYSUPGRADE_PATH
]), &err
);
790 if (ret
!= VJSON_SUCCESS
) {
791 sysupgrade_error(ctx
, req
, err
);
792 return UBUS_STATUS_UNKNOWN_ERROR
;
795 blobmsg_parse(validation_policy
, __VALIDATION_MAX
, validation
, blob_data(b
.head
), blob_len(b
.head
));
797 if (!validation
[VALIDATION_VALID
] || !validation
[VALIDATION_FORCEABLE
] ||
798 !validation
[VALIDATION_ALLOW_BACKUP
]) {
799 sysupgrade_error(ctx
, req
, "Validation script provided invalid input");
800 return UBUS_STATUS_INVALID_ARGUMENT
;
803 valid
= validation
[VALIDATION_VALID
] && blobmsg_get_bool(validation
[VALIDATION_VALID
]);
804 forceable
= validation
[VALIDATION_FORCEABLE
] && blobmsg_get_bool(validation
[VALIDATION_FORCEABLE
]);
805 allow_backup
= validation
[VALIDATION_ALLOW_BACKUP
] && blobmsg_get_bool(validation
[VALIDATION_ALLOW_BACKUP
]);
809 sysupgrade_error(ctx
, req
, "Firmware image is broken and cannot be installed");
810 return UBUS_STATUS_NOT_SUPPORTED
;
811 } else if (!tb
[SYSUPGRADE_FORCE
] || !blobmsg_get_bool(tb
[SYSUPGRADE_FORCE
])) {
812 sysupgrade_error(ctx
, req
, "Firmware image is invalid");
813 return UBUS_STATUS_NOT_SUPPORTED
;
815 } else if (!allow_backup
&& tb
[SYSUPGRADE_BACKUP
]) {
816 sysupgrade_error(ctx
, req
, "Firmware image doesn't allow preserving a backup");
817 return UBUS_STATUS_NOT_SUPPORTED
;
822 sysupgrade_exec_upgraded(blobmsg_get_string(tb
[SYSUPGRADE_PREFIX
]),
823 blobmsg_get_string(tb
[SYSUPGRADE_PATH
]),
824 tb
[SYSUPGRADE_BACKUP
] ? blobmsg_get_string(tb
[SYSUPGRADE_BACKUP
]) : NULL
,
825 tb
[SYSUPGRADE_COMMAND
] ? blobmsg_get_string(tb
[SYSUPGRADE_COMMAND
]) : NULL
,
826 tb
[SYSUPGRADE_OPTIONS
]);
828 /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
829 return UBUS_STATUS_UNKNOWN_ERROR
;
833 procd_subscribe_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
)
835 notify
= obj
->has_subscribers
;
839 static const struct ubus_method system_methods
[] = {
840 UBUS_METHOD_NOARG("board", system_board
),
841 UBUS_METHOD_NOARG("info", system_info
),
842 UBUS_METHOD_NOARG("reboot", system_reboot
),
843 UBUS_METHOD("watchdog", watchdog_set
, watchdog_policy
),
844 UBUS_METHOD("signal", proc_signal
, signal_policy
),
845 UBUS_METHOD("validate_firmware_image", validate_firmware_image
, validate_firmware_image_policy
),
846 UBUS_METHOD("sysupgrade", sysupgrade
, sysupgrade_policy
),
849 static struct ubus_object_type system_object_type
=
850 UBUS_OBJECT_TYPE("system", system_methods
);
852 static struct ubus_object system_object
= {
854 .type
= &system_object_type
,
855 .methods
= system_methods
,
856 .n_methods
= ARRAY_SIZE(system_methods
),
857 .subscribe_cb
= procd_subscribe_cb
,
861 procd_bcast_event(char *event
, struct blob_attr
*msg
)
868 ret
= ubus_notify(_ctx
, &system_object
, event
, msg
, -1);
870 fprintf(stderr
, "Failed to notify log: %s\n", ubus_strerror(ret
));
873 void ubus_init_system(struct ubus_context
*ctx
)
879 initramfs
= !!getenv("INITRAMFS");
881 unsetenv("INITRAMFS");
883 ret
= ubus_add_object(ctx
, &system_object
);
885 ERROR("Failed to add object: %s\n", ubus_strerror(ret
));