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_level = UNSET_INT;
|
||||||
static int report_dest = UNSET_INT;
|
static int report_dest = UNSET_INT;
|
||||||
char *pidfile = NULL;
|
char *pidfile = NULL;
|
||||||
|
int pidfile_written = FALSE;
|
||||||
char *displayname = NULL;
|
char *displayname = NULL;
|
||||||
char *default_shell = NULL;
|
char *default_shell = NULL;
|
||||||
|
|
||||||
@@ -144,6 +145,7 @@ int main(int argc, char **argv)
|
|||||||
if (pidf) {
|
if (pidf) {
|
||||||
fprintf(pidf, "%d\n", (int) getpid());
|
fprintf(pidf, "%d\n", (int) getpid());
|
||||||
fclose(pidf);
|
fclose(pidf);
|
||||||
|
pidfile_written = TRUE;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
||||||
pidfile, strerror(errno));
|
pidfile, strerror(errno));
|
||||||
@@ -178,7 +180,7 @@ static void exit_program(int val)
|
|||||||
//printf("exit program\n");
|
//printf("exit program\n");
|
||||||
Quit = 1;
|
Quit = 1;
|
||||||
sock_close(sock);
|
sock_close(sock);
|
||||||
if ((foreground != TRUE) && (pidfile != NULL))
|
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
exit(val);
|
exit(val);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,8 +115,9 @@ int port = LCDPORT;
|
|||||||
int foreground = FALSE;
|
int foreground = FALSE;
|
||||||
static int report_level = UNSET_INT;
|
static int report_level = UNSET_INT;
|
||||||
static int report_dest = UNSET_INT;
|
static int report_dest = UNSET_INT;
|
||||||
char *pidfile = NULL;
|
|
||||||
char *configfile = NULL;
|
char *configfile = NULL;
|
||||||
|
char *pidfile = NULL;
|
||||||
|
int pidfile_written = FALSE;
|
||||||
char *displayname = NULL;
|
char *displayname = NULL;
|
||||||
|
|
||||||
|
|
||||||
@@ -318,6 +319,7 @@ main(int argc, char **argv)
|
|||||||
if (pidf) {
|
if (pidf) {
|
||||||
fprintf(pidf, "%d\n", (int) getpid());
|
fprintf(pidf, "%d\n", (int) getpid());
|
||||||
fclose(pidf);
|
fclose(pidf);
|
||||||
|
pidfile_written = TRUE;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
||||||
pidfile, strerror(errno));
|
pidfile, strerror(errno));
|
||||||
@@ -474,7 +476,7 @@ exit_program(int val)
|
|||||||
Quit = 1;
|
Quit = 1;
|
||||||
sock_close(sock);
|
sock_close(sock);
|
||||||
mode_close();
|
mode_close();
|
||||||
if ((foreground != TRUE) && (pidfile != NULL))
|
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
exit(val);
|
exit(val);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,8 +65,9 @@ char *keys[4];
|
|||||||
|
|
||||||
/* Other global variables */
|
/* Other global variables */
|
||||||
char *progname = "lcdvc";
|
char *progname = "lcdvc";
|
||||||
char *pidfile = NULL;
|
|
||||||
char *configfile = UNSET_STR;
|
char *configfile = UNSET_STR;
|
||||||
|
char *pidfile = NULL;
|
||||||
|
int pidfile_written = FALSE;
|
||||||
|
|
||||||
int Quit = 0; /**< indicate end of main loop */
|
int Quit = 0; /**< indicate end of main loop */
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ int main(int argc, char **argv)
|
|||||||
if (pidf) {
|
if (pidf) {
|
||||||
fprintf(pidf, "%d\n", (int) getpid());
|
fprintf(pidf, "%d\n", (int) getpid());
|
||||||
fclose(pidf);
|
fclose(pidf);
|
||||||
|
pidfile_written = TRUE;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
fprintf(stderr, "Error creating pidfile %s: %s\n",
|
||||||
pidfile, strerror(errno));
|
pidfile, strerror(errno));
|
||||||
@@ -136,7 +138,7 @@ static void exit_program(int val)
|
|||||||
//printf("exit program\n");
|
//printf("exit program\n");
|
||||||
Quit = 1;
|
Quit = 1;
|
||||||
teardown_connection();
|
teardown_connection();
|
||||||
if ((foreground != TRUE) && (pidfile != NULL))
|
if ((foreground != TRUE) && (pidfile != NULL) && (pidfile_written == TRUE))
|
||||||
unlink(pidfile);
|
unlink(pidfile);
|
||||||
exit(val);
|
exit(val);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user