source: branches/minix3-book/servers/pm/time.c@ 12

Last change on this file since 12 was 4, checked in by Mattia Monga, 14 years ago

Importazione sorgenti libro

File size: 2.5 KB
Line 
1/* This file takes care of those system calls that deal with time.
2 *
3 * The entry points into this file are
4 * do_time: perform the TIME system call
5 * do_stime: perform the STIME system call
6 * do_times: perform the TIMES system call
7 */
8
9#include "pm.h"
10#include <minix/callnr.h>
11#include <minix/com.h>
12#include <signal.h>
13#include "mproc.h"
14#include "param.h"
15
16PRIVATE time_t boottime;
17
18/*===========================================================================*
19 * do_time *
20 *===========================================================================*/
21PUBLIC int do_time()
22{
23/* Perform the time(tp) system call. This returns the time in seconds since
24 * 1.1.1970. MINIX is an astrophysically naive system that assumes the earth
25 * rotates at a constant rate and that such things as leap seconds do not
26 * exist.
27 */
28 clock_t uptime;
29 int s;
30
31 if ( (s=getuptime(&uptime)) != OK)
32 panic(__FILE__,"do_time couldn't get uptime", s);
33
34 mp->mp_reply.reply_time = (time_t) (boottime + (uptime/HZ));
35 mp->mp_reply.reply_utime = (uptime%HZ)*1000000/HZ;
36 return(OK);
37}
38
39/*===========================================================================*
40 * do_stime *
41 *===========================================================================*/
42PUBLIC int do_stime()
43{
44/* Perform the stime(tp) system call. Retrieve the system's uptime (ticks
45 * since boot) and store the time in seconds at system boot in the global
46 * variable 'boottime'.
47 */
48 clock_t uptime;
49 int s;
50
51 if (mp->mp_effuid != SUPER_USER) {
52 return(EPERM);
53 }
54 if ( (s=getuptime(&uptime)) != OK)
55 panic(__FILE__,"do_stime couldn't get uptime", s);
56 boottime = (long) m_in.stime - (uptime/HZ);
57
58 /* Also inform FS about the new system time. */
59 tell_fs(STIME, boottime, 0, 0);
60
61 return(OK);
62}
63
64/*===========================================================================*
65 * do_times *
66 *===========================================================================*/
67PUBLIC int do_times()
68{
69/* Perform the times(buffer) system call. */
70 register struct mproc *rmp = mp;
71 clock_t t[5];
72 int s;
73
74 if (OK != (s=sys_times(who, t)))
75 panic(__FILE__,"do_times couldn't get times", s);
76 rmp->mp_reply.reply_t1 = t[0]; /* user time */
77 rmp->mp_reply.reply_t2 = t[1]; /* system time */
78 rmp->mp_reply.reply_t3 = rmp->mp_child_utime; /* child user time */
79 rmp->mp_reply.reply_t4 = rmp->mp_child_stime; /* child system time */
80 rmp->mp_reply.reply_t5 = t[4]; /* uptime since boot */
81
82 return(OK);
83}
84
Note: See TracBrowser for help on using the repository browser.