Added 'service run' to run a service without restart.

This commit is contained in:
Ben Gras 2006-08-15 15:54:51 +00:00
parent 82a5bffa7d
commit b888922d62
4 changed files with 20 additions and 14 deletions

View file

@ -81,8 +81,9 @@ PUBLIC int main(void)
*/
else {
switch(call_nr) {
case RS_UP: result = do_up(&m, FALSE /*!do_copy*/); break;
case RS_UP_COPY: result = do_up(&m, TRUE /*do_copy*/); break;
case RS_UP: result = do_up(&m, FALSE, 0); break;
case RS_UP_COPY: result = do_up(&m, TRUE, 0); break;
case RS_RUN: result = do_up(&m, FALSE, RS_EXITING); break;
case RS_DOWN: result = do_down(&m); break;
case RS_REFRESH: result = do_refresh(&m); break;
case RS_RESCUE: result = do_rescue(&m); break;

View file

@ -20,7 +20,7 @@ int nr_in_use; /* number of services */
extern int errno; /* error status */
/* Prototypes for internal functions that do the hard work. */
FORWARD _PROTOTYPE( int start_service, (struct rproc *rp) );
FORWARD _PROTOTYPE( int start_service, (struct rproc *rp, int flags) );
FORWARD _PROTOTYPE( int stop_service, (struct rproc *rp,int how) );
FORWARD _PROTOTYPE( int fork_nb, (void) );
FORWARD _PROTOTYPE( int read_exec, (struct rproc *rp) );
@ -32,9 +32,10 @@ PRIVATE int shutting_down = FALSE;
/*===========================================================================*
* do_up *
*===========================================================================*/
PUBLIC int do_up(m_ptr, do_copy)
PUBLIC int do_up(m_ptr, do_copy, flags)
message *m_ptr; /* request message pointer */
int do_copy; /* keep copy in memory */
int flags; /* extra flags, if any */
{
/* A request was made to start a new system service. Dismember the request
* message and gather all information needed to start the service. Starting
@ -99,7 +100,7 @@ int do_copy; /* keep copy in memory */
rp->r_restarts = -1; /* will be incremented */
/* All information was gathered. Now try to start the system service. */
return(start_service(rp));
return(start_service(rp, flags));
}
@ -236,7 +237,7 @@ PUBLIC void do_exit(message *m_ptr)
}
else if(rp->r_flags & RS_REFRESHING) {
rp->r_restarts = -1; /* reset counter */
start_service(rp); /* direct restart */
start_service(rp, 0); /* direct restart */
}
else if (WIFEXITED(exit_status) &&
WEXITSTATUS(exit_status) == EXEC_FAILED) {
@ -260,7 +261,7 @@ rp->r_restarts= 0;
rp->r_backoff= 1;
}
else {
start_service(rp); /* direct restart */
start_service(rp, 0); /* direct restart */
}
}
break;
@ -290,7 +291,7 @@ message *m_ptr;
if (rp->r_backoff > 0) {
rp->r_backoff -= 1;
if (rp->r_backoff == 0) {
start_service(rp);
start_service(rp, 0);
}
}
@ -345,8 +346,9 @@ message *m_ptr;
/*===========================================================================*
* start_service *
*===========================================================================*/
PRIVATE int start_service(rp)
PRIVATE int start_service(rp, flags)
struct rproc *rp;
int flags;
{
/* Try to execute the given system service. Fork a new process. The child
* process will be inhibited from running by the NO_PRIV flag. Only let the
@ -431,7 +433,7 @@ struct rproc *rp;
* that's the case, the child will exit.
*/
child_proc_nr_n = _ENDPOINT_P(child_proc_nr_e);
rp->r_flags = RS_IN_USE; /* mark slot in use */
rp->r_flags = RS_IN_USE | flags; /* mark slot in use */
rp->r_restarts += 1; /* raise nr of restarts */
rp->r_proc_nr_e = child_proc_nr_e; /* set child details */
rp->r_pid = child_pid;

View file

@ -8,7 +8,7 @@ _PROTOTYPE( int dev_execve, (int proc_e,
_PROTOTYPE( int main, (void));
/* manager.c */
_PROTOTYPE( int do_up, (message *m, int do_copy));
_PROTOTYPE( int do_up, (message *m, int do_copy, int flags));
_PROTOTYPE( int do_down, (message *m));
_PROTOTYPE( int do_refresh, (message *m));
_PROTOTYPE( int do_rescue, (message *m));

View file

@ -27,6 +27,8 @@ PRIVATE char *known_requests[] = {
"refresh",
"rescue",
"shutdown",
"upcopy", /* fill for RS_UP_COPY */
"run",
"catch for illegal requests"
};
#define ILLEGAL_REQUEST sizeof(known_requests)/sizeof(char *)
@ -74,7 +76,7 @@ PRIVATE void print_usage(char *app_name, char *problem)
{
printf("Warning, %s\n", problem);
printf("Usage:\n");
printf(" %s [-c] up <binary> [%s <args>] [%s <special>] [%s <ticks>]\n",
printf(" %s [-c] (up|run) <binary> [%s <args>] [%s <special>] [%s <ticks>]\n",
app_name, ARG_ARGS, ARG_DEV, ARG_PERIOD);
printf(" %s down <pid>\n", app_name);
printf(" %s refresh <pid>\n", app_name);
@ -137,9 +139,9 @@ PRIVATE int parse_arguments(int argc, char **argv)
}
req_nr = RS_RQ_BASE + req_type;
if (req_nr == RS_UP) {
if (req_nr == RS_UP || req_nr == RS_RUN) {
if (c_flag)
if (req_nr == RS_UP && c_flag)
req_nr= RS_UP_COPY;
/* Verify argument count. */
@ -266,6 +268,7 @@ PUBLIC int main(int argc, char **argv)
switch(request) {
case RS_UP:
case RS_UP_COPY:
case RS_RUN:
/* Build space-separated command string to be passed to RS server. */
strcpy(command, req_path);
command[strlen(req_path)] = ' ';