summaryrefslogtreecommitdiff
path: root/libexec/ftpd/logwtmp.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2005-06-23 04:20:41 +0000
committerchristos <christos@NetBSD.org>2005-06-23 04:20:41 +0000
commitea7965eb77a8c83ddb672fc3f8ea87fcebf34216 (patch)
tree453db28f5ec366c3ddf2890b5f24960cc1607eaa /libexec/ftpd/logwtmp.c
parent277396bd87bdd2798c8114fec80392e2e18c9c26 (diff)
cleanup utmp and utmpx support.
- make them symmetric - add a function to open the wtmp file explicitly very early in the game
Diffstat (limited to 'libexec/ftpd/logwtmp.c')
-rw-r--r--libexec/ftpd/logwtmp.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/libexec/ftpd/logwtmp.c b/libexec/ftpd/logwtmp.c
index a20c42093b9..33d73deea57 100644
--- a/libexec/ftpd/logwtmp.c
+++ b/libexec/ftpd/logwtmp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: logwtmp.c,v 1.23 2004/11/11 01:14:10 christos Exp $ */
+/* $NetBSD: logwtmp.c,v 1.24 2005/06/23 04:20:41 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: logwtmp.c,v 1.23 2004/11/11 01:14:10 christos Exp $");
+__RCSID("$NetBSD: logwtmp.c,v 1.24 2005/06/23 04:20:41 christos Exp $");
#endif
#endif /* not lint */
@@ -51,8 +51,11 @@ __RCSID("$NetBSD: logwtmp.c,v 1.23 2004/11/11 01:14:10 christos Exp $");
#include <stdio.h>
#include <string.h>
#include <time.h>
+#include <syslog.h>
#include <unistd.h>
+#ifdef SUPPORT_UTMP
#include <utmp.h>
+#endif
#ifdef SUPPORT_UTMPX
#include <utmpx.h>
#endif
@@ -64,10 +67,16 @@ __RCSID("$NetBSD: logwtmp.c,v 1.23 2004/11/11 01:14:10 christos Exp $");
#include "extern.h"
+#ifdef SUPPORT_UTMP
static int fd = -1;
-#ifdef SUPPORT_UTMPX
-static int fdx = -1;
-#endif
+
+void
+ftpd_initwtmp(void)
+{
+ const char *wf = _PATH_WTMP;
+ if ((fd = open(wf, O_WRONLY|O_APPEND, 0)) == -1)
+ syslog(LOG_ERR, "Cannot open `%s' (%m)", wf);
+}
/*
* Modified version of logwtmp that holds wtmp file open
@@ -92,8 +101,19 @@ ftpd_logwtmp(const char *line, const char *name, const char *host)
(void)ftruncate(fd, buf.st_size);
}
}
+#endif
#ifdef SUPPORT_UTMPX
+static int fdx = -1;
+
+void
+ftpd_initwtmpx(void)
+{
+ const char *wf = _PATH_WTMPX;
+ if ((fd = open(wf, O_WRONLY|O_APPEND, 0)) == -1)
+ syslog(LOG_ERR, "Cannot open `%s' (%m)", wf);
+}
+
void
ftpd_logwtmpx(const char *line, const char *name, const char *host,
struct sockinet *haddr, int status, int utx_type)
@@ -101,7 +121,7 @@ ftpd_logwtmpx(const char *line, const char *name, const char *host,
struct utmpx ut;
struct stat buf;
- if (fdx < 0 && (fdx = open(_PATH_WTMPX, O_WRONLY|O_APPEND, 0)) < 0)
+ if (fdx < 0)
return;
if (fstat(fdx, &buf) == 0) {
(void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));