Mercurial > emacs
comparison src/filelock.c @ 24816:cc789d9ef186
(get_boot_time): Don't look at /proc/uptime; it
doesn't work if the system date is changed, or if the system
is suspended. Look at the last-modified time of
/var/run/random-seed instead.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Sat, 05 Jun 1999 01:13:36 +0000 |
parents | 0895c669be5e |
children | 28e022c50e4f |
comparison
equal
deleted
inserted
replaced
24815:aea50239347a | 24816:cc789d9ef186 |
---|---|
110 extern Lisp_Object Vshell_file_name; | 110 extern Lisp_Object Vshell_file_name; |
111 | 111 |
112 static time_t | 112 static time_t |
113 get_boot_time () | 113 get_boot_time () |
114 { | 114 { |
115 struct utmp ut, *utp; | |
116 int fd; | |
117 EMACS_TIME time_before, after; | |
118 int counter; | 115 int counter; |
116 struct stat st; | |
119 | 117 |
120 if (boot_time_initialized) | 118 if (boot_time_initialized) |
121 return boot_time; | 119 return boot_time; |
122 boot_time_initialized = 1; | 120 boot_time_initialized = 1; |
123 | 121 |
124 EMACS_GET_TIME (time_before); | 122 if (stat ("/var/run/random-seed", &st) == 0) |
125 | 123 { |
126 /* Try calculating the last boot time | 124 boot_time = st.st_mtime; |
127 from the uptime as obtained from /proc/uptime. | 125 return boot_time; |
128 | 126 } |
129 This has a disadvantage in that if the system time has been | 127 |
130 changed (say to correct the clock), | |
131 then current_time - uptime != wtmp_boot_time. | |
132 However, the speedup from doing this can be so great | |
133 that I think it is worth that problem occasionally. */ | |
134 | |
135 while ((fd = open ("/proc/uptime", O_RDONLY)) >= 0) | |
136 { | |
137 char buf[100]; | |
138 int res; | |
139 double upsecs; | |
140 time_t uptime; | |
141 | |
142 read (fd, buf, sizeof buf); | |
143 close (fd); | |
144 | |
145 res = sscanf (buf, "%lf", &upsecs); | |
146 | |
147 /* If the current time did not tick while we were getting the | |
148 uptime, we have a valid result. */ | |
149 EMACS_GET_TIME (after); | |
150 if (res == 1 && EMACS_SECS (after) == EMACS_SECS (time_before)) | |
151 { | |
152 boot_time = EMACS_SECS (time_before) - (time_t) upsecs; | |
153 return boot_time; | |
154 } | |
155 | |
156 /* Otherwise, try again to read the uptime. */ | |
157 time_before = after; | |
158 } | |
159 #if defined (CTL_KERN) && defined (KERN_BOOTTIME) | 128 #if defined (CTL_KERN) && defined (KERN_BOOTTIME) |
160 { | 129 { |
161 int mib[2]; | 130 int mib[2]; |
162 size_t size; | 131 size_t size; |
163 struct timeval boottime_val; | 132 struct timeval boottime_val; |