comparison src/filelock.c @ 24869:28e022c50e4f

(BOOT_TIME_FILE): New macro. (get_boot_time): Use it instead of hardwiring the file name. Check BOOT_TIME_FILE only after inspecting the kernel directly.
author Paul Eggert <eggert@twinsun.com>
date Fri, 18 Jun 1999 05:49:18 +0000
parents cc789d9ef186
children 1dfff6fa0f05
comparison
equal deleted inserted replaced
24868:de2065294ca3 24869:28e022c50e4f
59 #endif 59 #endif
60 60
61 #ifdef CLASH_DETECTION 61 #ifdef CLASH_DETECTION
62 62
63 #include <utmp.h> 63 #include <utmp.h>
64
65 /* A file whose last-modified time is just after the most recent boot.
66 Define this to be NULL to disable checking for this file. */
67 #ifndef BOOT_TIME_FILE
68 #define BOOT_TIME_FILE "/var/run/random-seed"
69 #endif
64 70
65 #ifndef WTMP_FILE 71 #ifndef WTMP_FILE
66 #define WTMP_FILE "/var/log/wtmp" 72 #define WTMP_FILE "/var/log/wtmp"
67 #endif 73 #endif
68 74
111 117
112 static time_t 118 static time_t
113 get_boot_time () 119 get_boot_time ()
114 { 120 {
115 int counter; 121 int counter;
116 struct stat st;
117 122
118 if (boot_time_initialized) 123 if (boot_time_initialized)
119 return boot_time; 124 return boot_time;
120 boot_time_initialized = 1; 125 boot_time_initialized = 1;
121
122 if (stat ("/var/run/random-seed", &st) == 0)
123 {
124 boot_time = st.st_mtime;
125 return boot_time;
126 }
127 126
128 #if defined (CTL_KERN) && defined (KERN_BOOTTIME) 127 #if defined (CTL_KERN) && defined (KERN_BOOTTIME)
129 { 128 {
130 int mib[2]; 129 int mib[2];
131 size_t size; 130 size_t size;
140 boot_time = boottime_val.tv_sec; 139 boot_time = boottime_val.tv_sec;
141 return boot_time; 140 return boot_time;
142 } 141 }
143 } 142 }
144 #endif /* defined (CTL_KERN) && defined (KERN_BOOTTIME) */ 143 #endif /* defined (CTL_KERN) && defined (KERN_BOOTTIME) */
144
145 if (BOOT_TIME_FILE)
146 {
147 struct stat st;
148 if (stat (BOOT_TIME_FILE, &st) == 0)
149 {
150 boot_time = st.st_mtime;
151 return boot_time;
152 }
153 }
145 154
146 #if defined (BOOT_TIME) && ! defined (NO_WTMP_FILE) 155 #if defined (BOOT_TIME) && ! defined (NO_WTMP_FILE)
147 #ifndef CANNOT_DUMP 156 #ifndef CANNOT_DUMP
148 /* The utmp routines maintain static state. 157 /* The utmp routines maintain static state.
149 Don't touch that state unless we are initialized, 158 Don't touch that state unless we are initialized,