static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
void *c;
char line[256];
static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
void *c;
char line[256];
!strcasecmp(key, "processor") ||
!strcasecmp(key, "model name"))
{
!strcasecmp(key, "processor") ||
!strcasecmp(key, "model name"))
{
- blobmsg_add_string(&b, "system", val + 2);
- break;
+ strtoul(val + 2, &key, 0);
+
+ if (key == (val + 2) || *key != 0)
+ {
+ blobmsg_add_string(&b, "system", val + 2);
+ break;
+ }
- if ((f = fopen("/tmp/sysinfo/model", "r")) != NULL)
+ if ((f = fopen("/tmp/sysinfo/model", "r")) != NULL ||
+ (f = fopen("/proc/device-tree/model", "r")) != NULL)
- blobmsg_add_string(&b, "description", val);
+ key = "description";
+ else
+ continue;
+
+ dest = blobmsg_alloc_string_buffer(&b, key, strlen(val));
+ if (!dest) {
+ ERROR("Failed to allocate blob.\n");
+ continue;
+ }
+
+ while (val && (ch = *(val++)) != 0) {
+ switch (ch) {
+ case '\'':
+ case '"':
+ next = strchr(val, ch);
+ if (next)
+ *next = 0;
+
+ strcpy(dest, val);
+
+ if (next)
+ val = next + 1;
+
+ dest += strlen(dest);
+ break;
+ case '\\':
+ *(dest++) = *(val++);
+ break;
+ }
+ }
+ blobmsg_add_string_buffer(&b);
c = blobmsg_open_array(&b, "load");
blobmsg_add_u32(&b, NULL, info.loads[0]);
c = blobmsg_open_array(&b, "load");
blobmsg_add_u32(&b, NULL, info.loads[0]);
blobmsg_close_array(&b, c);
c = blobmsg_open_table(&b, "memory");
blobmsg_close_array(&b, c);
c = blobmsg_open_table(&b, "memory");
- blobmsg_add_u32(&b, "total", info.mem_unit * info.totalram);
- blobmsg_add_u32(&b, "free", info.mem_unit * info.freeram);
- blobmsg_add_u32(&b, "shared", info.mem_unit * info.sharedram);
- blobmsg_add_u32(&b, "buffered", info.mem_unit * info.bufferram);
+ blobmsg_add_u64(&b, "total", info.mem_unit * info.totalram);
+ blobmsg_add_u64(&b, "free", info.mem_unit * info.freeram);
+ blobmsg_add_u64(&b, "shared", info.mem_unit * info.sharedram);
+ blobmsg_add_u64(&b, "buffered", info.mem_unit * info.bufferram);
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "swap");
blobmsg_close_table(&b, c);
c = blobmsg_open_table(&b, "swap");
- blobmsg_add_u32(&b, "total", info.mem_unit * info.totalswap);
- blobmsg_add_u32(&b, "free", info.mem_unit * info.freeswap);
+ blobmsg_add_u64(&b, "total", info.mem_unit * info.totalswap);
+ blobmsg_add_u64(&b, "free", info.mem_unit * info.freeswap);
-static int system_upgrade(struct ubus_context *ctx, struct ubus_object *obj,
- struct ubus_request_data *req, const char *method,
- struct blob_attr *msg)
+static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
-static const struct blobmsg_policy nand_policy[__NAND_MAX] = {
- [NAND_FOLDER] = { .name = "folder", .type = BLOBMSG_TYPE_STRING },
+static const struct blobmsg_policy sysupgrade_policy[__SYSUPGRADE_MAX] = {
+ [SYSUPGRADE_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
+ [SYSUPGRADE_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING },
+ [SYSUPGRADE_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_STRING },
- char *argv[] = { "/tmp/upgraded", NULL, NULL};
+ char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
+
+ if (chroot(prefix)) {
+ fprintf(stderr, "Failed to chroot for upgraded exec.\n");
+ return;
+ }
-static int nand_set(struct ubus_context *ctx, struct ubus_object *obj,
- struct ubus_request_data *req, const char *method,
- struct blob_attr *msg)
+static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
- blobmsg_parse(nand_policy, __NAND_MAX, tb, blob_data(msg), blob_len(msg));
- if (!tb[NAND_FOLDER])
+ blobmsg_parse(sysupgrade_policy, __SYSUPGRADE_MAX, tb, blob_data(msg), blob_len(msg));
+ if (!tb[SYSUPGRADE_PATH] || !tb[SYSUPGRADE_PREFIX])
- procd_spawn_upgraded(blobmsg_get_string(tb[NAND_FOLDER]));
- fprintf(stderr, "Yikees, something went wrong. no /sbin/upgraded ?\n");
+ procd_exec_upgraded(blobmsg_get_string(tb[SYSUPGRADE_PREFIX]),
+ blobmsg_get_string(tb[SYSUPGRADE_PATH]),
+ tb[SYSUPGRADE_COMMAND] ? blobmsg_get_string(tb[SYSUPGRADE_COMMAND]) : NULL);
static const struct ubus_method system_methods[] = {
UBUS_METHOD_NOARG("board", system_board),
UBUS_METHOD_NOARG("info", system_info),
static const struct ubus_method system_methods[] = {
UBUS_METHOD_NOARG("board", system_board),
UBUS_METHOD_NOARG("info", system_info),
UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
UBUS_METHOD("signal", proc_signal, signal_policy),
UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
UBUS_METHOD("signal", proc_signal, signal_policy),
- UBUS_METHOD("nandupgrade", nand_set, nand_policy),
+ UBUS_METHOD("sysupgrade", sysupgrade, sysupgrade_policy),