discover/status: Use full URL in parse status message
[petitboot] / discover / sysinfo.c
index 3c132774e21b3599e0c61e45b6ceaba5ebb847c3..219369a0d5456f5bda27fed2ba7a534a4db7b64b 100644 (file)
@@ -5,25 +5,26 @@
 #include <process/process.h>
 
 #include "discover-server.h"
+#include "platform.h"
 #include "sysinfo.h"
 
 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;
 }
 
 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
-               const char *name)
+               const char *name, bool link)
 {
        struct interface_info *if_info;
        unsigned int i;
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
+               bool changed = false;
+
                if_info = sysinfo->interfaces[i];
 
                if (if_info->hwaddr_size != hwaddr_size)
@@ -32,10 +33,22 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
                if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
                        continue;
 
-               /* update the name and we're done */
-               talloc_free(if_info->name);
-               if_info->name = talloc_strdup(if_info, name);
-               discover_server_notify_system_info(server, sysinfo);
+               /* Found an existing interface. Notify clients on any name or
+                * link changes */
+               if (strcmp(if_info->name, name)) {
+                       talloc_free(if_info->name);
+                       if_info->name = talloc_strdup(if_info, name);
+                       changed = true;
+               }
+
+               if (if_info->link != link) {
+                       if_info->link = link;
+                       changed = true;
+               }
+
+               if (changed)
+                       discover_server_notify_system_info(server, sysinfo);
+
                return;
        }
 
@@ -43,6 +56,7 @@ void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
        if_info->hwaddr_size = hwaddr_size;
        if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
        if_info->name = talloc_strdup(if_info, name);
+       if_info->link = link;
 
        sysinfo->n_interfaces++;
        sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
@@ -87,41 +101,9 @@ void system_info_register_blockdev(const char *name, const char *uuid,
        discover_server_notify_system_info(server, sysinfo);
 }
 
-static void system_info_set_identifier(struct system_info *info)
-{
-       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)
 {
        server = s;
        sysinfo = talloc_zero(server, struct system_info);
-       system_info_set_identifier(sysinfo);
+       platform_get_sysinfo(sysinfo);
 }