diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-27 10:00:09 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-27 10:00:09 +0000 |
commit | 9f0a9332ed10aee6d8e9718de0d30d91ecb15850 (patch) | |
tree | b408f2340130bb684e5b82078f0e641f1885ac51 /src | |
parent | 70e85c3c58e8720f3a0fdb0240b475338652cdcd (diff) | |
download | utmps-9f0a9332ed10aee6d8e9718de0d30d91ecb15850.tar.gz utmps-9f0a9332ed10aee6d8e9718de0d30d91ecb15850.tar.xz utmps-9f0a9332ed10aee6d8e9718de0d30d91ecb15850.zip |
bugfix: return early on connection failure
That allows utmpx-using programs to keep working (returning a failure) when no server is present, instead of blocking forever.
Diffstat (limited to 'src')
-rw-r--r-- | src/utmps/getutxent.c | 2 | ||||
-rw-r--r-- | src/utmps/getutxid.c | 2 | ||||
-rw-r--r-- | src/utmps/getutxline.c | 2 | ||||
-rw-r--r-- | src/utmps/pututxline.c | 2 | ||||
-rw-r--r-- | src/utmps/setutxent.c | 2 | ||||
-rw-r--r-- | src/utmps/utmps-internal.h | 2 | ||||
-rw-r--r-- | src/utmps/utmps_here_maybe_init.c | 5 |
7 files changed, 8 insertions, 9 deletions
diff --git a/src/utmps/getutxent.c b/src/utmps/getutxent.c index 97a5917..688630f 100644 --- a/src/utmps/getutxent.c +++ b/src/utmps/getutxent.c @@ -6,7 +6,7 @@ struct utmpx *getutxent (void) { - utmps_here_maybe_init() ; + if (!utmps_here_maybe_init()) return 0 ; if (!utmps_getent(&utmps_here, &utmps_utmpx_here, 0, 0)) return 0 ; return &utmps_utmpx_here ; } diff --git a/src/utmps/getutxid.c b/src/utmps/getutxid.c index 262f35c..b6e66ab 100644 --- a/src/utmps/getutxid.c +++ b/src/utmps/getutxid.c @@ -6,7 +6,7 @@ struct utmpx *getutxid (struct utmpx const *b) { - utmps_here_maybe_init() ; + if (!utmps_here_maybe_init()) return 0 ; if (!utmps_getid(&utmps_here, (unsigned short)b->ut_type, b->ut_id, &utmps_utmpx_here, 0, 0)) return 0 ; return &utmps_utmpx_here ; } diff --git a/src/utmps/getutxline.c b/src/utmps/getutxline.c index e950816..daff189 100644 --- a/src/utmps/getutxline.c +++ b/src/utmps/getutxline.c @@ -6,7 +6,7 @@ struct utmpx *getutxline (struct utmpx const *b) { - utmps_here_maybe_init() ; + if (!utmps_here_maybe_init()) return 0 ; if (!utmps_getline(&utmps_here, b->ut_line, &utmps_utmpx_here, 0, 0)) return 0 ; return &utmps_utmpx_here ; } diff --git a/src/utmps/pututxline.c b/src/utmps/pututxline.c index 4e149d8..f60931d 100644 --- a/src/utmps/pututxline.c +++ b/src/utmps/pututxline.c @@ -7,7 +7,7 @@ struct utmpx *pututxline (struct utmpx const *b) { static struct utmpx here ; /* POSIX says we can't use utmps_utmpx_here */ - utmps_here_maybe_init() ; + if (!utmps_here_maybe_init()) return 0 ; if (!utmps_putline(&utmps_here, b, 0, 0)) return 0 ; here = *b ; return &here ; diff --git a/src/utmps/setutxent.c b/src/utmps/setutxent.c index b8b8199..b6d4913 100644 --- a/src/utmps/setutxent.c +++ b/src/utmps/setutxent.c @@ -6,6 +6,6 @@ void setutxent (void) { - utmps_here_maybe_init() ; + if (!utmps_here_maybe_init()) return ; utmps_rewind(&utmps_here, 0, 0) ; } diff --git a/src/utmps/utmps-internal.h b/src/utmps/utmps-internal.h index 476e100..9a51dcc 100644 --- a/src/utmps/utmps-internal.h +++ b/src/utmps/utmps-internal.h @@ -8,7 +8,7 @@ extern struct utmpx utmps_utmpx_here ; extern utmps utmps_here ; -extern void utmps_here_maybe_init (void) ; +extern int utmps_here_maybe_init (void) ; extern void utmps_utmpx_pack (char *, struct utmpx const *) ; extern void utmps_utmpx_unpack (char const *, struct utmpx *) ; diff --git a/src/utmps/utmps_here_maybe_init.c b/src/utmps/utmps_here_maybe_init.c index 4f3e207..d40e139 100644 --- a/src/utmps/utmps_here_maybe_init.c +++ b/src/utmps/utmps_here_maybe_init.c @@ -4,8 +4,7 @@ #include <utmps/utmps.h> #include "utmps-internal.h" -void utmps_here_maybe_init (void) +int utmps_here_maybe_init (void) { - if (utmps_here.fd < 0) - utmps_start(&utmps_here, UTMPS_UTMPD_PATH, 0, 0) ; + return utmps_here.fd >= 0 || utmps_start(&utmps_here, UTMPS_UTMPD_PATH, 0, 0) ; } |