recatagorize QEMU/KVM/etc. to correct baremetal classification
[systembsd.git] / src / interfaces / hostnamed / hostnamed.c
CommitLineData
3b82e3c1 1/*
2 * Copyright (c) 2014 Ian Sutton <ian@kremlin.cc>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
a35a69c5 17#include <unistd.h>
18#include <limits.h>
0f339959 19#include <signal.h>
f8257c5d 20#include <string.h>
fd8852d9 21
d15318db 22#include <sys/param.h>
f1ad9351 23#include <sys/sysctl.h>
f8257c5d 24#include <sys/sensors.h>
25#include <sys/ioctl.h>
bd24ff31 26#include <sys/utsname.h>
f8257c5d 27
28#include <machine/apmvar.h>
d15318db 29
4c04b514 30#include <glib/gprintf.h>
8caf1f61 31#include <glib-unix.h>
a1bcc33c 32/* #include <gtk/gtk.h> */
4c04b514 33
1e8c7c88 34#include "hostnamed-gen.h"
0f339959 35#include "hostnamed.h"
a35a69c5 36
a1bcc33c 37/* add any sysctl strings that suggest virtualization here */
38/* format: {
39 * (1) string to be matched against runtime machine's sysctl output.
40 * can be either the exact string or a substring contained
41 * within sysctl strings. no "guesses" here, a match should
42 * reliably indicate the chassis/icon.
43 *
44 * (2) string describing chassis type divulged by (1).
45 * must be one of "desktop", "laptop", "server",
46 * "tablet", "handset", "vm", "container" or NULL
47 * if only icon string can be ascertained. "vm" refers
48 * to operating systems running on baremetal hypervisors
49 * (hardware virtualization, like XEN) while "container"
50 * refers to OSs running on shared hypervisors like
51 * virtualbox or VMware. consider the distinction carefully
52 * as common virtualization software like KVM may share
53 * characteristics of both "vm" and "container" types.
54 *
55 * (3) string specifying icon to use. follows XDG icon spec.
56 * see http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
57 * for allowed strings.
58 *
59 * (4) chassis precedence bit. TRUE if (2) is defined and
60 * we're certain it is the proper string. FALSE in the
61 * circumstance (2) may be the correct string, unless
62 * a match with this bit set to TRUE overrides it.
63 * if (2) is NULL, this bit is inconsequential.
64 *
65 * (5) icon precedence bit. see previous definition.
66 * } */
67struct SYSCTL_LOOKUP_TABLE {
68 gchar *match_string;
69 gchar *chassis;
70 gchar *icon;
71 gboolean chassis_precedence;
72 gboolean icon_precedence;
73};
74
fd8852d9 75GPtrArray *hostnamed_freeable;
1be94ede 76Hostname1 *hostnamed_interf;
3d53b501 77
0f339959 78GMainLoop *hostnamed_loop;
79
80guint bus_descriptor;
81gboolean dbus_interface_exported; /* reliable because of gdbus operational guarantees */
82
a1bcc33c 83gchar *CHASSIS, *ICON;
bd24ff31 84gchar *OS_CPENAME;
85gchar *KERN_NAME, *KERN_RELEASE, *KERN_VERS;
a1bcc33c 86
87/* TODO no specific vm or laptop icon in gnome
88 * NOTE paravirtualization on xen is only available for linuxes right now
89 * dmesg on linux systems reveals xen and virtualization method (HVM or PVM)
90 * but we will worry about those later */
91const struct SYSCTL_LOOKUP_TABLE chassis_indicator_table[] =
92{
87df323f 93 { "QEMU Virtual CPU", "vm", NULL, FALSE, FALSE }, /* could be QEMU running in userspace or as part of KVM */
6edc347a 94 { "KVM", "vm", "drive-multidisk", FALSE, FALSE },
a1bcc33c 95 { "SmartDC HVM", "vm", "drive-multidisk", TRUE, TRUE }, /* oracle solaris kvm */
87df323f 96 { "VirtualBox", "vm", "drive-multidisk", TRUE, TRUE },
97 { "VMware, Inc.", "vm", "drive-multidisk", TRUE, TRUE },
98 { "VMware Virtual Platform", "vm", "drive-multidisk", TRUE, TRUE },
99 { "Parallels", "vm", "drive-multidisk", TRUE, TRUE }, /* need verification */
100 { "Xen", "vm", "drive-multidisk", TRUE, TRUE }
101}; /* TODO: chroots, etc. are the actual "containers", add them */
76b67a18 102
f8257c5d 103/* archs to check against when determining if machine is server */
104const gchar *server_archs[] = {
105 "hppa",
106 "sparc",
107 "sparc64"
108};
f1ad9351 109
a1bcc33c 110/* --- begin method/property/dbus signal code --- */
f1ad9351 111
3d53b501 112static gboolean
1be94ede 113on_handle_set_hostname(Hostname1 *hn1_passed_interf,
3d53b501 114 GDBusMethodInvocation *invoc,
115 const gchar *greet,
116 gpointer data) {
117 return FALSE;
118}
119
120static gboolean
1be94ede 121on_handle_set_static_hostname(Hostname1 *hn1_passed_interf,
3d53b501 122 GDBusMethodInvocation *invoc,
123 const gchar *greet,
124 gpointer data) {
125 return FALSE;
126}
127
128static gboolean
1be94ede 129on_handle_set_pretty_hostname(Hostname1 *hn1_passed_interf,
3d53b501 130 GDBusMethodInvocation *invoc,
131 const gchar *greet,
132 gpointer data) {
133 return FALSE;
134}
135
136static gboolean
1be94ede 137on_handle_set_chassis(Hostname1 *hn1_passed_interf,
3d53b501 138 GDBusMethodInvocation *invoc,
139 const gchar *greet,
140 gpointer data) {
141 return FALSE;
142}
143
144static gboolean
1be94ede 145on_handle_set_icon_name(Hostname1 *hn1_passed_interf,
3d53b501 146 GDBusMethodInvocation *invoc,
147 const gchar *greet,
148 gpointer data) {
149 return FALSE;
150}
151
76b67a18 152/* note: all hostnamed/hostname1's properties are read-only,
153 * and do not need set_ functions, gdbus-codegen realized
154 * this from the XML and handled the to-be error of trying
155 * to set a read-only property's value
156 */
157
158const gchar *
159our_get_hostname() {
160
90f54407 161 gchar *hostname_buf, *ret;
162 size_t hostname_divider;
d15318db 163
a2fffc07 164 hostname_buf = (gchar*) g_malloc0(MAXHOSTNAMELEN);
90f54407 165 ret = (gchar*) g_malloc0(MAXHOSTNAMELEN);
a2fffc07 166
90f54407 167 g_ptr_array_add(hostnamed_freeable, hostname_buf);
168 g_ptr_array_add(hostnamed_freeable, ret);
7323a4e4 169
a2fffc07 170 if(gethostname(hostname_buf, MAXHOSTNAMELEN) || g_strcmp0(hostname_buf, "") == 0)
171 return "localhost";
d15318db 172
90f54407 173 hostname_divider = strcspn(hostname_buf, ".");
28cac2f0 174
90f54407 175 return strncpy(ret, hostname_buf, hostname_divider);
76b67a18 176}
177
178const gchar *
179our_get_static_hostname() {
180
af14252f 181 const gchar *pretty_hostname;
182 const gchar *ret;
a2fffc07 183
184 pretty_hostname = our_get_pretty_hostname();
185
186 if(g_strcmp0(pretty_hostname, "") == 0)
187 ret = our_get_hostname();
188
af14252f 189 else if((ret = g_hostname_to_ascii(pretty_hostname))) {
a2fffc07 190
af14252f 191 g_ptr_array_add(hostnamed_freeable, (gpointer)ret);
a2fffc07 192 return ret;
193 }
194
195 return ret;
76b67a18 196}
197
198const gchar *
199our_get_pretty_hostname() {
200
a2fffc07 201 GKeyFile *config;
202 gchar *ret;
203
f1ad9351 204 config = g_key_file_new();
205
a2fffc07 206 if(g_key_file_load_from_file(config, "/etc/systemd_compat.conf", G_KEY_FILE_NONE, NULL)
af14252f 207 && (ret = g_key_file_get_value(config, "hostnamed", "PrettyHostname", NULL))) { /* ret might need to be freed, docs dont specify but i am suspicious */
a2fffc07 208
f1ad9351 209 g_key_file_unref(config);
a2fffc07 210 return ret;
211 }
212
213 if(config)
214 g_free(config);
215
216 return "";
76b67a18 217}
218
219const gchar *
220our_get_chassis() {
221
f8257c5d 222 if(CHASSIS)
223 return CHASSIS;
f1ad9351 224
f8257c5d 225 return "desktop";
76b67a18 226}
227
228const gchar *
229our_get_icon_name() {
230
f8257c5d 231 if(ICON)
232 return ICON;
233
234 return "";
76b67a18 235}
236
237const gchar *
238our_get_kernel_name() {
239
bd24ff31 240 if(KERN_NAME)
241 return KERN_NAME;
242
243 return "";
76b67a18 244}
245
246const gchar *
247our_get_kernel_version() {
248
bd24ff31 249 if(KERN_VERS)
250 return KERN_VERS;
251
252 return "";
76b67a18 253}
254
255const gchar *
256our_get_kernel_release() {
257
bd24ff31 258 if(KERN_RELEASE)
259 return KERN_RELEASE;
260
261 return "";
76b67a18 262}
263
264const gchar *
265our_get_os_cpename() {
266
bd24ff31 267 return "ONEDAY";
76b67a18 268}
269
270const gchar *
271our_get_os_pretty_name() {
272
bd24ff31 273 return "OpenBSD";
76b67a18 274}
275
1ce41045 276/* --- end method/property/dbus signal code, begin bus/name handlers --- */
0df0018d 277
5b005882 278static void hostnamed_on_bus_acquired(GDBusConnection *conn,
1cd5e6fe 279 const gchar *name,
280 gpointer user_data) {
d1e1db9e 281
0f339959 282 g_printf("got bus/name, exporting %s's interface...\n", name);
d1e1db9e 283
90f54407 284 hostnamed_interf = hostname1_skeleton_new();
3d53b501 285
76b67a18 286 /* attach function pointers to generated struct's method handlers */
3d53b501 287 g_signal_connect(hostnamed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
288 g_signal_connect(hostnamed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
289 g_signal_connect(hostnamed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
290 g_signal_connect(hostnamed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
291 g_signal_connect(hostnamed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL);
292
76b67a18 293 /* set our properties before export */
1be94ede 294 hostname1_set_hostname(hostnamed_interf, our_get_hostname());
295 hostname1_set_static_hostname(hostnamed_interf, our_get_static_hostname());
296 hostname1_set_pretty_hostname(hostnamed_interf, our_get_pretty_hostname());
297 hostname1_set_chassis(hostnamed_interf, our_get_chassis());
298 hostname1_set_icon_name(hostnamed_interf, our_get_icon_name());
299 hostname1_set_kernel_name(hostnamed_interf, our_get_kernel_name());
300 hostname1_set_kernel_version(hostnamed_interf, our_get_kernel_version());
301 hostname1_set_kernel_release(hostnamed_interf, our_get_kernel_release());
302 hostname1_set_operating_system_cpename(hostnamed_interf, our_get_os_cpename());
303 hostname1_set_operating_system_pretty_name(hostnamed_interf, our_get_os_pretty_name());
76b67a18 304
3d53b501 305 if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(hostnamed_interf),
1be94ede 306 conn,
307 "/org/freedesktop/hostname1",
308 NULL)) {
3d53b501 309
0f339959 310 g_printf("failed to export %s's interface!\n", name); /* unusual edge case, TODO check errno */
90f54407 311 hostnamed_mem_clean();
3d53b501 312
0f339959 313 } else {
ea207ed3 314
90f54407 315 dbus_interface_exported = TRUE;
316 g_printf("exported %s's interface on the system bus...\n", name);
317 }
0f339959 318}
1e8c7c88 319
0f339959 320static void hostnamed_on_name_acquired(GDBusConnection *conn,
90f54407 321 const gchar *name,
0f339959 322 gpointer user_data) {
323
324 g_printf("success!\n");
1e8c7c88 325}
326
5b005882 327static void hostnamed_on_name_lost(GDBusConnection *conn,
1be94ede 328 const gchar *name,
329 gpointer user_data) {
80043b36 330
90f54407 331 if(!conn) {
0f339959 332
90f54407 333 g_printf("failed to connect to the system bus while trying to acquire name '%s': either dbus-daemon isn't running or we don't have permission to push names and/or their interfaces to it.\n", name);
334 hostnamed_mem_clean();
335 }
0f339959 336
509599f0 337 g_printf("lost name %s, exiting...\n", name);
fd8852d9 338
1cd5e6fe 339 hostnamed_mem_clean();
0f339959 340}
341
342/* --- end bus/name handlers, begin misc unix functions --- */
343
344/* safe call to clean and then exit
509599f0 345 * this stops our GMainLoop safely before letting main() return */
0f339959 346void hostnamed_mem_clean() {
347
90f54407 348 g_printf("exiting...\n");
0f339959 349
90f54407 350 if(dbus_interface_exported)
351 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(hostnamed_interf));
0f339959 352
90f54407 353 if(g_main_loop_is_running(hostnamed_loop))
354 g_main_loop_quit(hostnamed_loop);
fd8852d9 355
ea207ed3 356}
357
0f339959 358/* wrapper for glib's unix signal handling; called only once if terminatating signal is raised against us */
359gboolean unix_sig_terminate_handler(gpointer data) {
c62bceb7 360
90f54407 361 g_printf("caught SIGINT/HUP/TERM, exiting\n");
0f339959 362
90f54407 363 hostnamed_mem_clean();
364 return G_SOURCE_REMOVE;
0f339959 365}
366
367void set_signal_handlers() {
368
90f54407 369 /* we don't care about its descriptor, we never need to unregister these */
370 g_unix_signal_add(SIGINT, unix_sig_terminate_handler, NULL);
371 g_unix_signal_add(SIGHUP, unix_sig_terminate_handler, NULL);
372 g_unix_signal_add(SIGTERM, unix_sig_terminate_handler, NULL);
04cc16f2 373
90f54407 374 /* TODO: the "only once" guarantee only counts towards specific signals.
375 * make sure calling a SIGINT and SIGHUP doesn't cause term_handler()
376 * to be called twice */
0f339959 377}
378
379int main() {
bd24ff31 380
381 hostnamed_freeable = g_ptr_array_new();
382
a0ebb315 383 /* TODO: check for valid, writable config at init. if no, complain to `make install` */
bd24ff31 384
385 CHASSIS = ICON = OS_CPENAME = 0;
386 KERN_NAME = KERN_RELEASE = KERN_VERS = 0;
a0ebb315 387
90f54407 388 set_signal_handlers();
387173cb 389
bd24ff31 390 if(!determine_chassis_and_icon() || !set_uname_properties())
a1bcc33c 391 return 1;
392
393 hostnamed_loop = g_main_loop_new(NULL, TRUE);
fd8852d9 394
90f54407 395 bus_descriptor = g_bus_own_name(G_BUS_TYPE_SYSTEM,
0f339959 396 "org.freedesktop.hostname1",
397 G_BUS_NAME_OWNER_FLAGS_NONE,
398 hostnamed_on_bus_acquired,
399 hostnamed_on_name_acquired,
400 hostnamed_on_name_lost,
401 NULL,
402 NULL);
496f5d66 403
90f54407 404 g_main_loop_run(hostnamed_loop);
405 /* runs until single g_main_loop_quit() call is raised inside <interface>_mem_clean() */
406 g_main_loop_unref(hostnamed_loop);
1e8c7c88 407
90f54407 408 /* guaranteed unownable */
409 g_bus_unown_name(bus_descriptor);
c62bceb7 410
90f54407 411 /* at this point no operations can occur with our data, it is safe to free it + its container */
412 g_ptr_array_free(hostnamed_freeable, TRUE);
7323a4e4 413
90f54407 414 return 0;
a35a69c5 415}
416
bd24ff31 417gboolean set_uname_properties() {
418
419 struct utsname un;
420
421 if(-1 == uname(&un))
422 return FALSE;
423
424 KERN_NAME = (gchar*)g_malloc0(sizeof(un.sysname));
425 g_ptr_array_add(hostnamed_freeable, KERN_NAME);
426 g_strlcpy(KERN_NAME, un.sysname, sizeof(un.sysname));
427
428 KERN_RELEASE = (gchar*)g_malloc0(sizeof(un.release));
429 g_ptr_array_add(hostnamed_freeable, KERN_RELEASE);
430 g_strlcpy(KERN_RELEASE, un.release, sizeof(un.release));
431
432 KERN_VERS = (gchar*)g_malloc0(sizeof(un.version));
433 g_ptr_array_add(hostnamed_freeable, KERN_VERS);
434 g_strlcpy(KERN_VERS, un.version, sizeof(un.version));
435
436 return TRUE;
437}
438
a1bcc33c 439gboolean determine_chassis_and_icon() {
440
b81ab32a 441 const size_t bufsize = 4096;
442
f8257c5d 443 char *hwproduct, *hwmodel, *hwvendor, *hwmachine;
444 size_t hwproduct_size, hwmodel_size, hwvendor_size, hwmachine_size;
445 int hwproduct_name[2], hwmodel_name[2], hwvendor_name[2], hwmachine_name[2];
f1ad9351 446 unsigned int i;
f8257c5d 447 gboolean UNSURE_CHASSIS_FLAG, UNSURE_ICON_FLAG;
448
b81ab32a 449 hwproduct_size = hwmodel_size = hwvendor_size = hwmachine_size = bufsize;
68e777c6 450 UNSURE_CHASSIS_FLAG = UNSURE_ICON_FLAG = FALSE;
5ac7f542 451 i = 0;
f1ad9351 452
b81ab32a 453 hwproduct = (char*)g_malloc0(4096);
454 hwmodel = (char*)g_malloc0(4096);
455 hwvendor = (char*)g_malloc0(4096);
456 hwmachine = (char*)g_malloc0(4096);
457
bd24ff31 458 g_ptr_array_add(hostnamed_freeable, hwproduct);
459 g_ptr_array_add(hostnamed_freeable, hwmodel);
460 g_ptr_array_add(hostnamed_freeable, hwvendor);
461 g_ptr_array_add(hostnamed_freeable, hwmachine);
462
a1bcc33c 463 hwproduct_name[0] = CTL_HW;
464 hwproduct_name[1] = HW_PRODUCT;
f1ad9351 465
a1bcc33c 466 hwmodel_name[0] = CTL_HW;
467 hwmodel_name[1] = HW_MODEL;
468
469 hwvendor_name[0] = CTL_HW;
470 hwvendor_name[1] = HW_VENDOR;
471
f8257c5d 472 hwmachine_name[0] = CTL_HW;
473 hwmachine_name[1] = HW_MACHINE;
474
a1bcc33c 475 /* pass NULL buffer to check size first, then pass hw to be filled according to freshly-set hw_size */
476 if(-1 == sysctl(hwproduct_name, 2, NULL, &hwproduct_size, NULL, 0) || -1 == sysctl(hwproduct_name, 2, hwproduct, &hwproduct_size, NULL, 0))
477 return FALSE;
478
479 if(-1 == sysctl(hwmodel_name, 2, NULL, &hwmodel_size, NULL, 0) || -1 == sysctl(hwmodel_name, 2, hwmodel, &hwmodel_size, NULL, 0))
480 return FALSE;
481
482 if(-1 == sysctl(hwvendor_name, 2, NULL, &hwvendor_size, NULL, 0) || -1 == sysctl(hwvendor_name, 2, hwvendor, &hwvendor_size, NULL, 0))
483 return FALSE;
484
f8257c5d 485 if(-1 == sysctl(hwmachine_name, 2, NULL, &hwmachine_size, NULL, 0) || -1 == sysctl(hwmachine_name, 2, hwmachine, &hwmachine_size, NULL, 0))
486 return FALSE;
487
a1bcc33c 488 /* TODO: test for laptop, if not, dmidecode for desktop vs. server
489 * probably move this code to vm test func and set a global after running it early, once */
490
f8257c5d 491 for(; i < G_N_ELEMENTS(chassis_indicator_table); i++) {
492 if(strcasestr(hwproduct, chassis_indicator_table[i].match_string)
493 || strcasestr(hwmodel, chassis_indicator_table[i].match_string)
494 || strcasestr(hwvendor, chassis_indicator_table[i].match_string)) {
495
496 if(!UNSURE_CHASSIS_FLAG && chassis_indicator_table[i].chassis) {
497
498 UNSURE_CHASSIS_FLAG = chassis_indicator_table[i].chassis_precedence;
499 CHASSIS = chassis_indicator_table[i].chassis;
500 }
501
502 if(!UNSURE_ICON_FLAG && chassis_indicator_table[i].icon) {
503
504 UNSURE_ICON_FLAG = chassis_indicator_table[i].icon_precedence;
505 ICON = chassis_indicator_table[i].icon;
506 }
507 }
508 }
509
510 if(up_native_is_laptop()) {
511
512 if(!CHASSIS)
513 CHASSIS = "laptop";
514 if(!ICON)
515 ICON = "input-touchpad"; /* TODO pull an icon package that actually has the icons we're looking for */
516
517 } else if(is_server(hwmachine)) {
518
519 if(!CHASSIS)
520 CHASSIS = "server";
521 if(!ICON)
522 ICON = "uninterruptible-power-supply";
523
524 } else if(!CHASSIS || !ICON) {
f1ad9351 525
f8257c5d 526 if(!CHASSIS)
527 CHASSIS = "desktop";
528 if(!ICON)
529 ICON = "computer";
530 }
531
532 return (CHASSIS && ICON);
533}
534
535gboolean is_server(gchar *arch) {
536
537 unsigned int i;
a1bcc33c 538
f8257c5d 539 for(; i < G_N_ELEMENTS(server_archs); i++)
540 if(strcasestr(arch, server_archs[i]))
541 return TRUE;
542
543 return FALSE;
544}
545
546gboolean up_native_is_laptop() {
547
548 struct apm_power_info bstate;
549 struct sensordev acpiac;
550
551 if (up_native_get_sensordev("acpiac0", &acpiac))
552 return TRUE;
553
554 if (-1 == ioctl(up_apm_get_fd(), APM_IOC_GETPOWER, &bstate))
555 g_error("ioctl on apm fd failed : %s", g_strerror(errno));
556
557 return bstate.ac_state != APM_AC_UNKNOWN;
558}
559
560int up_apm_get_fd() {
561
562 static int apm_fd = 0;
563
564 if(apm_fd == 0) {
565
566 g_debug("apm_fd is not initialized yet, opening");
567
568 /* open /dev/apm */
569 if((apm_fd = open("/dev/apm", O_RDONLY)) == -1) {
570 if(errno != ENXIO && errno != ENOENT)
571 g_error("cannot open device file");
572 }
573 }
574
575 return apm_fd;
576}
577
578gboolean up_native_get_sensordev(const char * id, struct sensordev * snsrdev) {
579
580 int devn;
581 size_t sdlen = sizeof(struct sensordev);
582 int mib[] = {CTL_HW, HW_SENSORS, 0, 0 ,0};
583
584 for (devn = 0 ; ; devn++) {
585 mib[2] = devn;
586 if(sysctl(mib, 3, snsrdev, &sdlen, NULL, 0) == -1) {
587 if(errno == ENXIO)
588 continue;
589 if(errno == ENOENT)
590 break;
591 }
592
593 if (!strcmp(snsrdev->xname, id))
594 return TRUE;
595 }
596
597 return FALSE;
f1ad9351 598}