]> code.delx.au - pulseaudio/blob - src/modules/module-udev-detect.c
module-udev-detect: When loading module-alsa-card, use namereg_fail=false.
[pulseaudio] / src / modules / module-udev-detect.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2009 Lennart Poettering
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <errno.h>
27 #include <limits.h>
28 #include <dirent.h>
29 #include <sys/inotify.h>
30 #include <libudev.h>
31
32 #include <pulse/timeval.h>
33
34 #include <pulsecore/modargs.h>
35 #include <pulsecore/core-error.h>
36 #include <pulsecore/core-util.h>
37 #include <pulsecore/namereg.h>
38 #include <pulsecore/ratelimit.h>
39
40 #include "module-udev-detect-symdef.h"
41
42 PA_MODULE_AUTHOR("Lennart Poettering");
43 PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers");
44 PA_MODULE_VERSION(PACKAGE_VERSION);
45 PA_MODULE_LOAD_ONCE(TRUE);
46 PA_MODULE_USAGE(
47 "tsched=<enable system timer based scheduling mode?> "
48 "ignore_dB=<ignore dB information from the device?>");
49
50 struct device {
51 char *path;
52 pa_bool_t need_verify;
53 char *card_name;
54 char *args;
55 uint32_t module;
56 pa_ratelimit ratelimit;
57 };
58
59 struct userdata {
60 pa_core *core;
61 pa_hashmap *devices;
62
63 pa_bool_t use_tsched:1;
64 pa_bool_t ignore_dB:1;
65
66 struct udev* udev;
67 struct udev_monitor *monitor;
68 pa_io_event *udev_io;
69
70 int inotify_fd;
71 pa_io_event *inotify_io;
72 };
73
74 static const char* const valid_modargs[] = {
75 "tsched",
76 "ignore_dB",
77 NULL
78 };
79
80 static int setup_inotify(struct userdata *u);
81
82 static void device_free(struct device *d) {
83 pa_assert(d);
84
85 pa_xfree(d->path);
86 pa_xfree(d->card_name);
87 pa_xfree(d->args);
88 pa_xfree(d);
89 }
90
91 static const char *path_get_card_id(const char *path) {
92 const char *e;
93
94 if (!path)
95 return NULL;
96
97 if (!(e = strrchr(path, '/')))
98 return NULL;
99
100 if (!pa_startswith(e, "/card"))
101 return NULL;
102
103 return e + 5;
104 }
105
106 static char *card_get_sysattr(const char *card_idx, const char *name) {
107 struct udev *udev;
108 struct udev_device *card = NULL;
109 char *t, *r = NULL;
110 const char *v;
111
112 pa_assert(card_idx);
113 pa_assert(name);
114
115 if (!(udev = udev_new())) {
116 pa_log_error("Failed to allocate udev context.");
117 goto finish;
118 }
119
120 t = pa_sprintf_malloc("%s/class/sound/card%s", udev_get_sys_path(udev), card_idx);
121 card = udev_device_new_from_syspath(udev, t);
122 pa_xfree(t);
123
124 if (!card) {
125 pa_log_error("Failed to get card object.");
126 goto finish;
127 }
128
129 if ((v = udev_device_get_sysattr_value(card, name)) && *v)
130 r = pa_xstrdup(v);
131
132 finish:
133
134 if (card)
135 udev_device_unref(card);
136
137 if (udev)
138 udev_unref(udev);
139
140 return r;
141 }
142
143 static pa_bool_t pcm_is_modem(const char *card_idx, const char *pcm) {
144 char *sysfs_path, *pcm_class;
145 pa_bool_t is_modem;
146
147 pa_assert(card_idx);
148 pa_assert(pcm);
149
150 /* Check /sys/class/sound/card.../pcmC...../pcm_class. An HDA
151 * modem can be used simultaneously with generic
152 * playback/record. */
153
154 sysfs_path = pa_sprintf_malloc("pcmC%sD%s/pcm_class", card_idx, pcm);
155 pcm_class = card_get_sysattr(card_idx, sysfs_path);
156 is_modem = pcm_class && pa_streq(pcm_class, "modem");
157 pa_xfree(pcm_class);
158 pa_xfree(sysfs_path);
159
160 return is_modem;
161 }
162
163 static pa_bool_t is_card_busy(const char *id) {
164 char *card_path = NULL, *pcm_path = NULL, *sub_status = NULL;
165 DIR *card_dir = NULL, *pcm_dir = NULL;
166 FILE *status_file = NULL;
167 size_t len;
168 struct dirent *space = NULL, *de;
169 pa_bool_t busy = FALSE;
170 int r;
171
172 pa_assert(id);
173
174 /* This simply uses /proc/asound/card.../pcm.../sub.../status to
175 * check whether there is still a process using this audio device. */
176
177 card_path = pa_sprintf_malloc("/proc/asound/card%s", id);
178
179 if (!(card_dir = opendir(card_path))) {
180 pa_log_warn("Failed to open %s: %s", card_path, pa_cstrerror(errno));
181 goto fail;
182 }
183
184 len = offsetof(struct dirent, d_name) + fpathconf(dirfd(card_dir), _PC_NAME_MAX) + 1;
185 space = pa_xmalloc(len);
186
187 for (;;) {
188 de = NULL;
189
190 if ((r = readdir_r(card_dir, space, &de)) != 0) {
191 pa_log_warn("readdir_r() failed: %s", pa_cstrerror(r));
192 goto fail;
193 }
194
195 if (!de)
196 break;
197
198 if (!pa_startswith(de->d_name, "pcm"))
199 continue;
200
201 if (pcm_is_modem(id, de->d_name + 3))
202 continue;
203
204 pa_xfree(pcm_path);
205 pcm_path = pa_sprintf_malloc("%s/%s", card_path, de->d_name);
206
207 if (pcm_dir)
208 closedir(pcm_dir);
209
210 if (!(pcm_dir = opendir(pcm_path))) {
211 pa_log_warn("Failed to open %s: %s", pcm_path, pa_cstrerror(errno));
212 continue;
213 }
214
215 for (;;) {
216 char line[32];
217
218 if ((r = readdir_r(pcm_dir, space, &de)) != 0) {
219 pa_log_warn("readdir_r() failed: %s", pa_cstrerror(r));
220 goto fail;
221 }
222
223 if (!de)
224 break;
225
226 if (!pa_startswith(de->d_name, "sub"))
227 continue;
228
229 pa_xfree(sub_status);
230 sub_status = pa_sprintf_malloc("%s/%s/status", pcm_path, de->d_name);
231
232 if (status_file)
233 fclose(status_file);
234
235 if (!(status_file = pa_fopen_cloexec(sub_status, "r"))) {
236 pa_log_warn("Failed to open %s: %s", sub_status, pa_cstrerror(errno));
237 continue;
238 }
239
240 if (!(fgets(line, sizeof(line)-1, status_file))) {
241 pa_log_warn("Failed to read from %s: %s", sub_status, pa_cstrerror(errno));
242 continue;
243 }
244
245 if (!pa_streq(line, "closed\n")) {
246 busy = TRUE;
247 break;
248 }
249 }
250 }
251
252 fail:
253
254 pa_xfree(card_path);
255 pa_xfree(pcm_path);
256 pa_xfree(sub_status);
257 pa_xfree(space);
258
259 if (card_dir)
260 closedir(card_dir);
261
262 if (pcm_dir)
263 closedir(pcm_dir);
264
265 if (status_file)
266 fclose(status_file);
267
268 return busy;
269 }
270
271 static void verify_access(struct userdata *u, struct device *d) {
272 char *cd;
273 pa_card *card;
274 pa_bool_t accessible;
275
276 pa_assert(u);
277 pa_assert(d);
278
279 cd = pa_sprintf_malloc("%s/snd/controlC%s", udev_get_dev_path(u->udev), path_get_card_id(d->path));
280 accessible = access(cd, R_OK|W_OK) >= 0;
281 pa_log_debug("%s is accessible: %s", cd, pa_yes_no(accessible));
282
283 pa_xfree(cd);
284
285 if (d->module == PA_INVALID_INDEX) {
286
287 /* If we are not loaded, try to load */
288
289 if (accessible) {
290 pa_module *m;
291 pa_bool_t busy;
292
293 /* Check if any of the PCM devices that belong to this
294 * card are currently busy. If they are, don't try to load
295 * right now, to make sure the probing phase can
296 * successfully complete. When the current user of the
297 * device closes it we will get another notification via
298 * inotify and can then recheck. */
299
300 busy = is_card_busy(path_get_card_id(d->path));
301 pa_log_debug("%s is busy: %s", d->path, pa_yes_no(busy));
302
303 if (!busy) {
304
305 /* So, why do we rate limit here? It's certainly ugly,
306 * but there seems to be no other way. Problem is
307 * this: if we are unable to configure/probe an audio
308 * device after opening it we will close it again and
309 * the module initialization will fail. This will then
310 * cause an inotify event on the device node which
311 * will be forwarded to us. We then try to reopen the
312 * audio device again, practically entering a busy
313 * loop.
314 *
315 * A clean fix would be if we would be able to ignore
316 * our own inotify close events. However, inotify
317 * lacks such functionality. Also, during probing of
318 * the device we cannot really distuingish between
319 * other processes causing EBUSY or ourselves, which
320 * means we have no way to figure out if the probing
321 * during opening was canceled by a "try again"
322 * failure or a "fatal" failure. */
323
324 if (pa_ratelimit_test(&d->ratelimit)) {
325 pa_log_debug("Loading module-alsa-card with arguments '%s'", d->args);
326 m = pa_module_load(u->core, "module-alsa-card", d->args);
327
328 if (m) {
329 d->module = m->index;
330 pa_log_info("Card %s (%s) module loaded.", d->path, d->card_name);
331 } else
332 pa_log_info("Card %s (%s) failed to load module.", d->path, d->card_name);
333 } else
334 pa_log_warn("Tried to configure %s (%s) more often than %u times in %llus",
335 d->path,
336 d->card_name,
337 d->ratelimit.burst,
338 (long long unsigned) (d->ratelimit.interval / PA_USEC_PER_SEC));
339 }
340 }
341
342 } else {
343
344 /* If we are already loaded update suspend status with
345 * accessible boolean */
346
347 if ((card = pa_namereg_get(u->core, d->card_name, PA_NAMEREG_CARD)))
348 pa_card_suspend(card, !accessible, PA_SUSPEND_SESSION);
349 }
350 }
351
352 static void card_changed(struct userdata *u, struct udev_device *dev) {
353 struct device *d;
354 const char *path;
355 const char *t;
356 char *n;
357
358 pa_assert(u);
359 pa_assert(dev);
360
361 /* Maybe /dev/snd is now available? */
362 setup_inotify(u);
363
364 path = udev_device_get_devpath(dev);
365
366 if ((d = pa_hashmap_get(u->devices, path))) {
367 verify_access(u, d);
368 return;
369 }
370
371 d = pa_xnew0(struct device, 1);
372 d->path = pa_xstrdup(path);
373 d->module = PA_INVALID_INDEX;
374 PA_INIT_RATELIMIT(d->ratelimit, 10*PA_USEC_PER_SEC, 5);
375
376 if (!(t = udev_device_get_property_value(dev, "PULSE_NAME")))
377 if (!(t = udev_device_get_property_value(dev, "ID_ID")))
378 if (!(t = udev_device_get_property_value(dev, "ID_PATH")))
379 t = path_get_card_id(path);
380
381 n = pa_namereg_make_valid_name(t);
382 d->card_name = pa_sprintf_malloc("alsa_card.%s", n);
383 d->args = pa_sprintf_malloc("device_id=\"%s\" "
384 "name=\"%s\" "
385 "card_name=\"%s\" "
386 "namereg_fail=false "
387 "tsched=%s "
388 "ignore_dB=%s "
389 "card_properties=\"module-udev-detect.discovered=1\"",
390 path_get_card_id(path),
391 n,
392 d->card_name,
393 pa_yes_no(u->use_tsched),
394 pa_yes_no(u->ignore_dB));
395 pa_xfree(n);
396
397 pa_hashmap_put(u->devices, d->path, d);
398
399 verify_access(u, d);
400 }
401
402 static void remove_card(struct userdata *u, struct udev_device *dev) {
403 struct device *d;
404
405 pa_assert(u);
406 pa_assert(dev);
407
408 if (!(d = pa_hashmap_remove(u->devices, udev_device_get_devpath(dev))))
409 return;
410
411 pa_log_info("Card %s removed.", d->path);
412
413 if (d->module != PA_INVALID_INDEX)
414 pa_module_unload_request_by_index(u->core, d->module, TRUE);
415
416 device_free(d);
417 }
418
419 static void process_device(struct userdata *u, struct udev_device *dev) {
420 const char *action, *ff;
421
422 pa_assert(u);
423 pa_assert(dev);
424
425 if (udev_device_get_property_value(dev, "PULSE_IGNORE")) {
426 pa_log_debug("Ignoring %s, because marked so.", udev_device_get_devpath(dev));
427 return;
428 }
429
430 if ((ff = udev_device_get_property_value(dev, "SOUND_CLASS")) &&
431 pa_streq(ff, "modem")) {
432 pa_log_debug("Ignoring %s, because it is a modem.", udev_device_get_devpath(dev));
433 return;
434 }
435
436 action = udev_device_get_action(dev);
437
438 if (action && pa_streq(action, "remove"))
439 remove_card(u, dev);
440 else if ((!action || pa_streq(action, "change")) &&
441 udev_device_get_property_value(dev, "SOUND_INITIALIZED"))
442 card_changed(u, dev);
443
444 /* For an explanation why we don't look for 'add' events here
445 * have a look into /lib/udev/rules.d/78-sound-card.rules! */
446 }
447
448 static void process_path(struct userdata *u, const char *path) {
449 struct udev_device *dev;
450
451 if (!path_get_card_id(path))
452 return;
453
454 if (!(dev = udev_device_new_from_syspath(u->udev, path))) {
455 pa_log("Failed to get udev device object from udev.");
456 return;
457 }
458
459 process_device(u, dev);
460 udev_device_unref(dev);
461 }
462
463 static void monitor_cb(
464 pa_mainloop_api*a,
465 pa_io_event* e,
466 int fd,
467 pa_io_event_flags_t events,
468 void *userdata) {
469
470 struct userdata *u = userdata;
471 struct udev_device *dev;
472
473 pa_assert(a);
474
475 if (!(dev = udev_monitor_receive_device(u->monitor))) {
476 pa_log("Failed to get udev device object from monitor.");
477 goto fail;
478 }
479
480 if (!path_get_card_id(udev_device_get_devpath(dev))) {
481 udev_device_unref(dev);
482 return;
483 }
484
485 process_device(u, dev);
486 udev_device_unref(dev);
487 return;
488
489 fail:
490 a->io_free(u->udev_io);
491 u->udev_io = NULL;
492 }
493
494 static pa_bool_t pcm_node_belongs_to_device(
495 struct device *d,
496 const char *node) {
497
498 char *cd;
499 pa_bool_t b;
500
501 cd = pa_sprintf_malloc("pcmC%sD", path_get_card_id(d->path));
502 b = pa_startswith(node, cd);
503 pa_xfree(cd);
504
505 return b;
506 }
507
508 static pa_bool_t control_node_belongs_to_device(
509 struct device *d,
510 const char *node) {
511
512 char *cd;
513 pa_bool_t b;
514
515 cd = pa_sprintf_malloc("controlC%s", path_get_card_id(d->path));
516 b = pa_streq(node, cd);
517 pa_xfree(cd);
518
519 return b;
520 }
521
522 static void inotify_cb(
523 pa_mainloop_api*a,
524 pa_io_event* e,
525 int fd,
526 pa_io_event_flags_t events,
527 void *userdata) {
528
529 struct {
530 struct inotify_event e;
531 char name[NAME_MAX];
532 } buf;
533 struct userdata *u = userdata;
534 static int type = 0;
535 pa_bool_t deleted = FALSE;
536 struct device *d;
537 void *state;
538
539 for (;;) {
540 ssize_t r;
541 struct inotify_event *event;
542
543 pa_zero(buf);
544 if ((r = pa_read(fd, &buf, sizeof(buf), &type)) <= 0) {
545
546 if (r < 0 && errno == EAGAIN)
547 break;
548
549 pa_log("read() from inotify failed: %s", r < 0 ? pa_cstrerror(errno) : "EOF");
550 goto fail;
551 }
552
553 event = &buf.e;
554 while (r > 0) {
555 size_t len;
556
557 if ((size_t) r < sizeof(struct inotify_event)) {
558 pa_log("read() too short.");
559 goto fail;
560 }
561
562 len = sizeof(struct inotify_event) + event->len;
563
564 if ((size_t) r < len) {
565 pa_log("Payload missing.");
566 goto fail;
567 }
568
569 /* From udev we get the guarantee that the control
570 * device's ACL is changed last. To avoid races when ACLs
571 * are changed we hence watch only the control device */
572 if (((event->mask & IN_ATTRIB) && pa_startswith(event->name, "controlC")))
573 PA_HASHMAP_FOREACH(d, u->devices, state)
574 if (control_node_belongs_to_device(d, event->name))
575 d->need_verify = TRUE;
576
577 /* ALSA doesn't really give us any guarantee on the closing
578 * order, so let's simply hope */
579 if (((event->mask & IN_CLOSE_WRITE) && pa_startswith(event->name, "pcmC")))
580 PA_HASHMAP_FOREACH(d, u->devices, state)
581 if (pcm_node_belongs_to_device(d, event->name))
582 d->need_verify = TRUE;
583
584 /* /dev/snd/ might have been removed */
585 if ((event->mask & (IN_DELETE_SELF|IN_MOVE_SELF)))
586 deleted = TRUE;
587
588 event = (struct inotify_event*) ((uint8_t*) event + len);
589 r -= len;
590 }
591 }
592
593 PA_HASHMAP_FOREACH(d, u->devices, state)
594 if (d->need_verify) {
595 d->need_verify = FALSE;
596 verify_access(u, d);
597 }
598
599 if (!deleted)
600 return;
601
602 fail:
603 if (u->inotify_io) {
604 a->io_free(u->inotify_io);
605 u->inotify_io = NULL;
606 }
607
608 if (u->inotify_fd >= 0) {
609 pa_close(u->inotify_fd);
610 u->inotify_fd = -1;
611 }
612 }
613
614 static int setup_inotify(struct userdata *u) {
615 char *dev_snd;
616 int r;
617
618 if (u->inotify_fd >= 0)
619 return 0;
620
621 if ((u->inotify_fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK)) < 0) {
622 pa_log("inotify_init1() failed: %s", pa_cstrerror(errno));
623 return -1;
624 }
625
626 dev_snd = pa_sprintf_malloc("%s/snd", udev_get_dev_path(u->udev));
627 r = inotify_add_watch(u->inotify_fd, dev_snd, IN_ATTRIB|IN_CLOSE_WRITE|IN_DELETE_SELF|IN_MOVE_SELF);
628 pa_xfree(dev_snd);
629
630 if (r < 0) {
631 int saved_errno = errno;
632
633 pa_close(u->inotify_fd);
634 u->inotify_fd = -1;
635
636 if (saved_errno == ENOENT) {
637 pa_log_debug("/dev/snd/ is apparently not existing yet, retrying to create inotify watch later.");
638 return 0;
639 }
640
641 if (saved_errno == ENOSPC) {
642 pa_log("You apparently ran out of inotify watches, probably because Tracker/Beagle took them all away. "
643 "I wished people would do their homework first and fix inotify before using it for watching whole "
644 "directory trees which is something the current inotify is certainly not useful for. "
645 "Please make sure to drop the Tracker/Beagle guys a line complaining about their broken use of inotify.");
646 return 0;
647 }
648
649 pa_log("inotify_add_watch() failed: %s", pa_cstrerror(saved_errno));
650 return -1;
651 }
652
653 pa_assert_se(u->inotify_io = u->core->mainloop->io_new(u->core->mainloop, u->inotify_fd, PA_IO_EVENT_INPUT, inotify_cb, u));
654
655 return 0;
656 }
657
658 int pa__init(pa_module *m) {
659 struct userdata *u = NULL;
660 pa_modargs *ma;
661 struct udev_enumerate *enumerate = NULL;
662 struct udev_list_entry *item = NULL, *first = NULL;
663 int fd;
664 pa_bool_t use_tsched = TRUE, ignore_dB = FALSE;
665
666 pa_assert(m);
667
668 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
669 pa_log("Failed to parse module arguments");
670 goto fail;
671 }
672
673 m->userdata = u = pa_xnew0(struct userdata, 1);
674 u->core = m->core;
675 u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
676 u->inotify_fd = -1;
677
678 if (pa_modargs_get_value_boolean(ma, "tsched", &use_tsched) < 0) {
679 pa_log("Failed to parse tsched= argument.");
680 goto fail;
681 }
682 u->use_tsched = use_tsched;
683
684 if (pa_modargs_get_value_boolean(ma, "ignore_dB", &ignore_dB) < 0) {
685 pa_log("Failed to parse ignore_dB= argument.");
686 goto fail;
687 }
688 u->ignore_dB = ignore_dB;
689
690 if (!(u->udev = udev_new())) {
691 pa_log("Failed to initialize udev library.");
692 goto fail;
693 }
694
695 if (setup_inotify(u) < 0)
696 goto fail;
697
698 if (!(u->monitor = udev_monitor_new_from_netlink(u->udev, "udev"))) {
699 pa_log("Failed to initialize monitor.");
700 goto fail;
701 }
702
703 if (udev_monitor_filter_add_match_subsystem_devtype(u->monitor, "sound", NULL) < 0) {
704 pa_log("Failed to subscribe to sound devices.");
705 goto fail;
706 }
707
708 errno = 0;
709 if (udev_monitor_enable_receiving(u->monitor) < 0) {
710 pa_log("Failed to enable monitor: %s", pa_cstrerror(errno));
711 if (errno == EPERM)
712 pa_log_info("Most likely your kernel is simply too old and "
713 "allows only priviliged processes to listen to device events. "
714 "Please upgrade your kernel to at least 2.6.30.");
715 goto fail;
716 }
717
718 if ((fd = udev_monitor_get_fd(u->monitor)) < 0) {
719 pa_log("Failed to get udev monitor fd.");
720 goto fail;
721 }
722
723 pa_assert_se(u->udev_io = u->core->mainloop->io_new(u->core->mainloop, fd, PA_IO_EVENT_INPUT, monitor_cb, u));
724
725 if (!(enumerate = udev_enumerate_new(u->udev))) {
726 pa_log("Failed to initialize udev enumerator.");
727 goto fail;
728 }
729
730 if (udev_enumerate_add_match_subsystem(enumerate, "sound") < 0) {
731 pa_log("Failed to match to subsystem.");
732 goto fail;
733 }
734
735 if (udev_enumerate_scan_devices(enumerate) < 0) {
736 pa_log("Failed to scan for devices.");
737 goto fail;
738 }
739
740 first = udev_enumerate_get_list_entry(enumerate);
741 udev_list_entry_foreach(item, first)
742 process_path(u, udev_list_entry_get_name(item));
743
744 udev_enumerate_unref(enumerate);
745
746 pa_log_info("Found %u cards.", pa_hashmap_size(u->devices));
747
748 pa_modargs_free(ma);
749
750 return 0;
751
752 fail:
753
754 if (enumerate)
755 udev_enumerate_unref(enumerate);
756
757 if (ma)
758 pa_modargs_free(ma);
759
760 pa__done(m);
761
762 return -1;
763 }
764
765 void pa__done(pa_module *m) {
766 struct userdata *u;
767
768 pa_assert(m);
769
770 if (!(u = m->userdata))
771 return;
772
773 if (u->udev_io)
774 m->core->mainloop->io_free(u->udev_io);
775
776 if (u->monitor)
777 udev_monitor_unref(u->monitor);
778
779 if (u->udev)
780 udev_unref(u->udev);
781
782 if (u->inotify_io)
783 m->core->mainloop->io_free(u->inotify_io);
784
785 if (u->inotify_fd >= 0)
786 pa_close(u->inotify_fd);
787
788 if (u->devices) {
789 struct device *d;
790
791 while ((d = pa_hashmap_steal_first(u->devices)))
792 device_free(d);
793
794 pa_hashmap_free(u->devices, NULL, NULL);
795 }
796
797 pa_xfree(u);
798 }