diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-08-08 00:27:22 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-08-08 00:27:22 +0000 |
commit | 4a5bd8f420993ca98e4db0d8c11572bc27d5d7dd (patch) | |
tree | 0946adce2e52f61f889b1752ccc28ef68bc73851 | |
parent | 990c55ad93c592f331aecab2c0e90f844e423a9e (diff) |
Move definition of updwtmp to updwtmp.c.
-rw-r--r-- | login/logwtmp.c | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/login/logwtmp.c b/login/logwtmp.c index b6af813e73..58f07ff1ce 100644 --- a/login/logwtmp.c +++ b/login/logwtmp.c @@ -17,53 +17,12 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include <errno.h> #include <string.h> +#include <sys/time.h> +#include <time.h> #include <unistd.h> #include <utmp.h> -#include <sys/file.h> -#include <sys/stat.h> -void -updwtmp (const char *wtmp_file, const struct utmp *ut) -{ - struct stat st; - size_t written; - int fd; - - /* Open WTMP file. */ - fd = __open (wtmp_file, O_WRONLY | O_APPEND); - if (fd < 0) - return; - - /* Try to lock the file. */ - if (__flock (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. */ - __flock (fd, LOCK_EX | LOCK_NB); - } - - /* Remember original size of log file: */ - if (__fstat (fd, &st) < 0) - goto done; - - /* Write the entry. If we can't write all the bytes, reset the file - size back to the original size. That way, no partial entries - will remain. */ - written = __write (fd, ut, sizeof (struct utmp)); - if (written > 0 && written != sizeof (struct utmp)) - ftruncate (fd, st.st_size); - -done: - /* And unlock the file. */ - __flock (fd, LOCK_UN); - - /* Close WTMP file. */ - __close (fd); -} void logwtmp (const char *line, const char *name, const char *host) @@ -90,5 +49,5 @@ logwtmp (const char *line, const char *name, const char *host) time (&ut.ut_time); #endif - updwtmp(_PATH_WTMP, &ut); + updwtmp (_PATH_WTMP, &ut); } |