diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-11-07 10:30:05 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-11-10 10:55:43 +0100 |
commit | 1b4d97dbb7f9976b623f527f47b3acfcdc1f4b73 (patch) | |
tree | 558c6f1b7a7892991a574f742d3eb4f354bdf748 /src | |
parent | 9cc61baaf592b126cde2dfeab3fbb8961970c1d6 (diff) | |
download | strongswan-1b4d97dbb7f9976b623f527f47b3acfcdc1f4b73.tar.bz2 strongswan-1b4d97dbb7f9976b623f527f47b3acfcdc1f4b73.tar.xz |
charon: Unlink PID file after daemon deinit (i.e. after unloading plugins etc.)
Make sure, though, that we only remove the file if we actually
created it (e.g. not for --help or --version). And do so before
deinitializing libstrongswan due to leak detective.
Fixes #2460.
Diffstat (limited to 'src')
-rw-r--r-- | src/charon/charon.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/charon/charon.c b/src/charon/charon.c index 520cb3c74..5d866ee0d 100644 --- a/src/charon/charon.c +++ b/src/charon/charon.c @@ -1,9 +1,9 @@ /* - * Copyright (C) 2006-2012 Tobias Brunner + * Copyright (C) 2006-2017 Tobias Brunner * Copyright (C) 2005-2009 Martin Willi * Copyright (C) 2006 Daniel Roethlisberger * Copyright (C) 2005 Jan Hutter - * Hochschule fuer Technik Rapperswil + * HSR Hochschule fuer Technik Rapperswil * * 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 @@ -203,8 +203,10 @@ static bool check_pidfile() pid = atoi(buf); } fclose(pidfile); + pidfile = NULL; if (pid && kill(pid, 0) == 0) - { /* such a process is running */ + { + DBG1(DBG_DMN, "charon already running ('"PID_FILE"' exists)"); return TRUE; } } @@ -224,13 +226,18 @@ static bool check_pidfile() DBG1(DBG_LIB, "setting FD_CLOEXEC for '"PID_FILE"' failed: %s", strerror(errno)); } - ignore_result(fchown(fileno(pidfile), + ignore_result(fchown(fd, lib->caps->get_uid(lib->caps), lib->caps->get_gid(lib->caps))); fprintf(pidfile, "%d\n", getpid()); fflush(pidfile); + return FALSE; + } + else + { + DBG1(DBG_DMN, "unable to create pidfile '"PID_FILE"'"); + return TRUE; } - return FALSE; } /** @@ -246,8 +253,8 @@ static void unlink_pidfile() { ignore_result(ftruncate(fileno(pidfile), 0)); fclose(pidfile); + unlink(PID_FILE); } - unlink(PID_FILE); } /** @@ -402,7 +409,6 @@ int main(int argc, char *argv[]) if (check_pidfile()) { - DBG1(DBG_DMN, "charon already running (\""PID_FILE"\" exists)"); goto deinit; } @@ -434,12 +440,11 @@ int main(int argc, char *argv[]) /* main thread goes to run loop */ run(); - /* normal termination, cleanup and exit */ - unlink_pidfile(); status = 0; deinit: libcharon_deinit(); + unlink_pidfile(); library_deinit(); return status; } |