diff options
author | Florian Weimer <fweimer@redhat.com> | 2019-08-05 15:54:10 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2019-08-05 15:55:05 +0200 |
commit | 1a7fe2ebe52b3c8bf465d1756e69452d05c1c103 (patch) | |
tree | 1d32b2e5a5c55d660354cefb1b02918b62127300 /login/utmp_file.c | |
parent | a6c1ce778e5c05a2e6925883b410157ef47654fd (diff) | |
download | glibc-1a7fe2ebe52b3c8bf465d1756e69452d05c1c103.tar.gz glibc-1a7fe2ebe52b3c8bf465d1756e69452d05c1c103.tar.xz glibc-1a7fe2ebe52b3c8bf465d1756e69452d05c1c103.zip |
login: Remove utmp backend jump tables [BZ #23518]
There is just one file-based implementation, so this dispatch mechanism is unnecessary. Instead of the vtable pointer __libc_utmp_jump_table, use a non-negative file_fd as the indicator that the backend is initialized.
Diffstat (limited to 'login/utmp_file.c')
-rw-r--r-- | login/utmp_file.c | 89 |
1 files changed, 33 insertions, 56 deletions
diff --git a/login/utmp_file.c b/login/utmp_file.c index b19d3caf0d..cb8a02825c 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -105,37 +105,12 @@ static void timeout_handler (int signum) {}; alarm (old_timeout); \ } while (0) - -/* Functions defined here. */ -static int setutent_file (void); -static int getutent_r_file (struct utmp *buffer, struct utmp **result); -static int getutid_r_file (const struct utmp *key, struct utmp *buffer, - struct utmp **result); -static int getutline_r_file (const struct utmp *key, struct utmp *buffer, - struct utmp **result); -static struct utmp *pututline_file (const struct utmp *data); -static void endutent_file (void); -static int updwtmp_file (const char *file, const struct utmp *utmp); - -/* Jump table for file functions. */ -const struct utfuncs __libc_utmp_file_functions = -{ - setutent_file, - getutent_r_file, - getutid_r_file, - getutline_r_file, - pututline_file, - endutent_file, - updwtmp_file -}; - - #ifndef TRANSFORM_UTMP_FILE_NAME # define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name) #endif -static int -setutent_file (void) +int +__libc_setutent (void) { if (file_fd < 0) { @@ -166,15 +141,19 @@ setutent_file (void) return 1; } +/* Preform initialization if necessary. */ +static bool +maybe_setutent (void) +{ + return file_fd >= 0 || __libc_setutent (); +} -static int -getutent_r_file (struct utmp *buffer, struct utmp **result) +int +__libc_getutent_r (struct utmp *buffer, struct utmp **result) { ssize_t nbytes; - assert (file_fd >= 0); - - if (file_offset == -1l) + if (!maybe_setutent () || file_offset == -1l) { /* Not available. */ *result = NULL; @@ -279,13 +258,11 @@ unlock_return: /* For implementing this function we don't use the getutent_r function because we can avoid the reposition on every new entry this way. */ -static int -getutid_r_file (const struct utmp *id, struct utmp *buffer, - struct utmp **result) +int +__libc_getutid_r (const struct utmp *id, struct utmp *buffer, + struct utmp **result) { - assert (file_fd >= 0); - - if (file_offset == -1l) + if (!maybe_setutent () || file_offset == -1l) { *result = NULL; return -1; @@ -309,13 +286,11 @@ getutid_r_file (const struct utmp *id, struct utmp *buffer, /* For implementing this function we don't use the getutent_r function because we can avoid the reposition on every new entry this way. */ -static int -getutline_r_file (const struct utmp *line, struct utmp *buffer, - struct utmp **result) +int +__libc_getutline_r (const struct utmp *line, struct utmp *buffer, + struct utmp **result) { - assert (file_fd >= 0); - - if (file_offset == -1l) + if (!maybe_setutent () || file_offset == -1l) { *result = NULL; return -1; @@ -361,15 +336,16 @@ unlock_return: } -static struct utmp * -pututline_file (const struct utmp *data) +struct utmp * +__libc_pututline (const struct utmp *data) { + if (!maybe_setutent ()) + return NULL; + struct utmp buffer; struct utmp *pbuf; int found; - assert (file_fd >= 0); - if (! file_writable) { /* We must make the file descriptor writable before going on. */ @@ -467,18 +443,19 @@ pututline_file (const struct utmp *data) } -static void -endutent_file (void) +void +__libc_endutent (void) { - assert (file_fd >= 0); - - __close_nocancel_nostatus (file_fd); - file_fd = -1; + if (file_fd >= 0) + { + __close_nocancel_nostatus (file_fd); + file_fd = -1; + } } -static int -updwtmp_file (const char *file, const struct utmp *utmp) +int +__libc_updwtmp (const char *file, const struct utmp *utmp) { int result = -1; off64_t offset; |