1 /* $XConsortium: AuLock.c,v 1.15 94/04/17 20:15:43 rws Exp $ */
2 /* $XFree86: xc/lib/Xau/AuLock.c,v 3.0 1994/10/20 06:04:31 dawes Exp $ */
6 Copyright (c) 1988 X Consortium
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
31 #include <X11/Xauth.h>
35 #if defined(X_NOT_STDC_ENV)
38 extern Time_t time ();
47 extern unsigned sleep ();
56 #if NeedFunctionPrototypes
59 _Xconst char *file_name,
65 XauLockAuth (file_name, retries, timeout, dead)
72 char creat_name[1025], link_name[1025];
77 if (strlen (file_name) > 1022)
79 (void) strcpy (creat_name, file_name);
80 (void) strcat (creat_name, "-c");
81 (void) strcpy (link_name, file_name);
82 (void) strcat (link_name, "-l");
83 if (stat (creat_name, &statb) != -1) {
84 now = time ((Time_t *) 0);
86 * NFS may cause ctime to be before now, special
87 * case a 0 deadtime to force lock removal
89 if (dead == 0 || now - statb.st_ctime > dead) {
90 (void) unlink (creat_name);
91 (void) unlink (link_name);
97 creat_fd = creat (creat_name, 0666);
102 (void) close (creat_fd);
104 if (creat_fd != -1) {
105 if (link (creat_name, link_name) != -1)
107 if (errno == ENOENT) {
108 creat_fd = -1; /* force re-creat next time around */
114 (void) sleep ((unsigned) timeout);