discover/sysinfo: Add helper script to populate sysinfo identifiers
authorJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 07:40:42 +0000 (15:40 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Wed, 9 Oct 2013 09:40:16 +0000 (17:40 +0800)
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/Makefile.am
discover/sysinfo.c
utils/Makefile.am
utils/pb-sysinfo [new file with mode: 0755]

index 1fd8d96c6001954c1620f6b5865e463146065b35..2a7885d7c7c1ebb379578766a579ec21b9f8c5cc 100644 (file)
@@ -22,6 +22,7 @@ AM_CFLAGS = $(DEFAULT_CFLAGS)  \
        -DPREFIX='"$(prefix)"' \
        -DPKG_SHARE_DIR='"$(pkgdatadir)"' \
        -DPKG_SYSCONF_DIR='"$(pkgsysconfdir)"' \
+       -DPKG_LIBEXEC_DIR='"$(pkglibexecdir)"' \
        -DLOCAL_STATE_DIR='"$(localstatedir)"'
 
 EXTRA_DIST = native-parser.c
index 19dac57f02fb26757948605f716a2e94ba44550a..f75819bd96ac02adc563b30afd046b457d97bd67 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 
 #include <talloc/talloc.h>
+#include <process/process.h>
 
 #include "discover-server.h"
 #include "sysinfo.h"
@@ -9,6 +10,8 @@
 static struct system_info *sysinfo;
 static struct discover_server *server;
 
+static const char *sysinfo_helper = PKG_LIBEXEC_DIR "/pb-sysinfo";
+
 const struct system_info *system_info_get(void)
 {
        return sysinfo;
@@ -50,10 +53,36 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
        discover_server_notify_system_info(server, sysinfo);
 }
 
-static void system_info_set_identifier(struct system_info *info
-               __attribute__((unused)))
+static void system_info_set_identifier(struct system_info *info)
 {
-       /* todo: call helpers to set type & id */
+       struct process *process;
+       int rc;
+       const char *argv[] = {
+               sysinfo_helper, NULL, NULL,
+       };
+
+       process = process_create(info);
+       process->path = sysinfo_helper;
+       process->argv = argv;
+       process->keep_stdout = true;
+
+       argv[1] = "--type";
+       rc = process_run_sync(process);
+
+       if (!rc) {
+               info->type = talloc_strndup(info, process->stdout_buf,
+                               process->stdout_len);
+       }
+
+       argv[1] = "--id";
+       rc = process_run_sync(process);
+
+       if (!rc) {
+               info->identifier = talloc_strndup(info, process->stdout_buf,
+                               process->stdout_len);
+       }
+
+       process_release(process);
 }
 
 void system_info_init(struct discover_server *s)
index 6758d6812dbc5987a6d0db9baa4feeaeca1ae328..a01bfe809825c2cd8294a56fadd54673fe30614d 100644 (file)
@@ -21,7 +21,7 @@ AM_CFLAGS = \
        $(DEFAULT_CFLAGS)
 
 dist_sbin_SCRIPTS = pb-udhcpc
-dist_pkglibexec_SCRIPTS = pb-console
+dist_pkglibexec_SCRIPTS = pb-console pb-sysinfo
 
 sbin_PROGRAMS = pb-event
 
diff --git a/utils/pb-sysinfo b/utils/pb-sysinfo
new file mode 100755 (executable)
index 0000000..bd2f0fe
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+case "$1" in
+'--type')
+       tr -d '\0' < /proc/device-tree/model
+       ;;
+'--id')
+       tr -d '\0' < /proc/device-tree/system-id
+       ;;
+esac