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 if that's not
100 if (!strcmp(mp
, "/rom"))
104 fseek(mounts
, 0, SEEK_SET
);
113 strncpy(fstype
, tmp
, sizeof(fstype
) - 1);
115 fstype
[sizeof(fstype
) - 1]= '\0';
125 static int system_board(struct ubus_context
*ctx
, struct ubus_object
*obj
,
126 struct ubus_request_data
*req
, const char *method
,
127 struct blob_attr
*msg
)
131 char *key
, *val
, *next
;
132 const char *rootfs_type
= system_rootfs_type();
133 struct utsname utsname
;
136 blob_buf_init(&b
, 0);
138 if (uname(&utsname
) >= 0)
140 blobmsg_add_string(&b
, "kernel", utsname
.release
);
141 blobmsg_add_string(&b
, "hostname", utsname
.nodename
);
144 if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
146 while(fgets(line
, sizeof(line
), f
))
148 key
= strtok(line
, "\t:");
149 val
= strtok(NULL
, "\t\n");
155 if (!strcasecmp(key
, "CPU revision")) {
156 snprintf(line
, sizeof(line
), "ARMv8 Processor rev %lu", strtoul(val
+ 2, NULL
, 16));
157 blobmsg_add_string(&b
, "system", line
);
161 if (!strcasecmp(key
, "isa")) {
162 snprintf(line
, sizeof(line
), "RISC-V (%s)", val
+ 2);
163 blobmsg_add_string(&b
, "system", line
);
167 if (!strcasecmp(key
, "system type") ||
168 !strcasecmp(key
, "processor") ||
169 !strcasecmp(key
, "cpu") ||
170 !strcasecmp(key
, "model name"))
172 strtoul(val
+ 2, &key
, 0);
174 if (key
== (val
+ 2) || *key
!= 0)
176 blobmsg_add_string(&b
, "system", val
+ 2);
186 if ((f
= fopen("/tmp/sysinfo/model", "r")) != NULL
||
187 (f
= fopen("/proc/device-tree/model", "r")) != NULL
)
189 if (fgets(line
, sizeof(line
), f
))
191 val
= strtok(line
, "\t\n");
194 blobmsg_add_string(&b
, "model", val
);
199 else if ((f
= fopen("/proc/cpuinfo", "r")) != NULL
)
201 while(fgets(line
, sizeof(line
), f
))
203 key
= strtok(line
, "\t:");
204 val
= strtok(NULL
, "\t\n");
209 if (!strcasecmp(key
, "machine") ||
210 !strcasecmp(key
, "hardware"))
212 blobmsg_add_string(&b
, "model", val
+ 2);
220 if ((f
= fopen("/tmp/sysinfo/board_name", "r")) != NULL
)
222 if (fgets(line
, sizeof(line
), f
))
224 val
= strtok(line
, "\t\n");
227 blobmsg_add_string(&b
, "board_name", val
);
232 else if ((f
= fopen("/proc/device-tree/compatible", "r")) != NULL
)
234 if (fgets(line
, sizeof(line
), f
))
236 val
= strtok(line
, "\t\n");
241 while ((next
= strchr(next
, ',')) != NULL
)
247 blobmsg_add_string(&b
, "board_name", val
);
255 blobmsg_add_string(&b
, "rootfs_type", rootfs_type
);
257 if ((f
= fopen("/etc/openwrt_release", "r")) != NULL
)
259 c
= blobmsg_open_table(&b
, "release");
261 while (fgets(line
, sizeof(line
), f
))
267 val
= strchr(line
, '=');
273 if (!strcasecmp(key
, "DISTRIB_ID"))
274 key
= "distribution";
275 else if (!strcasecmp(key
, "DISTRIB_RELEASE"))
277 else if (!strcasecmp(key
, "DISTRIB_REVISION"))
279 else if (!strcasecmp(key
, "DISTRIB_CODENAME"))
281 else if (!strcasecmp(key
, "DISTRIB_TARGET"))
283 else if (!strcasecmp(key
, "DISTRIB_DESCRIPTION"))
288 dest
= blobmsg_alloc_string_buffer(&b
, key
, strlen(val
));
290 ERROR("Failed to allocate blob.\n");
294 while (val
&& (ch
= *(val
++)) != 0) {
298 next
= strchr(val
, ch
);
307 dest
+= strlen(dest
);
310 *(dest
++) = *(val
++);
314 blobmsg_add_string_buffer(&b
);
317 blobmsg_close_array(&b
, c
);
322 ubus_send_reply(ctx
, req
, b
.head
);
324 return UBUS_STATUS_OK
;
328 kscale(unsigned long b
, unsigned long bs
)
330 return (b
* (unsigned long long) bs
+ 1024/2) / 1024;
333 static int system_info(struct ubus_context
*ctx
, struct ubus_object
*obj
,
334 struct ubus_request_data
*req
, const char *method
,
335 struct blob_attr
*msg
)
344 unsigned long long available
, cached
;
348 const char *fslist
[] = {
354 return UBUS_STATUS_UNKNOWN_ERROR
;
356 if ((f
= fopen("/proc/meminfo", "r")) == NULL
)
357 return UBUS_STATUS_UNKNOWN_ERROR
;
359 /* if linux < 3.14 MemAvailable is not in meminfo */
363 while (fgets(line
, sizeof(line
), f
))
365 key
= strtok(line
, " :");
366 val
= strtok(NULL
, " ");
371 if (!strcasecmp(key
, "MemAvailable"))
372 available
= 1024 * atoll(val
);
373 else if (!strcasecmp(key
, "Cached"))
374 cached
= 1024 * atoll(val
);
382 if (!(tm
= localtime(&now
)))
383 return UBUS_STATUS_UNKNOWN_ERROR
;
385 blob_buf_init(&b
, 0);
387 blobmsg_add_u32(&b
, "localtime", now
+ tm
->tm_gmtoff
);
390 blobmsg_add_u32(&b
, "uptime", info
.uptime
);
392 c
= blobmsg_open_array(&b
, "load");
393 blobmsg_add_u32(&b
, NULL
, info
.loads
[0]);
394 blobmsg_add_u32(&b
, NULL
, info
.loads
[1]);
395 blobmsg_add_u32(&b
, NULL
, info
.loads
[2]);
396 blobmsg_close_array(&b
, c
);
398 c
= blobmsg_open_table(&b
, "memory");
399 blobmsg_add_u64(&b
, "total",
400 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalram
);
401 blobmsg_add_u64(&b
, "free",
402 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeram
);
403 blobmsg_add_u64(&b
, "shared",
404 (uint64_t)info
.mem_unit
* (uint64_t)info
.sharedram
);
405 blobmsg_add_u64(&b
, "buffered",
406 (uint64_t)info
.mem_unit
* (uint64_t)info
.bufferram
);
407 blobmsg_add_u64(&b
, "available", available
);
408 blobmsg_add_u64(&b
, "cached", cached
);
409 blobmsg_close_table(&b
, c
);
411 for (i
= 0; i
< sizeof(fslist
) / sizeof(fslist
[0]); i
+= 2) {
412 if (statvfs(fslist
[i
], &s
))
415 c
= blobmsg_open_table(&b
, fslist
[i
+1]);
418 s
.f_frsize
= s
.f_bsize
;
420 blobmsg_add_u64(&b
, "total", kscale(s
.f_blocks
, s
.f_frsize
));
421 blobmsg_add_u64(&b
, "free", kscale(s
.f_bfree
, s
.f_frsize
));
422 blobmsg_add_u64(&b
, "used", kscale(s
.f_blocks
- s
.f_bfree
, s
.f_frsize
));
423 blobmsg_add_u64(&b
, "avail", kscale(s
.f_bavail
, s
.f_frsize
));
425 blobmsg_close_table(&b
, c
);
428 c
= blobmsg_open_table(&b
, "swap");
429 blobmsg_add_u64(&b
, "total",
430 (uint64_t)info
.mem_unit
* (uint64_t)info
.totalswap
);
431 blobmsg_add_u64(&b
, "free",
432 (uint64_t)info
.mem_unit
* (uint64_t)info
.freeswap
);
433 blobmsg_close_table(&b
, c
);
436 ubus_send_reply(ctx
, req
, b
.head
);
438 return UBUS_STATUS_OK
;
441 static int system_reboot(struct ubus_context
*ctx
, struct ubus_object
*obj
,
442 struct ubus_request_data
*req
, const char *method
,
443 struct blob_attr
*msg
)
445 procd_shutdown(RB_AUTOBOOT
);
457 static const struct blobmsg_policy watchdog_policy
[__WDT_MAX
] = {
458 [WDT_FREQUENCY
] = { .name
= "frequency", .type
= BLOBMSG_TYPE_INT32
},
459 [WDT_TIMEOUT
] = { .name
= "timeout", .type
= BLOBMSG_TYPE_INT32
},
460 [WDT_MAGICCLOSE
] = { .name
= "magicclose", .type
= BLOBMSG_TYPE_BOOL
},
461 [WDT_STOP
] = { .name
= "stop", .type
= BLOBMSG_TYPE_BOOL
},
464 static int watchdog_set(struct ubus_context
*ctx
, struct ubus_object
*obj
,
465 struct ubus_request_data
*req
, const char *method
,
466 struct blob_attr
*msg
)
468 struct blob_attr
*tb
[__WDT_MAX
];
472 return UBUS_STATUS_INVALID_ARGUMENT
;
474 blobmsg_parse(watchdog_policy
, __WDT_MAX
, tb
, blob_data(msg
), blob_len(msg
));
475 if (tb
[WDT_FREQUENCY
]) {
476 unsigned int timeout
= tb
[WDT_TIMEOUT
] ? blobmsg_get_u32(tb
[WDT_TIMEOUT
]) :
478 unsigned int freq
= blobmsg_get_u32(tb
[WDT_FREQUENCY
]);
481 if (freq
> timeout
/ 2)
483 watchdog_frequency(freq
);
487 if (tb
[WDT_TIMEOUT
]) {
488 unsigned int timeout
= blobmsg_get_u32(tb
[WDT_TIMEOUT
]);
489 unsigned int frequency
= watchdog_frequency(0);
491 if (timeout
<= frequency
)
492 timeout
= frequency
* 2;
493 watchdog_timeout(timeout
);
496 if (tb
[WDT_MAGICCLOSE
])
497 watchdog_set_magicclose(blobmsg_get_bool(tb
[WDT_MAGICCLOSE
]));
500 watchdog_set_stopped(blobmsg_get_bool(tb
[WDT_STOP
]));
502 if (watchdog_fd() == NULL
)
504 else if (watchdog_get_stopped())
509 blob_buf_init(&b
, 0);
510 blobmsg_add_string(&b
, "status", status
);
511 blobmsg_add_u32(&b
, "timeout", watchdog_timeout(0));
512 blobmsg_add_u32(&b
, "frequency", watchdog_frequency(0));
513 blobmsg_add_u8(&b
, "magicclose", watchdog_get_magicclose());
514 ubus_send_reply(ctx
, req
, b
.head
);
525 static const struct blobmsg_policy signal_policy
[__SIGNAL_MAX
] = {
526 [SIGNAL_PID
] = { .name
= "pid", .type
= BLOBMSG_TYPE_INT32
},
527 [SIGNAL_NUM
] = { .name
= "signum", .type
= BLOBMSG_TYPE_INT32
},
530 static int proc_signal(struct ubus_context
*ctx
, struct ubus_object
*obj
,
531 struct ubus_request_data
*req
, const char *method
,
532 struct blob_attr
*msg
)
534 struct blob_attr
*tb
[__SIGNAL_MAX
];
537 return UBUS_STATUS_INVALID_ARGUMENT
;
539 blobmsg_parse(signal_policy
, __SIGNAL_MAX
, tb
, blob_data(msg
), blob_len(msg
));
540 if (!tb
[SIGNAL_PID
|| !tb
[SIGNAL_NUM
]])
541 return UBUS_STATUS_INVALID_ARGUMENT
;
543 kill(blobmsg_get_u32(tb
[SIGNAL_PID
]), blobmsg_get_u32(tb
[SIGNAL_NUM
]));
548 __attribute__((format (printf
, 2, 3)))
549 static enum vjson_state
vjson_error(char **b
, const char *fmt
, ...)
551 static char buf
[256] = { 0 };
552 const char *pfx
= "Firmware image couldn't be validated: ";
556 r
= snprintf(buf
, sizeof(buf
), "%s", pfx
);
558 *b
= "vjson_error() snprintf failed";
563 r
= vsnprintf(buf
+r
, sizeof(buf
)-r
, fmt
, va
);
565 *b
= "vjson_error() vsnprintf failed";
574 static enum vjson_state
vjson_parse_token(json_tokener
*tok
, char *buf
, ssize_t len
, char **err
)
576 json_object
*jsobj
= NULL
;
578 jsobj
= json_tokener_parse_ex(tok
, buf
, len
);
579 if (json_tokener_get_error(tok
) == json_tokener_continue
)
580 return VJSON_CONTINUE
;
582 if (json_tokener_get_error(tok
) == json_tokener_success
) {
583 if (json_object_get_type(jsobj
) != json_type_object
) {
584 json_object_put(jsobj
);
585 return vjson_error(err
, "result is not an JSON object");
588 blobmsg_add_object(&b
, jsobj
);
589 json_object_put(jsobj
);
590 return VJSON_SUCCESS
;
593 return vjson_error(err
, "failed to parse JSON: %s (%d)",
594 json_tokener_error_desc(json_tokener_get_error(tok
)),
595 json_tokener_get_error(tok
));
598 static enum vjson_state
vjson_parse(int fd
, char **err
)
600 enum vjson_state r
= VJSON_ERROR
;
601 size_t read_count
= 0;
602 char buf
[64] = { 0 };
607 tok
= json_tokener_new();
609 return vjson_error(err
, "json_tokener_new() failed");
611 vjson_error(err
, "incomplete JSON input");
613 while ((len
= read(fd
, buf
, sizeof(buf
)))) {
614 if (len
< 0 && errno
== EINTR
)
619 json_tokener_free(tok
);
620 return vjson_error(err
, "read() failed: %s (%d)",
621 strerror(_errno
), _errno
);
625 r
= vjson_parse_token(tok
, buf
, len
, err
);
626 if (r
!= VJSON_CONTINUE
)
629 memset(buf
, 0, sizeof(buf
));
633 vjson_error(err
, "no JSON input");
635 json_tokener_free(tok
);
640 * validate_firmware_image_call - perform validation & store result in global b
642 * @file: firmware image path
644 static enum vjson_state
validate_firmware_image_call(const char *file
, char **err
)
646 const char *path
= "/usr/libexec/validate_firmware_image";
647 enum vjson_state ret
= VJSON_ERROR
;
652 blob_buf_init(&b
, 0);
653 vjson_error(err
, "unhandled error");
657 return vjson_error(err
, "pipe() failed: %s (%d)",
658 strerror(_errno
), _errno
);
668 return vjson_error(err
, "fork() failed: %s (%d)",
669 strerror(_errno
), _errno
);
671 /* Set stdin & stderr to /dev/null */
672 fd
= open("/dev/null", O_RDWR
);
679 /* Set stdout to the shared pipe */
684 execl(path
, path
, file
, NULL
);
691 ret
= vjson_parse(fds
[0], err
);
698 VALIDATE_FIRMWARE_IMAGE_PATH
,
699 __VALIDATE_FIRMWARE_IMAGE_MAX
,
702 static const struct blobmsg_policy validate_firmware_image_policy
[__VALIDATE_FIRMWARE_IMAGE_MAX
] = {
703 [VALIDATE_FIRMWARE_IMAGE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
706 static int validate_firmware_image(struct ubus_context
*ctx
,
707 struct ubus_object
*obj
,
708 struct ubus_request_data
*req
,
709 const char *method
, struct blob_attr
*msg
)
711 struct blob_attr
*tb
[__VALIDATE_FIRMWARE_IMAGE_MAX
];
712 enum vjson_state ret
= VJSON_ERROR
;
716 return UBUS_STATUS_INVALID_ARGUMENT
;
718 blobmsg_parse(validate_firmware_image_policy
, __VALIDATE_FIRMWARE_IMAGE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
719 if (!tb
[VALIDATE_FIRMWARE_IMAGE_PATH
])
720 return UBUS_STATUS_INVALID_ARGUMENT
;
722 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[VALIDATE_FIRMWARE_IMAGE_PATH
]), &err
);
723 if (ret
!= VJSON_SUCCESS
)
724 return UBUS_STATUS_UNKNOWN_ERROR
;
726 ubus_send_reply(ctx
, req
, b
.head
);
728 return UBUS_STATUS_OK
;
741 static const struct blobmsg_policy sysupgrade_policy
[__SYSUPGRADE_MAX
] = {
742 [SYSUPGRADE_PATH
] = { .name
= "path", .type
= BLOBMSG_TYPE_STRING
},
743 [SYSUPGRADE_FORCE
] = { .name
= "force", .type
= BLOBMSG_TYPE_BOOL
},
744 [SYSUPGRADE_BACKUP
] = { .name
= "backup", .type
= BLOBMSG_TYPE_STRING
},
745 [SYSUPGRADE_PREFIX
] = { .name
= "prefix", .type
= BLOBMSG_TYPE_STRING
},
746 [SYSUPGRADE_COMMAND
] = { .name
= "command", .type
= BLOBMSG_TYPE_STRING
},
747 [SYSUPGRADE_OPTIONS
] = { .name
= "options", .type
= BLOBMSG_TYPE_TABLE
},
750 static void sysupgrade_error(struct ubus_context
*ctx
,
751 struct ubus_request_data
*req
,
756 blob_buf_init(&b
, 0);
758 c
= blobmsg_open_table(&b
, "error");
759 blobmsg_add_string(&b
, "message", message
);
760 blobmsg_close_table(&b
, c
);
762 ubus_send_reply(ctx
, req
, b
.head
);
765 static int sysupgrade(struct ubus_context
*ctx
, struct ubus_object
*obj
,
766 struct ubus_request_data
*req
, const char *method
,
767 struct blob_attr
*msg
)
771 VALIDATION_FORCEABLE
,
772 VALIDATION_ALLOW_BACKUP
,
775 static const struct blobmsg_policy validation_policy
[__VALIDATION_MAX
] = {
776 [VALIDATION_VALID
] = { .name
= "valid", .type
= BLOBMSG_TYPE_BOOL
},
777 [VALIDATION_FORCEABLE
] = { .name
= "forceable", .type
= BLOBMSG_TYPE_BOOL
},
778 [VALIDATION_ALLOW_BACKUP
] = { .name
= "allow_backup", .type
= BLOBMSG_TYPE_BOOL
},
780 struct blob_attr
*validation
[__VALIDATION_MAX
];
781 struct blob_attr
*tb
[__SYSUPGRADE_MAX
];
782 bool valid
, forceable
, allow_backup
;
783 enum vjson_state ret
= VJSON_ERROR
;
787 return UBUS_STATUS_INVALID_ARGUMENT
;
789 blobmsg_parse(sysupgrade_policy
, __SYSUPGRADE_MAX
, tb
, blob_data(msg
), blob_len(msg
));
790 if (!tb
[SYSUPGRADE_PATH
] || !tb
[SYSUPGRADE_PREFIX
])
791 return UBUS_STATUS_INVALID_ARGUMENT
;
793 ret
= validate_firmware_image_call(blobmsg_get_string(tb
[SYSUPGRADE_PATH
]), &err
);
794 if (ret
!= VJSON_SUCCESS
) {
795 sysupgrade_error(ctx
, req
, err
);
796 return UBUS_STATUS_UNKNOWN_ERROR
;
799 blobmsg_parse(validation_policy
, __VALIDATION_MAX
, validation
, blob_data(b
.head
), blob_len(b
.head
));
801 if (!validation
[VALIDATION_VALID
] || !validation
[VALIDATION_FORCEABLE
] ||
802 !validation
[VALIDATION_ALLOW_BACKUP
]) {
803 sysupgrade_error(ctx
, req
, "Validation script provided invalid input");
804 return UBUS_STATUS_INVALID_ARGUMENT
;
807 valid
= validation
[VALIDATION_VALID
] && blobmsg_get_bool(validation
[VALIDATION_VALID
]);
808 forceable
= validation
[VALIDATION_FORCEABLE
] && blobmsg_get_bool(validation
[VALIDATION_FORCEABLE
]);
809 allow_backup
= validation
[VALIDATION_ALLOW_BACKUP
] && blobmsg_get_bool(validation
[VALIDATION_ALLOW_BACKUP
]);
813 sysupgrade_error(ctx
, req
, "Firmware image is broken and cannot be installed");
814 return UBUS_STATUS_NOT_SUPPORTED
;
815 } else if (!tb
[SYSUPGRADE_FORCE
] || !blobmsg_get_bool(tb
[SYSUPGRADE_FORCE
])) {
816 sysupgrade_error(ctx
, req
, "Firmware image is invalid");
817 return UBUS_STATUS_NOT_SUPPORTED
;
819 } else if (!allow_backup
&& tb
[SYSUPGRADE_BACKUP
]) {
820 sysupgrade_error(ctx
, req
, "Firmware image doesn't allow preserving a backup");
821 return UBUS_STATUS_NOT_SUPPORTED
;
826 sysupgrade_exec_upgraded(blobmsg_get_string(tb
[SYSUPGRADE_PREFIX
]),
827 blobmsg_get_string(tb
[SYSUPGRADE_PATH
]),
828 tb
[SYSUPGRADE_BACKUP
] ? blobmsg_get_string(tb
[SYSUPGRADE_BACKUP
]) : NULL
,
829 tb
[SYSUPGRADE_COMMAND
] ? blobmsg_get_string(tb
[SYSUPGRADE_COMMAND
]) : NULL
,
830 tb
[SYSUPGRADE_OPTIONS
]);
832 /* sysupgrade_exec_upgraded() will never return unless something has gone wrong */
833 return UBUS_STATUS_UNKNOWN_ERROR
;
837 procd_subscribe_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
)
839 notify
= obj
->has_subscribers
;
843 static const struct ubus_method system_methods
[] = {
844 UBUS_METHOD_NOARG("board", system_board
),
845 UBUS_METHOD_NOARG("info", system_info
),
846 UBUS_METHOD_NOARG("reboot", system_reboot
),
847 UBUS_METHOD("watchdog", watchdog_set
, watchdog_policy
),
848 UBUS_METHOD("signal", proc_signal
, signal_policy
),
849 UBUS_METHOD("validate_firmware_image", validate_firmware_image
, validate_firmware_image_policy
),
850 UBUS_METHOD("sysupgrade", sysupgrade
, sysupgrade_policy
),
853 static struct ubus_object_type system_object_type
=
854 UBUS_OBJECT_TYPE("system", system_methods
);
856 static struct ubus_object system_object
= {
858 .type
= &system_object_type
,
859 .methods
= system_methods
,
860 .n_methods
= ARRAY_SIZE(system_methods
),
861 .subscribe_cb
= procd_subscribe_cb
,
865 procd_bcast_event(char *event
, struct blob_attr
*msg
)
872 ret
= ubus_notify(_ctx
, &system_object
, event
, msg
, -1);
874 fprintf(stderr
, "Failed to notify log: %s\n", ubus_strerror(ret
));
877 void ubus_init_system(struct ubus_context
*ctx
)
883 initramfs
= !!getenv("INITRAMFS");
885 unsetenv("INITRAMFS");
887 ret
= ubus_add_object(ctx
, &system_object
);
889 ERROR("Failed to add object: %s\n", ubus_strerror(ret
));