diff options
author | 1992-02-15 18:10:33 +0000 | |
---|---|---|
committer | 1992-02-15 18:10:33 +0000 | |
commit | 7d97c2a57318a052d5bd8160cf08ec9736f65acf (patch) | |
tree | 0eab43ff5263dc1bd218f8012bc2f9faabee68e5 /clients/zmailnotify/zmailnotify.c | |
parent | 4f79a155bc43662fd46b613247bb7b1d00eb9754 (diff) |
added POSIX file locking,
ifdef'd on _POSIX_SOURCE
Diffstat (limited to 'clients/zmailnotify/zmailnotify.c')
-rw-r--r-- | clients/zmailnotify/zmailnotify.c | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/clients/zmailnotify/zmailnotify.c b/clients/zmailnotify/zmailnotify.c index 35e3be4..f3f6049 100644 --- a/clients/zmailnotify/zmailnotify.c +++ b/clients/zmailnotify/zmailnotify.c @@ -121,12 +121,25 @@ main(argc, argv) exit(1); } - lock = fopen(lockfile,"r"); + lock = fopen(lockfile,"w"); +#ifdef _POSIX_SOURCE + if (lock) { + struct flock fl; + + /* lock the whole file exclusively */ + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + (void) fcntl(fileno(lock),F_SETLKW,&fl); + } +#else #ifndef NO_FLOCK if (lock) (void) flock(fileno(lock),LOCK_EX); -#endif - +#endif /* ! NO_FLOCK */ +#endif /* POSIX_SOURCE */ + if (pop_init(host) == NOTOK) { fprintf(stderr,"%s: %s\n",prog, Errmsg); exit(1); @@ -152,9 +165,20 @@ main(argc, argv) if (!nmsgs) { if (lock) { +#ifdef _POSIX_SOURCE + struct flock fl; + + /* unlock the whole file */ + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + (void) fcntl(fileno(lock),F_SETLKW,&fl); +#else #ifndef NO_FLOCK (void) flock(fileno(lock),LOCK_UN); -#endif +#endif /* ! NO_FLOCK */ +#endif /* _POSIX_SOURCE */ (void) fclose(lock); } (void) unlink(lockfile); @@ -184,10 +208,23 @@ main(argc, argv) } else { lock = fopen(lockfile,"w"); +#ifdef _POSIX_SOURCE + if (lock) { + struct flock fl; + + /* lock the whole file exclusively */ + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + (void) fcntl(fileno(lock),F_SETLKW,&fl); + } +#else #ifndef NO_FLOCK if (lock) (void) flock(fileno(lock),LOCK_EX); -#endif +#endif /* ! NO_FLOCK */ +#endif /* POSIX_SOURCE */ uselock = 0; } @@ -210,9 +247,20 @@ main(argc, argv) mail_notify(&maillist[nmsgs-i]); i--; if (lock) { +#ifdef _POSIX_SOURCE + struct flock fl; + + /* unlock the whole file */ + fl.l_type = F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = 0; + fl.l_len = 0; + (void) fcntl(fileno(lock),F_SETLKW,&fl); +#else #ifndef NO_FLOCK (void) flock(fileno(lock),LOCK_UN); -#endif +#endif /* ! NO_FLOCK */ +#endif /* POSIX */ (void) fclose(lock); } lock = fopen(lockfile,"w"); |