void lock_file (Lisp_Object fn) { register Lisp_Object attack, orig_fn, encoded_fn; register char *lfname, *locker; lock_info_type lock_info; struct gcpro gcpro1; /* Don't do locking while dumping Emacs. Uncompressing wtmp files uses call-process, which does not work in an uninitialized Emacs. */ if (! NILP (Vpurify_flag)) return; orig_fn = fn; GCPRO1 (fn); fn = Fexpand_file_name (fn, Qnil); encoded_fn = ENCODE_FILE (fn); /* Create the name of the lock-file for file fn */ MAKE_LOCK_NAME (lfname, encoded_fn); /* See if this file is visited and has changed on disk since it was visited. */ { register Lisp_Object subject_buf; subject_buf = get_truename_buffer (orig_fn); if (!NILP (subject_buf) && NILP (Fverify_visited_file_modtime (subject_buf)) && !NILP (Ffile_exists_p (fn))) call1 (intern ("ask-user-about-supersession-threat"), fn); } UNGCPRO; /* Try to lock the lock. */ if (lock_if_free (&lock_info, lfname) <= 0) /* Return now if we have locked it, or if lock creation failed */ return; /* Else consider breaking the lock */ locker = (char *) alloca (strlen (lock_info.user) + strlen (lock_info.host) + LOCK_PID_MAX + 9); sprintf (locker, "%s@%s (pid %lu)", lock_info.user, lock_info.host, lock_info.pid); FREE_LOCK_INFO (lock_info); attack = call2 (intern ("ask-user-about-lock"), fn, build_string (locker)); if (!NILP (attack)) /* User says take the lock */ { lock_file_1 (lfname, 1); return; } /* User says ignore the lock */ }
static time_t get_boot_time (void) { #if defined (BOOT_TIME) int counter; #endif if (boot_time_initialized) return boot_time; boot_time_initialized = 1; #if defined (CTL_KERN) && defined (KERN_BOOTTIME) { int mib[2]; size_t size; struct timeval boottime_val; mib[0] = CTL_KERN; mib[1] = KERN_BOOTTIME; size = sizeof (boottime_val); if (sysctl (mib, 2, &boottime_val, &size, NULL, 0) >= 0) { boot_time = boottime_val.tv_sec; return boot_time; } } #endif /* defined (CTL_KERN) && defined (KERN_BOOTTIME) */ if (BOOT_TIME_FILE) { struct stat st; if (stat (BOOT_TIME_FILE, &st) == 0) { boot_time = st.st_mtime; return boot_time; } } #if defined (BOOT_TIME) #ifndef CANNOT_DUMP /* The utmp routines maintain static state. Don't touch that state unless we are initialized, since it might not survive dumping. */ if (! initialized) return boot_time; #endif /* not CANNOT_DUMP */ /* Try to get boot time from utmp before wtmp, since utmp is typically much smaller than wtmp. Passing a null pointer causes get_boot_time_1 to inspect the default file, namely utmp. */ get_boot_time_1 (0, 0); if (boot_time) return boot_time; /* Try to get boot time from the current wtmp file. */ get_boot_time_1 (WTMP_FILE, 1); /* If we did not find a boot time in wtmp, look at wtmp, and so on. */ for (counter = 0; counter < 20 && ! boot_time; counter++) { char cmd_string[sizeof WTMP_FILE ".19.gz"]; Lisp_Object tempname, filename; bool delete_flag = 0; filename = Qnil; tempname = make_formatted_string (cmd_string, "%s.%d", WTMP_FILE, counter); if (! NILP (Ffile_exists_p (tempname))) filename = tempname; else { tempname = make_formatted_string (cmd_string, "%s.%d.gz", WTMP_FILE, counter); if (! NILP (Ffile_exists_p (tempname))) { Lisp_Object args[6]; /* The utmp functions on mescaline.gnu.org accept only file names up to 8 characters long. Choose a 2 character long prefix, and call make_temp_file with second arg non-zero, so that it will add not more than 6 characters to the prefix. */ filename = Fexpand_file_name (build_string ("wt"), Vtemporary_file_directory); filename = make_temp_name (filename, 1); args[0] = build_string ("gzip"); args[1] = Qnil; args[2] = list2 (QCfile, filename); args[3] = Qnil; args[4] = build_string ("-cd"); args[5] = tempname; Fcall_process (6, args); delete_flag = 1; } } if (! NILP (filename)) { get_boot_time_1 (SSDATA (filename), 1); if (delete_flag) unlink (SSDATA (filename)); } } return boot_time; #else return 0; #endif }