swtpm: remove pidfile after process exits

Remove the pidfile once swtpm process exits.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2015-11-15 13:51:05 -05:00
parent 29cfd0a4fd
commit e47bd065ff
5 changed files with 19 additions and 0 deletions

View File

@ -1237,6 +1237,8 @@ cleanup:
if (exit_prg) {
logprintf(STDOUT_FILENO,
"CUSE TPM is shutting down.\n");
pidfile_remove();
exit(0);
}

View File

@ -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);
}

View File

@ -40,5 +40,6 @@
int pidfile_set(const char *pidfile);
int pidfile_write(pid_t pid);
void pidfile_remove(void);
#endif /* _SWTPM_PIDFILE_H_ */

View File

@ -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]);

View File

@ -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]);