- Better restconf debug: when restconf debug flag set in datastore, ensure the process is started with -D set
- Fixed native http support for base container - Changed test certs and restconf scripts to functions
This commit is contained in:
parent
244060fddc
commit
15d01c58d8
49 changed files with 539 additions and 103 deletions
|
|
@ -62,6 +62,7 @@ int clixon_proc_socket(char **argv, pid_t *pid, int *sock);
|
|||
int clixon_proc_socket_close(pid_t pid, int sock);
|
||||
int clixon_proc_background(char **argv, const char *netns, pid_t *pid);
|
||||
proc_operation clixon_process_op_str2int(char *opstr);
|
||||
int clixon_process_argv_get(clicon_handle h, const char *name, char ***argv, int *argc);
|
||||
int clixon_process_register(clicon_handle h, const char *name, const char *descr, const char *netns, proc_cb_t *callback, char **argv, int argc);
|
||||
int clixon_process_delete_all(clicon_handle h);
|
||||
int clixon_process_operation(clicon_handle h, const char *name, proc_operation op, const int wrapit);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,20 @@
|
|||
***** END LICENSE BLOCK *****
|
||||
|
||||
* Processes daemons
|
||||
* States of processes:
|
||||
A description of process states.
|
||||
It starts in a STOPPED state. On operation "start" or "restart" it gets a pid and goes into RUNNING:
|
||||
STOPPED --(re)start--> RUNNING
|
||||
In RUNNING several things can happen:
|
||||
- It is killed externally: the process then gets a SIGCHLD which triggers a wait and it goes into STOPPED:
|
||||
RUNNING --sigchld/wait--> STOPPED
|
||||
It is stopped due to an rpc or by config commit removing the config. In that case the parent
|
||||
process kills the process and enters into EXITING waiting for a SIGCHLD that triggers a wait:
|
||||
RUNNING --stop--> EXITING --sigchld/wait--> STOPPED
|
||||
It is restarted due to an rpc or config change (eg a server is added, a key modified, etc). Then
|
||||
a new process is started which enters RUNNING, while the old process (the dying clone) enters EXITING:
|
||||
STOPPED --restart--> RUNNING(newpid)
|
||||
RUNNING --stop--> EXITING --sigchld/wait--> REMOVED (oldpid/clone)
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
@ -313,7 +327,40 @@ clixon_process_op_str2int(char *opstr)
|
|||
return clicon_str2int(proc_operation_map, opstr);
|
||||
}
|
||||
|
||||
/*! Make a copy of process-entry struct */
|
||||
/*! Access function process list argv list
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] name Name of process
|
||||
* @param[out] argv Malloced argv list (Null terminated)
|
||||
* @param[out] argc Length of argv
|
||||
*
|
||||
* @note Can be used to change in the argv list elements directly with care: Dont change list
|
||||
* itself, but its elements can be freed and re-alloced.
|
||||
*/
|
||||
int
|
||||
clixon_process_argv_get(clicon_handle h,
|
||||
const char *name,
|
||||
char ***argv,
|
||||
int *argc)
|
||||
{
|
||||
process_entry_t *pe;
|
||||
|
||||
pe = _proc_entry_list;
|
||||
do {
|
||||
if (strcmp(pe->pe_name, name) == 0){
|
||||
*argv = pe->pe_argv;
|
||||
*argc = pe->pe_argc;
|
||||
}
|
||||
pe = NEXTQ(process_entry_t *, pe);
|
||||
} while (pe != _proc_entry_list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Make a copy of process-entry struct
|
||||
*
|
||||
* @param[in] pe0 Original process-entry
|
||||
* @param[in] pnew New copy of pe0
|
||||
*/
|
||||
static int
|
||||
clixon_process_register_dup(process_entry_t *pe0,
|
||||
process_entry_t **pnew)
|
||||
|
|
@ -604,10 +651,13 @@ clixon_process_status(clicon_handle h,
|
|||
cprintf(cbret, "%s", pe->pe_argv[i]);
|
||||
}
|
||||
cprintf(cbret, "</command>");
|
||||
cprintf(cbret, "<status xmlns=\"%s\">%u</status>", CLIXON_LIB_NS, pe->pe_status);
|
||||
if (run && time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0)
|
||||
goto done;
|
||||
cprintf(cbret, "<starttime xmlns=\"%s\">%s</starttime>", CLIXON_LIB_NS, timestr);
|
||||
if (run && timerisset(&pe->pe_starttime)){
|
||||
if (time2str(pe->pe_starttime, timestr, sizeof(timestr)) < 0){
|
||||
clicon_err(OE_UNIX, errno, "time2str");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cbret, "<starttime xmlns=\"%s\">%s</starttime>", CLIXON_LIB_NS, timestr);
|
||||
}
|
||||
cprintf(cbret, "</rpc-reply>");
|
||||
break; /* hit break here */
|
||||
}
|
||||
|
|
@ -706,16 +756,26 @@ clixon_process_sched(int fd,
|
|||
}
|
||||
if (op == PROC_OP_STOP)
|
||||
break;
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &newpid) < 0)
|
||||
goto done;
|
||||
gettimeofday(&pe->pe_starttime, NULL);
|
||||
clicon_debug(1, "%s restart pid:%d -> %d", __FUNCTION__, pe->pe_pid, newpid);
|
||||
/* Create a new pe */
|
||||
if (clixon_process_register_dup(pe, &pe1) < 0)
|
||||
goto done;
|
||||
pe->pe_clone = 1; /* Delete when reaped */
|
||||
pe1->pe_op = PROC_OP_NONE; /* Dont restart again */
|
||||
pe1->pe_pid = newpid;
|
||||
if (!run){
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &pe->pe_pid) < 0)
|
||||
goto done;
|
||||
gettimeofday(&pe->pe_starttime, NULL);
|
||||
clicon_debug(1, "%s started pid:%d", __FUNCTION__, pe->pe_pid);
|
||||
}
|
||||
else {
|
||||
/* This is the case where there is an existing process running.
|
||||
* it was killed above but still runs and needs to be reaped */
|
||||
if (clixon_proc_background(pe->pe_argv, pe->pe_netns, &newpid) < 0)
|
||||
goto done;
|
||||
gettimeofday(&pe->pe_starttime, NULL);
|
||||
clicon_debug(1, "%s restart pid:%d -> %d", __FUNCTION__, pe->pe_pid, newpid);
|
||||
/* Create a new pe */
|
||||
if (clixon_process_register_dup(pe, &pe1) < 0)
|
||||
goto done;
|
||||
pe->pe_clone = 1; /* Delete when reaped */
|
||||
pe1->pe_op = PROC_OP_NONE; /* Dont restart again */
|
||||
pe1->pe_pid = newpid;
|
||||
}
|
||||
break;
|
||||
case PROC_OP_START:
|
||||
if (run) /* Already runs */
|
||||
|
|
|
|||
|
|
@ -331,6 +331,7 @@ clicon_msg_send(int s,
|
|||
struct clicon_msg *msg)
|
||||
{
|
||||
int retval = -1;
|
||||
int e;
|
||||
|
||||
clicon_debug(2, "%s: send msg len=%d",
|
||||
__FUNCTION__, ntohl(msg->op_len));
|
||||
|
|
@ -338,9 +339,10 @@ clicon_msg_send(int s,
|
|||
msg_dump(msg);
|
||||
if (atomicio((ssize_t (*)(int, void *, size_t))write,
|
||||
s, msg, ntohl(msg->op_len)) < 0){
|
||||
clicon_err(OE_CFG, errno, "atomicio");
|
||||
e = errno;
|
||||
clicon_err(OE_CFG, e, "atomicio");
|
||||
clicon_log(LOG_WARNING, "%s: write: %s len:%u msg:%s", __FUNCTION__,
|
||||
strerror(errno), ntohs(msg->op_len), msg->op_body);
|
||||
strerror(e), ntohs(msg->op_len), msg->op_body);
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue