MCPcopy Create free account
hub / github.com/NetHack/NetHack / veryold

Function veryold

sys/unix/unixunix.c:37–77  ·  view source on GitHub ↗

see whether we should throw away this xlock file; if yes, close it, otherwise leave it open */

Source from the content-addressed store, hash-verified

35/* see whether we should throw away this xlock file;
36 if yes, close it, otherwise leave it open */
37static int
38veryold(int fd)
39{
40 time_t date;
41
42 if (fstat(fd, &buf))
43 return 0; /* cannot get status */
44#ifndef INSURANCE
45 if (buf.st_size != sizeof (int))
46 return 0; /* not an xlock file */
47#endif
48#if defined(BSD) && !defined(POSIX_TYPES)
49 (void) time((long *) (&date));
50#else
51 (void) time(&date);
52#endif
53 if (date - buf.st_mtime < 3L * 24L * 60L * 60L) { /* recent */
54 int lockedpid; /* should be the same size as hackpid */
55
56 if (read(fd, (genericptr_t) &lockedpid, sizeof lockedpid)
57 != sizeof lockedpid)
58 /* strange ... */
59 return 0;
60
61/* From: Rick Adams <seismo!rick> */
62/* This will work on 4.1cbsd, 4.2bsd and system 3? & 5. */
63/* It will do nothing on V7 or 4.1bsd. */
64#ifndef NETWORK
65 /* It will do a VERY BAD THING if the playground is shared
66 by more than one machine! -pem */
67 if (!(kill(lockedpid, 0) == -1 && errno == ESRCH))
68#endif
69 return 0;
70 }
71 /* this used to close the file upon success, leave it open upon failure;
72 that was supposed to simplify the caller's usage but ended up making
73 that be more complicated; always leave the file open so that caller
74 can close it unconditionally */
75 /*(void) close(fd);*/
76 return 1;
77}
78
79static int
80eraseoldlocks(void)

Callers 1

getlockFunction · 0.70

Calls 2

timeFunction · 0.85
readFunction · 0.85

Tested by

no test coverage detected