diff options
| author | Richard M. Stallman | 1999-02-26 10:47:36 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1999-02-26 10:47:36 +0000 |
| commit | 77e544a4cd34dbbc778b1fcfd9f393a6d05be7aa (patch) | |
| tree | 3150f98fb388aa2d195eca844dc6578c821d52e7 /src/filelock.c | |
| parent | 7c9cd4467d6c3f55dbd8c1fa4f2de5db6494034f (diff) | |
| download | emacs-77e544a4cd34dbbc778b1fcfd9f393a6d05be7aa.tar.gz emacs-77e544a4cd34dbbc778b1fcfd9f393a6d05be7aa.zip | |
(get_boot_time): Use WTMP_FILE for file name.
(WTMP_FILE): Default definition in case not defined.
(get_boot_time_1): Test that file exists before trying to read it.
Diffstat (limited to 'src/filelock.c')
| -rw-r--r-- | src/filelock.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/filelock.c b/src/filelock.c index c80f75ce924..cfcf30f85ed 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -54,6 +54,10 @@ extern int errno; | |||
| 54 | #ifdef CLASH_DETECTION | 54 | #ifdef CLASH_DETECTION |
| 55 | 55 | ||
| 56 | #include <utmp.h> | 56 | #include <utmp.h> |
| 57 | |||
| 58 | #ifndef WTMP_FILE | ||
| 59 | #define WTMP_FILE "/var/log/wtmp" | ||
| 60 | #endif | ||
| 57 | 61 | ||
| 58 | /* The strategy: to lock a file FN, create a symlink .#FN in FN's | 62 | /* The strategy: to lock a file FN, create a symlink .#FN in FN's |
| 59 | directory, with link data `user@host.pid'. This avoids a single | 63 | directory, with link data `user@host.pid'. This avoids a single |
| @@ -140,7 +144,7 @@ get_boot_time () | |||
| 140 | } | 144 | } |
| 141 | 145 | ||
| 142 | /* Try to get boot time from the current wtmp file. */ | 146 | /* Try to get boot time from the current wtmp file. */ |
| 143 | get_boot_time_1 ("/var/log/wtmp"); | 147 | get_boot_time_1 (WTMP_FILE); |
| 144 | 148 | ||
| 145 | /* If we did not find a boot time in wtmp, look at wtmp, and so on. */ | 149 | /* If we did not find a boot time in wtmp, look at wtmp, and so on. */ |
| 146 | for (counter = 0; counter < 20 && boot_time == 1; counter++) | 150 | for (counter = 0; counter < 20 && boot_time == 1; counter++) |
| @@ -151,13 +155,13 @@ get_boot_time () | |||
| 151 | 155 | ||
| 152 | filename = Qnil; | 156 | filename = Qnil; |
| 153 | 157 | ||
| 154 | sprintf (cmd_string, "/var/log/wtmp.%d", counter); | 158 | sprintf (cmd_string, "%s.%d", WTMP_FILE, counter); |
| 155 | tempname = build_string (cmd_string); | 159 | tempname = build_string (cmd_string); |
| 156 | if (! NILP (Ffile_exists_p (filename))) | 160 | if (! NILP (Ffile_exists_p (filename))) |
| 157 | filename = tempname; | 161 | filename = tempname; |
| 158 | else | 162 | else |
| 159 | { | 163 | { |
| 160 | sprintf (cmd_string, "/var/log/wtmp.%d.gz", counter); | 164 | sprintf (cmd_string, "%s.%d.gz", WTMP_FILE, counter); |
| 161 | tempname = build_string (cmd_string); | 165 | tempname = build_string (cmd_string); |
| 162 | if (! NILP (Ffile_exists_p (tempname))) | 166 | if (! NILP (Ffile_exists_p (tempname))) |
| 163 | { | 167 | { |
| @@ -168,8 +172,8 @@ get_boot_time () | |||
| 168 | args[2] = Qnil; | 172 | args[2] = Qnil; |
| 169 | args[3] = Qnil; | 173 | args[3] = Qnil; |
| 170 | args[4] = build_string ("-c"); | 174 | args[4] = build_string ("-c"); |
| 171 | sprintf (cmd_string, "gunzip < /var/log/wtmp.%d.gz > %s", | 175 | sprintf (cmd_string, "gunzip < %s.%d.gz > %s", |
| 172 | counter, XSTRING (tempname)->data); | 176 | WTMP_FILE, counter, XSTRING (tempname)->data); |
| 173 | args[5] = build_string (cmd_string); | 177 | args[5] = build_string (cmd_string); |
| 174 | Fcall_process (6, args); | 178 | Fcall_process (6, args); |
| 175 | filename = tempname; | 179 | filename = tempname; |
| @@ -200,7 +204,16 @@ get_boot_time_1 (filename) | |||
| 200 | char *filename; | 204 | char *filename; |
| 201 | { | 205 | { |
| 202 | struct utmp ut, *utp; | 206 | struct utmp ut, *utp; |
| 207 | int desc; | ||
| 203 | 208 | ||
| 209 | /* On some versions of IRIX, opening a nonexistent file name | ||
| 210 | is likely to crash in the utmp routines. */ | ||
| 211 | desc = open (filename, O_RDONLY); | ||
| 212 | if (desc < 0) | ||
| 213 | return; | ||
| 214 | |||
| 215 | close (desc); | ||
| 216 | |||
| 204 | utmpname (filename); | 217 | utmpname (filename); |
| 205 | setutent (); | 218 | setutent (); |
| 206 | while (1) | 219 | while (1) |