From 348738751c50c7d3c4c9ed22801a0c2cb917b790 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 1 Sep 2004 21:12:27 +0000 Subject: daemon auto spawn git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@173 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/cmdline.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'polyp/cmdline.c') diff --git a/polyp/cmdline.c b/polyp/cmdline.c index 6538b930..c07e7bdc 100644 --- a/polyp/cmdline.c +++ b/polyp/cmdline.c @@ -28,14 +28,36 @@ #include #include #include +#include #include "cmdline.h" #include "util.h" #include "strbuf.h" #include "xmalloc.h" +#define ENV_CONFIG_FILE "POLYP_CONFIG" + +char* config_file(void) { + char *p, *h; + + if ((p = getenv(ENV_CONFIG_FILE))) + return pa_xstrdup(p); + + if ((h = getenv("HOME"))) { + struct stat st; + p = pa_sprintf_malloc("%s/.polypaudio", h); + if (stat(p, &st) >= 0) + return p; + + pa_xfree(p); + } + + return pa_xstrdup(DEFAULT_CONFIG_FILE); +} + void pa_cmdline_help(const char *argv0) { const char *e; + char *cfg = config_file(); if ((e = strrchr(argv0, '/'))) e++; @@ -48,16 +70,18 @@ void pa_cmdline_help(const char *argv0) { " -L MODULE Load the specified plugin module with the specified argument\n" " -F FILE Run the specified script\n" " -C Open a command line on the running TTY\n" - " -n Don't load configuration file ("PA_DEFAULT_CONFIG_FILE")\n" + " -n Don't load configuration file (%s)\n" " -D Daemonize after loading the modules\n" " -f Dont quit when the startup fails\n" " -v Verbose startup\n" " -h Show this help\n" - " -V Show version\n", e); + " -V Show version\n", e, cfg); + + pa_xfree(cfg); } struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) { - char c; + char c, *cfg; struct pa_cmdline *cmdline = NULL; struct pa_strbuf *buf = NULL; int no_default_config_file = 0; @@ -111,9 +135,11 @@ struct pa_cmdline* pa_cmdline_parse(int argc, char * const argv []) { } } - if (!no_default_config_file) - pa_strbuf_puts(buf, ".include "PA_DEFAULT_CONFIG_FILE"\n"); - + if (!no_default_config_file) { + cfg = config_file(); + pa_strbuf_printf(buf, ".include %s\n", cfg); + pa_xfree(cfg); + } cmdline->cli_commands = pa_strbuf_tostring_free(buf); return cmdline; -- cgit