explicitely note & check whether a pidfile was written
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -115,8 +115,9 @@ int port = LCDPORT;
|
||||
int foreground = FALSE;
|
||||
static int report_level = UNSET_INT;
|
||||
static int report_dest = UNSET_INT;
|
||||
char *pidfile = NULL;
|
||||
char *configfile = NULL;
|
||||
char *pidfile = NULL;
|
||||
int pidfile_written = FALSE;
|
||||
char *displayname = NULL;
|
||||
|
||||
|
||||
@@ -318,6 +319,7 @@ 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));
|
||||
@@ -474,7 +476,7 @@ exit_program(int val)
|
||||
Quit = 1;
|
||||
sock_close(sock);
|
||||
mode_close();
|
||||
if ((foreground != TRUE) && (pidfile != NULL))
|
||||
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
|
||||
unlink(pidfile);
|
||||
exit(val);
|
||||
}
|
||||
|
||||
@@ -65,8 +65,9 @@ char *keys[4];
|
||||
|
||||
/* Other global variables */
|
||||
char *progname = "lcdvc";
|
||||
char *pidfile = NULL;
|
||||
char *configfile = UNSET_STR;
|
||||
char *pidfile = NULL;
|
||||
int pidfile_written = FALSE;
|
||||
|
||||
int Quit = 0; /**< indicate end of main loop */
|
||||
|
||||
@@ -108,6 +109,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));
|
||||
@@ -136,7 +138,7 @@ static void exit_program(int val)
|
||||
//printf("exit program\n");
|
||||
Quit = 1;
|
||||
teardown_connection();
|
||||
if ((foreground != TRUE) && (pidfile != NULL))
|
||||
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
|
||||
unlink(pidfile);
|
||||
exit(val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user