Calls and functionality for get/setpriority() and fsync().

This commit is contained in:
Ben Gras 2005-07-01 17:58:29 +00:00
parent bfc8f08ae7
commit 9cf24c3233
9 changed files with 91 additions and 1 deletions

View file

@ -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 *

View file

@ -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) );

View file

@ -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];

View file

@ -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);

View file

@ -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 <minix/callnr.h>
#include <signal.h>
#include <sys/svrctl.h>
#include <sys/resource.h>
#include <minix/com.h>
#include <minix/utils.h>
#include <string.h>
@ -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 *
*=====================================================================*/

View file

@ -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];

View file

@ -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));

View file

@ -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];

View file

@ -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;
}