system: introduce new attribute board_name
authorDaniel Golle <daniel@makrotopia.org>
Sun, 18 Jun 2017 22:53:00 +0000 (00:53 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 18 Jun 2017 23:00:11 +0000 (01:00 +0200)
Instead of modifying the already defined 'model' attribute rather
introduce a new attribute board_name to return either
/tmp/sysinfo/board_name or /proc/device-tree/compatible.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
system.c

index 4bbceee7bdf0cfb2a11d8e96817373cdb0864e98..6e85ad798808283c11166772bd9fcc5b59238333 100644 (file)
--- a/system.c
+++ b/system.c
@@ -80,7 +80,7 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
                fclose(f);
        }
 
-       if ((f = fopen("/tmp/sysinfo/board_name", "r")) != NULL ||
+       if ((f = fopen("/tmp/sysinfo/model", "r")) != NULL ||
            (f = fopen("/proc/device-tree/model", "r")) != NULL)
        {
                if (fgets(line, sizeof(line), f))
@@ -114,6 +114,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");