• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***
2   This file is part of PulseAudio.
3 
4   Copyright 2006 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 published
8   by the Free Software Foundation; either version 2.1 of the License,
9   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 License
17   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
18 ***/
19 
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 
27 #include <pulsecore/core-error.h>
28 #include <pulsecore/core-util.h>
29 #include <pulsecore/start-child.h>
30 
31 #include "../stdin-util.h"
32 
33 PA_MODULE_AUTHOR("Lennart Poettering");
34 PA_MODULE_DESCRIPTION("GConf Adapter");
35 PA_MODULE_VERSION(PACKAGE_VERSION);
36 PA_MODULE_LOAD_ONCE(true);
37 
pa__init(pa_module * m)38 int pa__init(pa_module*m) {
39     struct userdata *u;
40     int r;
41 
42     u = pa_xnew(struct userdata, 1);
43     u->core = m->core;
44     u->module = m;
45     m->userdata = u;
46     u->module_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) module_info_free);
47     u->pid = (pid_t) -1;
48     u->fd = -1;
49     u->fd_type = 0;
50     u->io_event = NULL;
51     u->buf_fill = 0;
52 
53     if ((u->fd = pa_start_child_for_read(
54 #if defined(__linux__) && defined(HAVE_RUNNING_FROM_BUILD_TREE)
55                               pa_run_from_build_tree() ? PA_BUILDDIR "/gconf-helper" :
56 #endif
57                  PA_GCONF_HELPER, NULL, &u->pid)) < 0)
58         goto fail;
59 
60     u->io_event = m->core->mainloop->io_new(
61             m->core->mainloop,
62             u->fd,
63             PA_IO_EVENT_INPUT,
64             io_event_cb,
65             u);
66 
67     do {
68         if ((r = handle_event(u)) < 0)
69             goto fail;
70 
71         /* Read until the client signalled us that it is ready with
72          * initialization */
73     } while (r != 1);
74 
75     return 0;
76 
77 fail:
78     pa__done(m);
79     return -1;
80 }
81 
pa__done(pa_module * m)82 void pa__done(pa_module*m) {
83     struct userdata *u;
84 
85     pa_assert(m);
86 
87     if (!(u = m->userdata))
88         return;
89 
90     if (u->pid != (pid_t) -1) {
91         kill(u->pid, SIGTERM);
92 
93         for (;;) {
94             if (waitpid(u->pid, NULL, 0) >= 0)
95                 break;
96 
97             if (errno != EINTR) {
98                 pa_log("waitpid() failed: %s", pa_cstrerror(errno));
99                 break;
100             }
101         }
102     }
103 
104     if (u->io_event)
105         m->core->mainloop->io_free(u->io_event);
106 
107     if (u->fd >= 0)
108         pa_close(u->fd);
109 
110     if (u->module_infos)
111         pa_hashmap_free(u->module_infos);
112 
113     pa_xfree(u);
114 }
115