From e090013056616397a11e6108d70306c22c7413f1 Mon Sep 17 00:00:00 2001 From: Cristiano Giuffrida Date: Thu, 17 Dec 2009 01:53:26 +0000 Subject: [PATCH] Drivers and servers are simply known as services. /etc CHANGES: - /etc/drivers.conf has been renamed to /etc/system.conf. Every entry in the file is now marked as "service" rather than driver. - user "service" has been added to password file /etc/passwd. - docs/UPDATING updated accordingly, as well as every other mention to the old drivers.conf in the system. RS CHANGES: - No more distinction between servers and drivers. - RS_START has been renamed to RS_UP and the old legacy RS_UP and RS_UP_COPY dropped. - RS asks PCI to set / remove ACL entries only for services whose ACL properties have been set. This change eliminates unnecessary warnings. - Temporarily minimize the risk of potential races at boot time or when starting a new service. Upcoming changes will eliminate races completely. - General cleanup. --- commands/scripts/readclock.sh | 2 +- commands/swifi/run_swifi | 2 +- commands/swifi/run_t1 | 2 +- commands/swifi/run_t2 | 2 +- docs/UPDATING | 4 +- drivers/memory/ramdisk/Makefile | 4 +- drivers/memory/ramdisk/proto | 2 +- drivers/memory/ramdisk/rc | 8 +- drivers/orinoco/INSTALL.txt | 2 +- etc/Makefile | 2 +- etc/passwd | 1 + etc/{drivers.conf => system.conf} | 182 +++++++++++++------------ include/minix/com.h | 12 +- include/minix/paths.h | 2 +- lib/other/_mount.c | 4 +- servers/rs/const.h | 10 +- servers/rs/main.c | 73 +++++----- servers/rs/manager.c | 212 +++++++----------------------- servers/rs/proto.h | 3 +- servers/rs/service.c | 79 ++++------- servers/rs/type.h | 2 +- 21 files changed, 237 insertions(+), 373 deletions(-) rename etc/{drivers.conf => system.conf} (80%) diff --git a/commands/scripts/readclock.sh b/commands/scripts/readclock.sh index e6a2e7879..f53e0d259 100644 --- a/commands/scripts/readclock.sh +++ b/commands/scripts/readclock.sh @@ -2,4 +2,4 @@ if [ $# -gt 0 ] then ARGS="-args $@" fi -/bin/service up /sbin/readclock.drv -config /etc/drivers.conf -script /etc/rs.single $ARGS +/bin/service up /sbin/readclock.drv -config /etc/system.conf -script /etc/rs.single $ARGS diff --git a/commands/swifi/run_swifi b/commands/swifi/run_swifi index 85534196b..8174831c8 100644 --- a/commands/swifi/run_swifi +++ b/commands/swifi/run_swifi @@ -46,7 +46,7 @@ one_round() # Start our own driver. service down $LABEL sleep 10 # Allow driver to die -service up $EXE -script `pwd`/rs.restart_imm -config /etc/drivers.conf -period 3HZ +service up $EXE -script `pwd`/rs.restart_imm -config /etc/system.conf -period 3HZ i=0 i=4000 diff --git a/commands/swifi/run_t1 b/commands/swifi/run_t1 index bea5420fb..33f6b12d4 100755 --- a/commands/swifi/run_t1 +++ b/commands/swifi/run_t1 @@ -103,7 +103,7 @@ esac # Start our own driver. service down $LABEL sleep 2 # Allow driver to die -service up $EXE -script `pwd`/rs.restart_imm -config /etc/drivers.conf -period 3HZ $DEV +service up $EXE -script `pwd`/rs.restart_imm -config /etc/system.conf -period 3HZ $DEV i=0 while [ $i -lt "$count" ] diff --git a/commands/swifi/run_t2 b/commands/swifi/run_t2 index debdf5706..d37bbf61a 100755 --- a/commands/swifi/run_t2 +++ b/commands/swifi/run_t2 @@ -123,7 +123,7 @@ esac # Start our own driver. service down $LABEL sleep 10 # Allow driver to die -service up $EXE -script `pwd`/rs.restart_imm -config /etc/drivers.conf -period 3HZ +service up $EXE -script `pwd`/rs.restart_imm -config /etc/system.conf -period 3HZ i=0 while [ $i -lt "$count" ] diff --git a/docs/UPDATING b/docs/UPDATING index 6c4ff8515..e980e1985 100644 --- a/docs/UPDATING +++ b/docs/UPDATING @@ -1,4 +1,6 @@ - +20091212: + /etc/drivers.conf has been renamed to /etc/system.conf. + user "service" has been added to password file /etc/passwd. 20060818: You need flex in your $PATH, which has become part of the base system. This needs bigger binaries. diff --git a/drivers/memory/ramdisk/Makefile b/drivers/memory/ramdisk/Makefile index bbf0f2e21..5f1b0bd0f 100644 --- a/drivers/memory/ramdisk/Makefile +++ b/drivers/memory/ramdisk/Makefile @@ -2,7 +2,7 @@ PROGRAMS=at_wini bios_wini cdprobe dev2name floppy loadramdisk newroot \ pci sh service sysenv mfs -EXTRA=drivers.conf passwd +EXTRA=system.conf passwd MAKEDEV=/usr/bin/MAKEDEV @@ -97,7 +97,7 @@ mfs: ../../../servers/mfs/mfs ../../../servers/mfs/mfs: cd ../../../servers/mfs && make -drivers.conf: ../../../etc/drivers.conf +system.conf: ../../../etc/system.conf install -s ../../../etc/$@ $@ passwd: ../../../etc/passwd diff --git a/drivers/memory/ramdisk/proto b/drivers/memory/ramdisk/proto index 75975da2e..bd21e6d88 100644 --- a/drivers/memory/ramdisk/proto +++ b/drivers/memory/ramdisk/proto @@ -21,7 +21,7 @@ d--755 0 0 @DEV@ $ etc d--755 0 0 - drivers.conf ---644 0 0 drivers.conf + system.conf ---644 0 0 system.conf mtab ---644 0 0 mtab passwd ---644 0 0 passwd rc ---755 0 0 rc diff --git a/drivers/memory/ramdisk/rc b/drivers/memory/ramdisk/rc index 4a28f9a10..4ef68b53c 100644 --- a/drivers/memory/ramdisk/rc +++ b/drivers/memory/ramdisk/rc @@ -5,15 +5,15 @@ exec >/dev/log exec 2>/dev/log exec = sizeof(cmd)) { + strlen(_PATH_SYSTEM_CONF)+strlen(args)+50 >= sizeof(cmd)) { errno = E2BIG; return -1; } - sprintf(cmd, _PATH_SERVICE " %sup %s -label '%s' -config " _PATH_DRIVERS_CONF + sprintf(cmd, _PATH_SERVICE " %sup %s -label '%s' -config " _PATH_SYSTEM_CONF " -args '%s%s' -printep yes", reuse ? "-r ": "", path, label, args[0] ? "-o " : "", args); diff --git a/servers/rs/const.h b/servers/rs/const.h index 25f135a0b..c415ad45d 100644 --- a/servers/rs/const.h +++ b/servers/rs/const.h @@ -6,7 +6,7 @@ /* Space reserved for program and arguments. */ #define MAX_COMMAND_LEN 512 /* maximum argument string length */ #define MAX_LABEL_LEN 16 /* Unique name of (this instance of) - * the driver + * the service */ #define MAX_SCRIPT_LEN 256 /* maximum restart script name length */ #define MAX_NR_ARGS 4 /* maximum number of arguments */ @@ -21,11 +21,11 @@ #define RS_IN_USE 0x001 /* set when process slot is in use */ #define RS_EXITING 0x004 /* set when exit is expected */ #define RS_REFRESHING 0x008 /* set when refresh must be done */ -#define RS_NOPINGREPLY 0x010 /* driver failed to reply to a ping request */ -#define RS_KILLED 0x020 /* driver is killed */ -#define RS_CRASHED 0x040 /* driver crashed */ +#define RS_NOPINGREPLY 0x010 /* service failed to reply to a ping request */ +#define RS_KILLED 0x020 /* service is killed */ +#define RS_CRASHED 0x040 /* service crashed */ #define RS_LATEREPLY 0x080 /* no reply sent to RS_DOWN caller yet */ -#define RS_SIGNALED 0x100 /* driver crashed */ +#define RS_SIGNALED 0x100 /* service crashed */ /* Sys flag values. */ #define SF_CORE_PROC 0x001 /* set for core system processes diff --git a/servers/rs/main.c b/servers/rs/main.c index b67cf5c06..7243614c0 100644 --- a/servers/rs/main.c +++ b/servers/rs/main.c @@ -86,7 +86,7 @@ PUBLIC int main(void) if (is_notify(m.m_type)) { switch (who_p) { case CLOCK: - do_period(&m); /* check drivers status */ + do_period(&m); /* check services status */ continue; case PM_PROC_NR: sig_handler(); @@ -116,9 +116,7 @@ PUBLIC int main(void) /* Handler functions are responsible for permission checking. */ switch(call_nr) { - case RS_UP: result = do_up(&m, FALSE, 0); break; - case RS_UP_COPY: result = do_up(&m, TRUE, 0); break; - case RS_START: result = do_start(&m); break; + case RS_UP: result = do_up(&m); break; case RS_DOWN: result = do_down(&m); break; case RS_REFRESH: result = do_refresh(&m); break; case RS_RESTART: result = do_restart(&m); break; @@ -455,6 +453,32 @@ PRIVATE void init_server(void) rp->r_dev_nr = boot_image_dev->dev_nr; /* major device number */ rp->r_dev_style = boot_image_dev->dev_style; /* device style */ rp->r_period = boot_image_dev->period; /* heartbeat period */ + + /* Get label. */ + strcpy(rp->r_label, ip->proc_name); + + /* Get command settings. */ + rp->r_cmd[0]= '\0'; + rp->r_argv[0] = rp->r_cmd; + rp->r_argv[1] = NULL; + rp->r_argc = 1; + rp->r_script[0]= '\0'; + + /* Get some settings from the boot image table. */ + rp->r_nice = ip->priority; + rp->r_proc_nr_e = ip->endpoint; + + /* Set some defaults. */ + rp->r_uid = 0; /* root */ + rp->r_check_tm = 0; /* not checked yet */ + getuptime(&rp->r_alive_tm); /* currently alive */ + rp->r_stop_tm = 0; /* not exiting yet */ + rp->r_restarts = 0; /* no restarts so far */ + rp->r_set_resources = 0; /* don't set resources */ + + /* Mark as in use. */ + rp->r_flags = RS_IN_USE; + rproc_ptr[_ENDPOINT_P(rp->r_proc_nr_e)]= rp; } /* - Step 2: allow every system service in the boot image to run. @@ -477,9 +501,9 @@ PRIVATE void init_server(void) } } - /* - Step 3: all the system services in the boot image are now running. Use - * the boot image table from the kernel and PM process table to complete - * the initialization of the system process table. + /* - Step 3: all the system services in the boot image are now running. + * Complete the initialization of the system process table in collaboration + * with other system processes. */ if ((s = getsysinfo(PM_PROC_NR, SI_PROC_TAB, mproc)) != OK) { panic("RS", "unable to get copy of PM process table", s); @@ -492,25 +516,9 @@ PRIVATE void init_server(void) continue; } - /* Lookup the corresponding entry in the boot image table. */ - boot_image_info_lookup(boot_image_priv->endpoint, image, - &ip, NULL, NULL, NULL); + /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; - /* Get label. */ - strcpy(rp->r_label, ip->proc_name); - - /* Get command settings. */ - rp->r_cmd[0]= '\0'; - rp->r_argv[0] = rp->r_cmd; - rp->r_argv[1] = NULL; - rp->r_argc = 1; - rp->r_script[0]= '\0'; - - /* Get settings from the boot image table. */ - rp->r_nice = ip->priority; - rp->r_proc_nr_e = ip->endpoint; - /* Get pid from PM process table. */ rp->r_pid = NO_PID; for (j = 0; j < NR_PROCS; j++) { @@ -523,19 +531,10 @@ PRIVATE void init_server(void) panic("RS", "unable to get pid", NO_NUM); } - /* Set some defaults. */ - rp->r_uid = 0; /* root */ - rp->r_check_tm = 0; /* not checked yet */ - getuptime(&rp->r_alive_tm); /* currently alive */ - rp->r_stop_tm = 0; /* not exiting yet */ - rp->r_restarts = 0; /* no restarts so far */ - rp->r_set_resources = 0; /* no resources */ - - /* Mark as in use. */ - rp->r_flags = RS_IN_USE; - rproc_ptr[_ENDPOINT_P(rp->r_proc_nr_e)]= rp; - - /* Publish the new system service. */ + /* Publish the new system service. + * XXX FIXME. Possible race condition. We should publish labels before + * allowing other processes to run. + */ s = publish_service(rp); if (s != OK) { panic("RS", "unable to publish boot system service", s); diff --git a/servers/rs/manager.c b/servers/rs/manager.c index 33897e5cb..c2fd0ca5c 100644 --- a/servers/rs/manager.c +++ b/servers/rs/manager.c @@ -128,120 +128,14 @@ size_t dst_len; dst_label[len] = 0; if (rs_verbose) - printf("RS: do_start: using label (custom) '%s'\n", dst_label); + printf("RS: copy_label: using label (custom) '%s'\n", dst_label); return OK; } /*===========================================================================* - * do_up * + * do_up * *===========================================================================*/ -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 - * is done by a helper routine. - */ - register struct rproc *rp; /* system process table */ - int slot_nr; /* local table entry */ - int arg_count; /* number of arguments */ - char *cmd_ptr; /* parse command string */ - char *label; /* unique name of command */ - enum dev_style dev_style; /* device style */ - int s; /* status variable */ - int len; /* length of string */ - int r; - endpoint_t ep; /* new endpoint no. */ - - /* This call requires special privileges. */ - if (!caller_is_root(m_ptr->m_source)) return(EPERM); - - /* See if there is a free entry in the table with system processes. */ - for (slot_nr = 0; slot_nr < NR_SYS_PROCS; slot_nr++) { - rp = &rproc[slot_nr]; /* get pointer to slot */ - if (! rp->r_flags & RS_IN_USE) /* check if available */ - break; - } - - /* Obtain command name and parameters. This is a space-separated string - * that looks like "/sbin/service arg1 arg2 ...". Arguments are optional. - */ - if (m_ptr->RS_CMD_LEN > MAX_COMMAND_LEN) return(E2BIG); - if (OK!=(s=sys_datacopy(m_ptr->m_source, (vir_bytes) m_ptr->RS_CMD_ADDR, - SELF, (vir_bytes) rp->r_cmd, m_ptr->RS_CMD_LEN))) return(s); - rp->r_cmd[m_ptr->RS_CMD_LEN] = '\0'; /* ensure it is terminated */ - if (rp->r_cmd[0] != '/') return(EINVAL); /* insist on absolute path */ - - rp->r_script[0]= '\0'; - - /* Build argument vector to be passed to execute call. The format of the - * arguments vector is: path, arguments, NULL. - */ - arg_count = 0; /* initialize arg count */ - rp->r_argv[arg_count++] = rp->r_cmd; /* start with path */ - cmd_ptr = rp->r_cmd; /* do some parsing */ - while(*cmd_ptr != '\0') { /* stop at end of string */ - if (*cmd_ptr == ' ') { /* next argument */ - *cmd_ptr = '\0'; /* terminate previous */ - while (*++cmd_ptr == ' ') ; /* skip spaces */ - if (*cmd_ptr == '\0') break; /* no arg following */ - if (arg_count>MAX_NR_ARGS+1) break; /* arg vector full */ - rp->r_argv[arg_count++] = cmd_ptr; /* add to arg vector */ - } - cmd_ptr ++; /* continue parsing */ - } - rp->r_argv[arg_count] = NULL; /* end with NULL pointer */ - rp->r_argc = arg_count; - - /* Default label for the driver */ - label= strrchr(rp->r_argv[0], '/'); - if (label) - label++; - else - label= rp->r_argv[0]; - len= strlen(label); - if (len > MAX_LABEL_LEN-1) - len= MAX_LABEL_LEN-1; /* truncate name */ - memcpy(rp->r_label, label, len); - rp->r_label[len]= '\0'; - if(rs_verbose) printf("RS: do_up: using label '%s'\n", rp->r_label); - - rp->r_uid= 0; - rp->r_nice= 0; - - rp->r_sys_flags = DSRV_SF; - rp->r_exec= NULL; - - if (do_copy) - { - s= read_exec(rp); - if (s != OK) - return s; - - rp->r_sys_flags |= SF_USE_COPY; - } - - /* Initialize some fields. */ - rp->r_period = m_ptr->RS_PERIOD; - rp->r_dev_nr = m_ptr->RS_DEV_MAJOR; - rp->r_dev_style = STYLE_DEV; - rp->r_restarts = -1; /* will be incremented */ - rp->r_set_resources= 0; /* old style */ - - /* All information was gathered. Now try to start the system service. */ - - r = start_service(rp, flags, &ep); - m_ptr->RS_ENDPOINT = ep; - return r; -} - - -/*===========================================================================* - * do_start * - *===========================================================================*/ -PUBLIC int do_start(m_ptr) +PUBLIC int do_up(m_ptr) message *m_ptr; /* request message pointer */ { /* A request was made to start a new system service. @@ -271,7 +165,7 @@ message *m_ptr; /* request message pointer */ } if (slot_nr >= NR_SYS_PROCS) { - printf("rs`do_start: driver table full\n"); + printf("RS: do_up: system process table full\n"); return ENOMEM; } @@ -310,15 +204,15 @@ message *m_ptr; /* request message pointer */ rp->r_argc = arg_count; if(rs_start.rss_label.l_len > 0) { - /* RS_START caller has supplied a custom label for this driver. */ + /* RS_UP caller has supplied a custom label for this service. */ int s = copy_label(m_ptr->m_source, &rs_start.rss_label, rp->r_label, sizeof(rp->r_label)); if(s != OK) return s; if(rs_verbose) - printf("RS: do_start: using label (custom) '%s'\n", rp->r_label); + printf("RS: do_up: using label (custom) '%s'\n", rp->r_label); } else { - /* Default label for the driver. */ + /* Default label for the service. */ label= strrchr(rp->r_argv[0], '/'); if (label) label++; @@ -330,7 +224,7 @@ message *m_ptr; /* request message pointer */ memcpy(rp->r_label, label, len); rp->r_label[len]= '\0'; if(rs_verbose) - printf("RS: do_start: using label (from binary %s) '%s'\n", + printf("RS: do_up: using label (from binary %s) '%s'\n", rp->r_argv[0], rp->r_label); } @@ -338,7 +232,7 @@ message *m_ptr; /* request message pointer */ int i, s; if (rs_start.rss_nr_control > RSS_NR_CONTROL) { - printf("RS: do_start: too many control labels\n"); + printf("RS: do_up: too many control labels\n"); return EINVAL; } for (i=0; ir_nr_control = rs_start.rss_nr_control; if (rs_verbose) { - printf("RS: do_start: control labels:"); + printf("RS: do_up: control labels:"); for (i=0; ir_nr_control; i++) printf(" %s", rp->r_control[i]); printf("\n"); @@ -443,7 +337,7 @@ message *m_ptr; /* request message pointer */ /* Copy granted resources */ if (rs_start.rss_nr_irq > NR_IRQ) { - printf("RS: do_start: too many IRQs requested\n"); + printf("RS: do_up: too many IRQs requested\n"); return EINVAL; } rp->r_priv.s_nr_irq= rs_start.rss_nr_irq; @@ -451,12 +345,12 @@ message *m_ptr; /* request message pointer */ { rp->r_priv.s_irq_tab[i]= rs_start.rss_irq[i]; if(rs_verbose) - printf("RS: do_start: IRQ %d\n", rp->r_priv.s_irq_tab[i]); + printf("RS: do_up: IRQ %d\n", rp->r_priv.s_irq_tab[i]); } if (rs_start.rss_nr_io > NR_IO_RANGE) { - printf("RS: do_start: too many I/O ranges requested\n"); + printf("RS: do_up: too many I/O ranges requested\n"); return EINVAL; } rp->r_priv.s_nr_io_range= rs_start.rss_nr_io; @@ -466,14 +360,14 @@ message *m_ptr; /* request message pointer */ rp->r_priv.s_io_tab[i].ior_limit= rs_start.rss_io[i].base+rs_start.rss_io[i].len-1; if(rs_verbose) - printf("RS: do_start: I/O [%x..%x]\n", + printf("RS: do_up: I/O [%x..%x]\n", rp->r_priv.s_io_tab[i].ior_base, rp->r_priv.s_io_tab[i].ior_limit); } if (rs_start.rss_nr_pci_id > RSS_NR_PCI_ID) { - printf("RS: do_start: too many PCI device IDs\n"); + printf("RS: do_up: too many PCI device IDs\n"); return EINVAL; } rp->r_nr_pci_id= rs_start.rss_nr_pci_id; @@ -482,12 +376,12 @@ message *m_ptr; /* request message pointer */ rp->r_pci_id[i].vid= rs_start.rss_pci_id[i].vid; rp->r_pci_id[i].did= rs_start.rss_pci_id[i].did; if(rs_verbose) - printf("RS: do_start: PCI %04x/%04x\n", + printf("RS: do_up: PCI %04x/%04x\n", rp->r_pci_id[i].vid, rp->r_pci_id[i].did); } if (rs_start.rss_nr_pci_class > RSS_NR_PCI_CLASS) { - printf("RS: do_start: too many PCI class IDs\n"); + printf("RS: do_up: too many PCI class IDs\n"); return EINVAL; } rp->r_nr_pci_class= rs_start.rss_nr_pci_class; @@ -496,7 +390,7 @@ message *m_ptr; /* request message pointer */ rp->r_pci_class[i].class= rs_start.rss_pci_class[i].class; rp->r_pci_class[i].mask= rs_start.rss_pci_class[i].mask; if(rs_verbose) - printf("RS: do_start: PCI class %06x mask %06x\n", + printf("RS: do_up: PCI class %06x mask %06x\n", rp->r_pci_class[i].class, rp->r_pci_class[i].mask); } @@ -510,7 +404,7 @@ message *m_ptr; /* request message pointer */ else { printf( - "RS: do_start: internal inconsistency: bad size of r_call_mask\n"); + "RS: do_up: internal inconsistency: bad size of r_call_mask\n"); memset(rp->r_call_mask, '\0', sizeof(rp->r_call_mask)); } @@ -519,9 +413,8 @@ message *m_ptr; /* request message pointer */ rp->r_dev_nr = rs_start.rss_major; rp->r_dev_style = STYLE_DEV; rp->r_restarts = -1; /* will be incremented */ - rp->r_set_resources= 1; /* new style, enforce - * I/O resources - */ + rp->r_set_resources= 1; /* set resources */ + if (sizeof(rp->r_vm) == sizeof(rs_start.rss_vm) && sizeof(rp->r_vm[0]) == sizeof(rs_start.rss_vm[0])) { @@ -529,7 +422,7 @@ message *m_ptr; /* request message pointer */ } else { - printf("RS: do_start: internal inconsistency: bad size of r_vm\n"); + printf("RS: do_up: internal inconsistency: bad size of r_vm\n"); memset(rp->r_vm, '\0', sizeof(rp->r_vm)); } @@ -767,7 +660,10 @@ PUBLIC void do_exit(message *m_ptr) rproc_ptr[proc] = NULL; /* invalidate */ rp->r_pid= -1; - pci_del_acl(rp->r_proc_nr_e); /* Ignore errors */ + /* If PCI properties are set, inform the PCI driver. */ + if(rp->r_nr_pci_id || rp->r_nr_pci_class) { + pci_del_acl(rp->r_proc_nr_e); + } if ((rp->r_flags & RS_EXITING) || shutting_down) { /* No reply sent to RS_DOWN yet. */ @@ -883,7 +779,7 @@ message *m_ptr; else if (rp->r_period > 0) { /* Check if an answer to a status request is still pending. If - * the driver didn't respond within time, kill it to simulate + * the service didn't respond within time, kill it to simulate * a crash. The failure will be detected and the service will * be restarted automatically. */ @@ -935,7 +831,6 @@ endpoint_t *endpoint; pid_t child_pid; /* child's process id */ char *file_only; int s, use_copy, slot_nr; - struct priv *privp; bitchunk_t *vm_mask; message m; char * null_env = NULL; @@ -1035,36 +930,25 @@ endpoint_t *endpoint; } } - privp= NULL; - vm_mask = NULL; + /* Set resources when asked to. */ if (rp->r_set_resources) { + /* Initialize privilege structure. */ init_privs(rp, &rp->r_priv); - privp= &rp->r_priv; - - /* Inform the PCI server about the driver */ - init_pci(rp, child_proc_nr_e); + /* Tell VM about allowed calls. */ vm_mask = &rp->r_vm[0]; + if ((s = vm_set_priv(child_proc_nr_e, vm_mask)) < 0) { + report("RS", "vm_set_priv call failed", s); + kill(child_pid, SIGKILL); + rp->r_flags |= RS_EXITING; + return (s); + } } - /* Tell VM about allowed calls, before actually letting the process run. */ - if ((s = vm_set_priv(child_proc_nr_e, vm_mask)) < 0) { - report("RS", "vm_set_priv call failed", s); - kill(child_pid, SIGKILL); - rp->r_flags |= RS_EXITING; - return (s); - } - - /* Set the privilege structure for the child process. - * That will also cause the child process to start running. - * This call should succeed: we tested number in use above. - */ - if ((s = set_privs(child_proc_nr_e, privp, SYS_PRIV_SET_SYS)) != OK) { - report("RS","set_privs failed", s); - kill(child_pid, SIGKILL); /* kill driver */ - rp->r_flags |= RS_EXITING; /* expect exit */ - return(s); /* return error */ + /* If PCI properties are set, inform the PCI driver about the new service. */ + if(rp->r_nr_pci_id || rp->r_nr_pci_class) { + init_pci(rp, child_proc_nr_e); } /* The purpose of non-blocking forks is to avoid involving VFS in the forking @@ -1089,14 +973,20 @@ endpoint_t *endpoint; if ((s=mapdriver5(rp->r_label, strlen(rp->r_label), rp->r_dev_nr, rp->r_dev_style, !!use_copy /* force */)) < 0) { report("RS", "couldn't map driver (continuing)", errno); -#if 0 - kill(child_pid, SIGKILL); /* kill driver */ - rp->r_flags |= RS_EXITING; /* expect exit */ - return(s); /* return error */ -#endif } } + /* Set the privilege structure for the child process. + * That will also cause the child process to start running. + * This call should succeed: we tested number in use above. + */ + if ((s = set_privs(child_proc_nr_e, &rp->r_priv, SYS_PRIV_SET_SYS)) != OK) { + report("RS","set_privs failed", s); + kill(child_pid, SIGKILL); /* kill the service */ + rp->r_flags |= RS_EXITING; /* expect exit */ + return(s); /* return error */ + } + if(rs_verbose) printf("RS: started '%s', major %d, pid %d, endpoint %d, proc %d\n", rp->r_cmd, rp->r_dev_nr, child_pid, @@ -1555,7 +1445,7 @@ PRIVATE void init_pci(rp, endpoint) struct rproc *rp; int endpoint; { - /* Tell the PCI driver about the new driver */ + /* Inform the PCI driver about the new service. */ size_t len; int i, r; struct rs_pci rs_pci; diff --git a/servers/rs/proto.h b/servers/rs/proto.h index e8d9a099f..4372f0ed0 100644 --- a/servers/rs/proto.h +++ b/servers/rs/proto.h @@ -11,8 +11,7 @@ _PROTOTYPE( int dev_execve, (int proc_e, _PROTOTYPE( int main, (void)); /* manager.c */ -_PROTOTYPE( int do_up, (message *m, int do_copy, int flags)); -_PROTOTYPE( int do_start, (message *m)); +_PROTOTYPE( int do_up, (message *m)); _PROTOTYPE( int do_down, (message *m)); _PROTOTYPE( int do_refresh, (message *m)); _PROTOTYPE( int do_restart, (message *m)); diff --git a/servers/rs/service.c b/servers/rs/service.c index 80c66e872..f1ed0114d 100644 --- a/servers/rs/service.c +++ b/servers/rs/service.c @@ -35,9 +35,7 @@ PRIVATE char *known_requests[] = { "down", "refresh", "restart", - "-unused", "shutdown", - "upcopy", /* fill for RS_UP_COPY */ "catch for illegal requests" }; #define ILLEGAL_REQUEST sizeof(known_requests)/sizeof(char *) @@ -47,7 +45,7 @@ PRIVATE char *known_requests[] = { #define RUN_CMD "run" #define RUN_SCRIPT "/etc/rs.single" /* Default script for 'run' */ -#define PATH_CONFIG _PATH_DRIVERS_CONF /* Default config file */ +#define PATH_CONFIG _PATH_SYSTEM_CONF /* Default config file */ /* Define names for arguments provided to this utility. The first few * arguments are required and have a known index. Thereafter, some optional @@ -66,7 +64,7 @@ PRIVATE char *known_requests[] = { #define ARG_DEV "-dev" /* major device number for drivers */ #define ARG_PERIOD "-period" /* heartbeat period in ticks */ #define ARG_SCRIPT "-script" /* name of the script to restart a - * driver + * system service */ #define ARG_LABELNAME "-label" /* custom label name */ #define ARG_CONFIG "-config" /* name of the file with the resource @@ -74,7 +72,7 @@ PRIVATE char *known_requests[] = { */ #define ARG_PRINTEP "-printep" /* print endpoint number after start */ -#define DRIVER_LOGIN "driver" /* Passwd file entry for drivers */ +#define SERVICE_LOGIN "service" /* passwd file entry for services */ #define MAX_CLASS_RECURS 100 /* Max nesting level for classes */ @@ -192,8 +190,6 @@ PRIVATE int parse_arguments(int argc, char **argv) } if (req_nr == RS_UP) { - req_nr= RS_START; - rs_start.rss_flags= RF_IPC_VALID; if (c_flag) rs_start.rss_flags |= RF_COPY; @@ -205,14 +201,8 @@ PRIVATE int parse_arguments(int argc, char **argv) { /* Set default recovery script for RUN */ req_script = RUN_SCRIPT; - req_nr = RS_START; } -#if 0 - if (req_nr == RS_UP && c_flag) - req_nr= RS_UP_COPY; -#endif - /* Verify argument count. */ if (argc - 1 < optind+ARG_PATH) { print_usage(argv[ARG_NAME], "action requires a binary to start"); @@ -276,15 +266,12 @@ PRIVATE int parse_arguments(int argc, char **argv) } else if (strcmp(argv[i], ARG_SCRIPT)==0) { req_script = argv[i+1]; - req_nr = RS_START; } else if (strcmp(argv[i], ARG_LABELNAME)==0) { req_label = argv[i+1]; - req_nr = RS_START; } else if (strcmp(argv[i], ARG_CONFIG)==0) { req_config = argv[i+1]; - req_nr = RS_START; } else if (strcmp(argv[i], ARG_PRINTEP)==0) { req_printep = 1; @@ -325,7 +312,7 @@ PRIVATE void fatal(char *fmt, ...) exit(1); } -#define KW_DRIVER "driver" +#define KW_SERVICE "service" #define KW_UID "uid" #define KW_NICE "nice" #define KW_IRQ "irq" @@ -338,7 +325,7 @@ PRIVATE void fatal(char *fmt, ...) #define KW_VM "vm" #define KW_CONTROL "control" -FORWARD void do_driver(config_t *cpe, config_t *config); +FORWARD void do_service(config_t *cpe, config_t *config); PRIVATE void do_class(config_t *cpe, config_t *config) { @@ -382,10 +369,10 @@ PRIVATE void do_class(config_t *cpe, config_t *config) cp1->file, cp1->line); } - /* At this place we expect the word 'driver' */ - if (strcmp(cp1->word, KW_DRIVER) != 0) + /* At this place we expect the word KW_SERVICE */ + if (strcmp(cp1->word, KW_SERVICE) != 0) fatal("do_class: exected word '%S' at %s:%d", - KW_DRIVER, cp1->file, cp1->line); + KW_SERVICE, cp1->file, cp1->line); cp1= cp1->next; if ((cp1->flags & CFG_STRING) || @@ -395,7 +382,7 @@ PRIVATE void do_class(config_t *cpe, config_t *config) cp1->file, cp1->line); } - /* At this place we expect the name of the driver */ + /* At this place we expect the name of the service */ if (strcmp(cp1->word, cpe->word) == 0) break; } @@ -405,7 +392,7 @@ PRIVATE void do_class(config_t *cpe, config_t *config) "do_class: no entry found for class '%s' at %s:%d", cpe->word, cpe->file, cpe->line); } - do_driver(cp1->next, config); + do_service(cp1->next, config); } class_recurs--; @@ -887,7 +874,7 @@ PRIVATE void do_control(config_t *cpe) } } -PRIVATE void do_driver(config_t *cpe, config_t *config) +PRIVATE void do_service(config_t *cpe, config_t *config) { config_t *cp; @@ -896,13 +883,13 @@ PRIVATE void do_driver(config_t *cpe, config_t *config) */ if (!(cpe->flags & CFG_SUBLIST)) { - fatal("do_driver: expected list at %s:%d", + fatal("do_service: expected list at %s:%d", cpe->file, cpe->line); } if (cpe->next != NULL) { cpe= cpe->next; - fatal("do_driver: expected end of list at %s:%d", + fatal("do_service: expected end of list at %s:%d", cpe->file, cpe->line); } cpe= cpe->list; @@ -912,13 +899,13 @@ PRIVATE void do_driver(config_t *cpe, config_t *config) { if (!(cp->flags & CFG_SUBLIST)) { - fatal("do_driver: expected list at %s:%d", + fatal("do_service: expected list at %s:%d", cp->file, cp->line); } cpe= cp->list; if ((cpe->flags & CFG_STRING) || (cpe->flags & CFG_SUBLIST)) { - fatal("do_driver: expected word at %s:%d", + fatal("do_service: expected word at %s:%d", cpe->file, cpe->line); } @@ -987,7 +974,7 @@ PRIVATE void do_config(char *label, char *filename) exit(1); } - /* Find an entry for our driver */ + /* Find an entry for our service */ for (cp= config; cp; cp= cp->next) { if (!(cp->flags & CFG_SUBLIST)) @@ -1002,10 +989,10 @@ PRIVATE void do_config(char *label, char *filename) cpe->file, cpe->line); } - /* At this place we expect the word 'driver' */ - if (strcmp(cpe->word, KW_DRIVER) != 0) + /* At this place we expect the word KW_SERVICE */ + if (strcmp(cpe->word, KW_SERVICE) != 0) fatal("do_config: exected word '%S' at %s:%d", - KW_DRIVER, cpe->file, cpe->line); + KW_SERVICE, cpe->file, cpe->line); cpe= cpe->next; if ((cpe->flags & CFG_STRING) || (cpe->flags & CFG_SUBLIST)) @@ -1014,20 +1001,20 @@ PRIVATE void do_config(char *label, char *filename) cpe->file, cpe->line); } - /* At this place we expect the name of the driver */ + /* At this place we expect the name of the service. */ if (strcmp(cpe->word, label) == 0) break; } if (cp == NULL) { - fprintf(stderr, "service: driver '%s' not found in config\n", + fprintf(stderr, "service: service '%s' not found in config\n", label); exit(1); } cpe= cpe->next; - do_driver(cpe, config); + do_service(cpe, config); } /* Main program. @@ -1060,22 +1047,6 @@ PUBLIC int main(int argc, char **argv) */ switch(request) { case RS_UP: - case RS_UP_COPY: - /* Build space-separated command string to be passed to RS server. */ - strcpy(command, req_path); - command[strlen(req_path)] = ' '; - strcpy(command+strlen(req_path)+1, req_args); - - /* Build request message and send the request. */ - m.RS_CMD_ADDR = command; - m.RS_CMD_LEN = strlen(command); - m.RS_DEV_MAJOR = req_major; - m.RS_PERIOD = req_period; - if (OK != (s=_taskcall(RS_PROC_NR, request, &m))) - failure(-s); - result = m.m_type; - break; - case RS_START: /* Build space-separated command string to be passed to RS server. */ strcpy(command, req_path); command[strlen(req_path)] = ' '; @@ -1098,12 +1069,12 @@ PUBLIC int main(int argc, char **argv) else rs_start.rss_scriptlen= 0; - pw= getpwnam(DRIVER_LOGIN); + pw= getpwnam(SERVICE_LOGIN); if (pw == NULL) - fatal("no passwd file entry for '%s'", DRIVER_LOGIN); + fatal("no passwd file entry for '%s'", SERVICE_LOGIN); rs_start.rss_uid= pw->pw_uid; - /* The name of the driver */ + /* The name of the system service. */ (label= strrchr(req_path, '/')) ? label++ : (label= req_path); if (req_config) { diff --git a/servers/rs/type.h b/servers/rs/type.h index aa2e2ce2c..4d1bd5ee0 100644 --- a/servers/rs/type.h +++ b/servers/rs/type.h @@ -50,7 +50,7 @@ struct rproc { char *r_exec; /* Executable image */ size_t r_exec_len; /* Length of image */ - char r_label[MAX_LABEL_LEN]; /* unique name of this driver */ + char r_label[MAX_LABEL_LEN]; /* unique name of this service */ char r_cmd[MAX_COMMAND_LEN]; /* raw command plus arguments */ char r_script[MAX_SCRIPT_LEN]; /* name of the restart script executable */ char *r_argv[MAX_NR_ARGS+2]; /* parsed arguments vector */