RS: allow service program name to be overridden

Until now, the program name of a service was always the file name
(without directory) of the service binary.  The program name is used
to, among other things, find the corresponding system.conf entry.
With ASR moving to a situation where all rerandomized service binaries
are stored in a single directory, this can no longer be maintained.
Instead, the service(8) command can now be instructed to override the
service program name, using its new -progname option.

Change-Id: I981e9b35232c88048d8804ec5eca58d1e4a5db82
This commit is contained in:
David van Moolenbroek 2015-11-13 11:26:56 +01:00 committed by Lionel Sambuc
parent 6068a2ee9f
commit 23199f6205
7 changed files with 37 additions and 28 deletions

View File

@ -123,6 +123,7 @@ static int known_request_types[] = {
* system service * system service
*/ */
#define ARG_LABELNAME "-label" /* custom label name */ #define ARG_LABELNAME "-label" /* custom label name */
#define ARG_PROGNAME "-progname" /* custom program name */
#define ARG_CONFIG "-config" /* name of the file with the resource #define ARG_CONFIG "-config" /* name of the file with the resource
* configuration * configuration
*/ */
@ -149,6 +150,7 @@ static char *req_label = NULL;
static char *req_trg_label = NULL; static char *req_trg_label = NULL;
static char *req_path = NULL; static char *req_path = NULL;
static char *req_path_self = SELF_REQ_PATH; static char *req_path_self = SELF_REQ_PATH;
static char *req_progname = NULL;
static char *req_args = ""; static char *req_args = "";
static int req_major = 0; static int req_major = 0;
static int devman_id = 0; static int devman_id = 0;
@ -177,14 +179,14 @@ static void print_usage(char *app_name, char *problem)
fprintf(stderr, "Warning, %s\n", problem); fprintf(stderr, "Warning, %s\n", problem);
fprintf(stderr, "Usage:\n"); fprintf(stderr, "Usage:\n");
fprintf(stderr, fprintf(stderr,
" %s [%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s] (up|run|edit|update) <binary|%s> [%s <args>] [%s <special>] [%s <major_nr>] [%s <dev_id>] [%s <ticks>] [%s <path>] [%s <name>] [%s <path>] [%s <state value|eval_expression>] [%s <time>] [%s <bytes>] [%s <bytes>] [%s <name>] [(%s|%s <src_label1,src_type1:src_label2,:,src_type3:...>)*] [%s <count>] [%s <restarts>]\n", " %s [%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s] (up|run|edit|update) <binary|%s> [%s <args>] [%s <special>] [%s <major_nr>] [%s <dev_id>] [%s <ticks>] [%s <path>] [%s <name>] [%s <name>] [%s <path>] [%s <state value|eval_expression>] [%s <time>] [%s <bytes>] [%s <bytes>] [%s <name>] [(%s|%s <src_label1,src_type1:src_label2,:,src_type3:...>)*] [%s <count>] [%s <restarts>]\n",
app_name, OPT_COPY, OPT_REUSE, OPT_NOBLOCK, OPT_REPLICA, OPT_NO_BIN_EXP, app_name, OPT_COPY, OPT_REUSE, OPT_NOBLOCK, OPT_REPLICA, OPT_NO_BIN_EXP,
OPT_BATCH, OPT_ASR_LU, OPT_PREPARE_ONLY_LU, OPT_FORCE_SELF_LU, OPT_BATCH, OPT_ASR_LU, OPT_PREPARE_ONLY_LU, OPT_FORCE_SELF_LU,
OPT_FORCE_INIT_CRASH, OPT_FORCE_INIT_FAIL, OPT_FORCE_INIT_TIMEOUT, OPT_FORCE_INIT_CRASH, OPT_FORCE_INIT_FAIL, OPT_FORCE_INIT_TIMEOUT,
OPT_FORCE_INIT_DEFCB, OPT_NOMMAP_LU, OPT_DETACH, OPT_FORCE_INIT_DEFCB, OPT_NOMMAP_LU, OPT_DETACH,
OPT_NORESTART, OPT_FORCE_INIT_ST, SELF_BINARY, OPT_NORESTART, OPT_FORCE_INIT_ST, SELF_BINARY,
ARG_ARGS, ARG_DEV, ARG_MAJOR, ARG_DEVMANID, ARG_PERIOD, ARG_ARGS, ARG_DEV, ARG_MAJOR, ARG_DEVMANID, ARG_PERIOD,
ARG_SCRIPT, ARG_LABELNAME, ARG_CONFIG, ARG_LU_STATE, ARG_LU_MAXTIME, ARG_SCRIPT, ARG_LABELNAME, ARG_PROGNAME, ARG_CONFIG, ARG_LU_STATE, ARG_LU_MAXTIME,
ARG_HEAP_PREALLOC, ARG_MAP_PREALLOC, ARG_TRG_LABELNAME, ARG_LU_IPC_BL, ARG_LU_IPC_WL, ARG_HEAP_PREALLOC, ARG_MAP_PREALLOC, ARG_TRG_LABELNAME, ARG_LU_IPC_BL, ARG_LU_IPC_WL,
ARG_ASR_COUNT, ARG_RESTARTS); ARG_ASR_COUNT, ARG_RESTARTS);
fprintf(stderr, " %s down <label>\n", app_name); fprintf(stderr, " %s down <label>\n", app_name);
@ -564,6 +566,9 @@ static int parse_arguments(int argc, char **argv, u32_t *rss_flags)
else if (strcmp(argv[i], ARG_TRG_LABELNAME)==0) { else if (strcmp(argv[i], ARG_TRG_LABELNAME)==0) {
req_trg_label = argv[i+1]; req_trg_label = argv[i+1];
} }
else if (strcmp(argv[i], ARG_PROGNAME)==0) {
req_progname = argv[i+1];
}
else if (strcmp(argv[i], ARG_CONFIG)==0) { else if (strcmp(argv[i], ARG_CONFIG)==0) {
req_config = argv[i+1]; req_config = argv[i+1];
custom_config_file = 1; custom_config_file = 1;
@ -734,9 +739,13 @@ int main(int argc, char **argv)
case RS_UP: case RS_UP:
case RS_EDIT: case RS_EDIT:
/* Build space-separated command string to be passed to RS server. */ /* Build space-separated command string to be passed to RS server. */
progname = strrchr(req_path, '/'); if (req_progname != NULL) {
assert(progname); /* an absolute path was required */ progname = req_progname;
progname++; /* skip last slash */ } else {
progname = strrchr(req_path, '/');
assert(progname); /* an absolute path was required */
progname++; /* skip last slash */
}
strcpy(command, req_path); strcpy(command, req_path);
command[strlen(req_path)] = ' '; command[strlen(req_path)] = ' ';
strcpy(command+strlen(req_path)+1, req_args); strcpy(command+strlen(req_path)+1, req_args);
@ -753,6 +762,8 @@ int main(int argc, char **argv)
/* Set specifics */ /* Set specifics */
config.rs_start.rss_cmd= command; config.rs_start.rss_cmd= command;
config.rs_start.rss_cmdlen= strlen(command); config.rs_start.rss_cmdlen= strlen(command);
config.rs_start.rss_progname= progname;
config.rs_start.rss_prognamelen= strlen(progname);
config.rs_start.rss_major= req_major; config.rs_start.rss_major= req_major;
config.rs_start.rss_period= req_period; config.rs_start.rss_period= req_period;
config.rs_start.rss_script= req_script; config.rs_start.rss_script= req_script;

View File

@ -135,6 +135,8 @@ struct rs_start
struct rss_label rss_control[RS_NR_CONTROL]; struct rss_label rss_control[RS_NR_CONTROL];
struct rs_state_data rss_state_data; struct rs_state_data rss_state_data;
int devman_id; int devman_id;
char *rss_progname;
size_t rss_prognamelen;
/* /*
* SMP specific data * SMP specific data
* *

View File

@ -18,8 +18,8 @@ static struct exec_loaders {
{ NULL } { NULL }
}; };
int srv_execve(int proc_e, char *exec, size_t exec_len, char **argv, int srv_execve(int proc_e, char *exec, size_t exec_len, char *progname,
char **envp) char **argv, char **envp)
{ {
size_t frame_size = 0; /* Size of the new initial stack. */ size_t frame_size = 0; /* Size of the new initial stack. */
int argc = 0; /* Argument count. */ int argc = 0; /* Argument count. */
@ -29,7 +29,6 @@ int srv_execve(int proc_e, char *exec, size_t exec_len, char **argv,
struct ps_strings *psp; struct ps_strings *psp;
int vsp = 0; /* (virtual) Stack pointer in new address space. */ int vsp = 0; /* (virtual) Stack pointer in new address space. */
char *progname;
int r; int r;
minix_stack_params(argv[0], argv, envp, &frame_size, &overflow, minix_stack_params(argv[0], argv, envp, &frame_size, &overflow,
@ -50,8 +49,6 @@ int srv_execve(int proc_e, char *exec, size_t exec_len, char **argv,
minix_stack_fill(argv[0], argc, argv, envc, envp, frame_size, frame, minix_stack_fill(argv[0], argc, argv, envc, envp, frame_size, frame,
&vsp, &psp); &vsp, &psp);
(progname=strrchr(argv[0], '/')) ? progname++ : (progname=argv[0]);
r = do_exec(proc_e, exec, exec_len, progname, frame, frame_size, r = do_exec(proc_e, exec, exec_len, progname, frame, frame_size,
vsp + ((char *)psp - frame)); vsp + ((char *)psp - frame));

View File

@ -305,11 +305,13 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
*/ */
rpub->dev_nr = boot_image_dev->dev_nr; /* major device number */ rpub->dev_nr = boot_image_dev->dev_nr; /* major device number */
/* Build command settings. This will also set the process name. */ /* Build command settings. Also set the process name. */
strlcpy(rp->r_cmd, ip->proc_name, sizeof(rp->r_cmd)); strlcpy(rp->r_cmd, ip->proc_name, sizeof(rp->r_cmd));
rp->r_script[0]= '\0'; rp->r_script[0]= '\0';
build_cmd_dep(rp); build_cmd_dep(rp);
strlcpy(rpub->proc_name, ip->proc_name, sizeof(rpub->proc_name));
/* Initialize vm call mask bitmap. */ /* Initialize vm call mask bitmap. */
calls = SRV_OR_USR(rp, SRV_VC, USR_VC) == ALL_C ? all_c : no_c; calls = SRV_OR_USR(rp, SRV_VC, USR_VC) == ALL_C ? all_c : no_c;
fill_call_mask(calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE); fill_call_mask(calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE);

View File

@ -320,18 +320,6 @@ void build_cmd_dep(struct rproc *rp)
assert(arg_count < ARGV_ELEMENTS); assert(arg_count < ARGV_ELEMENTS);
rp->r_argv[arg_count] = NULL; /* end with NULL pointer */ rp->r_argv[arg_count] = NULL; /* end with NULL pointer */
rp->r_argc = arg_count; rp->r_argc = arg_count;
/* Build process name. */
cmd_ptr = strrchr(rp->r_argv[0], '/');
if (cmd_ptr)
cmd_ptr++;
else
cmd_ptr= rp->r_argv[0];
len= strlen(cmd_ptr);
if (len > RS_MAX_LABEL_LEN-1)
len= RS_MAX_LABEL_LEN-1; /* truncate name */
memcpy(rpub->proc_name, cmd_ptr, len);
rpub->proc_name[len]= '\0';
} }
/*===========================================================================* /*===========================================================================*
@ -642,8 +630,8 @@ struct rproc *rp;
} }
if(rs_verbose) if(rs_verbose)
printf("RS: execing child with srv_execve()...\n"); printf("RS: execing child with srv_execve()...\n");
s = srv_execve(child_proc_nr_e, rp->r_exec, rp->r_exec_len, rp->r_argv, s = srv_execve(child_proc_nr_e, rp->r_exec, rp->r_exec_len, rpub->proc_name,
environ); rp->r_argv, environ);
vm_memctl(RS_PROC_NR, VM_RS_MEM_PIN, 0, 0); vm_memctl(RS_PROC_NR, VM_RS_MEM_PIN, 0, 0);
if (s != OK) { if (s != OK) {
printf("RS: srv_execve failed: %d\n", s); printf("RS: srv_execve failed: %d\n", s);
@ -1588,9 +1576,16 @@ endpoint_t source;
rp->r_cmd[rs_start->rss_cmdlen] = '\0'; /* ensure it is terminated */ rp->r_cmd[rs_start->rss_cmdlen] = '\0'; /* ensure it is terminated */
if (rp->r_cmd[0] != '/') return(EINVAL); /* insist on absolute path */ if (rp->r_cmd[0] != '/') return(EINVAL); /* insist on absolute path */
/* Build cmd dependencies: argv and program name. */ /* Build cmd dependencies (argv). */
build_cmd_dep(rp); build_cmd_dep(rp);
/* Copy in the program name. */
if (rs_start->rss_prognamelen > sizeof(rpub->proc_name)-1) return(E2BIG);
s=sys_datacopy(source, (vir_bytes) rs_start->rss_progname,
SELF, (vir_bytes) rpub->proc_name, rs_start->rss_prognamelen);
if (s != OK) return(s);
rpub->proc_name[rs_start->rss_prognamelen] = '\0';
/* Update label if not already set. */ /* Update label if not already set. */
if(!strcmp(rpub->label, "")) { if(!strcmp(rpub->label, "")) {
if(rs_start->rss_label.l_len > 0) { if(rs_start->rss_label.l_len > 0) {

View File

@ -5,8 +5,8 @@ struct rproc;
struct rprocupd; struct rprocupd;
/* exec.c */ /* exec.c */
int srv_execve(int proc_e, char *exec, size_t exec_len, char *argv[], int srv_execve(int proc_e, char *exec, size_t exec_len, char *progname,
char **env); char *argv[], char **env);
/* main.c */ /* main.c */
int main(void); int main(void);

View File

@ -27,6 +27,8 @@ put_struct_rs_start(struct trace_proc * proc, const char * name,
put_flags(proc, "rss_flags", rss_flags, COUNT(rss_flags), put_flags(proc, "rss_flags", rss_flags, COUNT(rss_flags),
"0x%x", buf.rss_flags); "0x%x", buf.rss_flags);
put_buf(proc, "rss_cmd", 0, (vir_bytes)buf.rss_cmd, buf.rss_cmdlen); put_buf(proc, "rss_cmd", 0, (vir_bytes)buf.rss_cmd, buf.rss_cmdlen);
put_buf(proc, "rss_progname", 0, (vir_bytes)buf.rss_progname,
buf.rss_prognamelen);
put_buf(proc, "rss_label", 0, (vir_bytes)buf.rss_label.l_addr, put_buf(proc, "rss_label", 0, (vir_bytes)buf.rss_label.l_addr,
buf.rss_label.l_len); buf.rss_label.l_len);
if (verbose > 0 || buf.rss_major != 0) if (verbose > 0 || buf.rss_major != 0)