0
|
1 /* lock.c - universal locking routines */
|
|
2 #ifndef lint
|
|
3 static char ident[] = "@(#)$Id$";
|
|
4 #endif
|
|
5 /* compile-time priority:
|
|
6 * MAILLOCK or LIBLOCKFILE use if defined
|
|
7 * LOCKF use if defined
|
|
8 * FCNTL use if SYS5 defined and LOCKF not defined
|
|
9 * FLOCK use if BSD42 defined and LOCKF and SYS5 not defined
|
|
10 */
|
|
11
|
|
12 #ifdef MMDFONLY
|
|
13 #define LOCKONLY
|
|
14 #endif
|
|
15
|
|
16 #include "../h/mh.h"
|
|
17 #include <stdio.h>
|
|
18 #ifndef LOCKONLY
|
|
19 #include "../h/strings.h"
|
|
20 #include "mts.h"
|
|
21 #else /* LOCKONLY */
|
|
22 #include "strings.h"
|
|
23 #ifdef MMDFONLY
|
|
24 #include "mmdfonly.h"
|
|
25 #include "mts.h"
|
|
26 #else /* not MMDFONLY */
|
|
27 #include "lockonly.h"
|
|
28 #endif /* not MMDFONLY */
|
|
29 #endif /* LOCKONLY */
|
|
30 #include <sys/types.h>
|
|
31 #include <sys/stat.h>
|
|
32 #ifdef SVR4
|
|
33 #ifndef LOCKF
|
|
34 #define LOCKF
|
|
35 #endif
|
|
36 #include <unistd.h>
|
|
37 #endif /* SVR4 */
|
|
38 #ifdef LOCKF
|
|
39 #include <sys/errno.h>
|
|
40 #include <sys/file.h>
|
|
41 #ifndef F_ULOCK
|
|
42 #ifdef UNISTD
|
|
43 #include <unistd.h>
|
|
44 #else /* UNISTD */
|
|
45 #include <sys/fcntl.h>
|
|
46 #endif /* UNISTD */
|
|
47 #endif
|
|
48 #endif /* LOCKF */
|
|
49 #if defined(_AIX) || defined(AUX)
|
|
50 #include <sys/file.h>
|
|
51 #endif
|
|
52 #if defined(__386BSD__) || defined(BSD44)
|
|
53 #include <fcntl.h>
|
|
54 #endif
|
|
55 #ifdef _AIX
|
|
56 #include <sys/time.h>
|
|
57 #include <time.h>
|
|
58 #else
|
|
59 #ifdef BSD42
|
|
60 #include <sys/time.h>
|
|
61 #else /* BSD42 */
|
|
62 #include <time.h>
|
|
63 #endif /* BSD42 */
|
|
64 #endif
|
|
65
|
|
66 #ifdef SYS5
|
|
67 #define u_short ushort
|
|
68 #define u_long ulong
|
|
69 #endif
|
|
70
|
|
71
|
|
72 #if defined(SYS5) && !defined(_AIX)
|
|
73 #define index strchr
|
|
74 #define rindex strrchr
|
|
75 #endif
|
|
76 #ifdef BSD42
|
|
77 #define FLOCK /* LOCKF will override this, if defined */
|
|
78 #endif
|
|
79
|
|
80 #include <errno.h>
|
|
81
|
|
82 #ifdef LOCKONLY
|
|
83 #ifndef MMDFONLY
|
|
84 char *lockldir = "/usr/spool/locks";
|
|
85 #endif /* not MMDFONLY */
|
|
86 #endif /* LOCKONLY */
|
|
87
|
|
88 #ifdef MAILLOCK
|
|
89 /* Both "mts.h" and <maillock.h> defines MAILDIR */
|
|
90 #undef MAILDIR
|
|
91 #include <maillock.h>
|
|
92 static int is_default_spool();
|
|
93 #undef LIBLOCKFILE
|
|
94 #else /* MAILLOCK */
|
|
95 #ifdef LIBLOCKFILE
|
|
96 #define LOCK_LIBLOCKFILE 1
|
|
97 #define LOCK_B_LKOPEN 2
|
|
98 char *lockname_from_fd();
|
|
99 #endif
|
|
100 #endif /* MAILLOCK */
|
|
101
|
|
102 static int b_lkopen(), lockit(), f_lkopen();
|
|
103 static lockname(), timerON(), timerOFF();
|
|
104
|
|
105 time_t time ();
|
|
106 char *mktemp ();
|
|
107
|
|
108 /* */
|
|
109
|
|
110 int lkopen (file, access)
|
|
111 register char *file;
|
|
112 register int access;
|
|
113 {
|
|
114 mts_init ("mts");
|
|
115 switch (lockstyle) {
|
|
116 case LOK_UNIX:
|
|
117 #ifdef MAILLOCK
|
|
118 if (is_default_spool (file))
|
|
119 return f_lkopen (file, access);
|
|
120 /* else fall */
|
|
121 #else /* MAILLOCK */
|
|
122 #if defined(FLOCK) || defined(LOCKF) || defined(FCNTL) || defined(LIBLOCKFILE)
|
|
123 return f_lkopen (file, access);
|
|
124 #endif
|
|
125 #endif /* MAILLOCK */
|
|
126
|
|
127 default:
|
|
128 return b_lkopen (file, access);
|
|
129 }
|
|
130 }
|
|
131
|
|
132 /* */
|
|
133
|
|
134 static int b_lkopen (file, access)
|
|
135 register char *file;
|
|
136 register int access;
|
|
137 {
|
|
138 register int i,
|
|
139 j;
|
|
140 time_t curtime;
|
|
141 char curlock[BUFSIZ],
|
|
142 tmplock[BUFSIZ];
|
|
143 struct stat st;
|
|
144
|
|
145 if (stat (file, &st) == NOTOK)
|
|
146 return NOTOK;
|
|
147 lockname (curlock, tmplock, file, (int) st.st_dev, (int) st.st_ino);
|
|
148
|
|
149 for (i = 0;;)
|
|
150 switch (lockit (tmplock, curlock)) {
|
|
151 case OK:
|
|
152 if ((i = open (file, access)) == NOTOK) {
|
|
153 j = errno;
|
|
154 (void) unlink (curlock);
|
|
155 errno = j;
|
|
156 }
|
|
157 #ifdef LIBLOCKFILE
|
|
158 timerON (curlock, i, LOCK_B_LKOPEN);
|
|
159 #else
|
|
160 timerON (curlock, i);
|
|
161 #endif
|
|
162 return i;
|
|
163
|
|
164 case NOTOK:
|
|
165 if (stat (curlock, &st) == NOTOK) {
|
|
166 if (i++ > 5)
|
|
167 return NOTOK;
|
|
168 sleep (5);
|
|
169 break;
|
|
170 }
|
|
171
|
|
172 i = 0;
|
|
173 (void) time (&curtime);
|
|
174 if (curtime < st.st_ctime + 60L)
|
|
175 sleep (5);
|
|
176 else
|
|
177 (void) unlink (curlock);
|
|
178 break;
|
|
179 }
|
|
180 }
|
|
181
|
|
182
|
|
183 static int lockit (tmp, file)
|
|
184 register char *tmp,
|
|
185 *file;
|
|
186 {
|
|
187 register int fd;
|
|
188
|
|
189 if ((fd = creat (tmp, 0400)) == NOTOK)
|
|
190 return NOTOK;
|
|
191 #if defined(hpux) || defined(ncr)
|
|
192 write(fd, "MH lock\n",8);
|
|
193 #endif /* hpux */
|
|
194 (void) close (fd);
|
|
195
|
|
196 fd = link (tmp, file);
|
|
197 (void) unlink (tmp);
|
|
198
|
|
199 return (fd != NOTOK ? OK : NOTOK);
|
|
200 }
|
|
201
|
|
202 /* */
|
|
203
|
|
204 static lockname (curlock, tmplock, file, dev, ino)
|
|
205 register char *curlock,
|
|
206 *tmplock,
|
|
207 *file;
|
|
208 register int dev,
|
|
209 ino;
|
|
210 {
|
|
211 register char *bp,
|
|
212 *cp;
|
|
213
|
|
214 bp = curlock;
|
|
215 if ((cp = rindex (file, '/')) == NULL || *++cp == 0)
|
|
216 cp = file;
|
|
217 if (lockldir == NULL || *lockldir == 0) {
|
|
218 if (cp != file) {
|
|
219 (void) sprintf (bp, "%.*s", cp - file, file);
|
|
220 bp += strlen (bp);
|
|
221 }
|
|
222 }
|
|
223 else {
|
|
224 (void) sprintf (bp, "%s/", lockldir);
|
|
225 bp += strlen (bp);
|
|
226 }
|
|
227
|
|
228 switch (lockstyle) {
|
|
229 case LOK_BELL:
|
|
230 default:
|
|
231 (void) sprintf (bp, "%s.lock", cp);
|
|
232 break;
|
|
233
|
|
234 case LOK_MMDF:
|
|
235 (void) sprintf (bp, "LCK%05d.%05d", dev, ino);
|
|
236 break;
|
|
237 }
|
|
238
|
|
239 if (tmplock) {
|
|
240 if ((cp = rindex (curlock, '/')) == NULL || *++cp == 0)
|
|
241 (void) strcpy (tmplock, ",LCK.XXXXXX");
|
|
242 else
|
|
243 (void) sprintf (tmplock, "%.*s,LCK.XXXXXX",
|
|
244 cp - curlock, curlock);
|
|
245 (void) unlink (mktemp (tmplock));
|
|
246 }
|
|
247 }
|
|
248
|
|
249 /* */
|
|
250
|
|
251 #if defined(BSD42) || defined(SVR4)
|
|
252 #include <sys/file.h>
|
|
253 #if defined(SUN40) || defined(SVR4)
|
|
254 #include <sys/fcntl.h>
|
|
255 #endif
|
|
256 #else
|
|
257 #ifdef FCNTL
|
|
258 #include <fcntl.h>
|
|
259 #endif
|
|
260 #endif
|
|
261
|
|
262 #ifdef MAILLOCK
|
|
263
|
|
264 static int f_lkopen (file, access)
|
|
265 register char *file;
|
|
266 register int access;
|
|
267 {
|
|
268 register int fd;
|
|
269
|
|
270 if (maillock (getusr (), 5) == L_SUCCESS) {
|
|
271 if ((fd = open (file, access | O_NDELAY)) == NOTOK)
|
|
272 return NOTOK;
|
|
273 return fd;
|
|
274 }
|
|
275
|
|
276 return NOTOK;
|
|
277 }
|
|
278
|
|
279 #else /* not MAILLOCK */
|
|
280 #ifdef LIBLOCKFILE
|
|
281 #include <lockfile.h>
|
|
282 #include <limits.h>
|
|
283
|
|
284 static int f_lkopen (file, access)
|
|
285 register char *file;
|
|
286 register int access;
|
|
287 {
|
|
288 int r, fd;
|
|
289 char mlockfile[PATH_MAX];
|
|
290
|
|
291 snprintf(mlockfile, PATH_MAX, "%s.lock", file);
|
|
292 r = lockfile_create(mlockfile, 5, 0);
|
|
293 if (r != 0)
|
|
294 return NOTOK;
|
|
295 fd = open(file, access | O_NDELAY);
|
|
296 if (fd == -1)
|
|
297 return NOTOK;
|
|
298 /* we have to set up a timer so we can touch the lockfile occasionally */
|
|
299 timerON(mlockfile, fd, LOCK_LIBLOCKFILE);
|
|
300 /* NB: it's OK to pass mlockfile as timerON immediately copies it
|
|
301 * and we then use the copy in all lockfile_foo() operations.
|
|
302 */
|
|
303 return fd;
|
|
304 }
|
|
305
|
|
306 #else /* not LIBLOCKFILE */
|
|
307 #if defined(FLOCK) || defined(LOCKF) || defined(FCNTL)
|
|
308
|
|
309 static int f_lkopen (file, access)
|
|
310 register char *file;
|
|
311 register int access;
|
|
312 {
|
|
313 register int fd,
|
|
314 i,
|
|
315 j;
|
|
316 #ifdef FCNTL
|
|
317 struct flock buf;
|
|
318 #endif /* FCNTL */
|
|
319
|
|
320 for (i = 0; i < 5; i++) {
|
|
321 #if defined(LOCKF) || defined(FCNTL)
|
|
322 j = access;
|
|
323 access &= ~O_APPEND; /* make sure we open at the beginning */
|
|
324 if ((access & 03) == O_RDONLY) {
|
|
325 /* We MUST have write permission or lockf/fcntl() won't work */
|
|
326 /* (Stupid eh?) */
|
|
327 access &= ~O_RDONLY;
|
|
328 access |= O_RDWR;
|
|
329 }
|
|
330 #endif /* LOCKF || FCNTL */
|
|
331 if ((fd = open (file, access | O_NDELAY)) == NOTOK)
|
|
332 return NOTOK;
|
|
333 #ifndef LOCKF
|
|
334 #ifndef FLOCK
|
|
335 #ifndef FCNTL
|
|
336 /* should be an error? */
|
|
337 #else /* FCNTL */
|
|
338 buf.l_type = F_WRLCK;
|
|
339 buf.l_whence = 0;
|
|
340 buf.l_start = 0;
|
|
341 buf.l_len = 0;
|
|
342 if (fcntl (fd, F_SETLK, &buf) != NOTOK)
|
|
343 return fd;
|
|
344 #endif
|
|
345 #else /* FLOCK */
|
|
346 if (flock (fd, LOCK_EX | LOCK_NB) != NOTOK)
|
|
347 return fd;
|
|
348 #endif
|
|
349 #else /* LOCKF */
|
|
350 if (lockf (fd, F_TLOCK, 0L) != NOTOK) {
|
|
351 /* see if we should be at the end */
|
|
352 if (j & O_APPEND)
|
|
353 #ifdef SVR4
|
|
354 lseek (fd, (off_t)0, SEEK_END);
|
|
355 #else
|
|
356 lseek (fd, (off_t)0, L_XTND);
|
|
357 #endif
|
|
358 return fd;
|
|
359 }
|
|
360 /* Fix errno - lockf screws it */
|
|
361 if (errno == EACCES)
|
|
362 errno = EWOULDBLOCK;
|
|
363 #endif
|
|
364 j = errno;
|
|
365 (void) close (fd);
|
|
366
|
|
367 sleep (5);
|
|
368 }
|
|
369
|
|
370 (void) close (fd);
|
|
371 errno = j;
|
|
372 return NOTOK;
|
|
373 }
|
|
374 #endif /* FLOCK || LOCKF || FCNTL */
|
|
375 #endif /* not LIBLOCKFILE */
|
|
376 #endif /* not MAILLOCK */
|
|
377
|
|
378 /* */
|
|
379
|
|
380 /* ARGSUSED */
|
|
381
|
|
382 int lkclose (fd, file)
|
|
383 register int fd;
|
|
384 register char *file;
|
|
385 {
|
|
386 char curlock[BUFSIZ];
|
|
387 struct stat st;
|
|
388 #ifdef FCNTL
|
|
389 struct flock buf;
|
|
390 #endif
|
|
391
|
|
392 if (fd == NOTOK)
|
|
393 return OK;
|
|
394 switch (lockstyle) {
|
|
395 case LOK_UNIX:
|
|
396 #ifndef MAILLOCK
|
|
397 #ifndef LIBLOCKFILE
|
|
398 #ifndef LOCKF
|
|
399 #ifndef FLOCK
|
|
400 #ifndef FCNTL
|
|
401 /* should be an error? */
|
|
402 #else /* FCNTL */
|
|
403 buf.l_type = F_UNLCK;
|
|
404 buf.l_whence = 0;
|
|
405 buf.l_start = 0;
|
|
406 buf.l_len = 0;
|
|
407 fcntl(fd, F_SETLK, &buf);
|
|
408 break;
|
|
409 #endif
|
|
410 #else /* FLOCK */
|
|
411 flock (fd, LOCK_UN);
|
|
412 break;
|
|
413 #endif
|
|
414 #else /* LOCKF */
|
|
415 lseek (fd, (off_t)0, L_SET); /* make sure we unlock the whole thing */
|
|
416 lockf (fd, F_ULOCK, 0L);
|
|
417 break;
|
|
418 #endif
|
|
419 #else /* LIBLOCKFILE */
|
|
420 {
|
|
421 char *n = lockname_from_fd(fd);
|
|
422 if (!n) /* shouldn't happen: would be program bug */
|
|
423 return NOTOK;
|
|
424 lockfile_remove(n);
|
|
425 timerOFF(fd);
|
|
426 break;
|
|
427 }
|
|
428 #endif
|
|
429 #else /* MAILLOCK */
|
|
430 if (is_default_spool (file)) {
|
|
431 mailunlock ();
|
|
432 break;
|
|
433 }
|
|
434 /* else fall */
|
|
435 #endif
|
|
436
|
|
437 default:
|
|
438 if (fstat (fd, &st) != NOTOK) {
|
|
439 lockname (curlock, NULLCP, file, (int) st.st_dev, (int) st.st_ino);
|
|
440 (void) unlink (curlock);
|
|
441 timerOFF (fd);
|
|
442 }
|
|
443 }
|
|
444
|
|
445 return (close (fd));
|
|
446 }
|
|
447
|
|
448
|
|
449 /* */
|
|
450
|
|
451 FILE *lkfopen (file, mode)
|
|
452 register char *file,
|
|
453 *mode;
|
|
454 {
|
|
455 register int fd;
|
|
456 register FILE *fp;
|
|
457
|
|
458 if ((fd = lkopen (file, strcmp (mode, "r") ? 2 : 0)) == NOTOK)
|
|
459 return NULL;
|
|
460
|
|
461 if ((fp = fdopen (fd, mode)) == NULL) {
|
|
462 (void) close (fd);
|
|
463 return NULL;
|
|
464 }
|
|
465
|
|
466 return fp;
|
|
467 }
|
|
468
|
|
469
|
|
470 /* ARGSUSED */
|
|
471
|
|
472 int lkfclose (fp, file)
|
|
473 register FILE *fp;
|
|
474 register char *file;
|
|
475 {
|
|
476 char curlock[BUFSIZ];
|
|
477 struct stat st;
|
|
478 #ifdef FCNTL
|
|
479 struct flock buf;
|
|
480 #endif
|
|
481
|
|
482 if (fp == NULL)
|
|
483 return OK;
|
|
484
|
|
485 switch (lockstyle) {
|
|
486 case LOK_UNIX:
|
|
487 #ifndef MAILLOCK
|
|
488 #ifndef LIBLOCKFILE
|
|
489 #ifndef LOCKF
|
|
490 #ifndef FLOCK
|
|
491 #ifndef FCNTL
|
|
492 /* should be an error? */
|
|
493 #else /* FCNTL */
|
|
494 buf.l_type = F_UNLCK;
|
|
495 buf.l_whence = 0;
|
|
496 buf.l_start = 0;
|
|
497 buf.l_len = 0;
|
|
498 fcntl(fileno(fp), F_SETLK, &buf);
|
|
499 break;
|
|
500 #endif
|
|
501 #else /* FLOCK */
|
|
502 flock (fileno(fp), LOCK_UN);
|
|
503 break;
|
|
504 #endif
|
|
505 #else /* LOCKF */
|
|
506 fseek (fp, 0L, 0); /* make sure we unlock the whole thing */
|
|
507 lockf (fileno(fp), F_ULOCK, 0L);
|
|
508 break;
|
|
509 #endif
|
|
510 #else /* LIBLOCKFILE */
|
|
511 {
|
|
512 char *n = lockname_from_fd(fileno(fp));
|
|
513 if (!n) /* shouldn't happen */
|
|
514 return NOTOK;
|
|
515 lockfile_remove(n);
|
|
516 timerOFF(fileno(fp));
|
|
517 break;
|
|
518 }
|
|
519 #endif
|
|
520 #else /* MAILLOCK */
|
|
521 if (is_default_spool (file)) {
|
|
522 mailunlock ();
|
|
523 break;
|
|
524 }
|
|
525 /* else fall */
|
|
526 #endif
|
|
527
|
|
528 default:
|
|
529 if (fstat (fileno (fp), &st) != NOTOK) {
|
|
530 lockname (curlock, NULLCP, file, (int) st.st_dev, (int) st.st_ino);
|
|
531 (void) unlink (curlock);
|
|
532 #ifdef LIBLOCKFILE
|
|
533 /* shouldn't we timerOFF(fileno(fp))? We do in lkclose() -- PMM */
|
|
534 #else
|
|
535 timerOFF (fileno (fp));
|
|
536 #endif
|
|
537 }
|
|
538 }
|
|
539
|
|
540 return (fclose (fp));
|
|
541 }
|
|
542
|
|
543 /* */
|
|
544
|
|
545 #include <signal.h>
|
|
546
|
|
547 #define NSECS ((unsigned) 20)
|
|
548
|
|
549
|
|
550 struct lock {
|
|
551 #ifdef LIBLOCKFILE
|
|
552 int l_locktype;
|
|
553 #endif
|
|
554 int l_fd;
|
|
555 char *l_lock;
|
|
556 struct lock *l_next;
|
|
557 };
|
|
558 #define NULLP ((struct lock *) 0)
|
|
559
|
|
560 static struct lock *l_top = NULLP;
|
|
561
|
|
562 #ifdef MAILLOCK
|
|
563 static int is_default_spool (file)
|
|
564 register char *file;
|
|
565 {
|
|
566 static char *default_spool = NULLCP;
|
|
567
|
|
568 if (! default_spool)
|
|
569 default_spool = concat (MAILDIR, getusr (), NULLCP);
|
|
570 return strcmp(file, default_spool) == 0;
|
|
571 }
|
|
572
|
|
573 #else /* MAILLOCK */
|
|
574 #ifdef LIBLOCKFILE
|
|
575 /* simple routine to allow us to get the filename given an fd.
|
|
576 * Returns NULL if the fd isn't valid.
|
|
577 */
|
|
578 char *lockname_from_fd(fd)
|
|
579 int fd;
|
|
580 {
|
|
581 struct lock *pp;
|
|
582
|
|
583 for (pp = l_top; pp; pp = pp -> l_next)
|
|
584 if (pp->l_fd == fd)
|
|
585 return pp->l_lock;
|
|
586
|
|
587 return NULL;
|
|
588 }
|
|
589 #endif /* LIBLOCKFILE */
|
|
590 #endif /* MAILLOCK */
|
|
591
|
|
592 /* ARGSUSED */
|
|
593
|
|
594 static TYPESIG alrmser (sig)
|
|
595 int sig;
|
|
596 {
|
|
597 register int j;
|
|
598 register char *cp;
|
|
599 register struct lock *lp;
|
|
600
|
|
601 #ifndef BSD42
|
|
602 (void) signal (SIGALRM, alrmser);
|
|
603 #endif /* BSD42 */
|
|
604
|
|
605 for (lp = l_top; lp; lp = lp -> l_next)
|
|
606 #ifdef LIBLOCKFILE
|
|
607 if (lp->l_locktype == LOCK_LIBLOCKFILE)
|
|
608 lockfile_touch(lp->l_lock);
|
|
609 else
|
|
610 #endif
|
|
611 if (*(cp = lp -> l_lock) && (j = creat (cp, 0400)) != NOTOK)
|
|
612 (void) close (j);
|
|
613
|
|
614 (void) alarm (NSECS);
|
|
615 }
|
|
616
|
|
617 /* */
|
|
618
|
|
619 #ifdef LIBLOCKFILE
|
|
620 static timerON (lock, fd, ltype)
|
|
621 int ltype;
|
|
622 #else
|
|
623 static timerON (lock, fd)
|
|
624 #endif
|
|
625 char *lock;
|
|
626 int fd;
|
|
627 {
|
|
628 register struct lock *lp;
|
|
629
|
|
630 if ((lp = (struct lock *) malloc ((unsigned) (sizeof *lp))) == NULLP)
|
|
631 return; /* XXX */
|
|
632
|
|
633 lp -> l_fd = fd;
|
|
634 #ifdef LIBLOCKFILE
|
|
635 lp -> l_locktype = ltype;
|
|
636 #endif
|
|
637 if ((lp -> l_lock = malloc ((unsigned) (strlen (lock) + 1))) == NULLCP) {
|
|
638 free ((char *) lp);
|
|
639 return; /* XXX */
|
|
640 }
|
|
641 (void) strcpy (lp -> l_lock, lock);
|
|
642 lp -> l_next = NULLP;
|
|
643
|
|
644 if (l_top)
|
|
645 lp -> l_next = l_top;
|
|
646 else {
|
|
647 (void) signal (SIGALRM, alrmser);/* perhaps SIGT{STP,TIN,TOU} */
|
|
648 (void) alarm (NSECS);
|
|
649 }
|
|
650 l_top = lp;
|
|
651 }
|
|
652
|
|
653
|
|
654 static timerOFF (fd)
|
|
655 int fd;
|
|
656 {
|
|
657 register struct lock *pp,
|
|
658 *lp;
|
|
659
|
|
660 (void) alarm (0);
|
|
661
|
|
662 if (l_top) {
|
|
663 for (pp = lp = l_top; lp; pp = lp, lp = lp -> l_next)
|
|
664 if (lp -> l_fd == fd)
|
|
665 break;
|
|
666 if (lp) {
|
|
667 if (lp == l_top)
|
|
668 l_top = lp -> l_next;
|
|
669 else
|
|
670 pp -> l_next = lp -> l_next;
|
|
671
|
|
672 free (lp -> l_lock);
|
|
673 free ((char *) lp);
|
|
674 }
|
|
675 }
|
|
676
|
|
677 if (l_top)
|
|
678 (void) alarm (NSECS);
|
|
679 }
|