aboutsummaryrefslogtreecommitdiffstats
path: root/src/daemon.c
diff options
context:
space:
mode:
authorThomas Jansen <mithi@mithi.net>2010-09-25 15:00:43 +0200
committerThomas Jansen <mithi@mithi.net>2010-09-25 15:00:43 +0200
commit28bcb8bdf568875eeea1349e39b7958d77c8fcc1 (patch)
tree17397be16e8067a48fd532a581081f68a1b17700 /src/daemon.c
parent9af9fd140032138894e4781caabee8a5a96edab8 (diff)
downloadmpd-28bcb8bdf568875eeea1349e39b7958d77c8fcc1.tar.gz
mpd-28bcb8bdf568875eeea1349e39b7958d77c8fcc1.tar.xz
mpd-28bcb8bdf568875eeea1349e39b7958d77c8fcc1.zip
eliminate g_error() usage
Replaced all occurrences of g_error() with MPD_ERROR() located in a new header file 'mpd_error.h'. This macro uses g_critical() to print the error message and then exits gracefully in contrast to g_error() which would internally call abort() to produce a core dump. The macro name is distinctive and allows to find all places with dubious error handling. The long-term goal is to get rid of MPD_ERROR() altogether. To facilitate the eventual removal of this macro it was added in a new header file rather than to an existing header file. This fixes #2995 and #3007.
Diffstat (limited to 'src/daemon.c')
-rw-r--r--src/daemon.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/daemon.c b/src/daemon.c
index e08afce4b..852541375 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -65,23 +65,23 @@ daemonize_kill(void)
int pid, ret;
if (pidfile == NULL)
- g_error("no pid_file specified in the config file");
+ MPD_ERROR("no pid_file specified in the config file");
fp = fopen(pidfile, "r");
if (fp == NULL)
- g_error("unable to open pid file \"%s\": %s",
- pidfile, g_strerror(errno));
+ MPD_ERROR("unable to open pid file \"%s\": %s",
+ pidfile, g_strerror(errno));
if (fscanf(fp, "%i", &pid) != 1) {
- g_error("unable to read the pid from file \"%s\"",
- pidfile);
+ MPD_ERROR("unable to read the pid from file \"%s\"",
+ pidfile);
}
fclose(fp);
ret = kill(pid, SIGTERM);
if (ret < 0)
- g_error("unable to kill proccess %i: %s",
- pid, g_strerror(errno));
+ MPD_ERROR("unable to kill proccess %i: %s",
+ pid, g_strerror(errno));
exit(EXIT_SUCCESS);
}
@@ -102,8 +102,8 @@ daemonize_set_user(void)
/* set gid */
if (user_gid != (gid_t)-1 && user_gid != getgid()) {
if (setgid(user_gid) == -1) {
- g_error("cannot setgid to %d: %s",
- (int)user_gid, g_strerror(errno));
+ MPD_ERROR("cannot setgid to %d: %s",
+ (int)user_gid, g_strerror(errno));
}
}
@@ -121,8 +121,8 @@ daemonize_set_user(void)
/* set uid */
if (user_uid != (uid_t)-1 && user_uid != getuid() &&
setuid(user_uid) == -1) {
- g_error("cannot change to uid of user \"%s\": %s",
- user_name, g_strerror(errno));
+ MPD_ERROR("cannot change to uid of user \"%s\": %s",
+ user_name, g_strerror(errno));
}
}
@@ -136,7 +136,7 @@ daemonize_detach(void)
#ifdef HAVE_DAEMON
if (daemon(0, 1))
- g_error("daemon() failed: %s", g_strerror(errno));
+ MPD_ERROR("daemon() failed: %s", g_strerror(errno));
#elif defined(HAVE_FORK)
@@ -144,7 +144,7 @@ daemonize_detach(void)
switch (fork()) {
case -1:
- g_error("fork() failed: %s", g_strerror(errno));
+ MPD_ERROR("fork() failed: %s", g_strerror(errno));
case 0:
break;
default:
@@ -155,14 +155,14 @@ daemonize_detach(void)
/* release the current working directory */
if (chdir("/") < 0)
- g_error("problems changing to root directory");
+ MPD_ERROR("problems changing to root directory");
/* detach from the current session */
setsid();
#else
- g_error("no support for daemonizing");
+ MPD_ERROR("no support for daemonizing");
#endif
g_debug("daemonized!");
@@ -179,8 +179,8 @@ daemonize(bool detach)
g_debug("opening pid file");
fp = fopen(pidfile, "w+");
if (!fp) {
- g_error("could not create pid file \"%s\": %s",
- pidfile, g_strerror(errno));
+ MPD_ERROR("could not create pid file \"%s\": %s",
+ pidfile, g_strerror(errno));
}
}
@@ -200,7 +200,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
if (user) {
struct passwd *pwd = getpwnam(user);
if (!pwd)
- g_error("no such user \"%s\"", user);
+ MPD_ERROR("no such user \"%s\"", user);
user_uid = pwd->pw_uid;
user_gid = pwd->pw_gid;
@@ -214,7 +214,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
if (group) {
struct group *grp = grp = getgrnam(group);
if (!grp)
- g_error("no such group \"%s\"", group);
+ MPD_ERROR("no such group \"%s\"", group);
user_gid = grp->gr_gid;
had_group = true;
}