X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=dab3e3dad7dfffa3ee5733355489b04f1762a6fa;hp=63d42cacb5218b92a8cea76c8a0626349437b8e6;hb=70d421705c23f15188808f5435b03583bd613485;hpb=40de1dd2fdbb054444d585aa70e2d50166a66e07 diff --git a/audiod.c b/audiod.c index 63d42cac..dab3e3da 100644 --- a/audiod.c +++ b/audiod.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 Andre Noll + * Copyright (C) 2005-2009 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -83,7 +83,6 @@ int audiod_status = AUDIOD_ON; struct audiod_args_info conf; static char *socket_name; -static FILE *logfile; static struct audio_format_info afi[NUM_AUDIO_FORMATS]; static struct signal_task signal_task_struct, *sig_task = &signal_task_struct; @@ -181,42 +180,27 @@ out: ); } -/** - * the log function of para_audiod - * - * \param ll loglevel - * \param fmt the format string - */ -__printf_2_3 void para_log(int ll, const char* fmt,...) +static int want_colors(void) { - va_list argp; - FILE *outfd; - struct tm *tm; - time_t t1; - char str[MAXLINE] = ""; - static char *hostname; - - if (ll < conf.loglevel_arg) - return; - if (!logfile && conf.daemon_given) - return; - if (!hostname) - hostname = para_hostname(); - outfd = logfile? logfile : stderr; - time(&t1); - tm = localtime(&t1); - strftime(str, MAXLINE, "%b %d %H:%M:%S", tm); - fprintf(outfd, "%s %s ", str, hostname); - if (conf.loglevel_arg <= INFO) - fprintf(outfd, "%i ", ll); - va_start(argp, fmt); - vfprintf(outfd, fmt, argp); - va_end(argp); + if (conf.color_arg == color_arg_no) + return 0; + if (conf.color_arg == color_arg_yes) + return 1; + if (conf.logfile_given) + return 0; + return isatty(STDERR_FILENO); } static void parse_config_or_die(void) { char *config_file; + struct audiod_cmdline_parser_params params = { + .override = 0, + .initialize = 0, + .check_required = 1, + .check_ambiguity = 0, + .print_errors = 1 + }; if (conf.config_file_given) config_file = para_strdup(conf.config_file_arg); @@ -229,20 +213,12 @@ static void parse_config_or_die(void) PARA_EMERG_LOG("can not read config file %s\n", config_file); goto err; } - if (config_file) { - struct audiod_cmdline_parser_params params = { - .override = 0, - .initialize = 0, - .check_required = 1, - .check_ambiguity = 0, - .print_errors = 1 - }; - if (audiod_cmdline_parser_config_file(config_file, &conf, ¶ms)) { - PARA_EMERG_LOG("parse error in config file\n"); - goto err; - } + if (audiod_cmdline_parser_config_file(config_file, &conf, ¶ms)) { + PARA_EMERG_LOG("parse error in config file\n"); + goto err; } free(config_file); + daemon_set_loglevel(conf.loglevel_arg); return; err: free(config_file); @@ -1045,13 +1021,13 @@ static void status_pre_select(struct sched *s, struct task *t) int argc = 3; PARA_INFO_LOG("clock diff count: %d\n", st->clock_diff_count); st->clock_diff_count--; - client_open(argc, argv, &st->ct); + client_open(argc, argv, &st->ct, NULL); set_stat_task_restart_barrier(2); } else { char *argv[] = {"audiod", "stat", NULL}; int argc = 2; - client_open(argc, argv, &st->ct); + client_open(argc, argv, &st->ct, NULL); set_stat_task_restart_barrier(5); } free(stat_item_values[SI_BASENAME]); @@ -1109,6 +1085,20 @@ __noreturn static void print_help_and_die(void) exit(0); } +static void init_colors_or_die(void) +{ + int ret, i; + + if (!want_colors()) + return; + daemon_set_default_log_colors(); + daemon_set_flag(DF_COLOR_LOG); + for (i = 0; i < conf.log_color_given; i++) { + ret = daemon_set_log_color(conf.log_color_arg[i]); + if (ret < 0) + exit(EXIT_FAILURE); + } +} /** * the main function of para_audiod @@ -1136,18 +1126,24 @@ int main(int argc, char *argv[]) valid_fd_012(); audiod_cmdline_parser_ext(argc, argv, &conf, ¶ms); HANDLE_VERSION_FLAG("audiod", conf); - para_drop_privileges(conf.user_arg, conf.group_arg); + drop_privileges_or_die(conf.user_arg, conf.group_arg); parse_config_or_die(); - if (conf.logfile_given) - logfile = open_log(conf.logfile_arg); - i = init_stream_io(); if (conf.help_given || conf.detailed_help_given) print_help_and_die(); + daemon_set_flag(DF_LOG_TIME); + daemon_set_flag(DF_LOG_HOSTNAME); + daemon_set_flag(DF_LOG_LL); + if (conf.logfile_given) { + daemon_set_logfile(conf.logfile_arg); + daemon_open_log_or_die(); + } + init_colors_or_die(); + i = init_stream_io(); if (i < 0) { PARA_EMERG_LOG("init stream io error: %s\n", para_strerror(-i)); exit(EXIT_FAILURE); } - log_welcome("para_audiod", conf.loglevel_arg); + log_welcome("para_audiod"); server_uptime(UPTIME_SET); set_initial_status(); FOR_EACH_SLOT(i) @@ -1160,7 +1156,7 @@ int main(int argc, char *argv[]) init_command_task(cmd_task); if (conf.daemon_given) - daemon_init(); + daemonize(); register_task(&sig_task->task); register_task(&cmd_task->task);