system: introduce new attribute board_name
[project/procd.git] / system.c
index 504cdc02f012af778aadd150def1949e8db3d148..c4d67a6dd4eefad3a931aed538c620a1e5080d11 100644 (file)
--- a/system.c
+++ b/system.c
@@ -18,6 +18,7 @@
 #endif
 #include <sys/ioctl.h>
 #include <sys/types.h>
+#include <sys/reboot.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <signal.h>
@@ -114,6 +115,40 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
                fclose(f);
        }
 
+       if ((f = fopen("/tmp/sysinfo/board_name", "r")) != NULL)
+       {
+               if (fgets(line, sizeof(line), f))
+               {
+                       val = strtok(line, "\t\n");
+
+                       if (val)
+                               blobmsg_add_string(&b, "board_name", val);
+               }
+
+               fclose(f);
+       }
+       else if ((f = fopen("/proc/device-tree/compatible", "r")) != NULL)
+       {
+               if (fgets(line, sizeof(line), f))
+               {
+                       val = strtok(line, "\t\n");
+
+                       if (val)
+                       {
+                               next = val;
+                               while ((next = strchr(next, ',')) != NULL)
+                               {
+                                       *next = '-';
+                                       next++;
+                               }
+
+                               blobmsg_add_string(&b, "board_name", val);
+                       }
+               }
+
+               fclose(f);
+       }
+
        if ((f = fopen("/etc/openwrt_release", "r")) != NULL)
        {
                c = blobmsg_open_table(&b, "release");
@@ -205,7 +240,7 @@ static int system_info(struct ubus_context *ctx, struct ubus_object *obj,
 
        blob_buf_init(&b, 0);
 
-       blobmsg_add_u32(&b, "localtime", mktime(tm));
+       blobmsg_add_u32(&b, "localtime", now + tm->tm_gmtoff);
 
 #ifdef linux
        blobmsg_add_u32(&b, "uptime",    info.uptime);
@@ -242,6 +277,14 @@ static int system_upgrade(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
+static int system_reboot(struct ubus_context *ctx, struct ubus_object *obj,
+                        struct ubus_request_data *req, const char *method,
+                        struct blob_attr *msg)
+{
+       procd_shutdown(RB_AUTOBOOT);
+       return 0;
+}
+
 enum {
        WDT_FREQUENCY,
        WDT_TIMEOUT,
@@ -388,6 +431,7 @@ static const struct ubus_method system_methods[] = {
        UBUS_METHOD_NOARG("board", system_board),
        UBUS_METHOD_NOARG("info",  system_info),
        UBUS_METHOD_NOARG("upgrade", system_upgrade),
+       UBUS_METHOD_NOARG("reboot", system_reboot),
        UBUS_METHOD("watchdog", watchdog_set, watchdog_policy),
        UBUS_METHOD("signal", proc_signal, signal_policy),