Mercurial > emacs
changeset 24406:76205fb50ca1
(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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 26 Feb 1999 10:47:36 +0000 |
parents | 61704c572291 |
children | dfdc50279d1e |
files | src/filelock.c |
diffstat | 1 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/filelock.c Fri Feb 26 09:23:52 1999 +0000 +++ b/src/filelock.c Fri Feb 26 10:47:36 1999 +0000 @@ -54,6 +54,10 @@ #ifdef CLASH_DETECTION #include <utmp.h> + +#ifndef WTMP_FILE +#define WTMP_FILE "/var/log/wtmp" +#endif /* The strategy: to lock a file FN, create a symlink .#FN in FN's directory, with link data `user@host.pid'. This avoids a single @@ -140,7 +144,7 @@ } /* Try to get boot time from the current wtmp file. */ - get_boot_time_1 ("/var/log/wtmp"); + get_boot_time_1 (WTMP_FILE); /* If we did not find a boot time in wtmp, look at wtmp, and so on. */ for (counter = 0; counter < 20 && boot_time == 1; counter++) @@ -151,13 +155,13 @@ filename = Qnil; - sprintf (cmd_string, "/var/log/wtmp.%d", counter); + sprintf (cmd_string, "%s.%d", WTMP_FILE, counter); tempname = build_string (cmd_string); if (! NILP (Ffile_exists_p (filename))) filename = tempname; else { - sprintf (cmd_string, "/var/log/wtmp.%d.gz", counter); + sprintf (cmd_string, "%s.%d.gz", WTMP_FILE, counter); tempname = build_string (cmd_string); if (! NILP (Ffile_exists_p (tempname))) { @@ -168,8 +172,8 @@ args[2] = Qnil; args[3] = Qnil; args[4] = build_string ("-c"); - sprintf (cmd_string, "gunzip < /var/log/wtmp.%d.gz > %s", - counter, XSTRING (tempname)->data); + sprintf (cmd_string, "gunzip < %s.%d.gz > %s", + WTMP_FILE, counter, XSTRING (tempname)->data); args[5] = build_string (cmd_string); Fcall_process (6, args); filename = tempname; @@ -200,7 +204,16 @@ char *filename; { struct utmp ut, *utp; + int desc; + /* On some versions of IRIX, opening a nonexistent file name + is likely to crash in the utmp routines. */ + desc = open (filename, O_RDONLY); + if (desc < 0) + return; + + close (desc); + utmpname (filename); setutent (); while (1)