diff options
33 files changed, 532 insertions, 444 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 5edd200f..8273d336 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -624,6 +624,7 @@ libpulsecore_la_SOURCES += \  		pulsecore/memchunk.c pulsecore/memchunk.h \  		pulsecore/modargs.c pulsecore/modargs.h \  		pulsecore/modinfo.c pulsecore/modinfo.h \ +		pulsecore/ltdl-helper.c pulsecore/ltdl-helper.h \  		pulsecore/module.c pulsecore/module.h \  		pulsecore/namereg.c pulsecore/namereg.h \  		pulsecore/pid.c pulsecore/pid.h \ @@ -1038,9 +1039,7 @@ EXTRA_DIST += $(SYMDEF_FILES)  BUILT_SOURCES += $(SYMDEF_FILES)  $(SYMDEF_FILES): modules/module-defs.h.m4 -	-mkdir modules -	-mkdir modules/gconf -	-mkdir modules/rtp +	$(mkdir_p) modules modules/gconf modules/rtp  	$(M4) -Dfname="$@" $< > $@  # Simple protocol diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c index cbe17d20..7e932c11 100644 --- a/src/modules/gconf/module-gconf.c +++ b/src/modules/gconf/module-gconf.c @@ -25,7 +25,6 @@  #include <config.h>  #endif -#include <assert.h>  #include <string.h>  #include <unistd.h>  #include <stdlib.h> @@ -34,6 +33,7 @@  #include <sys/types.h>  #include <sys/wait.h>  #include <fcntl.h> +#include <dirent.h>  #ifdef HAVE_SYS_PRCTL_H  #include <sys/prctl.h> @@ -95,7 +95,7 @@ struct userdata {  static int fill_buf(struct userdata *u) {      ssize_t r; -    assert(u); +    pa_assert(u);      if (u->buf_fill >= BUF_MAX) {          pa_log("read buffer overflow"); @@ -111,21 +111,21 @@ static int fill_buf(struct userdata *u) {  static int read_byte(struct userdata *u) {      int ret; -    assert(u); +    pa_assert(u);      if (u->buf_fill < 1)          if (fill_buf(u) < 0)              return -1;      ret = u->buf[0]; -    assert(u->buf_fill > 0); +    pa_assert(u->buf_fill > 0);      u->buf_fill--;      memmove(u->buf, u->buf+1, u->buf_fill);      return ret;  }  static char *read_string(struct userdata *u) { -    assert(u); +    pa_assert(u);      for (;;) {          char *e; @@ -143,9 +143,9 @@ static char *read_string(struct userdata *u) {  }  static void unload_one_module(struct userdata *u, struct module_info*m, unsigned i) { -    assert(u); -    assert(m); -    assert(i < m->n_items); +    pa_assert(u); +    pa_assert(m); +    pa_assert(i < m->n_items);      if (m->items[i].index == PA_INVALID_INDEX)          return; @@ -161,8 +161,8 @@ static void unload_one_module(struct userdata *u, struct module_info*m, unsigned  static void unload_all_modules(struct userdata *u, struct module_info*m) {      unsigned i; -    assert(u); -    assert(m); +    pa_assert(u); +    pa_assert(m);      for (i = 0; i < m->n_items; i++)          unload_one_module(u, m, i); @@ -180,10 +180,10 @@ static void load_module(      pa_module *mod; -    assert(u); -    assert(m); -    assert(name); -    assert(args); +    pa_assert(u); +    pa_assert(m); +    pa_assert(name); +    pa_assert(args);      if (!is_new) {          if (m->items[i].index != PA_INVALID_INDEX && @@ -212,8 +212,8 @@ static void module_info_free(void *p, void *userdata) {      struct module_info *m = p;      struct userdata *u = userdata; -    assert(m); -    assert(u); +    pa_assert(m); +    pa_assert(u);      unload_all_modules(u, m);      pa_xfree(m->name); @@ -356,8 +356,10 @@ static int start_client(const char *n, pid_t *pid) {          return pipe_fds[0];      } else { +#ifdef __linux__ +        DIR* d; +#endif          int max_fd, i; -          /* child */          close(pipe_fds[0]); @@ -372,19 +374,46 @@ static int start_client(const char *n, pid_t *pid) {          close(2);          open("/dev/null", O_WRONLY); -        max_fd = 1024; +#ifdef __linux__ + +        if ((d = opendir("/proc/self/fd/"))) { + +            struct dirent *de; + +            while ((de = readdir(d))) { +                char *e; +                int fd; +                 +                errno = 0; +                fd = strtol(de->d_name, &e, 10); +                pa_assert(errno == 0 && *e == 0); +                if (fd >= 3) +                    close(fd); +            } +             +            closedir(d); +        } else { +             +#endif +         +            max_fd = 1024; +              #ifdef HAVE_SYS_RESOURCE_H -        { -            struct rlimit r; -            if (getrlimit(RLIMIT_NOFILE, &r) == 0) -                max_fd = r.rlim_max; +            { +                struct rlimit r; +                if (getrlimit(RLIMIT_NOFILE, &r) == 0) +                    max_fd = r.rlim_max; +            } +#endif +             +            for (i = 3; i < max_fd; i++) +                close(i); +# +#ifdef __linux__          }  #endif -        for (i = 3; i < max_fd; i++) -            close(i); -  #ifdef PR_SET_PDEATHSIG          /* On Linux we can use PR_SET_PDEATHSIG to have the helper          process killed when the daemon dies abnormally. On non-Linux @@ -413,12 +442,12 @@ fail:      return -1;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u;      int r;      u = pa_xnew(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      u->module_infos = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); @@ -431,8 +460,8 @@ int pa__init(pa_core *c, pa_module*m) {      if ((u->fd = start_client(PA_GCONF_HELPER, &u->pid)) < 0)          goto fail; -    u->io_event = c->mainloop->io_new( -            c->mainloop, +    u->io_event = m->core->mainloop->io_new( +            m->core->mainloop,              u->fd,              PA_IO_EVENT_INPUT,              io_event_cb, @@ -449,21 +478,20 @@ int pa__init(pa_core *c, pa_module*m) {      return 0;  fail: -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    assert(c); -    assert(m); +    pa_assert(m);      if (!(u = m->userdata))          return;      if (u->io_event) -        c->mainloop->io_free(u->io_event); +        m->core->mainloop->io_free(u->io_event);      if (u->fd >= 0)          close(u->fd); diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 1a69954c..387e70c4 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -704,7 +704,7 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      int ret = -1; @@ -723,7 +723,6 @@ int pa__init(pa_core *c, pa_module*m) {      int namereg_fail;      int use_mmap = 1, b; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -731,7 +730,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {          pa_log("Failed to parse sample specification and channel map");          goto fail; @@ -756,7 +755,7 @@ int pa__init(pa_core *c, pa_module*m) {      }      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      u->use_mmap = use_mmap; @@ -824,7 +823,7 @@ int pa__init(pa_core *c, pa_module*m) {          namereg_fail = 0;      } -    u->sink = pa_sink_new(c, __FILE__, name, namereg_fail, &ss, &map); +    u->sink = pa_sink_new(m->core, __FILE__, name, namereg_fail, &ss, &map);      pa_xfree(name_buf);      if (!u->sink) { @@ -881,7 +880,7 @@ int pa__init(pa_core *c, pa_module*m) {          u->mixer_fdl = pa_alsa_fdlist_new(); -        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) { +        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, m->core->mainloop) < 0) {              pa_log("failed to initialise file descriptor monitoring");              goto fail;          } @@ -917,15 +916,14 @@ finish:  fail:      if (u) -        pa__done(c, m); +        pa__done(m);      goto finish;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 553d0283..7ed430e3 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -679,7 +679,7 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      int ret = -1; @@ -698,7 +698,6 @@ int pa__init(pa_core *c, pa_module*m) {      int namereg_fail;      int use_mmap = 1, b; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -706,7 +705,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_ALSA) < 0) {          pa_log("Failed to parse sample specification");          goto fail; @@ -732,7 +731,7 @@ int pa__init(pa_core *c, pa_module*m) {      }      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      u->use_mmap = use_mmap; @@ -796,7 +795,7 @@ int pa__init(pa_core *c, pa_module*m) {          namereg_fail = 0;      } -    u->source = pa_source_new(c, __FILE__, name, namereg_fail, &ss, &map); +    u->source = pa_source_new(m->core, __FILE__, name, namereg_fail, &ss, &map);      pa_xfree(name_buf);      if (!u->source) { @@ -849,7 +848,7 @@ int pa__init(pa_core *c, pa_module*m) {          u->mixer_fdl = pa_alsa_fdlist_new(); -        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, c->mainloop) < 0) { +        if (pa_alsa_fdlist_set_mixer(u->mixer_fdl, u->mixer_handle, m->core->mainloop) < 0) {              pa_log("failed to initialise file descriptor monitoring");              goto fail;          } @@ -886,15 +885,14 @@ finish:  fail:      if (u) -        pa__done(c, m); +        pa__done(m);      goto finish;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-cli.c b/src/modules/module-cli.c index 19ac0c26..fd180bc7 100644 --- a/src/modules/module-cli.c +++ b/src/modules/module-cli.c @@ -66,15 +66,14 @@ static void eof_and_exit_cb(pa_cli*c, void *userdata) {      m->core->mainloop->quit(m->core->mainloop, 0);  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_iochannel *io;      pa_modargs *ma;      int exit_on_eof = 0; -    assert(c);      assert(m); -    if (c->running_as_daemon) { +    if (m->core->running_as_daemon) {          pa_log_info("Running as daemon, refusing to load this module.");          return 0;      } @@ -94,12 +93,10 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    io = pa_iochannel_new(c->mainloop, STDIN_FILENO, STDOUT_FILENO); -    assert(io); +    io = pa_iochannel_new(m->core->mainloop, STDIN_FILENO, STDOUT_FILENO);      pa_iochannel_set_noclose(io, 1); -    m->userdata = pa_cli_new(c, io, m); -    assert(m->userdata); +    m->userdata = pa_cli_new(m->core, io, m);      pa_cli_set_eof_callback(m->userdata, exit_on_eof ? eof_and_exit_cb : eof_and_unload_cb, m); @@ -115,11 +112,10 @@ fail:      return -1;  } -void pa__done(pa_core *c, pa_module*m) { -    assert(c); +void pa__done(pa_module*m) {      assert(m); -    if (c->running_as_daemon == 0) { +    if (m->core->running_as_daemon == 0) {          pa_cli_free(m->userdata);          pa_stdio_release();      } diff --git a/src/modules/module-defs.h.m4 b/src/modules/module-defs.h.m4 index c961412d..5bff748e 100644 --- a/src/modules/module-defs.h.m4 +++ b/src/modules/module-defs.h.m4 @@ -18,8 +18,8 @@ gen_symbol(pa__get_description)  gen_symbol(pa__get_usage)  gen_symbol(pa__get_version) -int pa__init(struct pa_core *c, struct pa_module*m); -void pa__done(struct pa_core *c, struct pa_module*m); +int pa__init(pa_module*m); +void pa__done(pa_module*m);  const char* pa__get_author(void);  const char* pa__get_description(void); diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c index 190cda9d..858147e3 100644 --- a/src/modules/module-detect.c +++ b/src/modules/module-detect.c @@ -52,6 +52,11 @@ PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers  PA_MODULE_VERSION(PACKAGE_VERSION)  PA_MODULE_USAGE("just-one=<boolean>") +static const char* const valid_modargs[] = { +    "just-one", +    NULL +}; +  #ifdef HAVE_ALSA  static int detect_alsa(pa_core *c, int just_one) { @@ -215,17 +220,11 @@ static int detect_waveout(pa_core *c, int just_one) {  }  #endif -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      int just_one = 0, n = 0;      pa_modargs *ma; -    static const char* const valid_modargs[] = { -        "just-one", -        NULL -    }; - -    assert(c); -    assert(m); +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments"); @@ -238,16 +237,16 @@ int pa__init(pa_core *c, pa_module*m) {      }  #if HAVE_ALSA -    if ((n = detect_alsa(c, just_one)) <= 0) +    if ((n = detect_alsa(m->core, just_one)) <= 0)  #endif  #if HAVE_OSS -    if ((n = detect_oss(c, just_one)) <= 0) +    if ((n = detect_oss(m->core, just_one)) <= 0)  #endif  #if HAVE_SOLARIS -    if ((n = detect_solaris(c, just_one)) <= 0) +    if ((n = detect_solaris(m->core, just_one)) <= 0)  #endif  #if OS_IS_WIN32 -    if ((n = detect_waveout(c, just_one)) <= 0) +    if ((n = detect_waveout(m->core, just_one)) <= 0)  #endif      {          pa_log_warn("failed to detect any sound hardware."); @@ -269,9 +268,3 @@ fail:      return -1;  } - - -void pa__done(PA_GCC_UNUSED pa_core *c, PA_GCC_UNUSED pa_module*m) { -    /* NOP */ -} - diff --git a/src/modules/module-esound-compat-spawnfd.c b/src/modules/module-esound-compat-spawnfd.c index 1aecade5..890ebb16 100644 --- a/src/modules/module-esound-compat-spawnfd.c +++ b/src/modules/module-esound-compat-spawnfd.c @@ -26,7 +26,6 @@  #endif  #include <unistd.h> -#include <assert.h>  #include <string.h>  #include <errno.h> @@ -48,21 +47,23 @@ static const char* const valid_modargs[] = {      NULL,  }; -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      int ret = -1, fd = -1;      char x = 1; -    assert(c && m); +     +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs)) ||          pa_modargs_get_value_s32(ma, "fd", &fd) < 0 ||          fd < 0) { +                  pa_log("Failed to parse module arguments");          goto finish;      }      if (pa_loop_write(fd, &x, sizeof(x), NULL) != sizeof(x)) -        pa_log("WARNING: write(%u, 1, 1) failed: %s", fd, pa_cstrerror(errno)); +        pa_log_warn("WARNING: write(%u, 1, 1) failed: %s", fd, pa_cstrerror(errno));      close(fd); @@ -76,9 +77,3 @@ finish:      return ret;  } - -void pa__done(pa_core *c, pa_module*m) { -    assert(c && m); -} - - diff --git a/src/modules/module-esound-compat-spawnpid.c b/src/modules/module-esound-compat-spawnpid.c index a9fd166d..1cc86d20 100644 --- a/src/modules/module-esound-compat-spawnpid.c +++ b/src/modules/module-esound-compat-spawnpid.c @@ -25,7 +25,6 @@  #endif  #include <unistd.h> -#include <assert.h>  #include <string.h>  #include <errno.h>  #include <signal.h> @@ -48,11 +47,12 @@ static const char* const valid_modargs[] = {      NULL,  }; -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      int ret = -1;      uint32_t pid = 0; -    assert(c && m); +     +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs)) ||          pa_modargs_get_value_u32(ma, "pid", &pid) < 0 || @@ -62,7 +62,7 @@ int pa__init(pa_core *c, pa_module*m) {      }      if (kill(pid, SIGUSR1) < 0) -        pa_log("WARNING: kill(%u) failed: %s", pid, pa_cstrerror(errno)); +        pa_log_warn("WARNING: kill(%u) failed: %s", pid, pa_cstrerror(errno));      pa_module_unload_request(m); @@ -74,9 +74,3 @@ finish:      return ret;  } - -void pa__done(pa_core *c, pa_module*m) { -    assert(c && m); -} - - diff --git a/src/modules/module-hal-detect.c b/src/modules/module-hal-detect.c index d73ca0ce..672bdc06 100644 --- a/src/modules/module-hal-detect.c +++ b/src/modules/module-hal-detect.c @@ -46,6 +46,7 @@  #include <pulsecore/core-util.h>  #include <pulsecore/namereg.h>  #include <pulsecore/core-scache.h> +#include <pulsecore/modargs.h>  #include <hal/libhal.h> @@ -55,6 +56,13 @@  PA_MODULE_AUTHOR("Shahms King")  PA_MODULE_DESCRIPTION("Detect available audio hardware and load matching drivers")  PA_MODULE_VERSION(PACKAGE_VERSION) +#if defined(HAVE_ALSA) && defined(HAVE_OSS) +PA_MODULE_USAGE("api=<alsa or oss>") +#elif defined(HAVE_ALSA) +PA_MODULE_USAGE("api=<alsa>") +#elif defined(HAVE_OSS) +PA_MODULE_USAGE("api=<oss>") +#endif  struct device {      uint32_t index; @@ -78,6 +86,11 @@ struct timerdata {  #define CAPABILITY_ALSA "alsa"  #define CAPABILITY_OSS "oss" +static const char* const valid_modargs[] = { +    "api", +    NULL +}; +  static void hal_device_free(struct device* d) {      pa_assert(d); @@ -663,37 +676,65 @@ fail:      return NULL;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      DBusError error;      pa_dbus_connection *conn;      struct userdata *u = NULL;      LibHalContext *hal_context = NULL;      int n = 0; +    pa_modargs *ma; +    const char *api; -    pa_assert(c);      pa_assert(m);      dbus_error_init(&error); -     -    if (!(conn = pa_dbus_bus_get(c, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) { + +    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { +        pa_log("Failed to parse module arguments"); +        goto fail; +    } + +    if ((api = pa_modargs_get_value(ma, "api", NULL))) { +        int good = 0; + +#ifdef HAVE_ALSA +        if (strcmp(api, CAPABILITY_ALSA) == 0) { +            good = 1; +            api = CAPABILITY_ALSA; +        }  +#endif +#ifdef HAVE_OSS +        if (strcmp(api, CAPABILITY_OSS) == 0) { +            good = 1; +            api = CAPABILITY_OSS; +        } +#endif +         +        if (!good) { +            pa_log_error("Invalid API specification."); +            goto fail; +        } +    } +         +    if (!(conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &error)) || dbus_error_is_set(&error)) {          if (conn)              pa_dbus_connection_unref(conn);          pa_log_error("Unable to contact DBUS system bus: %s: %s", error.name, error.message);          goto fail;      } -    if (!(hal_context = hal_context_new(c, pa_dbus_connection_get(conn)))) { +    if (!(hal_context = hal_context_new(m->core, pa_dbus_connection_get(conn)))) {          /* pa_hal_context_new() logs appropriate errors */          pa_dbus_connection_unref(conn);          goto fail;      }      u = pa_xnew(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->context = hal_context;      u->connection = conn;      u->devices = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func); -    u->capability = NULL; +    u->capability = api;      m->userdata = u;  #ifdef HAVE_ALSA @@ -736,19 +777,24 @@ int pa__init(pa_core *c, pa_module*m) {      pa_log_info("Loaded %i modules.", n); +    pa_modargs_free(ma); +          return 0;  fail: +    if (ma) +        pa_modargs_free(ma); +          dbus_error_free(&error); -    pa__done(c, m); +    pa__done(m); +      return -1;  } -void pa__done(PA_GCC_UNUSED pa_core *c, pa_module *m) { +void pa__done(pa_module *m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-lirc.c b/src/modules/module-lirc.c index 452fa1f3..6f4e98dc 100644 --- a/src/modules/module-lirc.c +++ b/src/modules/module-lirc.c @@ -68,11 +68,12 @@ static int lirc_in_use = 0;  static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {      struct userdata *u = userdata;      char *name = NULL, *code = NULL; -    assert(io); -    assert(u); + +    pa_assert(io); +    pa_assert(u);      if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) { -        pa_log("lost connection to LIRC daemon."); +        pa_log("Lost connection to LIRC daemon.");          goto fail;      } @@ -86,7 +87,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC          c = pa_xstrdup(code);          c[strcspn(c, "\n\r")] = 0; -        pa_log_debug("raw IR code '%s'", c); +        pa_log_debug("Raw IR code '%s'", c);          pa_xfree(c);          while (lirc_code2char(u->config, code, &name) == 0 && name) { @@ -99,7 +100,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC                  MUTE_TOGGLE              } volchange = INVALID; -            pa_log_info("translated IR code '%s'", name); +            pa_log_info("Translated IR code '%s'", name);              if (strcasecmp(name, "volume-up") == 0)                  volchange = UP; @@ -113,12 +114,12 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC                  volchange = RESET;              if (volchange == INVALID) -                pa_log_warn("recieved unknown IR code '%s'", name); +                pa_log_warn("Recieved unknown IR code '%s'", name);              else {                  pa_sink *s;                  if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK, 1))) -                    pa_log("failed to get sink '%s'", u->sink_name); +                    pa_log("Failed to get sink '%s'", u->sink_name);                  else {                      int i;                      pa_cvolume cv = *pa_sink_get_volume(s); @@ -179,13 +180,14 @@ fail:      pa_module_unload_request(u->module); -    free(code); +    pa_xfree(code);  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u; -    assert(c && m); +     +    pa_assert(m);      if (lirc_in_use) {          pa_log("module-lirc may no be loaded twice."); @@ -197,7 +199,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    m->userdata = u = pa_xmalloc(sizeof(struct userdata)); +    m->userdata = u = pa_xnew(struct userdata, 1);      u->module = m;      u->io = NULL;      u->config = NULL; @@ -215,7 +217,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    u->io = c->mainloop->io_new(c->mainloop, u->lirc_fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u); +    u->io = m->core->mainloop->io_new(m->core->mainloop, u->lirc_fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);      lirc_in_use = 1; @@ -228,14 +230,13 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    assert(c); -    assert(m); +    pa_assert(m);      if (!(u = m->userdata))          return; diff --git a/src/modules/module-match.c b/src/modules/module-match.c index 0b051fac..373ed487 100644 --- a/src/modules/module-match.c +++ b/src/modules/module-match.c @@ -26,7 +26,6 @@  #endif  #include <unistd.h> -#include <assert.h>  #include <string.h>  #include <errno.h>  #include <sys/types.h> @@ -80,6 +79,8 @@ static int load_rules(struct userdata *u, const char *filename) {      struct rule *end = NULL;      char *fn = NULL; +    pa_assert(u); +      f = filename ?          fopen(fn = pa_xstrdup(filename), "r") :          pa_open_config_file(DEFAULT_MATCH_TABLE_FILE, DEFAULT_MATCH_TABLE_FILE_USER, NULL, &fn, "r"); @@ -132,7 +133,7 @@ static int load_rules(struct userdata *u, const char *filename) {              goto finish;          } -        rule = pa_xmalloc(sizeof(struct rule)); +        rule = pa_xnew(struct rule, 1);          rule->regex = regex;          rule->volume = volume;          rule->next = NULL; @@ -164,7 +165,9 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v      struct userdata *u =  userdata;      pa_sink_input *si;      struct rule *r; -    assert(c && u); +     +    pa_assert(c); +    pa_assert(u);      if (t != (PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW))          return; @@ -185,17 +188,18 @@ static void callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, v      }  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u; -    assert(c && m); +     +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments");          goto fail;      } -    u = pa_xmalloc(sizeof(struct userdata)); +    u = pa_xnew(struct userdata, 1);      u->rules = NULL;      u->subscription = NULL;      m->userdata = u; @@ -203,23 +207,24 @@ int pa__init(pa_core *c, pa_module*m) {      if (load_rules(u, pa_modargs_get_value(ma, "table", NULL)) < 0)          goto fail; -    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u); +    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT, callback, u);      pa_modargs_free(ma);      return 0;  fail: -    pa__done(c, m); +    pa__done(m);      if (ma)          pa_modargs_free(ma);      return  -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata* u;      struct rule *r, *n; -    assert(c && m); +     +    pa_assert(m);      if (!(u = m->userdata))          return; diff --git a/src/modules/module-mmkbd-evdev.c b/src/modules/module-mmkbd-evdev.c index 919b399d..03394c0a 100644 --- a/src/modules/module-mmkbd-evdev.c +++ b/src/modules/module-mmkbd-evdev.c @@ -26,7 +26,6 @@  #endif  #include <stdio.h> -#include <assert.h>  #include <unistd.h>  #include <string.h>  #include <stdlib.h> @@ -80,11 +79,12 @@ struct userdata {  static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void*userdata) {      struct userdata *u = userdata; -    assert(io); -    assert(u); +     +    pa_assert(io); +    pa_assert(u);      if (events & (PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR)) { -        pa_log("lost connection to evdev device."); +        pa_log("Lost connection to evdev device.");          goto fail;      } @@ -92,14 +92,14 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC          struct input_event ev;          if (pa_loop_read(u->fd, &ev, sizeof(ev), &u->fd_type) <= 0) { -            pa_log("failed to read from event device: %s", pa_cstrerror(errno)); +            pa_log("Failed to read from event device: %s", pa_cstrerror(errno));              goto fail;          }          if (ev.type == EV_KEY && (ev.value == 1 || ev.value == 2)) {              enum { INVALID, UP, DOWN, MUTE_TOGGLE } volchange = INVALID; -            pa_log_debug("key code=%u, value=%u", ev.code, ev.value); +            pa_log_debug("Key code=%u, value=%u", ev.code, ev.value);              switch (ev.code) {                  case KEY_VOLUMEDOWN:  volchange = DOWN; break; @@ -111,7 +111,7 @@ static void io_callback(pa_mainloop_api *io, PA_GCC_UNUSED pa_io_event *e, PA_GC                  pa_sink *s;                  if (!(s = pa_namereg_get(u->module->core, u->sink_name, PA_NAMEREG_SINK, 1))) -                    pa_log("failed to get sink '%s'", u->sink_name); +                    pa_log("Failed to get sink '%s'", u->sink_name);                  else {                      int i;                      pa_cvolume cv = *pa_sink_get_volume(s); @@ -165,21 +165,23 @@ fail:  #define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) { +          pa_modargs *ma = NULL;      struct userdata *u;      int version;      struct _input_id input_id;      char name[256];      uint8_t evtype_bitmask[EV_MAX/8 + 1]; -    assert(c && m); + +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments");          goto fail;      } -    m->userdata = u = pa_xmalloc(sizeof(struct userdata)); +    m->userdata = u = pa_xnew(struct userdata,1);      u->module = m;      u->io = NULL;      u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL)); @@ -221,11 +223,11 @@ int pa__init(pa_core *c, pa_module*m) {      }      if (!test_bit(EV_KEY, evtype_bitmask)) { -        pa_log("device has no keys."); +        pa_log("Device has no keys.");          goto fail;      } -    u->io = c->mainloop->io_new(c->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u); +    u->io = m->core->mainloop->io_new(m->core->mainloop, u->fd, PA_IO_EVENT_INPUT|PA_IO_EVENT_HANGUP, io_callback, u);      pa_modargs_free(ma); @@ -236,14 +238,14 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    assert(c); -    assert(m); + +    pa_assert(m);      if (!(u = m->userdata))          return; diff --git a/src/modules/module-native-protocol-fd.c b/src/modules/module-native-protocol-fd.c index 3c1c2bca..b0a9ebb0 100644 --- a/src/modules/module-native-protocol-fd.c +++ b/src/modules/module-native-protocol-fd.c @@ -26,10 +26,10 @@  #endif  #include <stdio.h> -#include <assert.h>  #include <unistd.h>  #include <pulsecore/module.h> +#include <pulsecore/macro.h>  #include <pulsecore/iochannel.h>  #include <pulsecore/modargs.h>  #include <pulsecore/protocol-native.h> @@ -48,25 +48,26 @@ static const char* const valid_modargs[] = {      NULL,  }; -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_iochannel *io;      pa_modargs *ma;      int fd, r = -1; -    assert(c && m); +     +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { -        pa_log("failed to parse module arguments."); +        pa_log("Failed to parse module arguments.");          goto finish;      }      if (pa_modargs_get_value_s32(ma, "fd", &fd) < 0) { -        pa_log("invalid file descriptor."); +        pa_log("Invalid file descriptor.");          goto finish;      } -    io = pa_iochannel_new(c->mainloop, fd, fd); +    io = pa_iochannel_new(m->core->mainloop, fd, fd); -    if (!(m->userdata = pa_protocol_native_new_iochannel(c, io, m, ma))) { +    if (!(m->userdata = pa_protocol_native_new_iochannel(m->core, io, m, ma))) {          pa_iochannel_free(io);          goto finish;      } @@ -80,8 +81,8 @@ finish:      return r;  } -void pa__done(pa_core *c, pa_module*m) { -    assert(c && m); +void pa__done(pa_module*m) { +    pa_assert(m);      pa_protocol_native_free(m->userdata);  } diff --git a/src/modules/module-null-sink.c b/src/modules/module-null-sink.c index f0e3a061..2ede01a4 100644 --- a/src/modules/module-null-sink.c +++ b/src/modules/module-null-sink.c @@ -198,13 +198,12 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u = NULL;      pa_sample_spec ss;      pa_channel_map map;      pa_modargs *ma = NULL; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -212,20 +211,20 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {          pa_log("Invalid sample format specification or channel map");          goto fail;      }      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      pa_assert_se(u->asyncmsgq = pa_asyncmsgq_new(0)); -    if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { +    if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {          pa_log("Failed to create sink.");          goto fail;      } @@ -254,15 +253,14 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-oss.c b/src/modules/module-oss.c index a43bdb3c..d93d8c79 100644 --- a/src/modules/module-oss.c +++ b/src/modules/module-oss.c @@ -1059,7 +1059,7 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct audio_buf_info info;      struct userdata *u = NULL; @@ -1075,7 +1075,6 @@ int pa__init(pa_core *c, pa_module*m) {      const char *name;      int namereg_fail; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -1095,7 +1094,7 @@ int pa__init(pa_core *c, pa_module*m) {      mode = (playback && record) ? O_RDWR : (playback ? O_WRONLY : (record ? O_RDONLY : 0)); -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_OSS) < 0) {          pa_log("Failed to parse sample specification or channel map");          goto fail; @@ -1150,7 +1149,7 @@ int pa__init(pa_core *c, pa_module*m) {      pa_assert(frag_size > 0);      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      u->fd = fd; @@ -1206,7 +1205,7 @@ int pa__init(pa_core *c, pa_module*m) {              namereg_fail = 0;          } -        u->source = pa_source_new(c, __FILE__, name, namereg_fail, &ss, &map); +        u->source = pa_source_new(m->core, __FILE__, name, namereg_fail, &ss, &map);          pa_xfree(name_buf);          if (!u->source) {              pa_log("Failed to create source object"); @@ -1260,7 +1259,7 @@ try_write:              namereg_fail = 0;          } -        u->sink = pa_sink_new(c, __FILE__, name, namereg_fail, &ss, &map); +        u->sink = pa_sink_new(m->core, __FILE__, name, namereg_fail, &ss, &map);          pa_xfree(name_buf);          if (!u->sink) {              pa_log("Failed to create sink object"); @@ -1310,7 +1309,7 @@ go_on:  fail:      if (u) -        pa__done(c, m); +        pa__done(m);      else if (fd >= 0)          close(fd); @@ -1320,10 +1319,9 @@ fail:      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-pipe-sink.c b/src/modules/module-pipe-sink.c index 83ee06b7..1b6d0813 100644 --- a/src/modules/module-pipe-sink.c +++ b/src/modules/module-pipe-sink.c @@ -232,7 +232,7 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u;      struct stat st;      pa_sample_spec ss; @@ -240,7 +240,6 @@ int pa__init(pa_core *c, pa_module*m) {      pa_modargs *ma;      char *t; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -248,14 +247,14 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {          pa_log("Invalid sample format specification or channel map");          goto fail;      }      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      pa_memchunk_reset(&u->memchunk); @@ -283,7 +282,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    if (!(u->sink = pa_sink_new(c, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) { +    if (!(u->sink = pa_sink_new(m->core, __FILE__, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME), 0, &ss, &map))) {          pa_log("Failed to create sink.");          goto fail;      } @@ -309,15 +308,14 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-pipe-source.c b/src/modules/module-pipe-source.c index a5f95f9a..a8fbcf3d 100644 --- a/src/modules/module-pipe-source.c +++ b/src/modules/module-pipe-source.c @@ -210,7 +210,7 @@ finish:      pa_log_debug("Thread shutting down");  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u;      struct stat st;      pa_sample_spec ss; @@ -218,7 +218,6 @@ int pa__init(pa_core *c, pa_module*m) {      pa_modargs *ma;      char *t; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -226,14 +225,14 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    ss = c->default_sample_spec; +    ss = m->core->default_sample_spec;      if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) {          pa_log("invalid sample format specification or channel map");          goto fail;      }      u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      m->userdata = u;      pa_memchunk_reset(&u->memchunk); @@ -261,7 +260,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    if (!(u->source = pa_source_new(c, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) { +    if (!(u->source = pa_source_new(m->core, __FILE__, pa_modargs_get_value(ma, "source_name", DEFAULT_SOURCE_NAME), 0, &ss, &map))) {          pa_log("Failed to create source.");          goto fail;      } @@ -286,15 +285,14 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-protocol-stub.c b/src/modules/module-protocol-stub.c index 3edb59e5..fb7cf22d 100644 --- a/src/modules/module-protocol-stub.c +++ b/src/modules/module-protocol-stub.c @@ -29,7 +29,6 @@  #include <string.h>  #include <errno.h>  #include <stdio.h> -#include <assert.h>  #include <unistd.h>  #include <limits.h> @@ -43,10 +42,9 @@  #include <netinet/in.h>  #endif -#include "../pulsecore/winsock.h" -  #include <pulse/xmalloc.h> +#include <pulsecore/winsock.h>  #include <pulsecore/core-error.h>  #include <pulsecore/module.h>  #include <pulsecore/socket-server.h> @@ -204,10 +202,9 @@ struct userdata {  #endif  }; -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      int ret = -1; -      struct userdata *u = NULL;  #if defined(USE_TCP_SOCKETS) @@ -224,7 +221,7 @@ int pa__init(pa_core *c, pa_module*m) {  #endif  #endif -    assert(c && m); +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments"); @@ -242,22 +239,22 @@ int pa__init(pa_core *c, pa_module*m) {      listen_on = pa_modargs_get_value(ma, "listen", NULL);      if (listen_on) { -        s_ipv6 = pa_socket_server_new_ipv6_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE); -        s_ipv4 = pa_socket_server_new_ipv4_string(c->mainloop, listen_on, port, TCPWRAP_SERVICE); +        s_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE); +        s_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, port, TCPWRAP_SERVICE);      } else { -        s_ipv6 = pa_socket_server_new_ipv6_any(c->mainloop, port, TCPWRAP_SERVICE); -        s_ipv4 = pa_socket_server_new_ipv4_any(c->mainloop, port, TCPWRAP_SERVICE); +        s_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, port, TCPWRAP_SERVICE); +        s_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, port, TCPWRAP_SERVICE);      }      if (!s_ipv4 && !s_ipv6)          goto fail;      if (s_ipv4) -        if (!(u->protocol_ipv4 = protocol_new(c, s_ipv4, m, ma))) +        if (!(u->protocol_ipv4 = protocol_new(m->core, s_ipv4, m, ma)))              pa_socket_server_unref(s_ipv4);      if (s_ipv6) -        if (!(u->protocol_ipv6 = protocol_new(c, s_ipv6, m, ma))) +        if (!(u->protocol_ipv6 = protocol_new(m->core, s_ipv6, m, ma)))              pa_socket_server_unref(s_ipv6);      if (!u->protocol_ipv4 && !u->protocol_ipv6) @@ -274,7 +271,7 @@ int pa__init(pa_core *c, pa_module*m) {      /* This socket doesn't reside in our own runtime dir but in       * /tmp/.esd/, hence we have to create the dir first */ -    if (pa_make_secure_parent_dir(u->socket_path, c->is_system_instance ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) { +    if (pa_make_secure_parent_dir(u->socket_path, m->core->is_system_instance ? 0755 : 0700, (uid_t)-1, (gid_t)-1) < 0) {          pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno));          goto fail;      } @@ -292,10 +289,10 @@ int pa__init(pa_core *c, pa_module*m) {      if (r)          pa_log("Removed stale UNIX socket '%s'.", tmp); -    if (!(s = pa_socket_server_new_unix(c->mainloop, tmp))) +    if (!(s = pa_socket_server_new_unix(m->core->mainloop, tmp)))          goto fail; -    if (!(u->protocol_unix = protocol_new(c, s, m, ma))) +    if (!(u->protocol_unix = protocol_new(m->core, s, m, ma)))          goto fail;  #endif @@ -341,11 +338,10 @@ fail:      goto finish;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    assert(c); -    assert(m); +    pa_assert(m);      u = m->userdata; @@ -366,7 +362,6 @@ void pa__done(pa_core *c, pa_module*m) {      }  #endif -      pa_xfree(u->socket_path);  #endif diff --git a/src/modules/module-rescue-streams.c b/src/modules/module-rescue-streams.c index 034660e4..fa22d60a 100644 --- a/src/modules/module-rescue-streams.c +++ b/src/modules/module-rescue-streams.c @@ -126,11 +126,10 @@ static pa_hook_result_t source_hook_callback(pa_core *c, pa_source *source, void      return PA_HOOK_OK;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -139,17 +138,16 @@ int pa__init(pa_core *c, pa_module*m) {      }      m->userdata = u = pa_xnew(struct userdata, 1); -    u->sink_slot = pa_hook_connect(&c->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL); -    u->source_slot = pa_hook_connect(&c->hook_source_disconnect, (pa_hook_cb_t) source_hook_callback, NULL); +    u->sink_slot = pa_hook_connect(&m->core->hook_sink_disconnect, (pa_hook_cb_t) sink_hook_callback, NULL); +    u->source_slot = pa_hook_connect(&m->core->hook_source_disconnect, (pa_hook_cb_t) source_hook_callback, NULL);      pa_modargs_free(ma);      return 0;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!m->userdata) diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c index 797ba440..f2830ff0 100644 --- a/src/modules/module-sine.c +++ b/src/modules/module-sine.c @@ -114,7 +114,7 @@ static void calc_sine(float *f, size_t l, float freq) {          f[i] = (float) sin((double) i/l*M_PI*2*freq)/2;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u;      pa_sink *sink; @@ -130,13 +130,13 @@ int pa__init(pa_core *c, pa_module*m) {      }      m->userdata = u = pa_xnew0(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->module = m;      u->sink_input = NULL;      u->memblock = NULL;      u->peek_index = 0; -    if (!(sink = pa_namereg_get(c, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, 1))) { +    if (!(sink = pa_namereg_get(m->core, pa_modargs_get_value(ma, "sink", NULL), PA_NAMEREG_SINK, 1))) {          pa_log("No such sink.");          goto fail;      } @@ -151,7 +151,7 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    u->memblock = pa_memblock_new(c->mempool, pa_bytes_per_second(&ss)); +    u->memblock = pa_memblock_new(m->core->mempool, pa_bytes_per_second(&ss));      p = pa_memblock_acquire(u->memblock);      calc_sine(p, pa_memblock_get_length(u->memblock), frequency);      pa_memblock_release(u->memblock); @@ -165,7 +165,7 @@ int pa__init(pa_core *c, pa_module*m) {      pa_sink_input_new_data_set_sample_spec(&data, &ss);      data.module = m; -    if (!(u->sink_input = pa_sink_input_new(c, &data, 0))) +    if (!(u->sink_input = pa_sink_input_new(m->core, &data, 0)))          goto fail;      u->sink_input->peek = sink_input_peek_cb; @@ -182,14 +182,13 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    pa_assert(c);      pa_assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-suspend-on-idle.c b/src/modules/module-suspend-on-idle.c index d2c51a10..ad148644 100644 --- a/src/modules/module-suspend-on-idle.c +++ b/src/modules/module-suspend-on-idle.c @@ -209,7 +209,7 @@ static pa_hook_result_t device_disconnect_hook_cb(pa_core *c, pa_object *o, stru      return PA_HOOK_OK;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u;      uint32_t timeout = 5; @@ -217,8 +217,7 @@ int pa__init(pa_core *c, pa_module*m) {      pa_sink *sink;      pa_source *source; -    assert(c); -    assert(m); +    pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments."); @@ -231,25 +230,25 @@ int pa__init(pa_core *c, pa_module*m) {      }      m->userdata = u = pa_xnew(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->timeout = timeout;      u->device_infos = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); -    for (sink = pa_idxset_first(c->sinks, &idx); sink; sink = pa_idxset_next(c->sinks, &idx)) -        device_new_hook_cb(c, PA_OBJECT(sink), u); +    for (sink = pa_idxset_first(m->core->sinks, &idx); sink; sink = pa_idxset_next(m->core->sinks, &idx)) +        device_new_hook_cb(m->core, PA_OBJECT(sink), u); -    for (source = pa_idxset_first(c->sources, &idx); source; source = pa_idxset_next(c->sources, &idx)) -        device_new_hook_cb(c, PA_OBJECT(source), u); +    for (source = pa_idxset_first(m->core->sources, &idx); source; source = pa_idxset_next(m->core->sources, &idx)) +        device_new_hook_cb(m->core, PA_OBJECT(source), u); -    u->sink_new_slot = pa_hook_connect(&c->hook_sink_new_post, (pa_hook_cb_t) device_new_hook_cb, u); -    u->source_new_slot = pa_hook_connect(&c->hook_source_new_post, (pa_hook_cb_t) device_new_hook_cb, u); -    u->sink_disconnect_slot = pa_hook_connect(&c->hook_sink_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u); -    u->source_disconnect_slot = pa_hook_connect(&c->hook_source_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u); +    u->sink_new_slot = pa_hook_connect(&m->core->hook_sink_new_post, (pa_hook_cb_t) device_new_hook_cb, u); +    u->source_new_slot = pa_hook_connect(&m->core->hook_source_new_post, (pa_hook_cb_t) device_new_hook_cb, u); +    u->sink_disconnect_slot = pa_hook_connect(&m->core->hook_sink_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u); +    u->source_disconnect_slot = pa_hook_connect(&m->core->hook_source_disconnect_post, (pa_hook_cb_t) device_disconnect_hook_cb, u); -    u->sink_input_new_slot = pa_hook_connect(&c->hook_sink_input_new_post, (pa_hook_cb_t) sink_input_new_hook_cb, u); -    u->source_output_new_slot = pa_hook_connect(&c->hook_source_output_new_post, (pa_hook_cb_t) source_output_new_hook_cb, u); -    u->sink_input_disconnect_slot = pa_hook_connect(&c->hook_sink_input_disconnect_post, (pa_hook_cb_t) sink_input_disconnect_hook_cb, u); -    u->source_output_disconnect_slot = pa_hook_connect(&c->hook_source_output_disconnect_post, (pa_hook_cb_t) source_output_disconnect_hook_cb, u); +    u->sink_input_new_slot = pa_hook_connect(&m->core->hook_sink_input_new_post, (pa_hook_cb_t) sink_input_new_hook_cb, u); +    u->source_output_new_slot = pa_hook_connect(&m->core->hook_source_output_new_post, (pa_hook_cb_t) source_output_new_hook_cb, u); +    u->sink_input_disconnect_slot = pa_hook_connect(&m->core->hook_sink_input_disconnect_post, (pa_hook_cb_t) sink_input_disconnect_hook_cb, u); +    u->source_output_disconnect_slot = pa_hook_connect(&m->core->hook_source_output_disconnect_post, (pa_hook_cb_t) source_output_disconnect_hook_cb, u);      pa_modargs_free(ma);      return 0; @@ -262,12 +261,11 @@ fail:      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u;      struct device_info *d; -    assert(c); -    assert(m); +    pa_assert(m);      if (!m->userdata)          return; diff --git a/src/modules/module-volume-restore.c b/src/modules/module-volume-restore.c index 0f0d998b..addd937b 100644 --- a/src/modules/module-volume-restore.c +++ b/src/modules/module-volume-restore.c @@ -420,11 +420,10 @@ static pa_hook_result_t source_output_hook_callback(pa_core *c, pa_source_output      return PA_HOOK_OK;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      pa_modargs *ma = NULL;      struct userdata *u; -    assert(c);      assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -444,16 +443,15 @@ int pa__init(pa_core *c, pa_module*m) {      if (load_rules(u) < 0)          goto fail; -    u->subscription = pa_subscription_new(c, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u); -    u->sink_input_hook_slot = pa_hook_connect(&c->hook_sink_input_new, (pa_hook_cb_t) sink_input_hook_callback, u); -    u->source_output_hook_slot = pa_hook_connect(&c->hook_source_output_new, (pa_hook_cb_t) source_output_hook_callback, u); +    u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK_INPUT|PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT, subscribe_callback, u); +    u->sink_input_hook_slot = pa_hook_connect(&m->core->hook_sink_input_new, (pa_hook_cb_t) sink_input_hook_callback, u); +    u->source_output_hook_slot = pa_hook_connect(&m->core->hook_source_output_new, (pa_hook_cb_t) source_output_hook_callback, u);      pa_modargs_free(ma);      return 0;  fail: -    pa__done(c, m); - +    pa__done(m);      if (ma)          pa_modargs_free(ma); @@ -470,10 +468,9 @@ static void free_func(void *p, void *userdata) {      pa_xfree(r);  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata* u; -    assert(c);      assert(m);      if (!(u = m->userdata)) diff --git a/src/modules/module-x11-bell.c b/src/modules/module-x11-bell.c index 0c3c63f3..e59db83c 100644 --- a/src/modules/module-x11-bell.c +++ b/src/modules/module-x11-bell.c @@ -88,14 +88,13 @@ static int x11_event_callback(pa_x11_wrapper *w, XEvent *e, void *userdata) {      return 1;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u = NULL;      pa_modargs *ma = NULL;      int major, minor;      unsigned int auto_ctrls, auto_values; -    pa_assert(c);      pa_assert(m);      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { @@ -104,12 +103,12 @@ int pa__init(pa_core *c, pa_module*m) {      }      m->userdata = u = pa_xnew(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->scache_item = pa_xstrdup(pa_modargs_get_value(ma, "sample", "x11-bell"));      u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));      u->x11_client = NULL; -    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL)))) +    if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))          goto fail;      major = XkbMajorVersion; @@ -143,16 +142,15 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata *u; -    assert(c); -    assert(m); +    pa_assert(m);      if (!m->userdata)          return; diff --git a/src/modules/module-x11-publish.c b/src/modules/module-x11-publish.c index fd1d532f..7da9cc2d 100644 --- a/src/modules/module-x11-publish.c +++ b/src/modules/module-x11-publish.c @@ -26,7 +26,6 @@  #endif  #include <stdio.h> -#include <assert.h>  #include <stdlib.h>  #include <string.h>  #include <unistd.h> @@ -76,7 +75,7 @@ struct userdata {  };  static int load_key(struct userdata *u, const char*fn) { -    assert(u); +    pa_assert(u);      u->auth_cookie_in_property = 0; @@ -93,7 +92,7 @@ static int load_key(struct userdata *u, const char*fn) {      if (pa_authkey_load_auto(fn, u->auth_cookie, sizeof(u->auth_cookie)) < 0)          return -1; -    pa_log_debug("loading cookie from disk."); +    pa_log_debug("Loading cookie from disk.");      if (pa_authkey_prop_put(u->core, PA_NATIVE_COOKIE_PROPERTY_NAME, u->auth_cookie, sizeof(u->auth_cookie)) >= 0)          u->auth_cookie_in_property = 1; @@ -101,7 +100,7 @@ static int load_key(struct userdata *u, const char*fn) {      return 0;  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) {      struct userdata *u;      pa_modargs *ma = NULL;      char hn[256], un[128]; @@ -110,23 +109,25 @@ int pa__init(pa_core *c, pa_module*m) {      char *s;      pa_strlist *l; +    pa_assert(m); +          if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("failed to parse module arguments");          goto fail;      }      m->userdata = u = pa_xmalloc(sizeof(struct userdata)); -    u->core = c; +    u->core = m->core;      u->id = NULL;      u->auth_cookie_in_property = 0;      if (load_key(u, pa_modargs_get_value(ma, "cookie", NULL)) < 0)          goto fail; -    if (!(u->x11_wrapper = pa_x11_wrapper_get(c, pa_modargs_get_value(ma, "display", NULL)))) +    if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))          goto fail; -    if (!(l = pa_property_get(c, PA_NATIVE_SERVER_PROPERTY_NAME))) +    if (!(l = pa_property_get(m->core, PA_NATIVE_SERVER_PROPERTY_NAME)))          goto fail;      s = pa_strlist_tostring(l); @@ -154,13 +155,14 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata*u; -    assert(c && m); +     +    pa_assert(m);      if (!(u = m->userdata))          return; @@ -185,7 +187,7 @@ void pa__done(pa_core *c, pa_module*m) {          pa_x11_wrapper_unref(u->x11_wrapper);      if (u->auth_cookie_in_property) -        pa_authkey_prop_unref(c, PA_NATIVE_COOKIE_PROPERTY_NAME); +        pa_authkey_prop_unref(m->core, PA_NATIVE_COOKIE_PROPERTY_NAME);      pa_xfree(u->id);      pa_xfree(u); diff --git a/src/modules/module-x11-xsmp.c b/src/modules/module-x11-xsmp.c index dc23ebe3..4ef437a1 100644 --- a/src/modules/module-x11-xsmp.c +++ b/src/modules/module-x11-xsmp.c @@ -49,17 +49,14 @@ PA_MODULE_AUTHOR("Lennart Poettering")  PA_MODULE_DESCRIPTION("X11 session management")  PA_MODULE_VERSION(PACKAGE_VERSION) -struct userdata { -    pa_core *core; -    SmcConn sm_conn; -}; +static int ice_in_use = 0;  static const char* const valid_modargs[] = {      NULL  };  static void die_cb(SmcConn connection, SmPointer client_data){ -    pa_core *c = client_data; +    pa_core *c = PA_CORE(client_data);      pa_log_debug("Got die message from XSM. Exiting..."); @@ -98,18 +95,26 @@ static void new_ice_connection(IceConn connection, IcePointer client_data, Bool          c->mainloop->io_free(*watch_data);  } -int pa__init(pa_core *c, pa_module*m) { -    struct userdata *u = NULL; +int pa__init(pa_module*m) { +      pa_modargs *ma = NULL;      char t[256], *vendor, *client_id;      SmcCallbacks callbacks;      SmProp prop_program, prop_user;      SmProp *prop_list[2];      SmPropValue val_program, val_user; +    SmcConn connection; -    pa_assert(c);      pa_assert(m); +    if (ice_in_use) { +        pa_log("module-x11-xsmp may no be loaded twice."); +        return -1; +    } +     +    IceAddConnectionWatch(new_ice_connection, m->core); +    ice_in_use = 1; +      if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {          pa_log("Failed to parse module arguments");          goto fail; @@ -119,23 +124,19 @@ int pa__init(pa_core *c, pa_module*m) {          pa_log("X11 session manager not running.");          goto fail;      } - -    m->userdata = u = pa_xnew(struct userdata, 1); -    u->core = c; -    u->sm_conn = NULL; - -    IceAddConnectionWatch(new_ice_connection, c);      memset(&callbacks, 0, sizeof(callbacks));      callbacks.die.callback = die_cb; -    callbacks.die.client_data = c; - +    callbacks.die.client_data = m->core;      callbacks.save_yourself.callback = save_yourself_cb; +    callbacks.save_yourself.client_data = m->core;      callbacks.save_complete.callback = save_complete_cb; +    callbacks.save_complete.client_data = m->core;      callbacks.shutdown_cancelled.callback = shutdown_cancelled_cb; +    callbacks.shutdown_cancelled.client_data = m->core; -    if (!(u->sm_conn = SmcOpenConnection( -                  NULL, u, +    if (!(m->userdata = connection = SmcOpenConnection( +                  NULL, m->core,                    SmProtoMajor, SmProtoMinor,                    SmcSaveYourselfProcMask | SmcDieProcMask | SmcSaveCompleteProcMask | SmcShutdownCancelledProcMask,                    &callbacks, NULL, &client_id, @@ -162,9 +163,9 @@ int pa__init(pa_core *c, pa_module*m) {      prop_user.vals = &val_user;      prop_list[1] = &prop_user; -    SmcSetProperties(u->sm_conn, PA_ELEMENTSOF(prop_list), prop_list); +    SmcSetProperties(connection, PA_ELEMENTSOF(prop_list), prop_list); -    pa_log_info("Connected to session manager '%s' as '%s'.", vendor = SmcVendor(u->sm_conn), client_id); +    pa_log_info("Connected to session manager '%s' as '%s'.", vendor = SmcVendor(connection), client_id);      free(vendor);      free(client_id); @@ -176,26 +177,19 @@ fail:      if (ma)          pa_modargs_free(ma); -    pa__done(c, m); +    pa__done(m);      return -1;  } -void pa__done(pa_core *c, pa_module*m) { -    struct userdata *u; -     -    assert(c); -    assert(m); - -    if (!m->userdata) -        return; - -    u = m->userdata; +void pa__done(pa_module*m) { +    pa_assert(m); -    if (u->sm_conn) -        SmcCloseConnection(u->sm_conn, 0, NULL); +    if (m->userdata) +        SmcCloseConnection(m->userdata, 0, NULL); -    IceRemoveConnectionWatch(new_ice_connection, c); -     -    pa_xfree(u); +    if (ice_in_use) { +        IceRemoveConnectionWatch(new_ice_connection, m->core); +        ice_in_use = 0; +    }  } diff --git a/src/modules/module-zeroconf-publish.c b/src/modules/module-zeroconf-publish.c index 69508ad0..34565395 100644 --- a/src/modules/module-zeroconf-publish.c +++ b/src/modules/module-zeroconf-publish.c @@ -102,25 +102,25 @@ struct userdata {  };  static void get_service_data(struct userdata *u, struct service *s, pa_sample_spec *ret_ss, char **ret_description) { -    assert(u && s && s->loaded.valid && ret_ss && ret_description); +    pa_assert(u && s && s->loaded.valid && ret_ss && ret_description);      if (s->loaded.type == PA_NAMEREG_SINK) {          pa_sink *sink = pa_idxset_get_by_index(u->core->sinks, s->loaded.index); -        assert(sink); +        pa_assert(sink);          *ret_ss = sink->sample_spec;          *ret_description = sink->description;      } else if (s->loaded.type == PA_NAMEREG_SOURCE) {          pa_source *source = pa_idxset_get_by_index(u->core->sources, s->loaded.index); -        assert(source); +        pa_assert(source);          *ret_ss = source->sample_spec;          *ret_description = source->description;      } else -        assert(0); +        pa_assert(0);  }  static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) {      char s[128]; -    assert(c); +    pa_assert(c);      l = avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "PACKAGE_VERSION);      l = avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, sizeof(s))); @@ -150,8 +150,8 @@ static int publish_service(struct userdata *u, struct service *s) {      int r = -1;      AvahiStringList *txt = NULL; -    assert(u); -    assert(s); +    pa_assert(u); +    pa_assert(s);      if (!u->client || avahi_client_get_state(u->client) != AVAHI_CLIENT_S_RUNNING)          return 0; @@ -265,7 +265,7 @@ static struct service *get_service(struct userdata *u, const char *name, const c  static int publish_sink(struct userdata *u, pa_sink *s) {      struct service *svc;      int ret; -    assert(u && s); +    pa_assert(u && s);      svc = get_service(u, s->name, s->description);      if (svc->loaded.valid) @@ -286,7 +286,7 @@ static int publish_source(struct userdata *u, pa_source *s) {      struct service *svc;      int ret; -    assert(u && s); +    pa_assert(u && s);      svc = get_service(u, s->name, s->description);      if (svc->loaded.valid) @@ -309,7 +309,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) {      struct service *svc;      int ret; -    assert(u && s); +    pa_assert(u && s);      svc = get_service(u, s->name, NULL);      if (svc->autoload.valid) @@ -328,7 +328,7 @@ static int publish_autoload(struct userdata *u, pa_autoload_entry *s) {  static int remove_sink(struct userdata *u, uint32_t idx) {      struct service *svc; -    assert(u && idx != PA_INVALID_INDEX); +    pa_assert(u && idx != PA_INVALID_INDEX);      if (!(svc = pa_dynarray_get(u->sink_dynarray, idx)))          return 0; @@ -344,7 +344,7 @@ static int remove_sink(struct userdata *u, uint32_t idx) {  static int remove_source(struct userdata *u, uint32_t idx) {      struct service *svc; -    assert(u && idx != PA_INVALID_INDEX); +    pa_assert(u && idx != PA_INVALID_INDEX);      if (!(svc = pa_dynarray_get(u->source_dynarray, idx)))          return 0; @@ -360,7 +360,7 @@ static int remove_source(struct userdata *u, uint32_t idx) {  static int remove_autoload(struct userdata *u, uint32_t idx) {      struct service *svc; -    assert(u && idx != PA_INVALID_INDEX); +    pa_assert(u && idx != PA_INVALID_INDEX);      if (!(svc = pa_dynarray_get(u->autoload_dynarray, idx)))          return 0; @@ -376,7 +376,7 @@ static int remove_autoload(struct userdata *u, uint32_t idx) {  static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {      struct userdata *u = userdata; -    assert(u && c); +    pa_assert(u && c);      switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK)          case PA_SUBSCRIPTION_EVENT_SINK: { @@ -439,7 +439,7 @@ static int publish_main_service(struct userdata *u);  static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {      struct userdata *u = userdata; -    assert(u); +    pa_assert(u);      if (state == AVAHI_ENTRY_GROUP_COLLISION) {          char *t; @@ -501,7 +501,7 @@ static int publish_all_services(struct userdata *u) {      int r = -1;      uint32_t idx; -    assert(u); +    pa_assert(u);      pa_log_debug("Publishing services in Zeroconf"); @@ -531,7 +531,7 @@ static void unpublish_all_services(struct userdata *u, int rem) {      void *state = NULL;      struct service *s; -    assert(u); +    pa_assert(u);      pa_log_debug("Unpublishing services in Zeroconf"); @@ -558,7 +558,7 @@ static void unpublish_all_services(struct userdata *u, int rem) {  static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) {      struct userdata *u = userdata; -    assert(c); +    pa_assert(c);      u->client = c; @@ -587,7 +587,8 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda      }  } -int pa__init(pa_core *c, pa_module*m) { +int pa__init(pa_module*m) { +          struct userdata *u;      uint32_t port = PA_NATIVE_DEFAULT_PORT;      pa_modargs *ma = NULL; @@ -599,23 +600,23 @@ int pa__init(pa_core *c, pa_module*m) {          goto fail;      } -    if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port == 0 || port >= 0xFFFF) { +    if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port <= 0 || port > 0xFFFF) {          pa_log("invalid port specified.");          goto fail;      }      m->userdata = u = pa_xnew(struct userdata, 1); -    u->core = c; +    u->core = m->core;      u->port = (uint16_t) port; -    u->avahi_poll = pa_avahi_poll_new(c->mainloop); +    u->avahi_poll = pa_avahi_poll_new(m->core->mainloop);      u->services = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);      u->sink_dynarray = pa_dynarray_new();      u->source_dynarray = pa_dynarray_new();      u->autoload_dynarray = pa_dynarray_new(); -    u->subscription = pa_subscription_new(c, +    u->subscription = pa_subscription_new(m->core,                                            PA_SUBSCRIPTION_MASK_SINK|                                            PA_SUBSCRIPTION_MASK_SOURCE|                                            PA_SUBSCRIPTION_MASK_AUTOLOAD, subscribe_callback, u); @@ -634,7 +635,7 @@ int pa__init(pa_core *c, pa_module*m) {      return 0;  fail: -    pa__done(c, m); +    pa__done(m);      if (ma)          pa_modargs_free(ma); @@ -646,8 +647,8 @@ static void service_free(void *p, void *userdata) {      struct service *s = p;      struct userdata *u = userdata; -    assert(s); -    assert(u); +    pa_assert(s); +    pa_assert(u);      if (s->entry_group)          avahi_entry_group_free(s->entry_group); @@ -657,9 +658,9 @@ static void service_free(void *p, void *userdata) {      pa_xfree(s);  } -void pa__done(pa_core *c, pa_module*m) { +void pa__done(pa_module*m) {      struct userdata*u; -    assert(c && m); +    pa_assert(m);      if (!(u = m->userdata))          return; diff --git a/src/pulsecore/ltdl-helper.c b/src/pulsecore/ltdl-helper.c new file mode 100644 index 00000000..bdce18ef --- /dev/null +++ b/src/pulsecore/ltdl-helper.c @@ -0,0 +1,64 @@ +/* $Id$ */ + +/*** +  This file is part of PulseAudio. + +  Copyright 2004-2006 Lennart Poettering +  Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB + +  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 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, write to the Free Software +  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +  USA. +***/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdlib.h> +#include <ctype.h> + +#include <pulse/xmalloc.h> +#include <pulse/util.h> + +#include <pulsecore/core-util.h> +#include <pulsecore/macro.h> + +#include "ltdl-helper.h" + +pa_void_func_t pa_load_sym(lt_dlhandle handle, const char *module, const char *symbol) { +    char *sn, *c; +    pa_void_func_t f; + +    pa_assert(handle); +    pa_assert(module); +    pa_assert(symbol); +     +    if ((f = ((pa_void_func_t) (long) lt_dlsym(handle, symbol)))) +        return f; + +    /* As the .la files might have been cleansed from the system, we should +     * try with the ltdl prefix as well. */ + +    sn = pa_sprintf_malloc("%s_LTX_%s", module, symbol); + +    for (c = sn; *c; c++) +        if (!isalnum(*c)) +            *c = '_'; + +    f = (pa_void_func_t) (long) lt_dlsym(handle, sn); +    pa_xfree(sn); + +    return f; +} diff --git a/src/pulsecore/ltdl-helper.h b/src/pulsecore/ltdl-helper.h new file mode 100644 index 00000000..5c7388a1 --- /dev/null +++ b/src/pulsecore/ltdl-helper.h @@ -0,0 +1,34 @@ +#ifndef foopulsecoreltdlhelperhfoo +#define foopulsecoreltdlhelperhfoo + +/* $Id$ */ + +/*** +  This file is part of PulseAudio. + +  Copyright 2004-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 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, write to the Free Software +  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +  USA. +***/ + +#include <ltdl.h> + +typedef void (*pa_void_func_t)(void); + +pa_void_func_t pa_load_sym(lt_dlhandle handle, const char*module, const char *symbol); + +#endif + diff --git a/src/pulsecore/modinfo.c b/src/pulsecore/modinfo.c index 58394e59..79baef84 100644 --- a/src/pulsecore/modinfo.c +++ b/src/pulsecore/modinfo.c @@ -26,12 +26,13 @@  #endif  #include <ltdl.h> -#include <assert.h>  #include <pulse/xmalloc.h>  #include <pulsecore/core-util.h>  #include <pulsecore/log.h> +#include <pulsecore/macro.h> +#include <pulsecore/ltdl-helper.h>  #include "modinfo.h" @@ -40,30 +41,24 @@  #define PA_SYMBOL_USAGE "pa__get_usage"  #define PA_SYMBOL_VERSION "pa__get_version" -/* lt_dlsym() violates ISO C, so confide the breakage into this function to - * avoid warnings. */ -typedef void (*fnptr)(void); -static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) { -    return (fnptr) (long) lt_dlsym(handle, symbol); -} - -pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) { +pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name) {      pa_modinfo *i;      const char* (*func)(void); -    assert(dl); + +    pa_assert(dl);      i = pa_xnew0(pa_modinfo, 1); -    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_AUTHOR))) +    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_AUTHOR)))          i->author = pa_xstrdup(func()); -    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_DESCRIPTION))) +    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_DESCRIPTION)))          i->description = pa_xstrdup(func()); -    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_USAGE))) +    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_USAGE)))          i->usage = pa_xstrdup(func()); -    if ((func = (const char* (*)(void)) lt_dlsym_fn(dl, PA_SYMBOL_VERSION))) +    if ((func = (const char* (*)(void)) pa_load_sym(dl, module_name, PA_SYMBOL_VERSION)))          i->version = pa_xstrdup(func());      return i; @@ -72,14 +67,15 @@ pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl) {  pa_modinfo *pa_modinfo_get_by_name(const char *name) {      lt_dlhandle dl;      pa_modinfo *i; -    assert(name); +     +    pa_assert(name);      if (!(dl = lt_dlopenext(name))) {          pa_log("Failed to open module \"%s\": %s", name, lt_dlerror());          return NULL;      } -    i = pa_modinfo_get_by_handle(dl); +    i = pa_modinfo_get_by_handle(dl, name);      lt_dlclose(dl);      return i; @@ -87,6 +83,7 @@ pa_modinfo *pa_modinfo_get_by_name(const char *name) {  void pa_modinfo_free(pa_modinfo *i) {      assert(i); +          pa_xfree(i->author);      pa_xfree(i->description);      pa_xfree(i->usage); diff --git a/src/pulsecore/modinfo.h b/src/pulsecore/modinfo.h index 3ee33ede..02e536c6 100644 --- a/src/pulsecore/modinfo.h +++ b/src/pulsecore/modinfo.h @@ -34,7 +34,7 @@ typedef struct pa_modinfo {  } pa_modinfo;  /* Read meta data from an libtool handle */ -pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl); +pa_modinfo *pa_modinfo_get_by_handle(lt_dlhandle dl, const char *module_name);  /* Read meta data from a module file */  pa_modinfo *pa_modinfo_get_by_name(const char *name); diff --git a/src/pulsecore/module.c b/src/pulsecore/module.c index 09b15b8b..bd565546 100644 --- a/src/pulsecore/module.c +++ b/src/pulsecore/module.c @@ -29,7 +29,6 @@  #include <limits.h>  #include <stdio.h>  #include <stdlib.h> -#include <assert.h>  #include <string.h>  #include <errno.h>  #include <ctype.h> @@ -40,6 +39,8 @@  #include <pulsecore/core-subscribe.h>  #include <pulsecore/log.h>  #include <pulsecore/core-util.h> +#include <pulsecore/macro.h> +#include <pulsecore/ltdl-helper.h>  #include "module.h" @@ -48,69 +49,31 @@  #define UNLOAD_POLL_TIME 2 -/* lt_dlsym() violates ISO C, so confide the breakage into this function to - * avoid warnings. */ -typedef void (*fnptr)(void); -static inline fnptr lt_dlsym_fn(lt_dlhandle handle, const char *symbol) { -    return (fnptr) (long) lt_dlsym(handle, symbol); -} -  static void timeout_callback(pa_mainloop_api *m, pa_time_event*e, PA_GCC_UNUSED const struct timeval *tv, void *userdata) { -    pa_core *c = userdata; +    pa_core *c = PA_CORE(userdata);      struct timeval ntv; -    assert(c && c->mainloop == m && c->module_auto_unload_event == e); + +    pa_core_assert_ref(c); +    pa_assert(c->mainloop == m); +    pa_assert(c->module_auto_unload_event == e);      pa_module_unload_unused(c);      pa_gettimeofday(&ntv); -    ntv.tv_sec += UNLOAD_POLL_TIME; +    pa_timeval_add(&ntv, UNLOAD_POLL_TIME*1000000);      m->time_restart(e, &ntv);  } -static inline fnptr load_sym(lt_dlhandle handle, const char *module, const char *symbol) { -    char *buffer, *ch; -    size_t buflen; -    fnptr res; - -    res = lt_dlsym_fn(handle, symbol); -    if (res) -        return res; - -    /* As the .la files might have been cleansed from the system, we should -     * try with the ltdl prefix as well. */ - -    buflen = strlen(symbol) + strlen(module) + strlen("_LTX_") + 1; -    buffer = pa_xmalloc(buflen); -    assert(buffer); - -    strcpy(buffer, module); - -    for (ch = buffer;*ch != '\0';ch++) { -        if (!isalnum(*ch)) -            *ch = '_'; -    } - -    strcat(buffer, "_LTX_"); -    strcat(buffer, symbol); - -    res = lt_dlsym_fn(handle, buffer); - -    pa_xfree(buffer); - -    return res; -} -  pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {      pa_module *m = NULL; -    int r; -    assert(c && name); +    pa_assert(c); +    pa_assert(name);      if (c->disallow_module_loading)          goto fail; -    m = pa_xmalloc(sizeof(pa_module)); - +    m = pa_xnew(pa_module, 1);      m->name = pa_xstrdup(name);      m->argument = pa_xstrdup(argument); @@ -119,24 +82,19 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {          goto fail;      } -    if (!(m->init = (int (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_INIT))) { +    if (!(m->init = (int (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_INIT))) {          pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_INIT"\" not found.", name);          goto fail;      } -    if (!(m->done = (void (*)(pa_core *_c, pa_module*_m)) load_sym(m->dl, name, PA_SYMBOL_DONE))) { -        pa_log("Failed to load module \"%s\": symbol \""PA_SYMBOL_DONE"\" not found.", name); -        goto fail; -    } - +    m->done = (void (*)(pa_module*_m)) pa_load_sym(m->dl, name, PA_SYMBOL_DONE);      m->userdata = NULL;      m->core = c;      m->n_used = -1;      m->auto_unload = 0;      m->unload_requested = 0; -    assert(m->init); -    if (m->init(c, m) < 0) { +    if (m->init(m) < 0) {          pa_log_error("Failed to load  module \"%s\" (argument: \"%s\"): initialization failed.", name, argument ? argument : "");          goto fail;      } @@ -147,14 +105,12 @@ pa_module* pa_module_load(pa_core *c, const char *name, const char *argument) {      if (!c->module_auto_unload_event) {          struct timeval ntv;          pa_gettimeofday(&ntv); -        ntv.tv_sec += UNLOAD_POLL_TIME; +        pa_timeval_add(&ntv, UNLOAD_POLL_TIME*1000000);          c->module_auto_unload_event = c->mainloop->time_new(c->mainloop, &ntv, timeout_callback, c);      } -    assert(c->module_auto_unload_event); -    assert(c->modules); -    r = pa_idxset_put(c->modules, m, &m->index); -    assert(r >= 0 && m->index != PA_IDXSET_INVALID); +    pa_assert_se(pa_idxset_put(c->modules, m, &m->index) >= 0); +    pa_assert(m->index != PA_IDXSET_INVALID);      pa_log_info("Loaded \"%s\" (index: #%u; argument: \"%s\").", m->name, m->index, m->argument ? m->argument : ""); @@ -178,14 +134,16 @@ fail:  }  static void pa_module_free(pa_module *m) { -    assert(m && m->done && m->core); +    pa_assert(m); +    pa_assert(m->core);      if (m->core->disallow_module_loading)          return;      pa_log_info("Unloading \"%s\" (index: #%u).", m->name, m->index); -    m->done(m->core, m); +    if (m->done) +        m->done(m);      lt_dlclose(m->dl); @@ -199,9 +157,9 @@ static void pa_module_free(pa_module *m) {  }  void pa_module_unload(pa_core *c, pa_module *m) { -    assert(c && m); +    pa_assert(c && m); -    assert(c->modules); +    pa_assert(c->modules);      if (!(m = pa_idxset_remove_by_data(c->modules, m, NULL)))          return; @@ -210,9 +168,9 @@ void pa_module_unload(pa_core *c, pa_module *m) {  void pa_module_unload_by_index(pa_core *c, uint32_t idx) {      pa_module *m; -    assert(c && idx != PA_IDXSET_INVALID); +    pa_assert(c); +    pa_assert(idx != PA_IDXSET_INVALID); -    assert(c->modules);      if (!(m = pa_idxset_remove_by_index(c->modules, idx)))          return; @@ -221,13 +179,14 @@ void pa_module_unload_by_index(pa_core *c, uint32_t idx) {  static void free_callback(void *p, PA_GCC_UNUSED void *userdata) {      pa_module *m = p; -    assert(m); +    pa_assert(m);      pa_module_free(m);  }  void pa_module_unload_all(pa_core *c) {      pa_module *m; -    assert(c); +     +    pa_assert(c);      if (!c->modules)          return; @@ -252,7 +211,10 @@ void pa_module_unload_all(pa_core *c) {  static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void *userdata) {      pa_module *m = p;      time_t *now = userdata; -    assert(p && del && now); +     +    pa_assert(m); +    pa_assert(del); +    pa_assert(now);      if (m->n_used == 0 && m->auto_unload && m->last_used_time+m->core->module_idle_time <= *now) {          pa_module_free(m); @@ -264,7 +226,7 @@ static int unused_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, void *  void pa_module_unload_unused(pa_core *c) {      time_t now; -    assert(c); +    pa_assert(c);      if (!c->modules)          return; @@ -275,7 +237,7 @@ void pa_module_unload_unused(pa_core *c) {  static int unload_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, PA_GCC_UNUSED void *userdata) {      pa_module *m = p; -    assert(m); +    pa_assert(m);      if (m->unload_requested) {          pa_module_free(m); @@ -286,18 +248,19 @@ static int unload_callback(void *p, PA_GCC_UNUSED uint32_t idx, int *del, PA_GCC  }  static void defer_cb(pa_mainloop_api*api, pa_defer_event *e, void *userdata) { -    pa_core *core = userdata; +    pa_core *core = PA_CORE(userdata); + +    pa_core_assert_ref(core);      api->defer_enable(e, 0);      if (!core->modules)          return;      pa_idxset_foreach(core->modules, unload_callback, NULL); -  }  void pa_module_unload_request(pa_module *m) { -    assert(m); +    pa_assert(m);      m->unload_requested = 1; @@ -308,19 +271,19 @@ void pa_module_unload_request(pa_module *m) {  }  void pa_module_set_used(pa_module*m, int used) { -    assert(m); +    pa_assert(m);      if (m->n_used != used)          pa_subscription_post(m->core, PA_SUBSCRIPTION_EVENT_MODULE|PA_SUBSCRIPTION_EVENT_CHANGE, m->index); -    if (m->n_used != used && used == 0) +    if (used == 0 && m->n_used > 0)          time(&m->last_used_time);      m->n_used = used;  }  pa_modinfo *pa_module_get_info(pa_module *m) { -    assert(m); +    pa_assert(m); -    return pa_modinfo_get_by_handle(m->dl); +    return pa_modinfo_get_by_handle(m->dl, m->name);  } diff --git a/src/pulsecore/module.h b/src/pulsecore/module.h index 750dfaa8..7a93a071 100644 --- a/src/pulsecore/module.h +++ b/src/pulsecore/module.h @@ -39,8 +39,8 @@ struct pa_module {      lt_dlhandle dl; -    int (*init)(pa_core *c, pa_module*m); -    void (*done)(pa_core *c, pa_module*m); +    int (*init)(pa_module*m); +    void (*done)(pa_module*m);      void *userdata; @@ -62,9 +62,9 @@ void pa_module_unload_request(pa_module *m);  void pa_module_set_used(pa_module*m, int used); -#define PA_MODULE_AUTHOR(s) const char * pa__get_author(void) { return s; } -#define PA_MODULE_DESCRIPTION(s) const char * pa__get_description(void) { return s; } -#define PA_MODULE_USAGE(s) const char * pa__get_usage(void) { return s; } +#define PA_MODULE_AUTHOR(s) const char *pa__get_author(void) { return s; } +#define PA_MODULE_DESCRIPTION(s) const char *pa__get_description(void) { return s; } +#define PA_MODULE_USAGE(s) const char *pa__get_usage(void) { return s; }  #define PA_MODULE_VERSION(s) const char * pa__get_version(void) { return s; }  pa_modinfo *pa_module_get_info(pa_module *m);  | 
