Add timeout 100ms before every kill restconf iteration
This commit is contained in:
parent
7023fe589f
commit
40f4df1390
2 changed files with 26 additions and 21 deletions
|
|
@ -69,7 +69,6 @@ int clixon_process_delete_all(clicon_handle h);
|
||||||
int clixon_process_operation(clicon_handle h, const char *name, proc_operation op, const int wrapit);
|
int clixon_process_operation(clicon_handle h, const char *name, proc_operation op, const int wrapit);
|
||||||
int clixon_process_status(clicon_handle h, const char *name, cbuf *cbret);
|
int clixon_process_status(clicon_handle h, const char *name, cbuf *cbret);
|
||||||
int clixon_process_start_all(clicon_handle h);
|
int clixon_process_start_all(clicon_handle h);
|
||||||
int clixon_process_sched_register(clicon_handle h);
|
|
||||||
int clixon_process_waitpid(clicon_handle h);
|
int clixon_process_waitpid(clicon_handle h);
|
||||||
|
|
||||||
#endif /* _CLIXON_PROC_H_ */
|
#endif /* _CLIXON_PROC_H_ */
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
| stop/| |
|
| stop/| |
|
||||||
| restart| | restart
|
| restart| | restart
|
||||||
| v |
|
| v |
|
||||||
wait(stop) ------- EXITING(dying pid)
|
wait(stop) ------- EXITING(dying pid) <----> kill after timeout
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
|
@ -151,6 +151,10 @@ struct process_entry_t {
|
||||||
proc_cb_t *pe_callback; /* Wrapper function, may be called from process_operation */
|
proc_cb_t *pe_callback; /* Wrapper function, may be called from process_operation */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Forward declaration */
|
||||||
|
static int clixon_process_sched_register(clicon_handle h, int delay);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clixon_proc_sigint(int sig)
|
clixon_proc_sigint(int sig)
|
||||||
{
|
{
|
||||||
|
|
@ -598,6 +602,7 @@ clixon_process_operation(clicon_handle h,
|
||||||
proc_operation op;
|
proc_operation op;
|
||||||
int sched = 0; /* If set, process action should be scheduled, register a timeout */
|
int sched = 0; /* If set, process action should be scheduled, register a timeout */
|
||||||
int isrunning = 0;
|
int isrunning = 0;
|
||||||
|
int delay = 0;
|
||||||
|
|
||||||
clicon_debug(1, "%s name:%s op:%s", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
|
clicon_debug(1, "%s name:%s op:%s", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
|
||||||
if (_proc_entry_list == NULL)
|
if (_proc_entry_list == NULL)
|
||||||
|
|
@ -624,7 +629,7 @@ clixon_process_operation(clicon_handle h,
|
||||||
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||||
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
||||||
kill(pe->pe_pid, SIGTERM);
|
kill(pe->pe_pid, SIGTERM);
|
||||||
|
delay = 1;
|
||||||
}
|
}
|
||||||
clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
|
clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__,
|
||||||
pe->pe_name, pe->pe_pid,
|
pe->pe_name, pe->pe_pid,
|
||||||
|
|
@ -633,9 +638,8 @@ clixon_process_operation(clicon_handle h,
|
||||||
clicon_int2str(proc_state_map, PROC_STATE_EXITING)
|
clicon_int2str(proc_state_map, PROC_STATE_EXITING)
|
||||||
);
|
);
|
||||||
pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */
|
pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */
|
||||||
// break;
|
}
|
||||||
}
|
sched++;/* start: immediate stop/restart: not immediate: wait timeout */
|
||||||
sched++;
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
clicon_debug(1, "%s name:%s op %s cancelled by wrwap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
|
clicon_debug(1, "%s name:%s op %s cancelled by wrwap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0));
|
||||||
|
|
@ -644,7 +648,7 @@ clixon_process_operation(clicon_handle h,
|
||||||
}
|
}
|
||||||
pe = NEXTQ(process_entry_t *, pe);
|
pe = NEXTQ(process_entry_t *, pe);
|
||||||
} while (pe != _proc_entry_list);
|
} while (pe != _proc_entry_list);
|
||||||
if (sched && clixon_process_sched_register(h) < 0)
|
if (sched && clixon_process_sched_register(h, delay) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -741,11 +745,11 @@ clixon_process_start_all(clicon_handle h)
|
||||||
goto done;
|
goto done;
|
||||||
if (op == PROC_OP_START){
|
if (op == PROC_OP_START){
|
||||||
pe->pe_operation = op;
|
pe->pe_operation = op;
|
||||||
sched++;
|
sched++; /* Immediate dont delay for start */
|
||||||
}
|
}
|
||||||
pe = NEXTQ(process_entry_t *, pe);
|
pe = NEXTQ(process_entry_t *, pe);
|
||||||
} while (pe != _proc_entry_list);
|
} while (pe != _proc_entry_list);
|
||||||
if (sched && clixon_process_sched_register(h) < 0)
|
if (sched && clixon_process_sched_register(h, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -793,7 +797,7 @@ clixon_process_sched(int fd,
|
||||||
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d",
|
||||||
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */
|
||||||
kill(pe->pe_pid, SIGTERM);
|
kill(pe->pe_pid, SIGTERM);
|
||||||
sched++;
|
sched++; /* Not immediate: wait timeout */
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -853,7 +857,7 @@ clixon_process_sched(int fd,
|
||||||
}
|
}
|
||||||
pe = NEXTQ(process_entry_t *, pe);
|
pe = NEXTQ(process_entry_t *, pe);
|
||||||
} while (pe != _proc_entry_list);
|
} while (pe != _proc_entry_list);
|
||||||
if (sched && clixon_process_sched_register(h) < 0)
|
if (sched && clixon_process_sched_register(h, 1) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
@ -863,23 +867,25 @@ clixon_process_sched(int fd,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Register scheduling of process start/stop/restart
|
/*! Register scheduling of process start/stop/restart
|
||||||
* After a delay t1, schedule the process
|
*
|
||||||
* @note The delay is for mitigating a race condition if a process is restarted that is used in the
|
* Schedule a process event. There are two cases:
|
||||||
* session restarting it. In this way, the process "should have" time to exit.
|
* 1) A process has been killed and is in EXITING, after a delay kill again.
|
||||||
* However, for slow machines, this delay may need to be longer.
|
* 2) A process is started, dont delay
|
||||||
* On a Raspberry pi it was measured to need be 1.5ms.
|
* @param[in] h Clixon handle
|
||||||
* However, if it is much longer, it may kill restconf as an unrelated session has been opened.
|
* @param[in] delay If 0 dont add a delay, if 1 add a delay
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
clixon_process_sched_register(clicon_handle h)
|
clixon_process_sched_register(clicon_handle h,
|
||||||
|
int delay)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
struct timeval t1 = {0, 1500}; /* See discussion ^*/
|
struct timeval t1 = {0, 100000}; /* 100ms */
|
||||||
|
|
||||||
clicon_debug(2, "%s", __FUNCTION__);
|
clicon_debug(2, "%s", __FUNCTION__);
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
timeradd(&t, &t1, &t);
|
if (delay)
|
||||||
|
timeradd(&t, &t1, &t);
|
||||||
if (clixon_event_reg_timeout(t, clixon_process_sched, h, "process") < 0)
|
if (clixon_event_reg_timeout(t, clixon_process_sched, h, "process") < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue