From e47bd065ffa456f6a328a2e4ece5a271f4fc4dc7 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Sun, 15 Nov 2015 13:51:05 -0500 Subject: [PATCH] swtpm: remove pidfile after process exits Remove the pidfile once swtpm process exits. Signed-off-by: Stefan Berger --- src/swtpm/cuse_tpm.c | 2 ++ src/swtpm/pidfile.c | 12 ++++++++++++ src/swtpm/pidfile.h | 1 + src/swtpm/swtpm.c | 2 ++ src/swtpm/swtpm_chardev.c | 2 ++ 5 files changed, 19 insertions(+) diff --git a/src/swtpm/cuse_tpm.c b/src/swtpm/cuse_tpm.c index b4a749c..3c0650f 100644 --- a/src/swtpm/cuse_tpm.c +++ b/src/swtpm/cuse_tpm.c @@ -1237,6 +1237,8 @@ cleanup: if (exit_prg) { logprintf(STDOUT_FILENO, "CUSE TPM is shutting down.\n"); + pidfile_remove(); + exit(0); } diff --git a/src/swtpm/pidfile.c b/src/swtpm/pidfile.c index 3a8991d..5a5c1e8 100644 --- a/src/swtpm/pidfile.c +++ b/src/swtpm/pidfile.c @@ -94,3 +94,15 @@ int pidfile_write(pid_t pid) error: return -1; } + +/* + * pidfile_remove: Remove the pid file + * + */ +void pidfile_remove(void) +{ + if (!g_pidfile) + return; + + unlink(g_pidfile); +} \ No newline at end of file diff --git a/src/swtpm/pidfile.h b/src/swtpm/pidfile.h index 83bd65f..b212a87 100644 --- a/src/swtpm/pidfile.h +++ b/src/swtpm/pidfile.h @@ -40,5 +40,6 @@ int pidfile_set(const char *pidfile); int pidfile_write(pid_t pid); +void pidfile_remove(void); #endif /* _SWTPM_PIDFILE_H_ */ diff --git a/src/swtpm/swtpm.c b/src/swtpm/swtpm.c index bbad9ce..1e452e8 100644 --- a/src/swtpm/swtpm.c +++ b/src/swtpm/swtpm.c @@ -322,6 +322,8 @@ int swtpm_main(int argc, char **argv, const char *prgname, const char *iface) TPMLIB_Terminate(); } + pidfile_remove(); + close(notify_fd[0]); notify_fd[0] = -1; close(notify_fd[1]); diff --git a/src/swtpm/swtpm_chardev.c b/src/swtpm/swtpm_chardev.c index 3f13dd8..c49ba54 100644 --- a/src/swtpm/swtpm_chardev.c +++ b/src/swtpm/swtpm_chardev.c @@ -311,6 +311,8 @@ int swtpm_chardev_main(int argc, char **argv, const char *prgname, const char *i TPMLIB_Terminate(); } + pidfile_remove(); + close(notify_fd[0]); notify_fd[0] = -1; close(notify_fd[1]);