From bba444524eca700970f69261bc470fb01a138222 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Sat, 26 May 2007 18:15:54 +0000 Subject: Changing all calls to ERROR() followed by exit(EXIT_FAILURE) with a single call to FATAL(). git-svn-id: https://svn.musicpd.org/mpd/trunk@6276 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/audio.c | 11 +++----- src/audioOutput.c | 9 +++---- src/audioOutputs/audioOutput_ao.c | 29 +++++++-------------- src/audioOutputs/audioOutput_oss.c | 2 +- src/audioOutputs/audioOutput_shout.c | 38 ++++++++++----------------- src/conf.c | 50 ++++++++++++------------------------ src/directory.c | 48 +++++++++++----------------------- src/inputStream_http.c | 24 ++++++----------- src/interface.c | 12 +++------ src/listen.c | 47 ++++++++++++--------------------- src/main.c | 44 +++++++++++-------------------- src/path.c | 6 ++--- src/pcm_utils.c | 12 +++------ src/permission.c | 10 +++----- src/playerData.c | 24 +++++------------ src/playlist.c | 3 +-- src/replayGain.c | 9 +++---- src/song.c | 12 +++------ src/state_file.c | 12 +++------ src/tag.c | 3 +-- src/volume.c | 3 +-- 21 files changed, 135 insertions(+), 273 deletions(-) (limited to 'src') diff --git a/src/audio.c b/src/audio.c index 92d688f38..912e46ffa 100644 --- a/src/audio.c +++ b/src/audio.c @@ -127,23 +127,21 @@ void initAudioDriver(void) if (!initAudioOutput(output, param)) { if (param) { - ERROR("problems configuring output device " + FATAL("problems configuring output device " "defined at line %i\n", param->line); } else { - ERROR("No audio_output specified and unable to " + FATAL("No audio_output specified and unable to " "detect a default audio output device\n"); } - exit(EXIT_FAILURE); } /* require output names to be unique: */ for (j = 0; j < i; j++) { if (!strcmp(output->name, audioOutputArray[j].name)) { - ERROR("output devices with identical " + FATAL("output devices with identical " "names: %s\n", output->name); - exit(EXIT_FAILURE); } } audioDeviceStates[i] = DEVICE_ENABLE; @@ -169,9 +167,8 @@ void initAudioConfig(void) audio_configFormat = xmalloc(sizeof(AudioFormat)); if (0 != parseAudioConfig(audio_configFormat, param->value)) { - ERROR("error parsing \"%s\" at line %i\n", + FATAL("error parsing \"%s\" at line %i\n", CONF_AUDIO_OUTPUT_FORMAT, param->line); - exit(EXIT_FAILURE); } } diff --git a/src/audioOutput.c b/src/audioOutput.c index 9f6172088..49a7ce258 100644 --- a/src/audioOutput.c +++ b/src/audioOutput.c @@ -58,10 +58,9 @@ void finishAudioOutputPlugins(void) #define getBlockParam(name, str, force) { \ bp = getBlockParam(param, name); \ if(force && bp == NULL) { \ - ERROR("couldn't find parameter \"%s\" in audio output " \ + FATAL("couldn't find parameter \"%s\" in audio output " \ "definition beginning at %i\n", \ name, param->line); \ - exit(EXIT_FAILURE); \ } \ if(bp) str = bp->value; \ } @@ -81,9 +80,8 @@ int initAudioOutput(AudioOutput *ao, ConfigParam * param) getBlockParam(AUDIO_OUTPUT_FORMAT, format, 0); if (!findInList(audioOutputPluginList, type, &data)) { - ERROR("couldn't find audio output plugin for type " + FATAL("couldn't find audio output plugin for type " "\"%s\" at line %i\n", type, param->line); - exit(EXIT_FAILURE); } plugin = (AudioOutputPlugin *) data; @@ -141,8 +139,7 @@ int initAudioOutput(AudioOutput *ao, ConfigParam * param) ao->convertAudioFormat = 1; if (0 != parseAudioConfig(&ao->reqAudioFormat, format)) { - ERROR("error parsing format at line %i\n", bp->line); - exit(EXIT_FAILURE); + FATAL("error parsing format at line %i\n", bp->line); } copyAudioFormat(&ao->outAudioFormat, &ao->reqAudioFormat); diff --git a/src/audioOutputs/audioOutput_ao.c b/src/audioOutputs/audioOutput_ao.c index df2975622..ee1a1e559 100644 --- a/src/audioOutputs/audioOutput_ao.c +++ b/src/audioOutputs/audioOutput_ao.c @@ -75,9 +75,8 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput, if ((blockParam = getBlockParam(param, "write_size"))) { ad->writeSize = strtol(blockParam->value, &test, 10); if (*test != '\0') { - ERROR("\"%s\" is not a valid write size at line %i\n", + FATAL("\"%s\" is not a valid write size at line %i\n", blockParam->value, blockParam->line); - exit(EXIT_FAILURE); } } else ad->writeSize = 1024; @@ -92,16 +91,13 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput, if (!blockParam || 0 == strcmp(blockParam->value, "default")) { ad->driverId = ao_default_driver_id(); } else if ((ad->driverId = ao_driver_id(blockParam->value)) < 0) { - ERROR("\"%s\" is not a valid ao driver at line %i\n", + FATAL("\"%s\" is not a valid ao driver at line %i\n", blockParam->value, blockParam->line); - exit(EXIT_FAILURE); } if ((ai = ao_driver_info(ad->driverId)) == NULL) { - ERROR("problems getting driver info for device defined at " - "line %i\n", param->line); - ERROR("you may not have permission to the audio device\n"); - exit(EXIT_FAILURE); + FATAL("problems getting driver info for device defined at line %i\n" + "you may not have permission to the audio device\n" param->line); } DEBUG("using ao driver \"%s\" for \"%s\"\n", ai->short_name, @@ -120,11 +116,8 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput, while (n1) { stk2 = NULL; key = strtok_r(n1, "=", &stk2); - if (!key) { - ERROR("problems parsing " - "options \"%s\"\n", n1); - exit(EXIT_FAILURE); - } + if (!key) + FATAL("problems parsing options \"%s\"\n", n1); /*found = 0; for(i=0;ioption_count;i++) { if(strcmp(ai->options[i],key)==0) { @@ -133,17 +126,13 @@ static int audioOutputAo_initDriver(AudioOutput * audioOutput, } } if(!found) { - ERROR("\"%s\" is not an option for " + FATAL("\"%s\" is not an option for " "\"%s\" ao driver\n",key, ai->short_name); - exit(EXIT_FAILURE); } */ value = strtok_r(NULL, "", &stk2); - if (!value) { - ERROR("problems parsing " - "options \"%s\"\n", n1); - exit(EXIT_FAILURE); - } + if (!value) + FATAL("problems parsing options \"%s\"\n", n1); ao_append_option(&ad->options, key, value); n1 = strtok_r(NULL, ";", &stk1); } diff --git a/src/audioOutputs/audioOutput_oss.c b/src/audioOutputs/audioOutput_oss.c index 1a27cae14..01293cbd1 100644 --- a/src/audioOutputs/audioOutput_oss.c +++ b/src/audioOutputs/audioOutput_oss.c @@ -359,7 +359,7 @@ static int oss_open_default(AudioOutput *ao, ConfigParam *param, OssData *od) } if (param) - ERROR("Error trying to open specified OSS device" + ERROR("error trying to open specified OSS device" " at line %i\n", param->line); else ERROR("error trying to open default OSS device\n"); diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c index 01fd50c1b..25966d172 100644 --- a/src/audioOutputs/audioOutput_shout.c +++ b/src/audioOutputs/audioOutput_shout.c @@ -100,10 +100,9 @@ static void freeShoutData(ShoutData * sd) #define checkBlockParam(name) { \ blockParam = getBlockParam(param, name); \ - if(!blockParam) { \ - ERROR("no \"%s\" defined for shout device defined at line " \ + if (!blockParam) { \ + FATAL("no \"%s\" defined for shout device defined at line " \ "%i\n", name, param->line); \ - exit(EXIT_FAILURE); \ } \ } @@ -138,9 +137,8 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) port = strtol(blockParam->value, &test, 10); if (*test != '\0' || port <= 0) { - ERROR("shout port \"%s\" is not a positive integer, line %i\n", + FATAL("shout port \"%s\" is not a positive integer, line %i\n", blockParam->value, blockParam->line); - exit(EXIT_FAILURE); } checkBlockParam("password"); @@ -151,14 +149,13 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) blockParam = getBlockParam(param, "public"); if (blockParam) { - if (0 == strcmp(blockParam->value, "yes")) + if (0 == strcmp(blockParam->value, "yes")) { public = 1; - else if (0 == strcmp(blockParam->value, "no")) + } else if (0 == strcmp(blockParam->value, "no")) { public = 0; - else { - ERROR("public \"%s\" is not \"yes\" or \"no\" at line " + } else { + FATAL("public \"%s\" is not \"yes\" or \"no\" at line " "%i\n", param->value, param->line); - exit(EXIT_FAILURE); } } else public = 0; @@ -177,35 +174,31 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) sd->quality = strtod(blockParam->value, &test); if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) { - ERROR("shout quality \"%s\" is not a number in the " + FATAL("shout quality \"%s\" is not a number in the " "range -1 to 10, line %i\n", blockParam->value, blockParam->line); - exit(EXIT_FAILURE); } blockParam = getBlockParam(param, "bitrate"); if (blockParam) { - ERROR("quality (line %i) and bitrate (line %i) are " + FATAL("quality (line %i) and bitrate (line %i) are " "both defined for shout output\n", line, blockParam->line); - exit(EXIT_FAILURE); } } else { blockParam = getBlockParam(param, "bitrate"); if (!blockParam) { - ERROR("neither bitrate nor quality defined for shout " + FATAL("neither bitrate nor quality defined for shout " "output at line %i\n", param->line); - exit(EXIT_FAILURE); } sd->bitrate = strtol(blockParam->value, &test, 10); if (*test != '\0' || sd->bitrate <= 0) { - ERROR("bitrate at line %i should be a positive integer " + FATAL("bitrate at line %i should be a positive integer " "\n", blockParam->line); - exit(EXIT_FAILURE); } } @@ -225,25 +218,22 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) shout_set_protocol(sd->shoutConn, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS || shout_set_agent(sd->shoutConn, "MPD") != SHOUTERR_SUCCESS) { - ERROR("error configuring shout defined at line %i: %s\n", + FATAL("error configuring shout defined at line %i: %s\n", param->line, shout_get_error(sd->shoutConn)); - exit(EXIT_FAILURE); } /* optional paramters */ blockParam = getBlockParam(param, "genre"); if (blockParam && shout_set_genre(sd->shoutConn, blockParam->value)) { - ERROR("error configuring shout defined at line %i: %s\n", + FATAL("error configuring shout defined at line %i: %s\n", param->line, shout_get_error(sd->shoutConn)); - exit(EXIT_FAILURE); } blockParam = getBlockParam(param, "description"); if (blockParam && shout_set_description(sd->shoutConn, blockParam->value)) { - ERROR("error configuring shout defined at line %i: %s\n", + FATAL("error configuring shout defined at line %i: %s\n", param->line, shout_get_error(sd->shoutConn)); - exit(EXIT_FAILURE); } { diff --git a/src/conf.c b/src/conf.c index 1c76226d1..8ab59a505 100644 --- a/src/conf.c +++ b/src/conf.c @@ -115,10 +115,8 @@ static void registerConfigParam(char *name, int repeatable, int block) { ConfigEntry *entry; - if (findInList(configEntriesList, name, NULL)) { - ERROR("config parameter \"%s\" already registered\n", name); - exit(EXIT_FAILURE); - } + if (findInList(configEntriesList, name, NULL)) + FATAL("config parameter \"%s\" already registered\n", name); entry = newConfigEntry(repeatable, block); @@ -225,19 +223,17 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string) } if (2 != argsMinusComment) { - ERROR("improperly formatted config file at line %i:" + FATAL("improperly formatted config file at line %i:" " %s\n", *count, string); - exit(EXIT_FAILURE); } if (0 == strcmp(array[0], CONF_BLOCK_BEGIN) || 0 == strcmp(array[1], CONF_BLOCK_BEGIN) || 0 == strcmp(array[0], CONF_BLOCK_END) || 0 == strcmp(array[1], CONF_BLOCK_END)) { - ERROR("improperly formatted config file at line %i:" - " %s\n", *count, string); - ERROR("in block beginning at line %i\n", ret->line); - exit(EXIT_FAILURE); + FATAL("improperly formatted config file at line %i: %s\n" + "in block beginning at line %i\n", + *count, string, ret->line);; } addBlockParam(ret, array[0], array[1], *count); @@ -259,9 +255,8 @@ void readConf(char *file) ConfigParam *param; if (!(fp = fopen(file, "r"))) { - ERROR("problems opening file %s for reading: %s\n", file, + FATAL("problems opening file %s for reading: %s\n", file, strerror(errno)); - exit(EXIT_FAILURE); } while (myFgets(string, MAX_STRING_SIZE, fp)) { @@ -282,15 +277,13 @@ void readConf(char *file) } if (2 != argsMinusComment) { - ERROR("improperly formatted config file at line %i:" + FATAL("improperly formatted config file at line %i:" " %s\n", count, string); - exit(EXIT_FAILURE); } if (!findInList(configEntriesList, array[0], &voidPtr)) { - ERROR("unrecognized parameter in config file at line " + FATAL("unrecognized parameter in config file at line " "%i: %s\n", count, string); - exit(EXIT_FAILURE); } entry = (ConfigEntry *) voidPtr; @@ -298,18 +291,15 @@ void readConf(char *file) if (!(entry->mask & CONF_REPEATABLE_MASK) && entry->configParamList->numberOfNodes) { param = entry->configParamList->firstNode->data; - ERROR - ("config parameter \"%s\" is first defined on line " + FATAL("config parameter \"%s\" is first defined on line " "%i and redefined on line %i\n", array[0], param->line, count); - exit(EXIT_FAILURE); } if (entry->mask & CONF_BLOCK_MASK) { if (0 != strcmp(array[1], CONF_BLOCK_BEGIN)) { - ERROR("improperly formatted config file at " + FATAL("improperly formatted config file at " "line %i: %s\n", count, string); - exit(EXIT_FAILURE); } param = readConfigBlock(fp, &count, string); } else @@ -400,10 +390,8 @@ ConfigParam *parseConfigFilePath(char *name, int force) ConfigParam *param = getConfigParam(name); char *path; - if (!param && force) { - ERROR("config parameter \"%s\" not found\n", name); - exit(EXIT_FAILURE); - } + if (!param && force) + FATAL("config parameter \"%s\" not found\n", name); if (!param) return NULL; @@ -411,9 +399,8 @@ ConfigParam *parseConfigFilePath(char *name, int force) path = param->value; if (path[0] != '/' && path[0] != '~') { - ERROR("\"%s\" is not an absolute path at line %i\n", + FATAL("\"%s\" is not an absolute path at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } /* Parse ~ in path */ else if (path[0] == '~') { @@ -426,17 +413,15 @@ ConfigParam *parseConfigFilePath(char *name, int force) if (userParam) { pwd = getpwnam(userParam->value); if (!pwd) { - ERROR("no such user %s at line %i\n", + FATAL("no such user %s at line %i\n", userParam->value, userParam->line); - exit(EXIT_FAILURE); } } else { uid_t uid = geteuid(); if ((pwd = getpwuid(uid)) == NULL) { - ERROR("problems getting passwd entry " + FATAL("problems getting passwd entry " "for current user\n"); - exit(EXIT_FAILURE); } } } else { @@ -448,9 +433,8 @@ ConfigParam *parseConfigFilePath(char *name, int force) *ch = '\0'; pos += ch - path - 1; if ((pwd = getpwnam(path + 1)) == NULL) { - ERROR("user \"%s\" not found at line %i\n", + FATAL("user \"%s\" not found at line %i\n", path + 1, param->line); - exit(EXIT_FAILURE); } if (foundSlash) *ch = '/'; diff --git a/src/directory.c b/src/directory.c index fb18ff91b..6ead9007c 100644 --- a/src/directory.c +++ b/src/directory.c @@ -951,23 +951,18 @@ static void readDirectoryInfo(FILE * fp, Directory * directory) && 0 != strncmp(DIRECTORY_END, buffer, strlen(DIRECTORY_END))) { if (0 == strncmp(DIRECTORY_DIR, buffer, strlen(DIRECTORY_DIR))) { key = xstrdup(&(buffer[strlen(DIRECTORY_DIR)])); - if (!myFgets(buffer, bufferSize, fp)) { - ERROR("Error reading db, fgets\n"); - exit(EXIT_FAILURE); - } + if (!myFgets(buffer, bufferSize, fp)) + FATAL("Error reading db, fgets\n"); /* for compatibility with db's prior to 0.11 */ if (0 == strncmp(DIRECTORY_MTIME, buffer, strlen(DIRECTORY_MTIME))) { - if (!myFgets(buffer, bufferSize, fp)) { - ERROR("Error reading db, fgets\n"); - exit(EXIT_FAILURE); - } + if (!myFgets(buffer, bufferSize, fp)) + FATAL("Error reading db, fgets\n"); } if (strncmp (DIRECTORY_BEGIN, buffer, strlen(DIRECTORY_BEGIN))) { - ERROR("Error reading db at line: %s\n", buffer); - exit(EXIT_FAILURE); + FATAL("Error reading db at line: %s\n", buffer); } name = xstrdup(&(buffer[strlen(DIRECTORY_BEGIN)])); @@ -1001,8 +996,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory) } else if (0 == strncmp(SONG_BEGIN, buffer, strlen(SONG_BEGIN))) { readSongInfoIntoList(fp, directory->songs, directory); } else { - ERROR("Unknown line in db: %s\n", buffer); - exit(EXIT_FAILURE); + FATAL("Unknown line in db: %s\n", buffer); } } @@ -1155,21 +1149,16 @@ int readDirectoryDB(void) int foundFsCharset = 0; int foundVersion = 0; - if (!myFgets(buffer, bufferSize, fp)) { - ERROR("Error reading db, fgets\n"); - exit(EXIT_FAILURE); - } + if (!myFgets(buffer, bufferSize, fp)) + FATAL("Error reading db, fgets\n"); if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) { while (myFgets(buffer, bufferSize, fp) && 0 != strcmp(DIRECTORY_INFO_END, buffer)) { if (0 == strncmp(DIRECTORY_MPD_VERSION, buffer, strlen(DIRECTORY_MPD_VERSION))) { - if (foundVersion) { - ERROR("already found " - "version in db\n"); - exit(EXIT_FAILURE); - } + if (foundVersion) + FATAL("already found version in db\n"); foundVersion = 1; } else if (0 == strncmp(DIRECTORY_FS_CHARSET, buffer, @@ -1178,11 +1167,8 @@ int readDirectoryDB(void) char *fsCharset; char *tempCharset; - if (foundFsCharset) { - WARNING("already found " - "fs charset in db\n"); - exit(EXIT_FAILURE); - } + if (foundFsCharset) + FATAL("already found fs charset in db\n"); foundFsCharset = 1; @@ -1198,10 +1184,8 @@ int readDirectoryDB(void) setFsCharset(fsCharset); } } else { - ERROR - ("directory: unknown line in db info: %s\n", + FATAL("directory: unknown line in db info: %s\n", buffer); - exit(EXIT_FAILURE); } } } else { @@ -1233,14 +1217,12 @@ void updateMp3Directory(void) /* nothing updated */ return; case 1: - if (writeDirectoryDB() < 0) { + if (writeDirectoryDB() < 0) exit(EXIT_FAILURE); - } break; default: /* something was updated and db should be written */ - ERROR("problems updating music db\n"); - exit(EXIT_FAILURE); + FATAL("problems updating music db\n"); } return; diff --git a/src/inputStream_http.c b/src/inputStream_http.c index 152fa4760..3f18575dd 100644 --- a/src/inputStream_http.c +++ b/src/inputStream_http.c @@ -81,9 +81,8 @@ void inputStream_initHttp(void) param = getConfigParam(CONF_HTTP_PROXY_PORT); if (!param) { - ERROR("%s specified but not %s", CONF_HTTP_PROXY_HOST, + FATAL("%s specified but not %s", CONF_HTTP_PROXY_HOST, CONF_HTTP_PROXY_PORT); - exit(EXIT_FAILURE); } proxyPort = param->value; @@ -95,10 +94,9 @@ void inputStream_initHttp(void) param = getConfigParam(CONF_HTTP_PROXY_PASSWORD); if (!param) { - ERROR("%s specified but not %s\n", + FATAL("%s specified but not %s\n", CONF_HTTP_PROXY_USER, CONF_HTTP_PROXY_PASSWORD); - exit(EXIT_FAILURE); } proxyPassword = param->value; @@ -106,24 +104,20 @@ void inputStream_initHttp(void) param = getConfigParam(CONF_HTTP_PROXY_PASSWORD); if (param) { - ERROR("%s specified but not %s\n", + FATAL("%s specified but not %s\n", CONF_HTTP_PROXY_PASSWORD, CONF_HTTP_PROXY_USER); - exit(EXIT_FAILURE); } } } else if ((param = getConfigParam(CONF_HTTP_PROXY_PORT))) { - ERROR("%s specified but not %s, line %i\n", + FATAL("%s specified but not %s, line %i\n", CONF_HTTP_PROXY_PORT, CONF_HTTP_PROXY_HOST, param->line); - exit(EXIT_FAILURE); } else if ((param = getConfigParam(CONF_HTTP_PROXY_USER))) { - ERROR("%s specified but not %s, line %i\n", + FATAL("%s specified but not %s, line %i\n", CONF_HTTP_PROXY_USER, CONF_HTTP_PROXY_HOST, param->line); - exit(EXIT_FAILURE); } else if ((param = getConfigParam(CONF_HTTP_PROXY_PASSWORD))) { - ERROR("%s specified but not %s, line %i\n", + FATAL("%s specified but not %s, line %i\n", CONF_HTTP_PROXY_PASSWORD, CONF_HTTP_PROXY_HOST, param->line); - exit(EXIT_FAILURE); } param = getConfigParam(CONF_HTTP_BUFFER_SIZE); @@ -132,10 +126,9 @@ void inputStream_initHttp(void) bufferSize = strtol(param->value, &test, 10); if (bufferSize <= 0 || *test != '\0') { - ERROR("\"%s\" specified for %s at line %i is not a " + FATAL("\"%s\" specified for %s at line %i is not a " "positive integer\n", param->value, CONF_HTTP_BUFFER_SIZE, param->line); - exit(EXIT_FAILURE); } bufferSize *= 1024; @@ -150,11 +143,10 @@ void inputStream_initHttp(void) prebufferSize = strtol(param->value, &test, 10); if (prebufferSize <= 0 || *test != '\0') { - ERROR("\"%s\" specified for %s at line %i is not a " + FATAL("\"%s\" specified for %s at line %i is not a " "positive integer\n", param->value, CONF_HTTP_PREBUFFER_SIZE, param->line); - exit(EXIT_FAILURE); } prebufferSize *= 1024; diff --git a/src/interface.c b/src/interface.c index fabc2d6e9..22660432f 100644 --- a/src/interface.c +++ b/src/interface.c @@ -585,10 +585,9 @@ void initInterfaces(void) if (param) { interface_timeout = strtol(param->value, &test, 10); if (*test != '\0' || interface_timeout <= 0) { - ERROR("connection timeout \"%s\" is not a positive " + FATAL("connection timeout \"%s\" is not a positive " "integer, line %i\n", CONF_CONN_TIMEOUT, param->line); - exit(EXIT_FAILURE); } } @@ -597,9 +596,8 @@ void initInterfaces(void) if (param) { interface_max_connections = strtol(param->value, &test, 10); if (*test != '\0' || interface_max_connections <= 0) { - ERROR("max connections \"%s\" is not a positive integer" + FATAL("max connections \"%s\" is not a positive integer" ", line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } } else interface_max_connections = INTERFACE_MAX_CONNECTIONS_DEFAULT; @@ -610,9 +608,8 @@ void initInterfaces(void) interface_max_command_list_size = strtol(param->value, &test, 10); if (*test != '\0' || interface_max_command_list_size <= 0) { - ERROR("max command list size \"%s\" is not a positive " + FATAL("max command list size \"%s\" is not a positive " "integer, line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } interface_max_command_list_size *= 1024; } @@ -623,9 +620,8 @@ void initInterfaces(void) interface_max_output_buffer_size = strtol(param->value, &test, 10); if (*test != '\0' || interface_max_output_buffer_size <= 0) { - ERROR("max output buffer size \"%s\" is not a positive " + FATAL("max output buffer size \"%s\" is not a positive " "integer, line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } interface_max_output_buffer_size *= 1024; } diff --git a/src/listen.c b/src/listen.c index 9240d4907..d2e7cf5a0 100644 --- a/src/listen.c +++ b/src/listen.c @@ -41,8 +41,9 @@ #define DEFAULT_PORT 6600 #define BINDERROR() do { \ - ERROR("unable to bind port %u: %s\n", port, strerror(errno)); \ - ERROR("maybe MPD is still running?\n"); \ + FATAL("unable to bind port %u: %s\n" \ + "maybe MPD is still running?\n", \ + port, strerror(errno)); \ } while (0); static int *listenSockets; @@ -69,25 +70,20 @@ static int establishListen(unsigned int port, pf = PF_UNIX; break; default: - ERROR("unknown address family: %i\n", addrp->sa_family); - exit(EXIT_FAILURE); + FATAL("unknown address family: %i\n", addrp->sa_family); } - if ((sock = socket(pf, SOCK_STREAM, 0)) < 0) { - ERROR("socket < 0\n"); - exit(EXIT_FAILURE); - } + if ((sock = socket(pf, SOCK_STREAM, 0)) < 0) + FATAL("socket < 0\n"); if (fcntl(sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK) < 0) { - ERROR("problems setting nonblocking on listen socket: %s\n", + FATAL("problems setting nonblocking on listen socket: %s\n", strerror(errno)); - exit(EXIT_FAILURE); } if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&allowReuse, sizeof(allowReuse)) < 0) { - ERROR("problems setsockopt'ing: %s\n", strerror(errno)); - exit(EXIT_FAILURE); + FATAL("problems setsockopt'ing: %s\n", strerror(errno)); } if (bind(sock, addrp, addrlen) < 0) { @@ -95,10 +91,8 @@ static int establishListen(unsigned int port, return -1; } - if (listen(sock, 5) < 0) { - ERROR("problems listen'ing: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } + if (listen(sock, 5) < 0) + FATAL("problems listen'ing: %s\n", strerror(errno)); numberOfListenSockets++; listenSockets = @@ -133,10 +127,8 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) sin6.sin6_addr = in6addr_any; addrp = (struct sockaddr *)&sin6; addrlen = sizeof(struct sockaddr_in6); - if (establishListen(port, addrp, addrlen) < 0) { + if (establishListen(port, addrp, addrlen) < 0) BINDERROR(); - exit(EXIT_FAILURE); - } } #endif sin.sin_addr.s_addr = INADDR_ANY; @@ -148,24 +140,21 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) if (establishListen(port, addrp, addrlen) < 0) { #endif BINDERROR(); - exit(EXIT_FAILURE); } } else { struct hostent *he; DEBUG("binding to address for %s\n", param->value); if (!(he = gethostbyname(param->value))) { - ERROR("can't lookup host \"%s\" at line %i\n", + FATAL("can't lookup host \"%s\" at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } switch (he->h_addrtype) { #ifdef HAVE_IPV6 case AF_INET6: if (!useIpv6) { - ERROR("no IPv6 support, but a IPv6 address " + FATAL("no IPv6 support, but a IPv6 address " "found for \"%s\" at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } memcpy((char *)&sin6.sin6_addr.s6_addr, (char *)he->h_addr, he->h_length); @@ -180,15 +169,12 @@ static void parseListenConfigParam(unsigned int port, ConfigParam * param) addrlen = sizeof(struct sockaddr_in); break; default: - ERROR("address type for \"%s\" is not IPv4 or IPv6 " + FATAL("address type for \"%s\" is not IPv4 or IPv6 " "at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } - if (establishListen(port, addrp, addrlen) < 0) { + if (establishListen(port, addrp, addrlen) < 0) BINDERROR(); - exit(EXIT_FAILURE); - } } } @@ -202,10 +188,9 @@ void listenOnPort(void) char *test; port = strtol(portParam->value, &test, 10); if (port <= 0 || *test != '\0') { - ERROR("%s \"%s\" specified at line %i is not a " + FATAL("%s \"%s\" specified at line %i is not a " "positive integer", CONF_PORT, portParam->value, portParam->line); - exit(EXIT_FAILURE); } } diff --git a/src/main.c b/src/main.c index c12dfc235..4c537eb1d 100644 --- a/src/main.c +++ b/src/main.c @@ -246,15 +246,13 @@ static void changeToUser(void) /* get uid */ struct passwd *userpwd; if ((userpwd = getpwnam(param->value)) == NULL) { - ERROR("no such user \"%s\" at line %i\n", param->value, + FATAL("no such user \"%s\" at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } if (setgid(userpwd->pw_gid) == -1) { - ERROR("cannot setgid for user \"%s\" at line %i: %s\n", + FATAL("cannot setgid for user \"%s\" at line %i: %s\n", param->value, param->line, strerror(errno)); - exit(EXIT_FAILURE); } #ifdef _BSD_SOURCE /* init suplementary groups @@ -269,10 +267,9 @@ static void changeToUser(void) /* set uid */ if (setuid(userpwd->pw_uid) == -1) { - ERROR("cannot change to uid of user " + FATAL("cannot change to uid of user " "\"%s\" at line %i: %s\n", param->value, param->line, strerror(errno)); - exit(EXIT_FAILURE); } /* this is needed by libs such as arts */ @@ -286,10 +283,9 @@ static void openDB(Options * options, char *argv0) { if (options->createDB > 0 || readDirectoryDB() < 0) { if (options->createDB < 0) { - ERROR("can't open db file and using \"--no-create-db\"" - " command line option\n"); - ERROR("try running \"%s --create-db\"\n", argv0); - exit(EXIT_FAILURE); + FATAL("can't open db file and using " + "\"--no-create-db\" command line option\n" + "try running \"%s --create-db\"\n", argv0); } flushWarningLog(); if (checkDirectoryDB() < 0) @@ -313,11 +309,9 @@ static void daemonize(Options * options) DEBUG("opening pid file\n"); fp = fopen(pidFileParam->value, "w+"); if (!fp) { - ERROR - ("could not open %s \"%s\" (at line %i) for writing: %s\n", + FATAL("could not open %s \"%s\" (at line %i) for writing: %s\n", CONF_PID_FILE, pidFileParam->value, pidFileParam->line, strerror(errno)); - exit(EXIT_FAILURE); } } @@ -329,18 +323,15 @@ static void daemonize(Options * options) if (pid > 0) _exit(EXIT_SUCCESS); else if (pid < 0) { - ERROR("problems fork'ing for daemon!\n"); - exit(EXIT_FAILURE); + FATAL("problems fork'ing for daemon!\n"); } if (chdir("/") < 0) { - ERROR("problems changing to root directory\n"); - exit(EXIT_FAILURE); + FATAL("problems changing to root directory\n"); } if (setsid() < 0) { - ERROR("problems setsid'ing\n"); - exit(EXIT_FAILURE); + FATAL("problems setsid'ing\n"); } fflush(NULL); @@ -348,8 +339,7 @@ static void daemonize(Options * options) if (pid > 0) _exit(EXIT_SUCCESS); else if (pid < 0) { - ERROR("problems fork'ing for daemon!\n"); - exit(EXIT_FAILURE); + FATAL("problems fork'ing for daemon!\n"); } DEBUG("daemonized!\n"); @@ -381,26 +371,22 @@ static void killFromPidFile(char *cmd, int killOption) int pid; if (!pidFileParam) { - ERROR("no pid_file specified in the config file\n"); - exit(EXIT_FAILURE); + FATAL("no pid_file specified in the config file\n"); } fp = fopen(pidFileParam->value, "r"); if (!fp) { - ERROR("unable to open %s \"%s\": %s\n", + FATAL("unable to open %s \"%s\": %s\n", CONF_PID_FILE, pidFileParam->value, strerror(errno)); - exit(EXIT_FAILURE); } if (fscanf(fp, "%i", &pid) != 1) { - ERROR("unable to read the pid from file \"%s\"\n", + FATAL("unable to read the pid from file \"%s\"\n", pidFileParam->value); - exit(EXIT_FAILURE); } fclose(fp); if (kill(pid, SIGTERM)) { - ERROR("unable to kill proccess %i: %s\n", pid, strerror(errno)); - exit(EXIT_FAILURE); + FATAL("unable to kill proccess %i: %s\n", pid, strerror(errno)); } exit(EXIT_SUCCESS); } diff --git a/src/path.c b/src/path.c index 513128a17..f30eb0793 100644 --- a/src/path.c +++ b/src/path.c @@ -142,18 +142,16 @@ void initPaths(void) playlistDir = appendSlash(&(playlistParam->value)); if ((dir = opendir(playlistDir)) == NULL) { - ERROR("cannot open %s \"%s\" (config line %i): %s\n", + FATAL("cannot open %s \"%s\" (config line %i): %s\n", CONF_PLAYLIST_DIR, playlistParam->value, playlistParam->line, strerror(errno)); - exit(EXIT_FAILURE); } closedir(dir); if ((dir = opendir(musicDir)) == NULL) { - ERROR("cannot open %s \"%s\" (config line %i): %s\n", + FATAL("cannot open %s \"%s\" (config line %i): %s\n", CONF_MUSIC_DIR, musicParam->value, musicParam->line, strerror(errno)); - exit(EXIT_FAILURE); } closedir(dir); diff --git a/src/pcm_utils.c b/src/pcm_utils.c index ab84850d7..534095620 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -72,9 +72,8 @@ void pcm_volumeChange(char *buffer, int bufferSize, AudioFormat * format, } break; default: - ERROR("%i bits not supported by pcm_volumeChange!\n", + FATAL("%i bits not supported by pcm_volumeChange!\n", format->bits); - exit(EXIT_FAILURE); } } @@ -129,8 +128,7 @@ static void pcm_add(char *buffer1, char *buffer2, size_t bufferSize1, memcpy(buffer8_1, buffer8_2, bufferSize2); break; default: - ERROR("%i bits not supported by pcm_add!\n", format->bits); - exit(EXIT_FAILURE); + FATAL("%i bits not supported by pcm_add!\n", format->bits); } } @@ -447,8 +445,7 @@ size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize, case 16: break; default: - ERROR("only 8 or 16 bits are supported for conversion!\n"); - exit(EXIT_FAILURE); + FATAL("only 8 or 16 bits are supported for conversion!\n"); } if (inFormat->channels != outFormat->channels) { @@ -460,9 +457,8 @@ size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize, outSize >>= 1; break; default: - ERROR("only 1 or 2 channels are supported " + FATAL("only 1 or 2 channels are supported " "for conversion!\n"); - exit(EXIT_FAILURE); } } diff --git a/src/permission.c b/src/permission.c index e12cdcdc8..3d597052c 100644 --- a/src/permission.c +++ b/src/permission.c @@ -57,8 +57,7 @@ static int parsePermissions(char *string) } else if (strcmp(temp, PERMISSION_ADMIN_STRING) == 0) { permission |= PERMISSION_ADMIN; } else { - ERROR("unknown permission \"%s\"\n", temp); - exit(EXIT_FAILURE); + FATAL("unknown permission \"%s\"\n", temp); } temp = strtok_r(NULL, PERMISSION_SEPERATOR, &tok); @@ -87,19 +86,16 @@ void initPermissions(void) do { if (!strstr(param->value, PERMISSION_PASSWORD_CHAR)) { - ERROR("\"%s\" not found in password string " + FATAL("\"%s\" not found in password string " "\"%s\", line %i\n", PERMISSION_PASSWORD_CHAR, param->value, param->line); - exit(EXIT_FAILURE); } if (!(temp = strtok_r(param->value, PERMISSION_PASSWORD_CHAR, &cp2))) { - ERROR - ("something weird just happened in permission.c\n"); - exit(EXIT_FAILURE); + FATAL("something weird just happened in permission.c\n"); } password = temp; diff --git a/src/playerData.c b/src/playerData.c index 0d5e6e9e4..e0c3abfe4 100644 --- a/src/playerData.c +++ b/src/playerData.c @@ -53,9 +53,8 @@ void initPlayerData(void) if (param) { bufferSize = strtol(param->value, &test, 10); if (*test != '\0' || bufferSize <= 0) { - ERROR("buffer size \"%s\" is not a positive integer, " + FATAL("buffer size \"%s\" is not a positive integer, " "line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } } @@ -64,8 +63,7 @@ void initPlayerData(void) buffered_chunks = bufferSize / CHUNK_SIZE; if (buffered_chunks >= 1 << 15) { - ERROR("buffer size \"%li\" is too big\n", (long)bufferSize); - exit(EXIT_FAILURE); + FATAL("buffer size \"%li\" is too big\n", (long)bufferSize); } param = getConfigParam(CONF_BUFFER_BEFORE_PLAY); @@ -73,10 +71,9 @@ void initPlayerData(void) if (param) { perc = strtod(param->value, &test); if (*test != '%' || perc < 0 || perc > 100) { - ERROR("buffered before play \"%s\" is not a positive " + FATAL("buffered before play \"%s\" is not a positive " "percentage and less than 100 percent, line %i" "\n", param->value, param->line); - exit(EXIT_FAILURE); } } @@ -97,20 +94,11 @@ void initPlayerData(void) allocationSize += device_array_size; if ((shmid = shmget(IPC_PRIVATE, allocationSize, IPC_CREAT | 0600)) < 0) - { - ERROR("problems shmget'ing\n"); - exit(EXIT_FAILURE); - } + FATAL("problems shmget'ing\n"); if (!(playerData_pd = shmat(shmid, NULL, 0))) - { - ERROR("problems shmat'ing\n"); - exit(EXIT_FAILURE); - } + FATAL("problems shmat'ing\n"); if (shmctl(shmid, IPC_RMID, NULL) < 0) - { - ERROR("problems shmctl'ing\n"); - exit(EXIT_FAILURE); - } + FATAL("problems shmctl'ing\n"); playerData_pd->audioDeviceStates = (mpd_uint8 *)playerData_pd + allocationSize - device_array_size; diff --git a/src/playlist.c b/src/playlist.c index 390cae8b9..d8f2c6b65 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -135,9 +135,8 @@ void initPlaylist(void) if (param) { playlist_max_length = strtol(param->value, &test, 10); if (*test != '\0') { - ERROR("max playlist length \"%s\" is not an integer, " + FATAL("max playlist length \"%s\" is not an integer, " "line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } } diff --git a/src/replayGain.c b/src/replayGain.c index eeda47f36..7c20919b8 100644 --- a/src/replayGain.c +++ b/src/replayGain.c @@ -44,9 +44,8 @@ void initReplayGainState(void) } else if (strcmp(param->value, "album") == 0) { replayGainState = REPLAYGAIN_ALBUM; } else { - ERROR("replaygain value \"%s\" at line %i is invalid\n", + FATAL("replaygain value \"%s\" at line %i is invalid\n", param->value, param->line); - exit(EXIT_FAILURE); } param = getConfigParam(CONF_REPLAYGAIN_PREAMP); @@ -56,15 +55,13 @@ void initReplayGainState(void) float f = strtod(param->value, &test); if (*test != '\0') { - ERROR("Replaygain preamp \"%s\" is not a number at " + FATAL("Replaygain preamp \"%s\" is not a number at " "line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } if (f < -15 || f > 15) { - ERROR("Replaygain preamp \"%s\" is not between -15 and" + FATAL("Replaygain preamp \"%s\" is not between -15 and" "15 at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } replayGainPreamp = pow(10, f / 20.0); diff --git a/src/song.c b/src/song.c index 6d8092b55..9bcb1a0b4 100644 --- a/src/song.c +++ b/src/song.c @@ -251,10 +251,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir) song->type = SONG_TYPE_FILE; song->parentDir = parentDir; } else if (0 == strncmp(SONG_FILE, buffer, strlen(SONG_FILE))) { - if (!song) { - ERROR("Problems reading song info\n"); - exit(EXIT_FAILURE); - } + if (!song) + FATAL("Problems reading song info\n"); /* we don't need this info anymore song->url = xstrdup(&(buffer[strlen(SONG_FILE)])); */ @@ -273,10 +271,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir) song->mtime = atoi(&(buffer[strlen(SONG_MTIME)])); } /* ignore empty lines (starting with '\0') */ - else if (*buffer) { - ERROR("songinfo: unknown line in db: %s\n", buffer); - exit(EXIT_FAILURE); - } + else if (*buffer) + FATAL("songinfo: unknown line in db: %s\n", buffer); } if (song) { diff --git a/src/state_file.c b/src/state_file.c index 2e6f83047..1b0b41f1a 100644 --- a/src/state_file.c +++ b/src/state_file.c @@ -87,16 +87,13 @@ void read_state_file(void) DEBUG("failed to stat state file: %s\n", sfpath); return; } - if (!S_ISREG(st.st_mode)) { - ERROR("state file \"%s\" is not a regular file\n", sfpath); - exit(EXIT_FAILURE); - } + if (!S_ISREG(st.st_mode)) + FATAL("state file \"%s\" is not a regular file\n", sfpath); while (!(fp = fopen(sfpath, "r")) && errno == EINTR); if (mpd_unlikely(!fp)) { - ERROR("problems opening state file \"%s\" for reading: %s\n", + FATAL("problems opening state file \"%s\" for reading: %s\n", sfpath, strerror(errno)); - exit(EXIT_FAILURE); } for (i = 0; i < ARRAY_SIZE(sf_callbacks); i++) { sf_callbacks[i].reader(fp); @@ -108,7 +105,6 @@ void read_state_file(void) void mpd_noreturn state_file_fatal(void) { - ERROR("error parsing state file \"%s\"\n", sfpath); - exit(EXIT_FAILURE); + FATAL("error parsing state file \"%s\"\n", sfpath); } diff --git a/src/tag.c b/src/tag.c index 1e3edc88d..92a597d0e 100644 --- a/src/tag.c +++ b/src/tag.c @@ -103,9 +103,8 @@ void initTagConfig(void) } } if (strlen(c) && i == TAG_NUM_OF_ITEM_TYPES) { - ERROR("error parsing metadata item \"%s\" at " + FATAL("error parsing metadata item \"%s\" at " "line %i\n", c, param->line); - exit(EXIT_FAILURE); } s++; c = s; diff --git a/src/volume.c b/src/volume.c index 58d8ee567..59e8b550c 100644 --- a/src/volume.c +++ b/src/volume.c @@ -430,9 +430,8 @@ void initVolume(void) volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE; volume_mixerDevice = VOLUME_MIXER_SOFTWARE_DEFAULT; } else { - ERROR("unknown mixer type %s at line %i\n", + FATAL("unknown mixer type %s at line %i\n", param->value, param->line); - exit(EXIT_FAILURE); } } -- cgit v1.2.3