home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / listserv5.31 / part01 / src / tlock.c < prev   
Encoding:
C/C++ Source or Header  |  1991-12-12  |  2.2 KB  |  60 lines

  1. /*
  2.   ----------------------------------------------------------------------------
  3.   |                        tlock UTILITY                      |
  4.   |                                                                          |
  5.   |                              Version 1.0                                 |
  6.   |                                                                          |
  7.   |                (or, when Computer Science gets to you)                   |
  8.   |                                                                          |
  9.   |                    Written by Anastasios Kotsikonas                      |
  10.   |                           (tasos@cs.bu.edu)                              |
  11.   |                                                                          |
  12.   | AGREEMENT: This software can be used and distributed freely as long      |
  13.   | as you do not remove or alter the Copyright notice in the file defs.h;   |
  14.   | this notice is #define'd in the symbol VERSION. Although you may alter   |
  15.   | the code provided, you may not alter the functions create_header()       |
  16.   | and create_multi_recipient_header() in list.c and listserv.c.            |
  17.   | By using this software you are bound by this agreement.                  |
  18.   | This software comes with no warranties and cannot be sold for profit.    |
  19.   | The AGREEMENT and COPYRIGHT notices should be included in all source     |
  20.   | files when distributing this software.                                   |
  21.   | COPYRIGHT: Copyright (c) 1991, Anastasios C. Kotsikonas                  |
  22.   ----------------------------------------------------------------------------
  23. */
  24.  
  25. #include <stdio.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <errno.h>
  29. #include "defs.h"
  30.  
  31. void main ();
  32.  
  33. char *s[] = { 
  34.   SERVERD_LOCK_FILE, LIST_LOCK_FILE, SERVER_LOCK_FILE, PQUEUE_LOCK_FILE, NULL
  35. };
  36.  
  37. /*
  38.   Test whether any locks exist on the above files by other processes.
  39. */
  40.  
  41. void main ()
  42. {
  43. #ifndef _MINIX
  44.   int i, fd, locks = 0;
  45.  
  46.   for (i = 0; s[i]; i++) {
  47.     if (lockf ((fd = open (s[i], O_RDWR)), F_TLOCK, 0))
  48.       if (errno == EBADF)
  49.     locks = -1,
  50.     fprintf (stderr, "Cannot access %s\n", s[i]);
  51.       else
  52.     ++locks,
  53.     printf ("Lock placed on %s\n", s[i]);
  54.     close (fd);
  55.   }
  56.   if (!locks)
  57. #endif
  58.     printf ("No files locked.\n");
  59. }
  60.