mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-25 05:20:02 +00:00
Fix broken stopfile logic
'start' command removes stopfile just before starting 'stop' command removes stopfile after stopping
This commit is contained in:
parent
329189ec8c
commit
391e8d7056
@ -570,6 +570,8 @@ int app_server_start(int argc, const char *const *argv, struct command_line_opti
|
||||
instance directory when it starts up.
|
||||
We can just become the server process ourselves --- no need to fork.
|
||||
*/
|
||||
if (server_remove_stopfile() == -1)
|
||||
return -1;
|
||||
rhizome_datastore_path = serval_instancepath();
|
||||
rhizome_opendb();
|
||||
overlayMode = 1;
|
||||
@ -678,6 +680,7 @@ int app_server_stop(int argc, const char *const *argv, struct command_line_optio
|
||||
nanosleep(&delay, NULL);
|
||||
} while ((running = server_pid()) == pid && overlay_gettime_ms() < timeout);
|
||||
}
|
||||
server_remove_stopfile();
|
||||
cli_puts("tries");
|
||||
cli_delim(":");
|
||||
cli_printf("%d", tries);
|
||||
|
1
serval.h
1
serval.h
@ -400,6 +400,7 @@ int server_pid();
|
||||
int server(char *backing_file);
|
||||
void server_shutdown_check();
|
||||
int server_create_stopfile();
|
||||
int server_remove_stopfile();
|
||||
int server_check_stopfile();
|
||||
void serverCleanUp();
|
||||
int isTransactionInCache(unsigned char *transaction_id);
|
||||
|
22
server.c
22
server.c
@ -212,11 +212,24 @@ int server_create_stopfile()
|
||||
return -1;
|
||||
FILE *f;
|
||||
if ((f = fopen(stopfile, "w")) == NULL)
|
||||
return WHYF("Could not create stopfile '%s'", stopfile);
|
||||
return WHYF("Could not create stopfile '%s': %s [errno=%d]", stopfile, strerror(errno), errno);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int server_remove_stopfile()
|
||||
{
|
||||
char stopfile[1024];
|
||||
if (!FORM_SERVAL_INSTANCE_PATH(stopfile, STOPFILE_NAME))
|
||||
return -1;
|
||||
if (unlink(stopfile) == -1) {
|
||||
if (errno == ENOENT)
|
||||
return 0;
|
||||
return WHYF("Could not unlink stopfile '%s': %s [errno=%d]", stopfile, strerror(errno), errno);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int server_check_stopfile()
|
||||
{
|
||||
char stopfile[1024];
|
||||
@ -234,13 +247,10 @@ int server_check_stopfile()
|
||||
void serverCleanUp()
|
||||
{
|
||||
/* Try to remove shutdown and PID files and exit */
|
||||
server_remove_stopfile();
|
||||
char filename[1024];
|
||||
if (FORM_SERVAL_INSTANCE_PATH(filename, STOPFILE_NAME)) {
|
||||
if (FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME))
|
||||
unlink(filename);
|
||||
}
|
||||
if (FORM_SERVAL_INSTANCE_PATH(filename, PIDFILE_NAME)) {
|
||||
unlink(filename);
|
||||
}
|
||||
if (mdp_client_socket==-1) {
|
||||
if (FORM_SERVAL_INSTANCE_PATH(filename, "mdp.socket")) {
|
||||
unlink(filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user