libsys: various updates

- move system calls for use by services from libminlib into libsys;
- move srv_fork(2) and srv_kill(2) from RS and into libsys;
- replace getprocnr(2) with sef_self(3);
- rename previous getnprocnr(2) to getprocnr(2);
- clean up getepinfo(2);
- change all libsys calls that used _syscall to use _taskcall, so as
  to avoid going through errno to pass errors; this is already how
  most calls work anyway, and many of the calls previously using
  _syscall were already assumed to return the actual error;
- initialize request messages to zero, for future compatibility
  (note that this does not include PCI calls, which are in need of a
  much bigger overhaul, nor kernel calls);
- clean up more of dead DS code as a side effect.

Change-Id: I8788f54c68598fcf58e23486e270c2d749780ebb
This commit is contained in:
David van Moolenbroek
2013-11-03 22:33:44 +01:00
committed by Lionel Sambuc
parent efd3487bc5
commit 80bd109cd3
82 changed files with 477 additions and 544 deletions

View File

@@ -413,8 +413,8 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
/* Get pid from PM. */
rp->r_pid = getnpid(rpub->endpoint);
if(rp->r_pid == -1) {
panic("unable to get pid");
if(rp->r_pid < 0) {
panic("unable to get pid: %d", rp->r_pid);
}
}
@@ -433,11 +433,12 @@ static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
/* Fork a new RS instance with root:operator. */
pid = srv_fork(0, 0);
if(pid == -1) {
panic("unable to fork a new RS instance");
if(pid < 0) {
panic("unable to fork a new RS instance: %d", pid);
}
replica_pid = pid ? pid : getpid();
replica_endpoint = getnprocnr(replica_pid);
if ((s = getprocnr(replica_pid, &replica_endpoint)) != 0)
panic("unable to get replica endpoint: %d", s);
replica_rp->r_pid = replica_pid;
replica_rp->r_pub->endpoint = replica_endpoint;

View File

@@ -210,30 +210,6 @@ void build_cmd_dep(struct rproc *rp)
rpub->proc_name[len]= '\0';
}
/*===========================================================================*
* srv_fork *
*===========================================================================*/
pid_t srv_fork(uid_t reuid, gid_t regid)
{
message m;
m.m1_i1 = (int) reuid;
m.m1_i2 = (int) regid;
return _syscall(PM_PROC_NR, SRV_FORK, &m);
}
/*===========================================================================*
* srv_kill *
*===========================================================================*/
int srv_kill(pid_t pid, int sig)
{
message m;
m.m1_i1 = pid;
m.m1_i2 = sig;
return(_syscall(PM_PROC_NR, SRV_KILL, &m));
}
/*===========================================================================*
* srv_update *
*===========================================================================*/
@@ -481,14 +457,15 @@ struct rproc *rp;
if(rs_verbose)
printf("RS: forking child with srv_fork()...\n");
child_pid= srv_fork(rp->r_uid, 0); /* Force group to operator for now */
if(child_pid == -1) {
printf("RS: srv_fork() failed (error %d)\n", errno);
if(child_pid < 0) {
printf("RS: srv_fork() failed (error %d)\n", child_pid);
free_slot(rp);
return(errno);
return(child_pid);
}
/* Get endpoint of the child. */
child_proc_nr_e = getnprocnr(child_pid);
if ((s = getprocnr(child_pid, &child_proc_nr_e)) != 0)
panic("unable to get child endpoint: %d", s);
/* There is now a child process. Update the system process table. */
child_proc_nr_n = _ENDPOINT_P(child_proc_nr_e);
@@ -677,8 +654,8 @@ struct rproc *rp; /* pointer to service slot */
*/
setuid(0);
if (mapdriver(rpub->label, rpub->dev_nr) != OK) {
return kill_service(rp, "couldn't map driver", errno);
if ((r = mapdriver(rpub->label, rpub->dev_nr)) != OK) {
return kill_service(rp, "couldn't map driver", r);
}
}
@@ -1133,7 +1110,8 @@ static int run_script(struct rproc *rp)
exit(1);
default:
/* Set the privilege structure for the child process. */
endpoint = getnprocnr(pid);
if ((r = getprocnr(pid, &endpoint)) != 0)
panic("unable to get child endpoint: %d", r);
if ((r = sys_privctl(endpoint, SYS_PRIV_SET_USER, NULL))
!= OK) {
return kill_service(rp,"can't set script privileges",r);

View File

@@ -34,8 +34,6 @@ int copy_rs_start(endpoint_t src_e, char *src_rs_start, struct rs_start
int copy_label(endpoint_t src_e, char *src_label, size_t src_len, char
*dst_label, size_t dst_len);
void build_cmd_dep(struct rproc *rp);
int srv_fork(uid_t reuid, gid_t regid);
int srv_kill(pid_t pid, int sig);
int srv_update(endpoint_t src_e, endpoint_t dst_e);
#define kill_service(rp, errstr, err) \
kill_service_debug(__FILE__, __LINE__, rp, errstr, err)