FatalError: new library to replace mpd_error.h
This commit is contained in:
parent
67e44b0f2c
commit
a27d105dcd
|
@ -91,6 +91,7 @@ src_mpd_SOURCES = \
|
||||||
src/thread/PosixCond.hxx \
|
src/thread/PosixCond.hxx \
|
||||||
src/thread/WindowsCond.hxx \
|
src/thread/WindowsCond.hxx \
|
||||||
src/thread/GLibCond.hxx \
|
src/thread/GLibCond.hxx \
|
||||||
|
src/FatalError.cxx src/FatalError.hxx \
|
||||||
src/clock.c src/clock.h \
|
src/clock.c src/clock.h \
|
||||||
src/notify.cxx src/notify.hxx \
|
src/notify.cxx src/notify.hxx \
|
||||||
src/AudioConfig.cxx src/AudioConfig.hxx \
|
src/AudioConfig.cxx src/AudioConfig.hxx \
|
||||||
|
@ -1360,6 +1361,7 @@ endif
|
||||||
if ENABLE_INOTIFY
|
if ENABLE_INOTIFY
|
||||||
noinst_PROGRAMS += test/run_inotify
|
noinst_PROGRAMS += test/run_inotify
|
||||||
test_run_inotify_SOURCES = test/run_inotify.cxx \
|
test_run_inotify_SOURCES = test/run_inotify.cxx \
|
||||||
|
src/FatalError.cxx \
|
||||||
src/fd_util.c \
|
src/fd_util.c \
|
||||||
src/InotifySource.cxx
|
src/InotifySource.cxx
|
||||||
test_run_inotify_LDADD = \
|
test_run_inotify_LDADD = \
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "Daemon.hxx"
|
#include "Daemon.hxx"
|
||||||
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -65,23 +65,23 @@ daemonize_kill(void)
|
||||||
int pid, ret;
|
int pid, ret;
|
||||||
|
|
||||||
if (pidfile == nullptr)
|
if (pidfile == nullptr)
|
||||||
MPD_ERROR("no pid_file specified in the config file");
|
FatalError("no pid_file specified in the config file");
|
||||||
|
|
||||||
fp = fopen(pidfile, "r");
|
fp = fopen(pidfile, "r");
|
||||||
if (fp == nullptr)
|
if (fp == nullptr)
|
||||||
MPD_ERROR("unable to open pid file \"%s\": %s",
|
FormatFatalSystemError("Unable to open pid file \"%s\"",
|
||||||
pidfile, g_strerror(errno));
|
pidfile);
|
||||||
|
|
||||||
if (fscanf(fp, "%i", &pid) != 1) {
|
if (fscanf(fp, "%i", &pid) != 1) {
|
||||||
MPD_ERROR("unable to read the pid from file \"%s\"",
|
FormatFatalError("unable to read the pid from file \"%s\"",
|
||||||
pidfile);
|
pidfile);
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
ret = kill(pid, SIGTERM);
|
ret = kill(pid, SIGTERM);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
MPD_ERROR("unable to kill process %i: %s",
|
FormatFatalSystemError("unable to kill process %i",
|
||||||
pid, g_strerror(errno));
|
int(pid));
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ daemonize_set_user(void)
|
||||||
/* set gid */
|
/* set gid */
|
||||||
if (user_gid != (gid_t)-1 && user_gid != getgid()) {
|
if (user_gid != (gid_t)-1 && user_gid != getgid()) {
|
||||||
if (setgid(user_gid) == -1) {
|
if (setgid(user_gid) == -1) {
|
||||||
MPD_ERROR("cannot setgid to %d: %s",
|
FormatFatalSystemError("Failed to set group %d",
|
||||||
(int)user_gid, g_strerror(errno));
|
(int)user_gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,17 +112,17 @@ daemonize_set_user(void)
|
||||||
* (must be done before we change our uid)
|
* (must be done before we change our uid)
|
||||||
*/
|
*/
|
||||||
if (!had_group && initgroups(user_name, user_gid) == -1) {
|
if (!had_group && initgroups(user_name, user_gid) == -1) {
|
||||||
g_warning("cannot init supplementary groups "
|
FormatFatalSystemError("Failed to set supplementary groups "
|
||||||
"of user \"%s\": %s",
|
"of user \"%s\"",
|
||||||
user_name, g_strerror(errno));
|
user_name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set uid */
|
/* set uid */
|
||||||
if (user_uid != (uid_t)-1 && user_uid != getuid() &&
|
if (user_uid != (uid_t)-1 && user_uid != getuid() &&
|
||||||
setuid(user_uid) == -1) {
|
setuid(user_uid) == -1) {
|
||||||
MPD_ERROR("cannot change to uid of user \"%s\": %s",
|
FormatFatalSystemError("Failed to set user \"%s\"",
|
||||||
user_name, g_strerror(errno));
|
user_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ daemonize_detach(void)
|
||||||
#ifdef HAVE_DAEMON
|
#ifdef HAVE_DAEMON
|
||||||
|
|
||||||
if (daemon(0, 1))
|
if (daemon(0, 1))
|
||||||
MPD_ERROR("daemon() failed: %s", g_strerror(errno));
|
FatalSystemError("daemon() failed");
|
||||||
|
|
||||||
#elif defined(HAVE_FORK)
|
#elif defined(HAVE_FORK)
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ daemonize_detach(void)
|
||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
MPD_ERROR("fork() failed: %s", g_strerror(errno));
|
FatalSystemError("fork() failed");
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -155,14 +155,14 @@ daemonize_detach(void)
|
||||||
/* release the current working directory */
|
/* release the current working directory */
|
||||||
|
|
||||||
if (chdir("/") < 0)
|
if (chdir("/") < 0)
|
||||||
MPD_ERROR("problems changing to root directory");
|
FatalError("problems changing to root directory");
|
||||||
|
|
||||||
/* detach from the current session */
|
/* detach from the current session */
|
||||||
|
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
MPD_ERROR("no support for daemonizing");
|
FatalError("no support for daemonizing");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_debug("daemonized!");
|
g_debug("daemonized!");
|
||||||
|
@ -179,8 +179,8 @@ daemonize(bool detach)
|
||||||
g_debug("opening pid file");
|
g_debug("opening pid file");
|
||||||
fp = fopen(pidfile, "w+");
|
fp = fopen(pidfile, "w+");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
MPD_ERROR("could not create pid file \"%s\": %s",
|
FormatFatalSystemError("Failed to create pid file \"%s\"",
|
||||||
pidfile, g_strerror(errno));
|
pidfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,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 == nullptr)
|
if (pwd == nullptr)
|
||||||
MPD_ERROR("no such user \"%s\"", user);
|
FormatFatalError("no such user \"%s\"", user);
|
||||||
|
|
||||||
user_uid = pwd->pw_uid;
|
user_uid = pwd->pw_uid;
|
||||||
user_gid = pwd->pw_gid;
|
user_gid = pwd->pw_gid;
|
||||||
|
@ -214,7 +214,7 @@ daemonize_init(const char *user, const char *group, const char *_pidfile)
|
||||||
if (group) {
|
if (group) {
|
||||||
struct group *grp = getgrnam(group);
|
struct group *grp = getgrnam(group);
|
||||||
if (grp == nullptr)
|
if (grp == nullptr)
|
||||||
MPD_ERROR("no such group \"%s\"", group);
|
FormatFatalError("no such group \"%s\"", group);
|
||||||
user_gid = grp->gr_gid;
|
user_gid = grp->gr_gid;
|
||||||
had_group = true;
|
had_group = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
#ifndef MPD_DAEMON_HXX
|
#ifndef MPD_DAEMON_HXX
|
||||||
#define MPD_DAEMON_HXX
|
#define MPD_DAEMON_HXX
|
||||||
|
|
||||||
#include "mpd_error.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);
|
||||||
|
@ -48,10 +46,12 @@ daemonize_finish(void)
|
||||||
void
|
void
|
||||||
daemonize_kill(void);
|
daemonize_kill(void);
|
||||||
#else
|
#else
|
||||||
#include <glib.h>
|
#include "FatalError.hxx"
|
||||||
static inline void
|
static inline void
|
||||||
daemonize_kill(void)
|
daemonize_kill(void)
|
||||||
{ MPD_ERROR("--kill is not available on WIN32"); }
|
{
|
||||||
|
FatalError("--kill is not available on WIN32");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "DecoderError.hxx"
|
#include "DecoderError.hxx"
|
||||||
#include "DecoderPlugin.hxx"
|
#include "DecoderPlugin.hxx"
|
||||||
#include "Song.hxx"
|
#include "Song.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
#include "Mapper.hxx"
|
#include "Mapper.hxx"
|
||||||
#include "fs/Path.hxx"
|
#include "fs/Path.hxx"
|
||||||
#include "DecoderAPI.hxx"
|
#include "DecoderAPI.hxx"
|
||||||
|
@ -501,6 +501,6 @@ decoder_thread_start(struct decoder_control *dc)
|
||||||
GError *e = NULL;
|
GError *e = NULL;
|
||||||
dc->thread = g_thread_create(decoder_task, dc, true, &e);
|
dc->thread = g_thread_create(decoder_task, dc, true, &e);
|
||||||
if (dc->thread == NULL)
|
if (dc->thread == NULL)
|
||||||
MPD_ERROR("Failed to spawn decoder task: %s", e->message);
|
FatalError("Failed to spawn decoder task", e);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef G_LOG_DOMAIN
|
||||||
|
#define G_LOG_DOMAIN "FatalError"
|
||||||
|
|
||||||
|
void
|
||||||
|
FatalError(const char *msg)
|
||||||
|
{
|
||||||
|
g_critical("%s", msg);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FormatFatalError(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FatalError(GError *error)
|
||||||
|
{
|
||||||
|
FatalError(error->message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FatalError(const char *msg, GError *error)
|
||||||
|
{
|
||||||
|
FormatFatalError("%s: %s", msg, error->message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FatalSystemError(const char *msg)
|
||||||
|
{
|
||||||
|
const char *system_error;
|
||||||
|
#ifdef WIN32
|
||||||
|
system_error = g_win32_error_message(GetLastError());
|
||||||
|
#else
|
||||||
|
system_error = g_strerror(errno);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_critical("%s: %s", msg, system_error);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FormatFatalSystemError(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buffer[1024];
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(buffer, sizeof(buffer), fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
FatalSystemError(buffer);
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPD_FATAL_ERROR_HXX
|
||||||
|
#define MPD_FATAL_ERROR_HXX
|
||||||
|
|
||||||
|
#include "gerror.h"
|
||||||
|
#include "gcc.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log the specified message and abort the process.
|
||||||
|
*/
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FatalError(const char *msg);
|
||||||
|
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FormatFatalError(const char *fmt, ...);
|
||||||
|
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FatalError(GError *error);
|
||||||
|
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FatalError(const char *msg, GError *error);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call this after a system call has failed that is not supposed to
|
||||||
|
* fail. Prints the given message, the system error message (from
|
||||||
|
* errno or GetLastError()) and abort the process.
|
||||||
|
*/
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FatalSystemError(const char *msg);
|
||||||
|
|
||||||
|
gcc_noreturn
|
||||||
|
void
|
||||||
|
FormatFatalSystemError(const char *fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
|
@ -21,7 +21,7 @@
|
||||||
#include "InotifySource.hxx"
|
#include "InotifySource.hxx"
|
||||||
#include "util/fifo_buffer.h"
|
#include "util/fifo_buffer.h"
|
||||||
#include "fd_util.h"
|
#include "fd_util.h"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
@ -50,14 +50,13 @@ InotifySource::OnSocketReady(gcc_unused unsigned flags)
|
||||||
|
|
||||||
dest = fifo_buffer_write(buffer, &length);
|
dest = fifo_buffer_write(buffer, &length);
|
||||||
if (dest == NULL)
|
if (dest == NULL)
|
||||||
MPD_ERROR("buffer full");
|
FatalError("buffer full");
|
||||||
|
|
||||||
nbytes = read(Get(), dest, length);
|
nbytes = read(Get(), dest, length);
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
MPD_ERROR("failed to read from inotify: %s",
|
FatalSystemError("Failed to read from inotify");
|
||||||
g_strerror(errno));
|
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
MPD_ERROR("end of file from inotify");
|
FatalError("end of file from inotify");
|
||||||
|
|
||||||
fifo_buffer_append(buffer, nbytes);
|
fifo_buffer_append(buffer, nbytes);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "fd_util.h"
|
#include "fd_util.h"
|
||||||
|
#include "FatalError.hxx"
|
||||||
#include "mpd_error.h"
|
#include "mpd_error.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -60,9 +61,9 @@ static void redirect_logs(int fd)
|
||||||
{
|
{
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
if (dup2(fd, STDOUT_FILENO) < 0)
|
if (dup2(fd, STDOUT_FILENO) < 0)
|
||||||
MPD_ERROR("problems dup2 stdout : %s\n", strerror(errno));
|
FatalSystemError("Failed to dup2 stdout");
|
||||||
if (dup2(fd, STDERR_FILENO) < 0)
|
if (dup2(fd, STDERR_FILENO) < 0)
|
||||||
MPD_ERROR("problems dup2 stderr : %s\n", strerror(errno));
|
FatalSystemError("Failed to dup2 stderr");
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *log_date(void)
|
static const char *log_date(void)
|
||||||
|
|
36
src/Main.cxx
36
src/Main.cxx
|
@ -55,13 +55,12 @@
|
||||||
#include "AudioConfig.hxx"
|
#include "AudioConfig.hxx"
|
||||||
#include "pcm/PcmResample.hxx"
|
#include "pcm/PcmResample.hxx"
|
||||||
#include "Daemon.hxx"
|
#include "Daemon.hxx"
|
||||||
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "mpd_error.h"
|
|
||||||
|
|
||||||
#ifdef ENABLE_INOTIFY
|
#ifdef ENABLE_INOTIFY
|
||||||
#include "InotifyUpdate.hxx"
|
#include "InotifyUpdate.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
@ -194,13 +193,13 @@ glue_db_init_and_load(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DatabaseGlobalInit(*param, &error))
|
if (!DatabaseGlobalInit(*param, &error))
|
||||||
MPD_ERROR("%s", error->message);
|
FatalError(error);
|
||||||
|
|
||||||
delete allocated;
|
delete allocated;
|
||||||
|
|
||||||
ret = DatabaseGlobalOpen(&error);
|
ret = DatabaseGlobalOpen(&error);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
MPD_ERROR("%s", error->message);
|
FatalError(error);
|
||||||
|
|
||||||
/* run database update after daemonization? */
|
/* run database update after daemonization? */
|
||||||
return !db_is_simple() || db_exists();
|
return !db_is_simple() || db_exists();
|
||||||
|
@ -216,10 +215,10 @@ glue_sticker_init(void)
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *sticker_file = config_dup_path(CONF_STICKER_FILE, &error);
|
char *sticker_file = config_dup_path(CONF_STICKER_FILE, &error);
|
||||||
if (sticker_file == NULL && error != NULL)
|
if (sticker_file == NULL && error != NULL)
|
||||||
MPD_ERROR("%s", error->message);
|
FatalError(error);
|
||||||
|
|
||||||
if (!sticker_global_init(sticker_file, &error))
|
if (!sticker_global_init(sticker_file, &error))
|
||||||
MPD_ERROR("%s", error->message);
|
FatalError(error);
|
||||||
|
|
||||||
g_free(sticker_file);
|
g_free(sticker_file);
|
||||||
#endif
|
#endif
|
||||||
|
@ -268,16 +267,12 @@ static void winsock_init(void)
|
||||||
|
|
||||||
retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
|
retval = WSAStartup(MAKEWORD(2, 2), &sockinfo);
|
||||||
if(retval != 0)
|
if(retval != 0)
|
||||||
{
|
FormatFatalError("Attempt to open Winsock2 failed; error code %d",
|
||||||
MPD_ERROR("Attempt to open Winsock2 failed; error code %d\n",
|
|
||||||
retval);
|
retval);
|
||||||
}
|
|
||||||
|
|
||||||
if (LOBYTE(sockinfo.wVersion) != 2)
|
if (LOBYTE(sockinfo.wVersion) != 2)
|
||||||
{
|
FatalError("We use Winsock2 but your version is either too new "
|
||||||
MPD_ERROR("We use Winsock2 but your version is either too new "
|
"or old; please install Winsock 2.x");
|
||||||
"or old; please install Winsock 2.x\n");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,8 +293,9 @@ initialize_decoder_and_player(void)
|
||||||
if (param != NULL) {
|
if (param != NULL) {
|
||||||
long tmp = strtol(param->value, &test, 10);
|
long tmp = strtol(param->value, &test, 10);
|
||||||
if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
|
if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
|
||||||
MPD_ERROR("buffer size \"%s\" is not a positive integer, "
|
FormatFatalError("buffer size \"%s\" is not a "
|
||||||
"line %i\n", param->value, param->line);
|
"positive integer, line %i",
|
||||||
|
param->value, param->line);
|
||||||
buffer_size = tmp;
|
buffer_size = tmp;
|
||||||
} else
|
} else
|
||||||
buffer_size = DEFAULT_BUFFER_SIZE;
|
buffer_size = DEFAULT_BUFFER_SIZE;
|
||||||
|
@ -309,14 +305,16 @@ initialize_decoder_and_player(void)
|
||||||
buffered_chunks = buffer_size / CHUNK_SIZE;
|
buffered_chunks = buffer_size / CHUNK_SIZE;
|
||||||
|
|
||||||
if (buffered_chunks >= 1 << 15)
|
if (buffered_chunks >= 1 << 15)
|
||||||
MPD_ERROR("buffer size \"%li\" is too big\n", (long)buffer_size);
|
FormatFatalError("buffer size \"%lu\" is too big",
|
||||||
|
(unsigned long)buffer_size);
|
||||||
|
|
||||||
param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
|
param = config_get_param(CONF_BUFFER_BEFORE_PLAY);
|
||||||
if (param != NULL) {
|
if (param != NULL) {
|
||||||
perc = strtod(param->value, &test);
|
perc = strtod(param->value, &test);
|
||||||
if (*test != '%' || perc < 0 || perc > 100) {
|
if (*test != '%' || perc < 0 || perc > 100) {
|
||||||
MPD_ERROR("buffered before play \"%s\" is not a positive "
|
FormatFatalError("buffered before play \"%s\" is not "
|
||||||
"percentage and less than 100 percent, line %i",
|
"a positive percentage and less "
|
||||||
|
"than 100 percent, line %i",
|
||||||
param->value, param->line);
|
param->value, param->line);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -505,7 +503,7 @@ int mpd_main(int argc, char *argv[])
|
||||||
database */
|
database */
|
||||||
unsigned job = update_enqueue(NULL, true);
|
unsigned job = update_enqueue(NULL, true);
|
||||||
if (job == 0)
|
if (job == 0)
|
||||||
MPD_ERROR("directory update failed");
|
FatalError("directory update failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!glue_state_file_init(&error)) {
|
if (!glue_state_file_init(&error)) {
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "util/SliceBuffer.hxx"
|
#include "util/SliceBuffer.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ struct music_buffer : public SliceBuffer<music_chunk> {
|
||||||
music_buffer(unsigned num_chunks)
|
music_buffer(unsigned num_chunks)
|
||||||
:SliceBuffer(num_chunks) {
|
:SliceBuffer(num_chunks) {
|
||||||
if (IsOOM())
|
if (IsOOM())
|
||||||
MPD_ERROR("Failed to allocate buffer");
|
FatalError("Failed to allocate buffer");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "MusicBuffer.hxx"
|
#include "MusicBuffer.hxx"
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "notify.hxx"
|
#include "notify.hxx"
|
||||||
|
|
||||||
|
@ -128,10 +128,10 @@ audio_output_all_init(struct player_control *pc)
|
||||||
struct audio_output *output = audio_output_new(*param, pc, &error);
|
struct audio_output *output = audio_output_new(*param, pc, &error);
|
||||||
if (output == NULL) {
|
if (output == NULL) {
|
||||||
if (param != NULL)
|
if (param != NULL)
|
||||||
MPD_ERROR("line %i: %s",
|
FormatFatalError("line %i: %s",
|
||||||
param->line, error->message);
|
param->line, error->message);
|
||||||
else
|
else
|
||||||
MPD_ERROR("%s", error->message);
|
FatalError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
audio_outputs[i] = output;
|
audio_outputs[i] = output;
|
||||||
|
@ -139,8 +139,8 @@ audio_output_all_init(struct player_control *pc)
|
||||||
/* require output names to be unique: */
|
/* require output names to be unique: */
|
||||||
for (j = 0; j < i; j++) {
|
for (j = 0; j < i; j++) {
|
||||||
if (!strcmp(output->name, audio_outputs[j]->name)) {
|
if (!strcmp(output->name, audio_outputs[j]->name)) {
|
||||||
MPD_ERROR("output devices with identical "
|
FormatFatalError("output devices with identical "
|
||||||
"names: %s\n", output->name);
|
"names: %s", output->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
#include "PlayerControl.hxx"
|
#include "PlayerControl.hxx"
|
||||||
#include "MusicPipe.hxx"
|
#include "MusicPipe.hxx"
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
|
#include "FatalError.hxx"
|
||||||
#include "mpd_error.h"
|
|
||||||
#include "gcc.h"
|
#include "gcc.h"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
@ -676,6 +675,6 @@ void audio_output_thread_start(struct audio_output *ao)
|
||||||
#else
|
#else
|
||||||
GError *e = nullptr;
|
GError *e = nullptr;
|
||||||
if (!(ao->thread = g_thread_create(audio_output_task, ao, true, &e)))
|
if (!(ao->thread = g_thread_create(audio_output_task, ao, true, &e)))
|
||||||
MPD_ERROR("Failed to spawn output task: %s\n", e->message);
|
FatalError("Failed to spawn output task", e);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include "MusicChunk.hxx"
|
#include "MusicChunk.hxx"
|
||||||
#include "Song.hxx"
|
#include "Song.hxx"
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
#include "CrossFade.hxx"
|
#include "CrossFade.hxx"
|
||||||
#include "PlayerControl.hxx"
|
#include "PlayerControl.hxx"
|
||||||
#include "OutputAll.hxx"
|
#include "OutputAll.hxx"
|
||||||
|
@ -1207,6 +1207,6 @@ player_create(struct player_control *pc)
|
||||||
GError *e = NULL;
|
GError *e = NULL;
|
||||||
pc->thread = g_thread_create(player_task, pc, true, &e);
|
pc->thread = g_thread_create(player_task, pc, true, &e);
|
||||||
if (pc->thread == NULL)
|
if (pc->thread == NULL)
|
||||||
MPD_ERROR("Failed to spawn player task: %s", e->message);
|
FatalError("Failed to spawn player task", e);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,11 @@
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
#include "event/Loop.hxx"
|
#include "event/Loop.hxx"
|
||||||
#include "GlobalEvents.hxx"
|
#include "GlobalEvents.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static void exit_signal_handler(gcc_unused int signum)
|
static void exit_signal_handler(gcc_unused int signum)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +46,7 @@ static void
|
||||||
x_sigaction(int signum, const struct sigaction *act)
|
x_sigaction(int signum, const struct sigaction *act)
|
||||||
{
|
{
|
||||||
if (sigaction(signum, act, NULL) < 0)
|
if (sigaction(signum, act, NULL) < 0)
|
||||||
MPD_ERROR("sigaction() failed: %s", strerror(errno));
|
FatalSystemError("sigaction() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -33,7 +33,7 @@ extern "C" {
|
||||||
|
|
||||||
#include "Main.hxx"
|
#include "Main.hxx"
|
||||||
#include "Instance.hxx"
|
#include "Instance.hxx"
|
||||||
#include "mpd_error.h"
|
#include "FatalError.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ spawn_update_task(const char *path)
|
||||||
GError *e = NULL;
|
GError *e = NULL;
|
||||||
update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
|
update_thr = g_thread_create(update_task, g_strdup(path), TRUE, &e);
|
||||||
if (update_thr == NULL)
|
if (update_thr == NULL)
|
||||||
MPD_ERROR("Failed to spawn update task: %s", e->message);
|
FatalError("Failed to spawn update task", e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (++update_task_id > update_task_id_max)
|
if (++update_task_id > update_task_id_max)
|
||||||
|
|
Loading…
Reference in New Issue