From 860d3729868a749f782f6ad5dae1138cb239c4d3 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Mon, 16 Dec 1996 01:40:21 +0000 Subject: update from main archive 961215 Mon Dec 16 02:15:42 1996 Ulrich Drepper Make sure tzset() sets always tzname[]. * time/tzfile.c: De-ANSI-declfy. (find_transition): New function. Set tzname according to given time. (__tzread_file): Use find_transition to set tzname. (__tzfile_compute): Use find_transition instead of doing the work self. * time/tzset.c (tzset): Set tzname[] directly only if !__use_tzfile. Sun Dec 15 16:52:34 1996 Ulrich Drepper * login/utmp-file.c (pututline_file): Open file if closed. Reported by Roma Ekzhanov . Use fcntl instead of flock. Sun Dec 15 14:20:51 1996 Ulrich Drepper * manual/time.texi: Update documentation of strftime function. --- login/utmp_file.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'login/utmp_file.c') diff --git a/login/utmp_file.c b/login/utmp_file.c index c728d9a1f2..102eba02e1 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -140,14 +140,14 @@ getutent_r_file (struct utmp *buffer, struct utmp **result) memset (&fl, '\0', sizeof (struct flock)); fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; - result = fcntl (file_fd, F_SETLKW, &fl); + fcntl (file_fd, F_SETLKW, &fl); /* Read the next entry. */ nbytes = read (file_fd, &last_entry, sizeof (struct utmp)); /* And unlock the file. */ fl.l_type = F_UNLCK; - result = fcntl (file_fd, F_SETLKW, &fl); + fcntl (file_fd, F_SETLKW, &fl); if (nbytes != sizeof (struct utmp)) { @@ -292,6 +292,7 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer, static struct utmp * pututline_file (const struct utmp *data) { + struct flock fl; /* Information struct for locking. */ struct utmp buffer; struct utmp *pbuf; int found; @@ -300,6 +301,10 @@ pututline_file (const struct utmp *data) /* Something went wrong. */ return NULL; + if (file_fd == INT_MIN) + /* The file is closed. Open it again. */ + setutent_file (0); + /* Find the correct place to insert the data. */ if (file_offset > 0) found = 0; @@ -318,14 +323,10 @@ pututline_file (const struct utmp *data) found = internal_getutid_r (data, &buffer); /* Try to lock the file. */ - if (flock (file_fd, LOCK_EX | LOCK_NB) < 0 && errno != ENOSYS) - { - /* Oh, oh. The file is already locked. Wait a bit and try again. */ - sleep (1); - - /* This time we ignore the error. */ - (void) flock (file_fd, LOCK_EX | LOCK_NB); - } + memset (&fl, '\0', sizeof (struct flock)); + fl.l_type = F_WRLCK; + fl.l_whence = SEEK_SET; + fcntl (file_fd, F_SETLKW, &fl); if (found < 0) { @@ -338,8 +339,8 @@ pututline_file (const struct utmp *data) if (lseek (file_fd, 0, SEEK_END) < 0) { - (void) flock (file_fd, LOCK_UN); - return NULL; + pbuf = NULL; + goto unlock_return; } } } @@ -365,8 +366,10 @@ pututline_file (const struct utmp *data) pbuf = (struct utmp *) data; } + unlock_return: /* And unlock the file. */ - (void) flock (file_fd, LOCK_UN); + fl.l_type = F_UNLCK; + fcntl (file_fd, F_SETLKW, &fl); return pbuf; } -- cgit 1.4.1