* for more details.
*/
+#define _GNU_SOURCE /* for asprintf() */
#include <stdio.h>
#define _POSIX_PTHREAD_SEMANTICS /* for two param sigwait on OpenSolaris */
#include <signal.h>
#include <private/android_filesystem_config.h> /* for AID_VPN */
#endif
-/**
- * PID file, in which charon stores its process id
- */
-#define PID_FILE IPSEC_PIDDIR "/charon.pid"
-
/**
* Default user and group
*/
#define IPSEC_GROUP NULL
#endif
+/**
+ * Path to the PID file
+ */
+static char *pidfile_name = NULL;
+
/**
* Global reference to PID file (required to truncate, if undeletable)
*/
{
struct stat stb;
- if (stat(PID_FILE, &stb) == 0)
+ if (stat(pidfile_name, &stb) == 0)
{
- pidfile = fopen(PID_FILE, "r");
+ pidfile = fopen(pidfile_name, "r");
if (pidfile)
{
char buf[64];
return TRUE;
}
}
- DBG1(DBG_DMN, "removing pidfile '"PID_FILE"', process not running");
- unlink(PID_FILE);
+ DBG1(DBG_DMN, "removing pidfile '%s', process not running",
+ pidfile_name);
+ unlink(pidfile_name);
}
/* create new pidfile */
- pidfile = fopen(PID_FILE, "w");
+ pidfile = fopen(pidfile_name, "w");
if (pidfile)
{
int fd;
fd = fileno(pidfile);
if (fd == -1 || fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
{
- DBG1(DBG_LIB, "setting FD_CLOEXEC for '"PID_FILE"' failed: %s",
- strerror(errno));
+ DBG1(DBG_LIB, "setting FD_CLOEXEC for '%s' failed: %s",
+ pidfile_name, strerror(errno));
}
ignore_result(fchown(fileno(pidfile),
lib->caps->get_uid(lib->caps),
ignore_result(ftruncate(fileno(pidfile), 0));
fclose(pidfile);
}
- unlink(PID_FILE);
+ unlink(pidfile_name);
}
/**
struct sigaction action;
int group, status = SS_RC_INITIALIZATION_FAILED;
struct utsname utsname;
+ char *piddir;
/* logging for library during initialization, as we have no bus yet */
dbg = dbg_stderr;
}
lib->plugins->status(lib->plugins, LEVEL_CTRL);
+ piddir = lib->settings->get_str(lib->settings, "%s.piddir", IPSEC_PIDDIR,
+ lib->ns);
+ if (asprintf(&pidfile_name, "%s/charon.pid", piddir) < 0)
+ {
+ DBG1(DBG_DMN, "unable to set pidfile name - aborting charon");
+ goto deinit;
+ }
+
if (check_pidfile())
{
- DBG1(DBG_DMN, "charon already running (\""PID_FILE"\" exists)");
+ DBG1(DBG_DMN, "charon already running (\"%s\" exists)", pidfile_name);
goto deinit;
}
status = 0;
deinit:
+ free(pidfile_name);
libcharon_deinit();
libhydra_deinit();
library_deinit();