diff options
author | ed <ed@FreeBSD.org> | 2010-01-17 21:40:05 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2010-01-17 21:40:05 +0000 |
commit | f9a77ba26579e3f9f2b0eec8ffe1f24442e5a59a (patch) | |
tree | 2916f578d99718849996bd8bce13ccfae4447a99 /lib/libc/gen/utxdb.c | |
parent | ea1469181ddbe4bbb08569416a314290534b1d7a (diff) | |
download | FreeBSD-src-f9a77ba26579e3f9f2b0eec8ffe1f24442e5a59a.zip FreeBSD-src-f9a77ba26579e3f9f2b0eec8ffe1f24442e5a59a.tar.gz |
Perform several small cleanups to the utmpx code.
- Massively reduce BSS usage. Let futx_to_utx() dynamically allocate the
structure. There is only a very small amount of applications out there
that needs to use the utmpx database. Wasting 1 KB on unused
structures makes little sense.
- Just let getutxid() search for matching ut_id's for any *PROCESS-type.
This makes the code a bit more future-proof.
- Fix a POSIX-mistake: when reading POSIX and the OpenSolaris
implementation, getutxline() must return USER_PROCESS and
LOGIN_PROCESS records whose ut_lines match. When reading POSIX, it
seems LOGIN_PROCESS should not use ut_line at the first place. I have
reported this issue.
Diffstat (limited to 'lib/libc/gen/utxdb.c')
-rw-r--r-- | lib/libc/gen/utxdb.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/libc/gen/utxdb.c b/lib/libc/gen/utxdb.c index d7e2b34..224d86b 100644 --- a/lib/libc/gen/utxdb.c +++ b/lib/libc/gen/utxdb.c @@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$"); #include "namespace.h" #include <sys/endian.h> #include <sys/param.h> +#include <stdlib.h> #include <string.h> #include <utmpx.h> #include "utxdb.h" @@ -82,6 +83,8 @@ utx_to_futx(const struct utmpx *ut, struct futx *fu) case LOGIN_PROCESS: UTOF_ID(ut, fu); UTOF_STRING(ut, fu, user); + /* XXX: bug in the specification? Needed for getutxline(). */ + UTOF_STRING(ut, fu, line); UTOF_PID(ut, fu); break; case DEAD_PROCESS: @@ -118,11 +121,18 @@ utx_to_futx(const struct utmpx *ut, struct futx *fu) (ut)->ut_tv.tv_usec = t % 1000000; \ } while (0) -void -futx_to_utx(const struct futx *fu, struct utmpx *ut) +struct utmpx * +futx_to_utx(const struct futx *fu) { + static struct utmpx *ut; - memset(ut, 0, sizeof *ut); + if (ut == NULL) { + ut = calloc(1, sizeof *ut); + if (ut == NULL) + return (NULL); + } else { + memset(ut, 0, sizeof *ut); + } switch (fu->fu_type) { case BOOT_TIME: @@ -146,6 +156,8 @@ futx_to_utx(const struct futx *fu, struct utmpx *ut) case LOGIN_PROCESS: FTOU_ID(fu, ut); FTOU_STRING(fu, ut, user); + /* XXX: bug in the specification? Needed for getutxline(). */ + FTOU_STRING(fu, ut, line); FTOU_PID(fu, ut); break; case DEAD_PROCESS: @@ -154,9 +166,10 @@ futx_to_utx(const struct futx *fu, struct utmpx *ut) break; default: ut->ut_type = EMPTY; - return; + return (ut); } FTOU_TYPE(fu, ut); FTOU_TV(fu, ut); + return (ut); } |