explicitely note & check whether a pidfile was written

This commit is contained in:
marschap
2008-02-15 07:41:09 +00:00
parent 675083f78e
commit bdd5fd780a
3 changed files with 11 additions and 5 deletions
+3 -1
View File
@@ -82,6 +82,7 @@ int foreground = FALSE;
static int report_level = UNSET_INT;
static int report_dest = UNSET_INT;
char *pidfile = NULL;
int pidfile_written = FALSE;
char *displayname = NULL;
char *default_shell = NULL;
@@ -144,6 +145,7 @@ int main(int argc, char **argv)
if (pidf) {
fprintf(pidf, "%d\n", (int) getpid());
fclose(pidf);
pidfile_written = TRUE;
} else {
fprintf(stderr, "Error creating pidfile %s: %s\n",
pidfile, strerror(errno));
@@ -178,7 +180,7 @@ static void exit_program(int val)
//printf("exit program\n");
Quit = 1;
sock_close(sock);
if ((foreground != TRUE) && (pidfile != NULL))
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
unlink(pidfile);
exit(val);
}