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