diff options
| author | Karl Heuer | 1999-06-05 01:13:36 +0000 |
|---|---|---|
| committer | Karl Heuer | 1999-06-05 01:13:36 +0000 |
| commit | 445ebb943f6f44e1731d59873d839633e33bb7a1 (patch) | |
| tree | aa19551bc34ce604e42c498bd4a215e6304e4a9d /src | |
| parent | 57ec49bae044d8b3a62094160f5e345c8f24a5da (diff) | |
| download | emacs-445ebb943f6f44e1731d59873d839633e33bb7a1.tar.gz emacs-445ebb943f6f44e1731d59873d839633e33bb7a1.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/filelock.c | 41 |
1 files changed, 5 insertions, 36 deletions
diff --git a/src/filelock.c b/src/filelock.c index 2f880d10d2d..9217b58f188 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -112,50 +112,19 @@ extern Lisp_Object Vshell_file_name; | |||
| 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 | |||
| 126 | /* Try calculating the last boot time | ||
| 127 | from the uptime as obtained from /proc/uptime. | ||
| 128 | |||
| 129 | This has a disadvantage in that if the system time has been | ||
| 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 | { | 123 | { |
| 137 | char buf[100]; | 124 | boot_time = st.st_mtime; |
| 138 | int res; | 125 | return boot_time; |
| 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 | } | 126 | } |
| 127 | |||
| 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]; |