aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-07 09:53:33 +0200
committerMax Kellermann <max@duempel.org>2013-08-07 09:53:33 +0200
commit67e44b0f2c76a8c4913048fe3b8fe90116fa595b (patch)
tree65987ff62f3f2760b9646b752f32433d03ffbcd1
parentbf840700e4a525ec50aaee2eb9a5a537b83cbbc2 (diff)
downloadmpd-67e44b0f2c76a8c4913048fe3b8fe90116fa595b.tar.gz
mpd-67e44b0f2c76a8c4913048fe3b8fe90116fa595b.tar.xz
mpd-67e44b0f2c76a8c4913048fe3b8fe90116fa595b.zip
daemon: convert to C++
-rw-r--r--Makefile.am3
-rw-r--r--src/Daemon.cxx (renamed from src/daemon.c)26
-rw-r--r--src/Daemon.hxx (renamed from src/daemon.h)8
-rw-r--r--src/Main.cxx2
4 files changed, 18 insertions, 21 deletions
diff --git a/Makefile.am b/Makefile.am
index 57d553587..245f1f396 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -62,7 +62,6 @@ mpd_headers = \
src/TextInputStream.hxx \
src/ls.h \
src/mixer_plugin.h \
- src/daemon.h \
src/AudioCompress/config.h \
src/AudioCompress/compress.h \
src/open.h \
@@ -173,7 +172,7 @@ src_mpd_SOURCES = \
src/Instance.cxx src/Instance.hxx \
src/Win32Main.cxx \
src/GlobalEvents.cxx src/GlobalEvents.hxx \
- src/daemon.c \
+ src/Daemon.cxx src/Daemon.hxx \
src/AudioCompress/compress.c \
src/MusicBuffer.cxx src/MusicBuffer.hxx \
src/MusicPipe.cxx src/MusicPipe.hxx \
diff --git a/src/daemon.c b/src/Daemon.cxx
index 8bca9095a..e14b8aee7 100644
--- a/src/daemon.c
+++ b/src/Daemon.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "daemon.h"
+#include "Daemon.hxx"
#include <glib.h>
@@ -64,11 +64,11 @@ daemonize_kill(void)
FILE *fp;
int pid, ret;
- if (pidfile == NULL)
+ if (pidfile == nullptr)
MPD_ERROR("no pid_file specified in the config file");
fp = fopen(pidfile, "r");
- if (fp == NULL)
+ if (fp == nullptr)
MPD_ERROR("unable to open pid file \"%s\": %s",
pidfile, g_strerror(errno));
@@ -96,7 +96,7 @@ daemonize_close_stdin(void)
void
daemonize_set_user(void)
{
- if (user_name == NULL)
+ if (user_name == nullptr)
return;
/* set gid */
@@ -131,7 +131,7 @@ daemonize_detach(void)
{
/* flush all file handles before duplicating the buffers */
- fflush(NULL);
+ fflush(nullptr);
#ifdef HAVE_DAEMON
@@ -171,9 +171,9 @@ daemonize_detach(void)
void
daemonize(bool detach)
{
- FILE *fp = NULL;
+ FILE *fp = nullptr;
- if (pidfile != NULL) {
+ if (pidfile != nullptr) {
/* do this before daemon'izing so we can fail gracefully if we can't
* write to the pid file */
g_debug("opening pid file");
@@ -187,7 +187,7 @@ daemonize(bool detach)
if (detach)
daemonize_detach();
- if (pidfile != NULL) {
+ if (pidfile != nullptr) {
g_debug("writing pid file");
fprintf(fp, "%lu\n", (unsigned long)getpid());
fclose(fp);
@@ -199,7 +199,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
{
if (user) {
struct passwd *pwd = getpwnam(user);
- if (!pwd)
+ if (pwd == nullptr)
MPD_ERROR("no such user \"%s\"", user);
user_uid = pwd->pw_uid;
@@ -212,8 +212,8 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
}
if (group) {
- struct group *grp = grp = getgrnam(group);
- if (!grp)
+ struct group *grp = getgrnam(group);
+ if (grp == nullptr)
MPD_ERROR("no such group \"%s\"", group);
user_gid = grp->gr_gid;
had_group = true;
@@ -226,7 +226,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
void
daemonize_finish(void)
{
- if (pidfile != NULL)
+ if (pidfile != nullptr)
unlink(pidfile);
g_free(user_name);
diff --git a/src/daemon.h b/src/Daemon.hxx
index c43a74cfd..a4117537d 100644
--- a/src/daemon.h
+++ b/src/Daemon.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,13 +17,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef DAEMON_H
-#define DAEMON_H
+#ifndef MPD_DAEMON_HXX
+#define MPD_DAEMON_HXX
#include "mpd_error.h"
-#include <stdbool.h>
-
#ifndef WIN32
void
daemonize_init(const char *user, const char *group, const char *pidfile);
diff --git a/src/Main.cxx b/src/Main.cxx
index c0824fc55..307811380 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -54,9 +54,9 @@
#include "DecoderList.hxx"
#include "AudioConfig.hxx"
#include "pcm/PcmResample.hxx"
+#include "Daemon.hxx"
extern "C" {
-#include "daemon.h"
#include "stats.h"
}