Fix restart of restconf processes
This commit is contained in:
parent
f65efa3e5e
commit
40008f182e
5 changed files with 77 additions and 35 deletions
|
|
@ -154,6 +154,7 @@ create_socket(struct sockaddr *sa,
|
|||
*sock = s;
|
||||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, retval);
|
||||
if (retval != 0 && s != -1)
|
||||
close(s);
|
||||
return retval;
|
||||
|
|
@ -178,29 +179,36 @@ fork_netns_socket(const char *netns,
|
|||
int sp[2] = {-1, -1};
|
||||
pid_t child;
|
||||
int status = 0;
|
||||
char nspath[MAXPATHLEN]; /* Path to namespace file */
|
||||
struct stat st;
|
||||
|
||||
clicon_debug(1, "%s %s", __FUNCTION__, netns);
|
||||
if (socketpair(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0, sp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "socketpair");
|
||||
goto done;
|
||||
}
|
||||
/* Check namespace exists */
|
||||
sprintf(nspath,"/var/run/netns/%s", netns);
|
||||
if (stat(nspath, &st) < 0){
|
||||
clicon_err(OE_UNIX, errno, ": stat(%s)", nspath);
|
||||
goto done;
|
||||
}
|
||||
if ((child = fork()) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "fork");
|
||||
goto done;
|
||||
}
|
||||
if (child == 0) { /* Child */
|
||||
char path[MAXPATHLEN];
|
||||
int fd;
|
||||
int s = -1;
|
||||
|
||||
close(sp[0]);
|
||||
/* Switch to namespace */
|
||||
sprintf(path,"/var/run/netns/%s", netns);
|
||||
if ((fd=open(path, O_RDONLY)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "open");
|
||||
if ((fd=open(nspath, O_RDONLY)) < 0) {
|
||||
clicon_err(OE_UNIX, errno, "open(%s)", nspath);
|
||||
return -1;
|
||||
}
|
||||
if (setns(fd, CLONE_NEWNET) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setns");
|
||||
clicon_err(OE_UNIX, errno, "setns(%s)%d", netns, errno);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
|
@ -220,8 +228,10 @@ fork_netns_socket(const char *netns,
|
|||
goto done;
|
||||
close(sp[0]);
|
||||
if(waitpid(child, &status, 0) == child)
|
||||
retval = WEXITSTATUS(status);
|
||||
; // retval = WEXITSTATUS(status); /* Dont know what to do with status */
|
||||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
@ -254,5 +264,6 @@ clixon_netns_socket(const char *netns,
|
|||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s %d", __FUNCTION__, retval);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ struct process_entry_t {
|
|||
char *pe_netns; /* Network namespace */
|
||||
char **pe_argv; /* argv with command as element 0 and NULL-terminated */
|
||||
pid_t pe_pid; /* Running process id (state) or 0 if dead */
|
||||
proc_cb_t *pe_callback; /* Wrapper function */
|
||||
proc_cb_t *pe_callback; /* Wrapper function, may be called from process_operation */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -303,12 +303,14 @@ static process_entry_t *proc_entry_list = NULL;
|
|||
|
||||
/*! Register an internal process
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] name Process name
|
||||
* @param[in] netns Namespace netspace (or NULL)
|
||||
* @param[in] argv NULL-terminated vector of vectors
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] name Process name
|
||||
* @param[in] netns Namespace netspace (or NULL)
|
||||
* @param[in] callback
|
||||
* @param[in] argv NULL-terminated vector of vectors
|
||||
* @param[in] argc Length of argv
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note name, netns, argv and its elements are all copied / re-alloced.
|
||||
*/
|
||||
int
|
||||
|
|
@ -502,3 +504,37 @@ clixon_process_operation(clicon_handle h,
|
|||
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Start all processes that are enabled
|
||||
* @param[in] h Clixon handle
|
||||
* Commit rules should have done this, but there are some cases such as backend -s none mode
|
||||
* where commits are not made.
|
||||
*/
|
||||
int
|
||||
clixon_process_start_all(clicon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
process_entry_t *pe;
|
||||
char *op;
|
||||
|
||||
clicon_debug(1, "%s",__FUNCTION__);
|
||||
if (proc_entry_list == NULL)
|
||||
goto ok;
|
||||
pe = proc_entry_list;
|
||||
do {
|
||||
op = "start";
|
||||
/* Call wrapper function that eg changes op based on config */
|
||||
if (pe->pe_callback != NULL)
|
||||
if (pe->pe_callback(h, pe, &op) < 0)
|
||||
goto done;
|
||||
if (strcmp(op, "start") == 0)
|
||||
if (clixon_process_operation_one("start", pe->pe_netns, pe->pe_argv, &pe->pe_pid) < 0)
|
||||
goto done;
|
||||
pe = NEXTQ(process_entry_t *, pe);
|
||||
} while (pe != proc_entry_list);
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
clicon_debug(1, "%s retval:%d", __FUNCTION__, retval);
|
||||
return retval;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue