7 /* open or create file and lock it for exclusive access
9 /* #include <open_lock.h>
11 /* VSTREAM *open_lock(path, flags, mode, why)
17 /* This module opens or creates the named file and attempts to
18 /* acquire an exclusive lock. The lock is lost when the last
19 /* process closes the file.
22 /* .IP "path, flags, mode"
23 /* These are passed on to safe_open().
25 /* storage for diagnostics.
27 /* safe_open(3) carefully open or create file
28 /* myflock(3) get exclusive lock on file
30 /* In case of problems the result is a null pointer and a problem
31 /* description is returned via the global \fIerrno\fR variable.
35 /* The Secure Mailer license must be distributed with this software.
38 /* IBM T.J. Watson Research
40 /* Yorktown Heights, NY 10598, USA
49 /* Utility library. */
54 #include <safe_open.h>
56 #include <open_lock.h>
58 /* open_lock - open file and lock it for exclusive access */
60 VSTREAM
*open_lock(const char *path
, int flags
, mode_t mode
, VSTRING
*why
)
65 * Carefully create or open the file, and lock it down. Some systems
66 * don't have the O_LOCK open() flag, or the flag does not do what we
67 * want, so we roll our own lock.
69 if ((fp
= safe_open(path
, flags
, mode
, (struct stat
*) 0, -1, -1, why
)) == 0)
71 if (myflock(vstream_fileno(fp
), INTERNAL_LOCK
,
72 MYFLOCK_OP_EXCLUSIVE
| MYFLOCK_OP_NOWAIT
) < 0) {
73 vstring_sprintf(why
, "unable to set exclusive lock: %m");