4 #include <talloc/talloc.h>
5 #include <process/process.h>
7 #include "discover-server.h"
11 static struct system_info *sysinfo;
12 static struct discover_server *server;
14 const struct system_info *system_info_get(void)
19 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
20 const char *name, bool link)
22 struct interface_info *if_info;
25 for (i = 0; i < sysinfo->n_interfaces; i++) {
28 if_info = sysinfo->interfaces[i];
30 if (if_info->hwaddr_size != hwaddr_size)
33 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
36 /* Found an existing interface. Notify clients on any name or
38 if (strcmp(if_info->name, name)) {
39 talloc_free(if_info->name);
40 if_info->name = talloc_strdup(if_info, name);
44 if (if_info->link != link) {
50 discover_server_notify_system_info(server, sysinfo);
55 if_info = talloc_zero(sysinfo, struct interface_info);
56 if_info->hwaddr_size = hwaddr_size;
57 if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
58 if_info->name = talloc_strdup(if_info, name);
61 sysinfo->n_interfaces++;
62 sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
63 struct interface_info *,
64 sysinfo->n_interfaces);
65 sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
67 discover_server_notify_system_info(server, sysinfo);
70 void system_info_register_blockdev(const char *name, const char *uuid,
71 const char *mountpoint)
73 struct blockdev_info *bd_info;
76 for (i = 0; i < sysinfo->n_blockdevs; i++) {
77 bd_info = sysinfo->blockdevs[i];
79 if (strcmp(bd_info->name, name))
82 /* update the mountpoint and UUID, and we're done */
83 talloc_free(bd_info->mountpoint);
84 bd_info->uuid = talloc_strdup(bd_info, uuid);
85 bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
86 discover_server_notify_system_info(server, sysinfo);
90 bd_info = talloc_zero(sysinfo, struct blockdev_info);
91 bd_info->name = talloc_strdup(bd_info, name);
92 bd_info->uuid = talloc_strdup(bd_info, uuid);
93 bd_info->mountpoint = talloc_strdup(bd_info, mountpoint);
95 sysinfo->n_blockdevs++;
96 sysinfo->blockdevs = talloc_realloc(sysinfo, sysinfo->blockdevs,
97 struct blockdev_info *,
98 sysinfo->n_blockdevs);
99 sysinfo->blockdevs[sysinfo->n_blockdevs - 1] = bd_info;
101 discover_server_notify_system_info(server, sysinfo);
104 void system_info_init(struct discover_server *s)
107 sysinfo = talloc_zero(server, struct system_info);
108 platform_get_sysinfo(sysinfo);