aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-01 04:18:53 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-01 04:18:53 +0000
commit89073cfbba6126ce28221ad54e75a69b05b21fd6 (patch)
tree370c1a9cfad359d919911242753b62b7495472c0 /src/main.c
parent2532bc36d25318724f5bf50cfe2b122160665386 (diff)
downloadmpd-89073cfbba6126ce28221ad54e75a69b05b21fd6.tar.gz
mpd-89073cfbba6126ce28221ad54e75a69b05b21fd6.tar.xz
mpd-89073cfbba6126ce28221ad54e75a69b05b21fd6.zip
logging cleanups
* Moved all logging-related stuff into log.c (and not myfprintf.c) * ISO C90-compliant strftime usage: %e and %R replaced with %d and %H:%M respectively * Got rid of variadic macros since some old-school compilers don't like them * compiling with -DNDEBUG disables the DEBUG() macro git-svn-id: https://svn.musicpd.org/mpd/trunk@4512 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/main.c82
1 files changed, 7 insertions, 75 deletions
diff --git a/src/main.c b/src/main.c
index 3ba2afeb4..7f7709a52 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,6 +68,7 @@ typedef struct _Options {
int stdOutput;
int createDB;
int updateDB;
+ int verbose;
} Options;
/*
@@ -186,7 +187,7 @@ static void parseOptions(int argc, char **argv, Options * options)
options->createDB = -1;
argcLeft--;
} else if (strcmp(argv[i], "--verbose") == 0) {
- logLevel = LOG_LEVEL_DEBUG;
+ options->verbose = 1;
argcLeft--;
} else if (strcmp(argv[i], "--version") == 0) {
version();
@@ -284,36 +285,6 @@ static void changeToUser(void)
}
}
-static void openLogFiles(Options * options, FILE ** out, FILE ** err)
-{
- ConfigParam *logParam = parseConfigFilePath(CONF_LOG_FILE, 1);
- ConfigParam *errorParam = parseConfigFilePath(CONF_ERROR_FILE, 1);
-
- mode_t prev;
-
- if (options->stdOutput) {
- flushWarningLog();
- return;
- }
-
- /* be sure to create log files w/ rw permissions */
- prev = umask(0066);
-
- if (NULL == (*out = fopen(logParam->value, "a"))) {
- ERROR("problem opening log file \"%s\" (config line %i) for "
- "writing\n", logParam->value, logParam->line);
- exit(EXIT_FAILURE);
- }
-
- if (NULL == (*err = fopen(errorParam->value, "a"))) {
- ERROR("problem opening error file \"%s\" (config line %i) for "
- "writing\n", errorParam->value, errorParam->line);
- exit(EXIT_FAILURE);
- }
-
- umask(prev);
-}
-
static void openDB(Options * options, char *argv0)
{
if (options->createDB > 0 || readDirectoryDB() < 0) {
@@ -369,7 +340,7 @@ static void startMainProcess(void)
kill(mainPid, SIGTERM);
waitpid(mainPid, NULL, 0);
finishConf();
- myfprintfCloseLogFile();
+ close_log_files();
exit(EXIT_SUCCESS);
} else if (pid < 0) {
@@ -441,43 +412,6 @@ static void daemonize(Options * options)
}
}
-static void setupLogOutput(Options * options, FILE * out, FILE * err)
-{
- if (!options->stdOutput) {
- fflush(NULL);
-
- if (dup2(fileno(out), STDOUT_FILENO) < 0) {
- fprintf(err, "problems dup2 stdout : %s\n",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- if (dup2(fileno(err), STDERR_FILENO) < 0) {
- fprintf(err, "problems dup2 stderr : %s\n",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- myfprintfStdLogMode(out, err);
- }
- flushWarningLog();
-
- /* lets redirect stdin to dev null as a work around for libao bug */
- {
- int fd = open("/dev/null", O_RDONLY);
- if (fd < 0) {
- ERROR("not able to open /dev/null to redirect stdin: "
- "%s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- if (dup2(fd, STDIN_FILENO) < 0) {
- ERROR("problems dup2's stdin for redirection: "
- "%s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- }
-}
-
static void cleanUpPidFile(void)
{
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
@@ -523,8 +457,6 @@ static void killFromPidFile(char *cmd, int killOption)
int main(int argc, char *argv[])
{
- FILE *out = NULL;
- FILE *err = NULL;
Options options;
closeAllFDs();
@@ -538,14 +470,14 @@ int main(int argc, char *argv[])
initStats();
initTagConfig();
- initLog();
+ initLog(options.verbose);
if (options.createDB <= 0 && !options.updateDB)
listenOnPort();
changeToUser();
- openLogFiles(&options, &out, &err);
+ open_log_files(options.stdOutput);
initPlayerData();
@@ -560,7 +492,7 @@ int main(int argc, char *argv[])
daemonize(&options);
initSigHandlers();
- setupLogOutput(&options, out, err);
+ setup_log_output(options.stdOutput);
startMainProcess();
/* This is the main process which has
* been forked from the master process.
@@ -613,6 +545,6 @@ int main(int argc, char *argv[])
cleanUpPidFile();
finishConf();
- myfprintfCloseLogFile();
+ close_log_files();
return EXIT_SUCCESS;
}