daemon: convert to C++
This commit is contained in:
parent
bf840700e4
commit
67e44b0f2c
@ -62,7 +62,6 @@ mpd_headers = \
|
|||||||
src/TextInputStream.hxx \
|
src/TextInputStream.hxx \
|
||||||
src/ls.h \
|
src/ls.h \
|
||||||
src/mixer_plugin.h \
|
src/mixer_plugin.h \
|
||||||
src/daemon.h \
|
|
||||||
src/AudioCompress/config.h \
|
src/AudioCompress/config.h \
|
||||||
src/AudioCompress/compress.h \
|
src/AudioCompress/compress.h \
|
||||||
src/open.h \
|
src/open.h \
|
||||||
@ -173,7 +172,7 @@ src_mpd_SOURCES = \
|
|||||||
src/Instance.cxx src/Instance.hxx \
|
src/Instance.cxx src/Instance.hxx \
|
||||||
src/Win32Main.cxx \
|
src/Win32Main.cxx \
|
||||||
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
||||||
src/daemon.c \
|
src/Daemon.cxx src/Daemon.hxx \
|
||||||
src/AudioCompress/compress.c \
|
src/AudioCompress/compress.c \
|
||||||
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
||||||
src/MusicPipe.cxx src/MusicPipe.hxx \
|
src/MusicPipe.cxx src/MusicPipe.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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "daemon.h"
|
#include "Daemon.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
@ -64,11 +64,11 @@ daemonize_kill(void)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
int pid, ret;
|
int pid, ret;
|
||||||
|
|
||||||
if (pidfile == NULL)
|
if (pidfile == nullptr)
|
||||||
MPD_ERROR("no pid_file specified in the config file");
|
MPD_ERROR("no pid_file specified in the config file");
|
||||||
|
|
||||||
fp = fopen(pidfile, "r");
|
fp = fopen(pidfile, "r");
|
||||||
if (fp == NULL)
|
if (fp == nullptr)
|
||||||
MPD_ERROR("unable to open pid file \"%s\": %s",
|
MPD_ERROR("unable to open pid file \"%s\": %s",
|
||||||
pidfile, g_strerror(errno));
|
pidfile, g_strerror(errno));
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ daemonize_close_stdin(void)
|
|||||||
void
|
void
|
||||||
daemonize_set_user(void)
|
daemonize_set_user(void)
|
||||||
{
|
{
|
||||||
if (user_name == NULL)
|
if (user_name == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* set gid */
|
/* set gid */
|
||||||
@ -131,7 +131,7 @@ daemonize_detach(void)
|
|||||||
{
|
{
|
||||||
/* flush all file handles before duplicating the buffers */
|
/* flush all file handles before duplicating the buffers */
|
||||||
|
|
||||||
fflush(NULL);
|
fflush(nullptr);
|
||||||
|
|
||||||
#ifdef HAVE_DAEMON
|
#ifdef HAVE_DAEMON
|
||||||
|
|
||||||
@ -171,9 +171,9 @@ daemonize_detach(void)
|
|||||||
void
|
void
|
||||||
daemonize(bool detach)
|
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
|
/* do this before daemon'izing so we can fail gracefully if we can't
|
||||||
* write to the pid file */
|
* write to the pid file */
|
||||||
g_debug("opening pid file");
|
g_debug("opening pid file");
|
||||||
@ -187,7 +187,7 @@ daemonize(bool detach)
|
|||||||
if (detach)
|
if (detach)
|
||||||
daemonize_detach();
|
daemonize_detach();
|
||||||
|
|
||||||
if (pidfile != NULL) {
|
if (pidfile != nullptr) {
|
||||||
g_debug("writing pid file");
|
g_debug("writing pid file");
|
||||||
fprintf(fp, "%lu\n", (unsigned long)getpid());
|
fprintf(fp, "%lu\n", (unsigned long)getpid());
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -199,7 +199,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
|
|||||||
{
|
{
|
||||||
if (user) {
|
if (user) {
|
||||||
struct passwd *pwd = getpwnam(user);
|
struct passwd *pwd = getpwnam(user);
|
||||||
if (!pwd)
|
if (pwd == nullptr)
|
||||||
MPD_ERROR("no such user \"%s\"", user);
|
MPD_ERROR("no such user \"%s\"", user);
|
||||||
|
|
||||||
user_uid = pwd->pw_uid;
|
user_uid = pwd->pw_uid;
|
||||||
@ -212,8 +212,8 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (group) {
|
if (group) {
|
||||||
struct group *grp = grp = getgrnam(group);
|
struct group *grp = getgrnam(group);
|
||||||
if (!grp)
|
if (grp == nullptr)
|
||||||
MPD_ERROR("no such group \"%s\"", group);
|
MPD_ERROR("no such group \"%s\"", group);
|
||||||
user_gid = grp->gr_gid;
|
user_gid = grp->gr_gid;
|
||||||
had_group = true;
|
had_group = true;
|
||||||
@ -226,7 +226,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
|
|||||||
void
|
void
|
||||||
daemonize_finish(void)
|
daemonize_finish(void)
|
||||||
{
|
{
|
||||||
if (pidfile != NULL)
|
if (pidfile != nullptr)
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
|
|
||||||
g_free(user_name);
|
g_free(user_name);
|
@ -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
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DAEMON_H
|
#ifndef MPD_DAEMON_HXX
|
||||||
#define DAEMON_H
|
#define MPD_DAEMON_HXX
|
||||||
|
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
void
|
void
|
||||||
daemonize_init(const char *user, const char *group, const char *pidfile);
|
daemonize_init(const char *user, const char *group, const char *pidfile);
|
@ -54,9 +54,9 @@
|
|||||||
#include "DecoderList.hxx"
|
#include "DecoderList.hxx"
|
||||||
#include "AudioConfig.hxx"
|
#include "AudioConfig.hxx"
|
||||||
#include "pcm/PcmResample.hxx"
|
#include "pcm/PcmResample.hxx"
|
||||||
|
#include "Daemon.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "daemon.h"
|
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user