added PID file location to autoconf (i.e. use localstatedir/var), fixed empty PID file and permissions

This commit is contained in:
john30
2015-01-31 11:39:52 +01:00
parent a8231fd5db
commit e007e85762
3 changed files with 14 additions and 6 deletions
+3 -1
View File
@@ -31,7 +31,7 @@ AC_CHECK_FUNC([pselect], [AC_DEFINE(HAVE_PSELECT, [1], ["Define to 1 if pselect(
AC_CHECK_FUNC([ppoll], [AC_DEFINE(HAVE_PPOLL, [1], ["Define to 1 if ppoll() is available."])])
AC_CONFIG_AUX_DIR([build])
AC_CONFIG_SRCDIR([src/ebusd/ebusd.cpp])
AC_CONFIG_SRCDIR([src/ebusd/main.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile
docs/Makefile
@@ -41,6 +41,8 @@ AC_CONFIG_FILES([Makefile
src/ebusd/Makefile
src/tools/Makefile])
AC_DEFINE_UNQUOTED(PACKAGE_PIDFILE, LOCALSTATEDIR "/" PACKAGE ".pid", [The name of the PID file.])
AC_CHECK_PROGS([HAVE_DOXYGEN], [doxygen])
if test -z "$HAVE_DOXYGEN";
then AC_MSG_WARN([Doxygen not found - continuing without Doxygen support.])
+2 -1
View File
@@ -2,7 +2,8 @@ AM_CXXFLAGS = -fpic \
-Wall \
-Wextra \
-isystem$(top_srcdir)/src/lib/utils \
-isystem$(top_srcdir)/src/lib/ebus
-isystem$(top_srcdir)/src/lib/ebus \
-DLOCALSTATEDIR=\"$(localstatedir)\"
bin_PROGRAMS = ebusd
+9 -4
View File
@@ -34,7 +34,11 @@
#include <sys/stat.h>
/** the name of the PID file. */
#ifdef PACKAGE_PIDFILE
#define PID_FILE_NAME PACKAGE_PIDFILE
#else
#define PID_FILE_NAME "/var/run/ebusd.pid"
#endif
/** the opened PID file, or NULL. */
static FILE* pidFile = NULL;
@@ -297,7 +301,7 @@ void daemonize()
// Change the current working directory. This prevents the current
// directory from being locked; hence not being able to remove it.
if (chdir("/tmp") < 0) { // TODO
if (chdir("/tmp") < 0) { // TODO use constant
logError(lf_main, "daemon chdir() failed");
exit(EXIT_FAILURE);
}
@@ -308,11 +312,12 @@ void daemonize()
close(STDERR_FILENO);
// create pid file and try to lock it
umask(077); // leads to pidFile created in mode 0600
pidFile = fopen(PID_FILE_NAME, "w");
umask(027); // Set file permissions 750
pidFile = fopen(PID_FILE_NAME, "w+");
umask(S_IWGRP | S_IRWXO); // set permissions of newly created files to 750
if (pidFile != NULL) {
setbuf(pidFile, NULL); // disable buffering
if (lockf(fileno(pidFile), F_TLOCK, 0) < 0
|| fprintf(pidFile, "%d\n", getpid()) <=0) {
fclose(pidFile);