X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=dump%2Fitime.c;h=aeaaec01f8f9ee8c92ed88d717b398956cc4cdf4;hb=7af4fa89be1fb5dfae84ff45b96c2f9bd521d135;hp=da968db3423641521bef681acdbe4daa232ceac8;hpb=11856e771fadee7ddb9b5a613c91f562bf363da7;p=dump.git diff --git a/dump/itime.c b/dump/itime.c index da968db..aeaaec0 100644 --- a/dump/itime.c +++ b/dump/itime.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: itime.c,v 1.21 2002/01/16 09:32:14 stelian Exp $"; + "$Id: itime.c,v 1.23 2002/08/01 10:23:26 stelian Exp $"; #endif /* not lint */ #include @@ -56,6 +56,7 @@ static const char rcsid[] = #include #include #include +#include #ifdef __linux__ #ifdef HAVE_EXT2FS_EXT2_FS_H #include @@ -94,6 +95,7 @@ void initdumptimes(int createdumpdates) { FILE *df; + struct flock lock; if ((df = fopen(dumpdates, "r")) == NULL) { if (errno != ENOENT) { @@ -122,7 +124,11 @@ initdumptimes(int createdumpdates) msg("WARNING: no file `%s'\n", dumpdates); } if (df != NULL) { - (void) flock(fileno(df), LOCK_SH); + memset(&lock, 0, sizeof(lock)); + lock.l_type = F_RDLCK; + if (fcntl(fileno(df), F_SETLKW, &lock) < 0) + quit("cannot set read lock on %s: %s\n", + dumpdates, strerror(errno)); readdumptimes(df); (void) fclose(df); } @@ -131,8 +137,8 @@ initdumptimes(int createdumpdates) static void readdumptimes(FILE *df) { - register int i; - register struct dumptime *dtwalk; + int i; + struct dumptime *dtwalk; for (;;) { dtwalk = (struct dumptime *)calloc(1, sizeof (struct dumptime)); @@ -158,8 +164,8 @@ readdumptimes(FILE *df) void getdumptime(int createdumpdates) { - register struct dumpdates *ddp; - register int i; + struct dumpdates *ddp; + int i; #ifdef FDEBUG msg("Looking for name %s in dumpdates = %s for level = %c\n", @@ -197,16 +203,20 @@ void putdumptime(void) { FILE *df; - register struct dumpdates *dtwalk; - register int i; + struct dumpdates *dtwalk; + int i; int fd; + struct flock lock; if(uflag == 0) return; if ((df = fopen(dumpdates, "r+")) == NULL) quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno)); fd = fileno(df); - (void) flock(fd, LOCK_EX); + memset(&lock, 0, sizeof(lock)); + lock.l_type = F_WRLCK; + if (fcntl(fd, F_SETLKW, &lock) < 0) + quit("cannot set write lock on %s: %s\n", dumpdates, strerror(errno)); free((char *)ddatev); ddatev = 0; nddates = 0;