* New process-control RPC feature in clixon-lib.yang to manage processes

* This is an alternative to manage a clixon daemon via sudtemd, containerd or other
  * One important special case is starting the clixon-restconf daemon internally
  * This is how it works:
    * Register a process via `clixon_process_register(h, name, namespace, argv, argc)`
    * Use process-control RPC defined in clixon-lib.yang to start/stop/restart or query status on that process
  * Example code in the main example
This commit is contained in:
Olof hagsand 2020-12-15 14:43:01 +01:00
parent 8540820698
commit 22adc58187
19 changed files with 971 additions and 47 deletions

View file

@ -80,7 +80,6 @@ set_signal(int signo,
#endif
}
/*! Block signal.
* @param[in] sig Signal number to block, If 0, block all signals
*/
@ -117,34 +116,50 @@ clicon_signal_unblock (int sig)
sigprocmask (SIG_UNBLOCK, &set, NULL);
}
/*! Read pidfile and return pid using file descriptor
*
* @param[in] pidfile Name of pidfile
* @param[out] pid Process id of (eventual) existing daemon process
* @retval 0 OK. if pid > 0 old process exists w that pid
* @retval -1 Error, and clicon_err() called
*/
int
pidfile_get_fd(FILE *f,
pid_t *pid0)
{
char *ptr;
char buf[32];
pid_t pid;
*pid0 = 0;
ptr = fgets(buf, sizeof(buf), f);
if (ptr != NULL && (pid = atoi(ptr)) > 1) {
if (kill(pid, 0) == 0 || errno != ESRCH) {
/* Yes there is a process */
*pid0 = pid;
}
}
return 0;
}
/*! Read pidfile and return pid, if any
*
* @param[in] pidfile Name of pidfile
* @param[out] pid0 Process id of (eventual) existing daemon process
* @param[out] pid Process id of (eventual) existing daemon process
* @retval 0 OK. if pid > 0 old process exists w that pid
* @retval -1 Error, and clicon_err() called
*/
int
pidfile_get(char *pidfile,
pid_t *pid0)
pid_t *pid)
{
FILE *f;
char *ptr;
char buf[32];
pid_t pid;
if ((f = fopen (pidfile, "r")) != NULL){
ptr = fgets(buf, sizeof(buf), f);
fclose (f);
if (ptr != NULL && (pid = atoi (ptr)) > 1) {
if (kill (pid, 0) == 0 || errno != ESRCH) {
/* Yes there is a process */
*pid0 = pid;
return 0;
}
}
*pid = 0;
if ((f = fopen(pidfile, "r")) != NULL){
pidfile_get_fd(f, pid);
fclose(f);
}
*pid0 = 0;
return 0;
}
@ -169,7 +184,7 @@ pidfile_zapold(pid_t pid)
clicon_err(OE_UNIX, errno, "usleep");
goto done;
}
if ((kill (pid, 0)) < 0){
if ((kill(pid, 0)) < 0){
if (errno != ESRCH){
clicon_err(OE_DAEMON, errno, "Killing old demon");
goto done;