summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-03-20 20:15:03 +0000
committerLaurent Bercot <ska@appnovation.com>2022-03-20 20:15:03 +0000
commit40aafbcda2b0373ba0f2d306141af477e3273fe1 (patch)
tree7fbd864021909f2340b5f429dd6c623697ee5a09 /src
parenta7b0b9a99bee135a57aa696d7057226a0f8105ff (diff)
downloadutmps-40aafbcda2b0373ba0f2d306141af477e3273fe1.tar.xz
Prepare for 0.1.2.0; add file arg to utmps-wtmpd
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/utmps/utmps-wtmpd.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/utmps/utmps-wtmpd.c b/src/utmps/utmps-wtmpd.c
index 7ca3eff..b19f997 100644
--- a/src/utmps/utmps-wtmpd.c
+++ b/src/utmps/utmps-wtmpd.c
@@ -25,9 +25,10 @@ static void answer (int e)
write(1, (char *)&c, 1) ;
}
-int main (void)
+int main (int argc, char const *const *argv)
{
struct utmpx b ;
+ char const *file = "wtmp" ;
char const *x ;
tain deadline ;
size_t w ;
@@ -37,9 +38,10 @@ int main (void)
PROG = "utmps-wtmpd" ;
x = ucspi_get("REMOTEEUID") ;
- if (!x) strerr_diefu1x(100, "get $IPCREMOTEEUID from environment") ;
+ if (!x) strerr_diefu1x(100, "get PROTO or IPCREMOTEEUID from environment") ;
if (!uid0_scan(x, &uid)) strerr_dieinvalid(100, "IPCREMOTEEUID") ;
if (ndelay_on(0) < 0) strerr_diefu1sys(111, "set stdin non-blocking") ;
+ if (argc >= 2 && argv[1]) file = argv[1] ;
tain_now_set_stopwatch_g() ;
tain_ulong(&deadline, 30) ;
tain_add_g(&deadline, &deadline) ;
@@ -48,7 +50,11 @@ int main (void)
if (!w) strerr_diefu1sys(111, "read from stdin") ;
if (buf[0] != '+') { errno = EPROTO ; strerr_diefu1sys(111, "read command") ; }
w = buffer_timed_get_g(buffer_0small, buf, sizeof(struct utmpx), &deadline) ;
- if (w < sizeof(struct utmpx)) strerr_diefu1sys(111, "read from stdin") ;
+ if (w < sizeof(struct utmpx))
+ {
+ errno = EPIPE ;
+ strerr_diefu1sys(111, "read from stdin") ;
+ }
utmps_utmpx_unpack(buf, &b) ;
b.ut_user[UTMPS_UT_NAMESIZE - 1] = 0 ;
if (uid)
@@ -76,21 +82,21 @@ int main (void)
}
}
- fd = open_append("wtmp") ;
+ fd = open_append(file) ;
if (fd < 0)
{
answer(errno) ;
- strerr_diefu2sys(111, "open", " wtmp") ;
+ strerr_diefu2sys(111, "open ", file) ;
}
if (fd_lock(fd, 1, 0) < 1)
{
answer(errno) ;
- strerr_diefu2sys(111, "lock", " wtmp") ;
+ strerr_diefu2sys(111, "lock ", file) ;
}
if (lseek(fd, 0, SEEK_END) < 0)
{
answer(errno) ;
- strerr_diefu2sys(111, "lseek on", " wtmp") ;
+ strerr_diefu2sys(111, "lseek on ", file) ;
}
w = allwrite(fd, buf, sizeof(struct utmpx)) ;
if (w < sizeof(struct utmpx))
@@ -104,7 +110,7 @@ int main (void)
fd_unlock(fd) ;
answer(e) ;
errno = e ;
- strerr_diefu2sys(111, "append to", " wtmp") ;
+ strerr_diefu2sys(111, "append to ", file) ;
}
fsync(fd) ;
fd_unlock(fd) ;