4 #include <talloc/talloc.h>
5 #include <process/process.h>
7 #include "discover-server.h"
10 static struct system_info *sysinfo;
11 static struct discover_server *server;
13 static const char *sysinfo_helper = PKG_LIBEXEC_DIR "/pb-sysinfo";
15 const struct system_info *system_info_get(void)
20 void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,
23 struct interface_info *if_info;
26 for (i = 0; i < sysinfo->n_interfaces; i++) {
27 if_info = sysinfo->interfaces[i];
29 if (if_info->hwaddr_size != hwaddr_size)
32 if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size))
35 /* update the name and we're done */
36 talloc_free(if_info->name);
37 if_info->name = talloc_strdup(if_info, name);
38 discover_server_notify_system_info(server, sysinfo);
42 if_info = talloc_zero(sysinfo, struct interface_info);
43 if_info->hwaddr_size = hwaddr_size;
44 if_info->hwaddr = talloc_memdup(if_info, hwaddr, hwaddr_size);
45 if_info->name = talloc_strdup(if_info, name);
47 sysinfo->n_interfaces++;
48 sysinfo->interfaces = talloc_realloc(sysinfo, sysinfo->interfaces,
49 struct interface_info *,
50 sysinfo->n_interfaces);
51 sysinfo->interfaces[sysinfo->n_interfaces - 1] = if_info;
53 discover_server_notify_system_info(server, sysinfo);
56 static void system_info_set_identifier(struct system_info *info)
58 struct process *process;
60 const char *argv[] = {
61 sysinfo_helper, NULL, NULL,
64 process = process_create(info);
65 process->path = sysinfo_helper;
67 process->keep_stdout = true;
70 rc = process_run_sync(process);
73 info->type = talloc_strndup(info, process->stdout_buf,
78 rc = process_run_sync(process);
81 info->identifier = talloc_strndup(info, process->stdout_buf,
85 process_release(process);
88 void system_info_init(struct discover_server *s)
91 sysinfo = talloc_zero(server, struct system_info);
92 system_info_set_identifier(sysinfo);