pulseaudio/src/modules/gsettings/module-gsettings.c

115 lines
2.8 KiB
C
Raw Normal View History

module-gsettings: new module to store configuration using gsettings GConf is deprecated, and distributions are removing it. paprefs depends on GConf, so in order to avoid paprefs getting removed as well, paprefs has to be changed to use something else than GConf. GSettings is the easiest alternative to migrate to, although it has the same problems that GConf had: no support for system mode or networking. This patch takes the non-GConf specific code from module-gconf and puts it in stdin-util.[ch], which is then reused by module-gsettings. module-gsettings is designed to be very similar to module-gconf. Migration is expected to happen as follows: Distributions update PulseAudio and paprefs at the same time, or first PulseAudio and then paprefs. paprefs depends on module-gsettings, and module-gsettings conflicts with module-gconf. Therefore module-gconf gets automatically removed during the paprefs update. After the update an old PulseAudio is likely to be running with module-gconf loaded. If the user tries to use paprefs during this period, whatever the user does in paprefs won't have any effect until PulseAudio is restarted (probably by a reboot or relogin). This is not ideal, but will have to do. When module-gsettings is loaded, it runs gsettings-data-convert (implemented in a later patch). That will copy the settings from GConf to GSettings. If gsettings-data-convert is not available (it's part of GConf, so it may have already been uninstalled), then any previous paprefs settings are lost.
2016-07-25 21:58:48 +02:00
/***
This file is part of PulseAudio.
Copyright 2006 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
module-gsettings: new module to store configuration using gsettings GConf is deprecated, and distributions are removing it. paprefs depends on GConf, so in order to avoid paprefs getting removed as well, paprefs has to be changed to use something else than GConf. GSettings is the easiest alternative to migrate to, although it has the same problems that GConf had: no support for system mode or networking. This patch takes the non-GConf specific code from module-gconf and puts it in stdin-util.[ch], which is then reused by module-gsettings. module-gsettings is designed to be very similar to module-gconf. Migration is expected to happen as follows: Distributions update PulseAudio and paprefs at the same time, or first PulseAudio and then paprefs. paprefs depends on module-gsettings, and module-gsettings conflicts with module-gconf. Therefore module-gconf gets automatically removed during the paprefs update. After the update an old PulseAudio is likely to be running with module-gconf loaded. If the user tries to use paprefs during this period, whatever the user does in paprefs won't have any effect until PulseAudio is restarted (probably by a reboot or relogin). This is not ideal, but will have to do. When module-gsettings is loaded, it runs gsettings-data-convert (implemented in a later patch). That will copy the settings from GConf to GSettings. If gsettings-data-convert is not available (it's part of GConf, so it may have already been uninstalled), then any previous paprefs settings are lost.
2016-07-25 21:58:48 +02:00
#include <sys/types.h>
#include <sys/wait.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/start-child.h>
#include "../stdin-util.h"
module-gsettings: new module to store configuration using gsettings GConf is deprecated, and distributions are removing it. paprefs depends on GConf, so in order to avoid paprefs getting removed as well, paprefs has to be changed to use something else than GConf. GSettings is the easiest alternative to migrate to, although it has the same problems that GConf had: no support for system mode or networking. This patch takes the non-GConf specific code from module-gconf and puts it in stdin-util.[ch], which is then reused by module-gsettings. module-gsettings is designed to be very similar to module-gconf. Migration is expected to happen as follows: Distributions update PulseAudio and paprefs at the same time, or first PulseAudio and then paprefs. paprefs depends on module-gsettings, and module-gsettings conflicts with module-gconf. Therefore module-gconf gets automatically removed during the paprefs update. After the update an old PulseAudio is likely to be running with module-gconf loaded. If the user tries to use paprefs during this period, whatever the user does in paprefs won't have any effect until PulseAudio is restarted (probably by a reboot or relogin). This is not ideal, but will have to do. When module-gsettings is loaded, it runs gsettings-data-convert (implemented in a later patch). That will copy the settings from GConf to GSettings. If gsettings-data-convert is not available (it's part of GConf, so it may have already been uninstalled), then any previous paprefs settings are lost.
2016-07-25 21:58:48 +02:00
PA_MODULE_AUTHOR("Sylvain Baubeau");
PA_MODULE_DESCRIPTION("GSettings Adapter");
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(true);
int pa__init(pa_module*m) {
struct userdata *u;
int r;
u = pa_xnew(struct userdata, 1);
u->core = m->core;
u->module = m;
m->userdata = u;
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);
u->pid = (pid_t) -1;
u->fd = -1;
u->fd_type = 0;
u->io_event = NULL;
u->buf_fill = 0;
if ((u->fd = pa_start_child_for_read(
#if defined(__linux__) && !defined(__OPTIMIZE__)
pa_run_from_build_tree() ? PA_BUILDDIR "/gsettings-helper" :
#endif
PA_GSETTINGS_HELPER, NULL, &u->pid)) < 0)
goto fail;
u->io_event = m->core->mainloop->io_new(
m->core->mainloop,
u->fd,
PA_IO_EVENT_INPUT,
io_event_cb,
u);
do {
if ((r = handle_event(u)) < 0)
goto fail;
/* Read until the client signalled us that it is ready with
* initialization */
} while (r != 1);
return 0;
fail:
pa__done(m);
return -1;
}
void pa__done(pa_module*m) {
struct userdata *u;
pa_assert(m);
if (!(u = m->userdata))
return;
if (u->pid != (pid_t) -1) {
kill(u->pid, SIGTERM);
for (;;) {
if (waitpid(u->pid, NULL, 0) >= 0)
break;
if (errno != EINTR) {
pa_log("waitpid() failed: %s", pa_cstrerror(errno));
break;
}
}
}
if (u->io_event)
m->core->mainloop->io_free(u->io_event);
if (u->fd >= 0)
pa_close(u->fd);
if (u->module_infos)
pa_hashmap_free(u->module_infos);
pa_xfree(u);
}