add support for vars from uname(3)
[systembsd.git] / src / interfaces / hostnamed / hostnamed.c
CommitLineData
baa40e28 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
71e3eef1 17#include <unistd.h>
18#include <limits.h>
3eb1ef91 19#include <signal.h>
041ce20b 20#include <string.h>
ed99526e 21
043bd2ed 22#include <sys/param.h>
962fad6d 23#include <sys/sysctl.h>
041ce20b 24#include <sys/sensors.h>
25#include <sys/ioctl.h>
8504b5df 26#include <sys/utsname.h>
041ce20b 27
28#include <machine/apmvar.h>
043bd2ed 29
cd16a588 30#include <glib/gprintf.h>
ba9914b6 31#include <glib-unix.h>
7a9b162a 32/* #include <gtk/gtk.h> */
cd16a588 33
3c3794ac 34#include "hostnamed-gen.h"
3eb1ef91 35#include "hostnamed.h"
71e3eef1 36
7a9b162a 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
ed99526e 75GPtrArray *hostnamed_freeable;
9d2500b0 76Hostname1 *hostnamed_interf;
7ce16a35 77
3eb1ef91 78GMainLoop *hostnamed_loop;
79
80guint bus_descriptor;
81gboolean dbus_interface_exported; /* reliable because of gdbus operational guarantees */
82
7a9b162a 83gchar *CHASSIS, *ICON;
8504b5df 84gchar *OS_CPENAME;
85gchar *KERN_NAME, *KERN_RELEASE, *KERN_VERS;
7a9b162a 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{
041ce20b 93 { "QEMU Virtual CPU", "container", NULL, FALSE, FALSE }, /* could be QEMU running in userspace or as part of KVM */
7c613054 94 { "KVM", "vm", "drive-multidisk", FALSE, FALSE },
7a9b162a 95 { "SmartDC HVM", "vm", "drive-multidisk", TRUE, TRUE }, /* oracle solaris kvm */
96 { "VirtualBox", "container", "drive-optical", TRUE, TRUE },
97 { "VMware, Inc.", "container", "drive-optical", TRUE, TRUE },
98 { "VMware Virtual Platform", "container", "drive-optical", TRUE, TRUE },
99 { "Parallels", "container", "drive-optical", TRUE, TRUE } /* need verification */
100};
355f60ae 101
041ce20b 102/* archs to check against when determining if machine is server */
103const gchar *server_archs[] = {
104 "hppa",
105 "sparc",
106 "sparc64"
107};
962fad6d 108
7a9b162a 109/* --- begin method/property/dbus signal code --- */
962fad6d 110
7ce16a35 111static gboolean
9d2500b0 112on_handle_set_hostname(Hostname1 *hn1_passed_interf,
7ce16a35 113 GDBusMethodInvocation *invoc,
114 const gchar *greet,
115 gpointer data) {
116 return FALSE;
117}
118
119static gboolean
9d2500b0 120on_handle_set_static_hostname(Hostname1 *hn1_passed_interf,
7ce16a35 121 GDBusMethodInvocation *invoc,
122 const gchar *greet,
123 gpointer data) {
124 return FALSE;
125}
126
127static gboolean
9d2500b0 128on_handle_set_pretty_hostname(Hostname1 *hn1_passed_interf,
7ce16a35 129 GDBusMethodInvocation *invoc,
130 const gchar *greet,
131 gpointer data) {
132 return FALSE;
133}
134
135static gboolean
9d2500b0 136on_handle_set_chassis(Hostname1 *hn1_passed_interf,
7ce16a35 137 GDBusMethodInvocation *invoc,
138 const gchar *greet,
139 gpointer data) {
140 return FALSE;
141}
142
143static gboolean
9d2500b0 144on_handle_set_icon_name(Hostname1 *hn1_passed_interf,
7ce16a35 145 GDBusMethodInvocation *invoc,
146 const gchar *greet,
147 gpointer data) {
148 return FALSE;
149}
150
355f60ae 151/* note: all hostnamed/hostname1's properties are read-only,
152 * and do not need set_ functions, gdbus-codegen realized
153 * this from the XML and handled the to-be error of trying
154 * to set a read-only property's value
155 */
156
157const gchar *
158our_get_hostname() {
159
99ef55dd 160 gchar *hostname_buf, *ret;
161 size_t hostname_divider;
043bd2ed 162
8e18351c 163 hostname_buf = (gchar*) g_malloc0(MAXHOSTNAMELEN);
99ef55dd 164 ret = (gchar*) g_malloc0(MAXHOSTNAMELEN);
8e18351c 165
99ef55dd 166 g_ptr_array_add(hostnamed_freeable, hostname_buf);
167 g_ptr_array_add(hostnamed_freeable, ret);
af9f8b50 168
8e18351c 169 if(gethostname(hostname_buf, MAXHOSTNAMELEN) || g_strcmp0(hostname_buf, "") == 0)
170 return "localhost";
043bd2ed 171
99ef55dd 172 hostname_divider = strcspn(hostname_buf, ".");
8f3d38b1 173
99ef55dd 174 return strncpy(ret, hostname_buf, hostname_divider);
355f60ae 175}
176
177const gchar *
178our_get_static_hostname() {
179
82a6a0d8 180 const gchar *pretty_hostname;
181 const gchar *ret;
8e18351c 182
183 pretty_hostname = our_get_pretty_hostname();
184
185 if(g_strcmp0(pretty_hostname, "") == 0)
186 ret = our_get_hostname();
187
82a6a0d8 188 else if((ret = g_hostname_to_ascii(pretty_hostname))) {
8e18351c 189
82a6a0d8 190 g_ptr_array_add(hostnamed_freeable, (gpointer)ret);
8e18351c 191 return ret;
192 }
193
194 return ret;
355f60ae 195}
196
197const gchar *
198our_get_pretty_hostname() {
199
8e18351c 200 GKeyFile *config;
201 gchar *ret;
202
962fad6d 203 config = g_key_file_new();
204
8e18351c 205 if(g_key_file_load_from_file(config, "/etc/systemd_compat.conf", G_KEY_FILE_NONE, NULL)
82a6a0d8 206 && (ret = g_key_file_get_value(config, "hostnamed", "PrettyHostname", NULL))) { /* ret might need to be freed, docs dont specify but i am suspicious */
8e18351c 207
962fad6d 208 g_key_file_unref(config);
8e18351c 209 return ret;
210 }
211
212 if(config)
213 g_free(config);
214
215 return "";
355f60ae 216}
217
218const gchar *
219our_get_chassis() {
220
041ce20b 221 if(CHASSIS)
222 return CHASSIS;
962fad6d 223
041ce20b 224 return "desktop";
355f60ae 225}
226
227const gchar *
228our_get_icon_name() {
229
041ce20b 230 if(ICON)
231 return ICON;
232
233 return "";
355f60ae 234}
235
236const gchar *
237our_get_kernel_name() {
238
8504b5df 239 if(KERN_NAME)
240 return KERN_NAME;
241
242 return "";
355f60ae 243}
244
245const gchar *
246our_get_kernel_version() {
247
8504b5df 248 if(KERN_VERS)
249 return KERN_VERS;
250
251 return "";
355f60ae 252}
253
254const gchar *
255our_get_kernel_release() {
256
8504b5df 257 if(KERN_RELEASE)
258 return KERN_RELEASE;
259
260 return "";
355f60ae 261}
262
263const gchar *
264our_get_os_cpename() {
265
8504b5df 266 return "ONEDAY";
355f60ae 267}
268
269const gchar *
270our_get_os_pretty_name() {
271
8504b5df 272 return "OpenBSD";
355f60ae 273}
274
ff036f75 275/* --- end method/property/dbus signal code, begin bus/name handlers --- */
0df0018d 276
828caf9a 277static void hostnamed_on_bus_acquired(GDBusConnection *conn,
fbc0295f 278 const gchar *name,
279 gpointer user_data) {
11475670 280
3eb1ef91 281 g_printf("got bus/name, exporting %s's interface...\n", name);
11475670 282
99ef55dd 283 hostnamed_interf = hostname1_skeleton_new();
7ce16a35 284
355f60ae 285 /* attach function pointers to generated struct's method handlers */
7ce16a35 286 g_signal_connect(hostnamed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
287 g_signal_connect(hostnamed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
288 g_signal_connect(hostnamed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
289 g_signal_connect(hostnamed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
290 g_signal_connect(hostnamed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL);
291
355f60ae 292 /* set our properties before export */
9d2500b0 293 hostname1_set_hostname(hostnamed_interf, our_get_hostname());
294 hostname1_set_static_hostname(hostnamed_interf, our_get_static_hostname());
295 hostname1_set_pretty_hostname(hostnamed_interf, our_get_pretty_hostname());
296 hostname1_set_chassis(hostnamed_interf, our_get_chassis());
297 hostname1_set_icon_name(hostnamed_interf, our_get_icon_name());
298 hostname1_set_kernel_name(hostnamed_interf, our_get_kernel_name());
299 hostname1_set_kernel_version(hostnamed_interf, our_get_kernel_version());
300 hostname1_set_kernel_release(hostnamed_interf, our_get_kernel_release());
301 hostname1_set_operating_system_cpename(hostnamed_interf, our_get_os_cpename());
302 hostname1_set_operating_system_pretty_name(hostnamed_interf, our_get_os_pretty_name());
355f60ae 303
7ce16a35 304 if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(hostnamed_interf),
9d2500b0 305 conn,
306 "/org/freedesktop/hostname1",
307 NULL)) {
7ce16a35 308
3eb1ef91 309 g_printf("failed to export %s's interface!\n", name); /* unusual edge case, TODO check errno */
99ef55dd 310 hostnamed_mem_clean();
7ce16a35 311
3eb1ef91 312 } else {
ea207ed3 313
99ef55dd 314 dbus_interface_exported = TRUE;
315 g_printf("exported %s's interface on the system bus...\n", name);
316 }
3eb1ef91 317}
3c3794ac 318
3eb1ef91 319static void hostnamed_on_name_acquired(GDBusConnection *conn,
99ef55dd 320 const gchar *name,
3eb1ef91 321 gpointer user_data) {
322
323 g_printf("success!\n");
3c3794ac 324}
325
828caf9a 326static void hostnamed_on_name_lost(GDBusConnection *conn,
9d2500b0 327 const gchar *name,
328 gpointer user_data) {
80043b36 329
99ef55dd 330 if(!conn) {
3eb1ef91 331
99ef55dd 332 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);
333 hostnamed_mem_clean();
334 }
3eb1ef91 335
ca5a7f9f 336 g_printf("lost name %s, exiting...\n", name);
ed99526e 337
fbc0295f 338 hostnamed_mem_clean();
3eb1ef91 339}
340
341/* --- end bus/name handlers, begin misc unix functions --- */
342
343/* safe call to clean and then exit
ca5a7f9f 344 * this stops our GMainLoop safely before letting main() return */
3eb1ef91 345void hostnamed_mem_clean() {
346
99ef55dd 347 g_printf("exiting...\n");
3eb1ef91 348
99ef55dd 349 if(dbus_interface_exported)
350 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(hostnamed_interf));
3eb1ef91 351
99ef55dd 352 if(g_main_loop_is_running(hostnamed_loop))
353 g_main_loop_quit(hostnamed_loop);
ed99526e 354
ea207ed3 355}
356
3eb1ef91 357/* wrapper for glib's unix signal handling; called only once if terminatating signal is raised against us */
358gboolean unix_sig_terminate_handler(gpointer data) {
a3041e78 359
99ef55dd 360 g_printf("caught SIGINT/HUP/TERM, exiting\n");
3eb1ef91 361
99ef55dd 362 hostnamed_mem_clean();
363 return G_SOURCE_REMOVE;
3eb1ef91 364}
365
366void set_signal_handlers() {
367
99ef55dd 368 /* we don't care about its descriptor, we never need to unregister these */
369 g_unix_signal_add(SIGINT, unix_sig_terminate_handler, NULL);
370 g_unix_signal_add(SIGHUP, unix_sig_terminate_handler, NULL);
371 g_unix_signal_add(SIGTERM, unix_sig_terminate_handler, NULL);
5c2460ab 372
99ef55dd 373 /* TODO: the "only once" guarantee only counts towards specific signals.
374 * make sure calling a SIGINT and SIGHUP doesn't cause term_handler()
375 * to be called twice */
3eb1ef91 376}
377
378int main() {
8504b5df 379
380 hostnamed_freeable = g_ptr_array_new();
381
4babc29e 382 /* TODO: check for valid, writable config at init. if no, complain to `make install` */
8504b5df 383
384 CHASSIS = ICON = OS_CPENAME = 0;
385 KERN_NAME = KERN_RELEASE = KERN_VERS = 0;
4babc29e 386
99ef55dd 387 set_signal_handlers();
387173cb 388
8504b5df 389 if(!determine_chassis_and_icon() || !set_uname_properties())
7a9b162a 390 return 1;
391
392 hostnamed_loop = g_main_loop_new(NULL, TRUE);
ed99526e 393
99ef55dd 394 bus_descriptor = g_bus_own_name(G_BUS_TYPE_SYSTEM,
3eb1ef91 395 "org.freedesktop.hostname1",
396 G_BUS_NAME_OWNER_FLAGS_NONE,
397 hostnamed_on_bus_acquired,
398 hostnamed_on_name_acquired,
399 hostnamed_on_name_lost,
400 NULL,
401 NULL);
496f5d66 402
99ef55dd 403 g_main_loop_run(hostnamed_loop);
404 /* runs until single g_main_loop_quit() call is raised inside <interface>_mem_clean() */
405 g_main_loop_unref(hostnamed_loop);
3c3794ac 406
99ef55dd 407 /* guaranteed unownable */
408 g_bus_unown_name(bus_descriptor);
a3041e78 409
99ef55dd 410 /* at this point no operations can occur with our data, it is safe to free it + its container */
411 g_ptr_array_free(hostnamed_freeable, TRUE);
af9f8b50 412
99ef55dd 413 return 0;
71e3eef1 414}
415
8504b5df 416gboolean set_uname_properties() {
417
418 struct utsname un;
419
420 if(-1 == uname(&un))
421 return FALSE;
422
423 KERN_NAME = (gchar*)g_malloc0(sizeof(un.sysname));
424 g_ptr_array_add(hostnamed_freeable, KERN_NAME);
425 g_strlcpy(KERN_NAME, un.sysname, sizeof(un.sysname));
426
427 KERN_RELEASE = (gchar*)g_malloc0(sizeof(un.release));
428 g_ptr_array_add(hostnamed_freeable, KERN_RELEASE);
429 g_strlcpy(KERN_RELEASE, un.release, sizeof(un.release));
430
431 KERN_VERS = (gchar*)g_malloc0(sizeof(un.version));
432 g_ptr_array_add(hostnamed_freeable, KERN_VERS);
433 g_strlcpy(KERN_VERS, un.version, sizeof(un.version));
434
435 return TRUE;
436}
437
7a9b162a 438gboolean determine_chassis_and_icon() {
439
22b13250 440 const size_t bufsize = 4096;
441
041ce20b 442 char *hwproduct, *hwmodel, *hwvendor, *hwmachine;
443 size_t hwproduct_size, hwmodel_size, hwvendor_size, hwmachine_size;
444 int hwproduct_name[2], hwmodel_name[2], hwvendor_name[2], hwmachine_name[2];
962fad6d 445 unsigned int i;
041ce20b 446 gboolean UNSURE_CHASSIS_FLAG, UNSURE_ICON_FLAG;
447
22b13250 448 hwproduct_size = hwmodel_size = hwvendor_size = hwmachine_size = bufsize;
a112db4c 449 UNSURE_CHASSIS_FLAG = UNSURE_ICON_FLAG = FALSE;
1ed17375 450 i = 0;
962fad6d 451
22b13250 452 hwproduct = (char*)g_malloc0(4096);
453 hwmodel = (char*)g_malloc0(4096);
454 hwvendor = (char*)g_malloc0(4096);
455 hwmachine = (char*)g_malloc0(4096);
456
8504b5df 457 g_ptr_array_add(hostnamed_freeable, hwproduct);
458 g_ptr_array_add(hostnamed_freeable, hwmodel);
459 g_ptr_array_add(hostnamed_freeable, hwvendor);
460 g_ptr_array_add(hostnamed_freeable, hwmachine);
461
7a9b162a 462 hwproduct_name[0] = CTL_HW;
463 hwproduct_name[1] = HW_PRODUCT;
962fad6d 464
7a9b162a 465 hwmodel_name[0] = CTL_HW;
466 hwmodel_name[1] = HW_MODEL;
467
468 hwvendor_name[0] = CTL_HW;
469 hwvendor_name[1] = HW_VENDOR;
470
041ce20b 471 hwmachine_name[0] = CTL_HW;
472 hwmachine_name[1] = HW_MACHINE;
473
7a9b162a 474 /* pass NULL buffer to check size first, then pass hw to be filled according to freshly-set hw_size */
475 if(-1 == sysctl(hwproduct_name, 2, NULL, &hwproduct_size, NULL, 0) || -1 == sysctl(hwproduct_name, 2, hwproduct, &hwproduct_size, NULL, 0))
476 return FALSE;
477
478 if(-1 == sysctl(hwmodel_name, 2, NULL, &hwmodel_size, NULL, 0) || -1 == sysctl(hwmodel_name, 2, hwmodel, &hwmodel_size, NULL, 0))
479 return FALSE;
480
481 if(-1 == sysctl(hwvendor_name, 2, NULL, &hwvendor_size, NULL, 0) || -1 == sysctl(hwvendor_name, 2, hwvendor, &hwvendor_size, NULL, 0))
482 return FALSE;
483
041ce20b 484 if(-1 == sysctl(hwmachine_name, 2, NULL, &hwmachine_size, NULL, 0) || -1 == sysctl(hwmachine_name, 2, hwmachine, &hwmachine_size, NULL, 0))
485 return FALSE;
486
7a9b162a 487 /* TODO: test for laptop, if not, dmidecode for desktop vs. server
488 * probably move this code to vm test func and set a global after running it early, once */
489
041ce20b 490 for(; i < G_N_ELEMENTS(chassis_indicator_table); i++) {
491 if(strcasestr(hwproduct, chassis_indicator_table[i].match_string)
492 || strcasestr(hwmodel, chassis_indicator_table[i].match_string)
493 || strcasestr(hwvendor, chassis_indicator_table[i].match_string)) {
494
495 if(!UNSURE_CHASSIS_FLAG && chassis_indicator_table[i].chassis) {
496
497 UNSURE_CHASSIS_FLAG = chassis_indicator_table[i].chassis_precedence;
498 CHASSIS = chassis_indicator_table[i].chassis;
499 }
500
501 if(!UNSURE_ICON_FLAG && chassis_indicator_table[i].icon) {
502
503 UNSURE_ICON_FLAG = chassis_indicator_table[i].icon_precedence;
504 ICON = chassis_indicator_table[i].icon;
505 }
506 }
507 }
508
509 if(up_native_is_laptop()) {
510
511 if(!CHASSIS)
512 CHASSIS = "laptop";
513 if(!ICON)
514 ICON = "input-touchpad"; /* TODO pull an icon package that actually has the icons we're looking for */
515
516 } else if(is_server(hwmachine)) {
517
518 if(!CHASSIS)
519 CHASSIS = "server";
520 if(!ICON)
521 ICON = "uninterruptible-power-supply";
522
523 } else if(!CHASSIS || !ICON) {
962fad6d 524
041ce20b 525 if(!CHASSIS)
526 CHASSIS = "desktop";
527 if(!ICON)
528 ICON = "computer";
529 }
530
531 return (CHASSIS && ICON);
532}
533
534gboolean is_server(gchar *arch) {
535
536 unsigned int i;
7a9b162a 537
041ce20b 538 for(; i < G_N_ELEMENTS(server_archs); i++)
539 if(strcasestr(arch, server_archs[i]))
540 return TRUE;
541
542 return FALSE;
543}
544
545gboolean up_native_is_laptop() {
546
547 struct apm_power_info bstate;
548 struct sensordev acpiac;
549
550 if (up_native_get_sensordev("acpiac0", &acpiac))
551 return TRUE;
552
553 if (-1 == ioctl(up_apm_get_fd(), APM_IOC_GETPOWER, &bstate))
554 g_error("ioctl on apm fd failed : %s", g_strerror(errno));
555
556 return bstate.ac_state != APM_AC_UNKNOWN;
557}
558
559int up_apm_get_fd() {
560
561 static int apm_fd = 0;
562
563 if(apm_fd == 0) {
564
565 g_debug("apm_fd is not initialized yet, opening");
566
567 /* open /dev/apm */
568 if((apm_fd = open("/dev/apm", O_RDONLY)) == -1) {
569 if(errno != ENXIO && errno != ENOENT)
570 g_error("cannot open device file");
571 }
572 }
573
574 return apm_fd;
575}
576
577gboolean up_native_get_sensordev(const char * id, struct sensordev * snsrdev) {
578
579 int devn;
580 size_t sdlen = sizeof(struct sensordev);
581 int mib[] = {CTL_HW, HW_SENSORS, 0, 0 ,0};
582
583 for (devn = 0 ; ; devn++) {
584 mib[2] = devn;
585 if(sysctl(mib, 3, snsrdev, &sdlen, NULL, 0) == -1) {
586 if(errno == ENXIO)
587 continue;
588 if(errno == ENOENT)
589 break;
590 }
591
592 if (!strcmp(snsrdev->xname, id))
593 return TRUE;
594 }
595
596 return FALSE;
962fad6d 597}