daemon auto spawn

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@173 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2004-09-01 21:12:27 +00:00
parent ee91cb6c9d
commit 348738751c
14 changed files with 292 additions and 42 deletions

View file

@ -28,14 +28,36 @@
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <sys/stat.h>
#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;