From: Ben Gras Date: Fri, 1 Jul 2005 17:58:29 +0000 (+0000) Subject: Calls and functionality for get/setpriority() and fsync(). X-Git-Tag: v3.1.0~657 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.named.html?a=commitdiff_plain;h=9cf24c32331ddeb13920700e4ae58fd6f60b683c;p=minix.git Calls and functionality for get/setpriority() and fsync(). --- diff --git a/servers/fs/misc.c b/servers/fs/misc.c index 773a89ebb..78a209918 100644 --- a/servers/fs/misc.c +++ b/servers/fs/misc.c @@ -6,6 +6,7 @@ * do_dup: perform the DUP system call * do_fcntl: perform the FCNTL system call * do_sync: perform the SYNC system call + * do_fsync: perform the FSYNC system call * do_reboot: sync disks and prepare for shutdown * do_fork: adjust the tables after MM has performed a FORK system call * do_exec: handle files with FD_CLOEXEC on after MM has done an EXEC @@ -187,6 +188,19 @@ PUBLIC int do_sync() return(OK); /* sync() can't fail */ } +/*===========================================================================* + * do_fsync * + *===========================================================================*/ +PUBLIC int do_fsync() +{ +/* Perform the fsync() system call. For now, don't be unnecessarily smart. */ + + do_sync(); + + return(OK); +} + + /*===========================================================================* * do_reboot * diff --git a/servers/fs/proto.h b/servers/fs/proto.h index 915501e5f..0f813ddc0 100644 --- a/servers/fs/proto.h +++ b/servers/fs/proto.h @@ -87,6 +87,7 @@ _PROTOTYPE( int do_exec, (void) ); _PROTOTYPE( int do_revive, (void) ); _PROTOTYPE( int do_set, (void) ); _PROTOTYPE( int do_sync, (void) ); +_PROTOTYPE( int do_fsync, (void) ); _PROTOTYPE( int do_reboot, (void) ); _PROTOTYPE( int do_svrctl, (void) ); _PROTOTYPE( int do_getsysinfo, (void) ); diff --git a/servers/fs/table.c b/servers/fs/table.c index 9e9c463af..cc8bbbf4e 100644 --- a/servers/fs/table.c +++ b/servers/fs/table.c @@ -104,6 +104,9 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { no_sys, /* 84 = memfree */ do_select, /* 85 = select */ do_fchdir, /* 86 = fchdir */ + do_fsync, /* 87 = fsync */ + no_sys, /* 88 = getpriority */ + no_sys, /* 89 = setpriority */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; diff --git a/servers/pm/main.c b/servers/pm/main.c index fd40d7697..6d12bae32 100644 --- a/servers/pm/main.c +++ b/servers/pm/main.c @@ -210,6 +210,7 @@ PRIVATE void pm_init() * handling behaviour for PM, since PM cannot call sigaction() as others. */ mproc[INIT_PROC_NR].mp_pid = INIT_PID; + mproc[INIT_PROC_NR].mp_nice = 0; mproc[INIT_PROC_NR].mp_parent = PM_PROC_NR; sigemptyset(&mproc[INIT_PROC_NR].mp_ignore); sigemptyset(&mproc[INIT_PROC_NR].mp_sigmask); diff --git a/servers/pm/misc.c b/servers/pm/misc.c index bf22f52c4..69b825b14 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -7,12 +7,14 @@ * do_getprocnr: lookup process slot number (Jorrit N. Herder) * do_memalloc: allocate a chunk of memory (Jorrit N. Herder) * do_memfree: deallocate a chunk of memory (Jorrit N. Herder) + * do_getsetpriority: get/set process priority */ #include "pm.h" #include #include #include +#include #include #include #include @@ -164,6 +166,52 @@ PUBLIC int do_reboot() return(SUSPEND); /* don't reply to killed process */ } +/*=====================================================================* + * do_getsetpriority * + *=====================================================================*/ +PUBLIC int do_getsetpriority() +{ + int arg_which, arg_who, arg_pri; + int rmp_nr; + struct mproc *rmp; + + arg_which = m_in.m1_i1; + arg_who = m_in.m1_i2; + arg_pri = m_in.m1_i3; /* for SETPRIORITY */ + + /* Code common to GETPRIORITY and SETPRIORITY. */ + + /* Only support PRIO_PROCESS for now. */ + if(arg_which != PRIO_PROCESS) + return EINVAL; + + if(arg_who == 0) + rmp_nr = who; + else + if((rmp_nr = proc_from_pid(arg_who)) < 0) + return ESRCH; + + rmp = &mproc[rmp_nr]; + + if(mp->mp_effuid != SUPER_USER && + mp->mp_effuid != rmp->mp_effuid && mp->mp_effuid != rmp->mp_realuid) + return EPERM; + + /* If GET, that's it. */ + + if(call_nr == GETPRIORITY) { + return rmp->mp_nice - PRIO_MIN; + } + + /* Only root is allowed to reduce the nice level. */ + if(rmp->mp_nice > arg_pri && mp->mp_effuid != SUPER_USER) + return EACCES; + + /* We're SET, and it's allowed. Do it and tell kernel. */ + rmp->mp_nice = arg_pri; + return sys_setpriority(rmp_nr, arg_pri); +} + /*=====================================================================* * do_svrctl * *=====================================================================*/ diff --git a/servers/pm/mproc.h b/servers/pm/mproc.h index b873e35fd..755fd2ba0 100644 --- a/servers/pm/mproc.h +++ b/servers/pm/mproc.h @@ -46,6 +46,9 @@ EXTERN struct mproc { struct mproc *mp_swapq; /* queue of procs waiting to be swapped in */ message mp_reply; /* reply message to be sent to one */ + /* Scheduling priority. */ + signed int mp_nice; /* nice is PRIO_MIN..PRIO_MAX, standard 0. */ + char mp_name[PROC_NAME_LEN]; /* process name */ } mproc[NR_PROCS]; diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 2e29ebee3..108992b43 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -59,7 +59,7 @@ _PROTOTYPE( int do_getprocnr, (void) ); _PROTOTYPE( int do_svrctl, (void) ); _PROTOTYPE( int do_allocmem, (void) ); _PROTOTYPE( int do_freemem, (void) ); -_PROTOTYPE( int do_mstats, (void) ); +_PROTOTYPE( int do_getsetpriority, (void) ); #if (MACHINE == MACINTOSH) _PROTOTYPE( phys_clicks start_click, (void) ); @@ -100,4 +100,5 @@ _PROTOTYPE( void tell_fs, (int what, int p1, int p2, int p3) ); _PROTOTYPE( int get_stack_ptr, (int proc_nr, vir_bytes *sp) ); _PROTOTYPE( int get_mem_map, (int proc_nr, struct mem_map *mem_map) ); _PROTOTYPE( char *find_param, (const char *key)); +_PROTOTYPE( int proc_from_pid, (pid_t p)); diff --git a/servers/pm/table.c b/servers/pm/table.c index 3adec3153..1768dd414 100644 --- a/servers/pm/table.c +++ b/servers/pm/table.c @@ -103,6 +103,9 @@ _PROTOTYPE (int (*call_vec[NCALLS]), (void) ) = { do_freemem, /* 84 = memfree */ no_sys, /* 85 = select */ no_sys, /* 86 = fchdir */ + no_sys, /* 87 = fsync */ + do_getsetpriority, /* 88 = getpriority */ + do_getsetpriority, /* 89 = setpriority */ }; /* This should not fail with "array size is negative": */ extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1]; diff --git a/servers/pm/utility.c b/servers/pm/utility.c index 0e8c577c9..8301adda0 100644 --- a/servers/pm/utility.c +++ b/servers/pm/utility.c @@ -9,6 +9,7 @@ * tell_fs: interface to FS * get_mem_map: get memory map of given process * get_stack_ptr: get stack pointer of given process + * proc_from_pid: return process pointer from pid number */ #include "pm.h" @@ -200,3 +201,18 @@ vir_bytes *sp; /* put stack pointer here */ return(OK); } +/*===========================================================================* + * proc_from_pid * + *===========================================================================*/ +PUBLIC int proc_from_pid(mp_pid) +pid_t mp_pid; +{ + int rmp; + + for (rmp = 0; rmp < NR_PROCS; rmp++) + if (mproc[rmp].mp_pid == mp_pid) + return rmp; + + return -1; +} +