+2002-09-29 Bruno Haible <bruno@clisp.org>
+
+ * sysdeps/generic/utmp_file.c (LOCKING_FAILED): New macro.
+ (UNLOCK_FILE): Add a label.
+ (getutent_r_file, internal_getut_r, getutline_r_file, pututline_file,
+ updwtmp_file): Shut off the alarm clock when locking failed.
+
2002-09-30 Isamu Hasegawa <isamu@yamato.ibm.com>
* posix/regex_internal.h (re_match_context_t): Add a new member.
/* Do-nothing handler for locking timeout. */
static void timeout_handler (int signum) {};
+/* LOCK_FILE(fd, type) failure_statement
+ attempts to get a lock on the utmp file referenced by FD. If it fails,
+ the failure_statement is executed, otherwise it is skipped.
+ LOCKING_FAILED()
+ jumps into the UNLOCK_FILE macro and ensures cleanup of LOCK_FILE.
+ UNLOCK_FILE(fd)
+ unlocks the utmp file referenced by FD and performs the cleanup of
+ LOCK_FILE.
+ */
#define LOCK_FILE(fd, type) \
{ \
struct flock fl; \
fl.l_whence = SEEK_SET; \
if (__fcntl ((fd), F_SETLKW, &fl) < 0)
+#define LOCKING_FAILED() \
+ goto unalarm_return
+
#define UNLOCK_FILE(fd) \
/* Unlock the file. */ \
fl.l_type = F_UNLCK; \
__fcntl ((fd), F_SETLKW, &fl); \
\
+ unalarm_return: \
/* Reset the signal handler and alarm. We must reset the alarm \
before resetting the handler so our alarm does not generate a \
spurious SIGALRM seen by the user. However, we cannot just set \
LOCK_FILE (file_fd, F_RDLCK)
{
- *result = NULL;
- return -1;
+ nbytes = 0;
+ LOCKING_FAILED ();
}
/* Read the next entry. */
if (nbytes != sizeof (struct utmp))
{
- file_offset = -1l;
+ if (nbytes != 0)
+ file_offset = -1l;
*result = NULL;
return -1;
}
int result = -1;
LOCK_FILE (file_fd, F_RDLCK)
- return result;
+ LOCKING_FAILED ();
#if _HAVE_UT_TYPE - 0
if (id->ut_type == RUN_LVL || id->ut_type == BOOT_TIME
LOCK_FILE (file_fd, F_RDLCK)
{
*result = NULL;
- return -1;
+ LOCKING_FAILED ();
}
while (1)
found = internal_getut_r (data, &buffer);
LOCK_FILE (file_fd, F_WRLCK)
- return NULL;
+ {
+ pbuf = NULL;
+ LOCKING_FAILED ();
+ }
if (found < 0)
{
return -1;
LOCK_FILE (fd, F_WRLCK)
- {
- __close (fd);
- return result;
- }
+ LOCKING_FAILED ();
/* Remember original size of log file. */
offset = __lseek64 (fd, 0, SEEK_END);