From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1791) id 9052B3945C15; Tue, 23 Feb 2021 20:39:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9052B3945C15 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Adhemerval Zanella To: glibc-cvs@sourceware.org Subject: [glibc/azanella/y2038] Consolidate and simplify internal utmp definitions X-Act-Checkin: glibc X-Git-Author: Adhemerval Zanella X-Git-Refname: refs/heads/azanella/y2038 X-Git-Oldrev: 8569f443b5bdf0d6c46154e8106c3df6ae0d196a X-Git-Newrev: 478e9bc9a6dfac64b5f6658a8b470ee875bb95a2 Message-Id: <20210223203902.9052B3945C15@sourceware.org> Date: Tue, 23 Feb 2021 20:39:02 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2021 20:39:02 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=478e9bc9a6dfac64b5f6658a8b470ee875bb95a2 commit 478e9bc9a6dfac64b5f6658a8b470ee875bb95a2 Author: Adhemerval Zanella Date: Tue Aug 4 09:35:03 2020 -0300 Consolidate and simplify internal utmp definitions The TRANSFORM_UTMP_FILE_NAME macro is moved to the inline function utmp_file_name_time32 at utmp-path.h and the __utmp_equal function is removed and inlined on its only usage (matches_last_entry at utmp_file.c). Checked with make check run-built-tests=no on all afftected ABIs. Diff: --- login/updwtmp.c | 14 +------ sysdeps/gnu/utmp_file.c => login/utmp-path.h | 32 ++++++++++------ login/utmp_file.c | 26 +++++++++---- manual/users.texi | 4 +- sysdeps/generic/paths.h | 8 ++-- sysdeps/generic/utmp-equal.h | 42 --------------------- sysdeps/unix/sysv/linux/paths.h | 6 ++- sysdeps/unix/sysv/linux/updwtmp.c | 37 ------------------- sysdeps/unix/sysv/linux/utmp-path.h | 55 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/utmp_file.c | 37 ------------------- 10 files changed, 107 insertions(+), 154 deletions(-) diff --git a/login/updwtmp.c b/login/updwtmp.c index ae67cfc10a..e67a9cf2d9 100644 --- a/login/updwtmp.c +++ b/login/updwtmp.c @@ -21,22 +21,12 @@ #include #include "utmp-private.h" - -#ifndef TRANSFORM_UTMP_FILE_NAME -# define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)) -#endif +#include void __updwtmp (const char *wtmp_file, const struct utmp *utmp) { - const char *file_name = TRANSFORM_UTMP_FILE_NAME (wtmp_file); + const char *file_name = utmp_file_name_time32 (wtmp_file); __libc_updwtmp (file_name, utmp); } diff --git a/sysdeps/gnu/utmp_file.c b/login/utmp-path.h similarity index 50% rename from sysdeps/gnu/utmp_file.c rename to login/utmp-path.h index 696fb38fa8..351a932862 100644 --- a/sysdeps/gnu/utmp_file.c +++ b/login/utmp-path.h @@ -1,6 +1,6 @@ -/* Copyright (C) 1998-2021 Free Software Foundation, Inc. +/* Handle {u,w}tmp and {u,w}tmpx file name usage. + Copyright (C) 1998-2021 Free Software Foundation, Inc. This file is part of the GNU C Library. - Contributed by Mark Kettenis , 1998. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -16,16 +16,26 @@ License along with the GNU C Library; if not, see . */ +#ifndef _UTMP_PATH_H +#define _UTMP_PATH_H 1 + #include #include -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)) +/* The function returns the utmp database for 32-bit utmp{x} entries based + on FILE_NAME. If the argument ends with 'x' and the file does not + exits the default old utmp{x} name is returned instead. */ +static inline const char * +utmp_file_name_time32 (const char *file_name) +{ + if (strcmp (file_name, _PATH_UTMP_BASE "x") == 0 + && __access (_PATH_UTMP_BASE "x", F_OK) != 0) + return _PATH_UTMP_BASE; + else if (strcmp (file_name, _PATH_WTMP_BASE "x") == 0 + && __access (_PATH_WTMP_BASE "x", F_OK) != 0) + return _PATH_UTMP_BASE; + + return file_name; +} -#include +#endif /* _UTMP_PATH_H */ diff --git a/login/utmp_file.c b/login/utmp_file.c index 8c0b3a0bb4..377209b26d 100644 --- a/login/utmp_file.c +++ b/login/utmp_file.c @@ -32,7 +32,7 @@ #include #include "utmp-private.h" -#include "utmp-equal.h" +#include /* Descriptor for the file and position. */ @@ -60,7 +60,21 @@ matches_last_entry (const struct utmp *data) return data->ut_type == last_entry.ut_type; else /* For the process-related entries, a full match is needed. */ - return __utmp_equal (&last_entry, data); + return (data->ut_type == INIT_PROCESS + || data->ut_type == LOGIN_PROCESS + || data->ut_type == USER_PROCESS + || data->ut_type == DEAD_PROCESS) + && (last_entry.ut_type == INIT_PROCESS + || last_entry.ut_type == LOGIN_PROCESS + || last_entry.ut_type == USER_PROCESS + || last_entry.ut_type == DEAD_PROCESS) + && (data->ut_id[0] && last_entry.ut_id[0] + ? strncmp (data->ut_id, last_entry.ut_id, + sizeof last_entry.ut_id) + == 0 + : (strncmp (data->ut_line, last_entry.ut_line, + sizeof last_entry.ut_line) + == 0)); } /* Locking timeout. */ @@ -129,10 +143,6 @@ file_unlock (int fd) __fcntl64_nocancel (fd, F_SETLKW, &fl); } -#ifndef TRANSFORM_UTMP_FILE_NAME -# define TRANSFORM_UTMP_FILE_NAME(file_name) (file_name) -#endif - int __libc_setutent (void) { @@ -140,7 +150,7 @@ __libc_setutent (void) { const char *file_name; - file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); + file_name = utmp_file_name_time32 (__libc_utmp_file_name); file_writable = false; file_fd = __open_nocancel @@ -353,7 +363,7 @@ __libc_pututline (const struct utmp *data) if (! file_writable) { /* We must make the file descriptor writable before going on. */ - const char *file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name); + const char *file_name = utmp_file_name_time32 (__libc_utmp_file_name); int new_fd = __open_nocancel (file_name, O_RDWR | O_LARGEFILE | O_CLOEXEC); diff --git a/manual/users.texi b/manual/users.texi index ec22ce6c1c..dcaca1dcf1 100644 --- a/manual/users.texi +++ b/manual/users.texi @@ -1234,7 +1234,7 @@ over again. @c pututline_unknown @mtasurace:utent @acsfd @c setutent_unknown dup @mtasurace:utent @acsfd @c pututline_file @mtascusig:ALRM @mtascutimer @acsfd -@c TRANSFORM_UTMP_FILE_NAME ok +@c utmp_file_name_time32 ok @c strcmp dup ok @c acesss dup ok @c open_not_cancel_2 dup @acsfd @@ -1427,7 +1427,7 @@ the following function: @standards{SVID, utmp.h} @safety{@prelim{}@mtunsafe{@mtascusig{:ALRM} @mtascutimer{}}@asunsafe{}@acunsafe{@acsfd{}}} @c updwtmp @mtascusig:ALRM @mtascutimer @acsfd -@c TRANSFORM_UTMP_FILE_NAME dup ok +@c utmp_file_name_time32 dup ok @c *libc_utmp_file_functions->updwtmp = updwtmp_file @mtascusig:ALRM @mtascutimer @acsfd @c open_not_cancel_2 dup @acsfd @c LOCK_FILE dup @mtascusig:ALRM @mtascutimer diff --git a/sysdeps/generic/paths.h b/sysdeps/generic/paths.h index 893b4c2286..99a791ce31 100644 --- a/sysdeps/generic/paths.h +++ b/sysdeps/generic/paths.h @@ -60,10 +60,12 @@ #define _PATH_SHELLS "/etc/shells" #define _PATH_TTY "/dev/tty" #define _PATH_UNIX "/vmunix" -#define _PATH_UTMP "/var/run/utmp" -#define _PATH_UTMP_DB "/var/run/utmp.db" +#define _PATH_UTMP_BASE "/var/run/utmp" +#define _PATH_UTMP _PATH_UTMP_BASE +#define _PATH_UTMP_DB _PATH_UTMP_BASE ".db" #define _PATH_VI "/usr/bin/vi" -#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_WTMP_BASE "/var/log/wtmp" +#define _PATH_WTMP _PATH_WTMP_BASE /* Provide trailing slash, since mostly used for building pathnames. */ #define _PATH_DEV "/dev/" diff --git a/sysdeps/generic/utmp-equal.h b/sysdeps/generic/utmp-equal.h deleted file mode 100644 index b1c4f008b9..0000000000 --- a/sysdeps/generic/utmp-equal.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Helper function for utmp functions to see if two entries are equal. - Copyright (C) 1996-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper - and Paul Janzen , 1996. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#include "utmp-private.h" - -/* Test whether two entries match. */ -static int -__utmp_equal (const struct utmp *entry, const struct utmp *match) -{ - return (entry->ut_type == INIT_PROCESS - || entry->ut_type == LOGIN_PROCESS - || entry->ut_type == USER_PROCESS - || entry->ut_type == DEAD_PROCESS) - && (match->ut_type == INIT_PROCESS - || match->ut_type == LOGIN_PROCESS - || match->ut_type == USER_PROCESS - || match->ut_type == DEAD_PROCESS) - && (entry->ut_id[0] && match->ut_id[0] - ? strncmp (entry->ut_id, match->ut_id, sizeof match->ut_id) == 0 - : (strncmp (entry->ut_line, match->ut_line, sizeof match->ut_line) - == 0)); -} diff --git a/sysdeps/unix/sysv/linux/paths.h b/sysdeps/unix/sysv/linux/paths.h index 1342ab3a96..3b8aeab788 100644 --- a/sysdeps/unix/sysv/linux/paths.h +++ b/sysdeps/unix/sysv/linux/paths.h @@ -61,9 +61,11 @@ #define _PATH_SHELLS "/etc/shells" #define _PATH_TTY "/dev/tty" #define _PATH_UNIX "/boot/vmlinux" -#define _PATH_UTMP "/var/run/utmp" +#define _PATH_UTMP_BASE "/var/run/utmp" +#define _PATH_UTMP _PATH_UTMP_BASE #define _PATH_VI "/usr/bin/vi" -#define _PATH_WTMP "/var/log/wtmp" +#define _PATH_WTMP_BASE "/var/log/wtmp" +#define _PATH_WTMP _PATH_WTMP_BASE /* Provide trailing slash, since mostly used for building pathnames. */ #define _PATH_DEV "/dev/" diff --git a/sysdeps/unix/sysv/linux/updwtmp.c b/sysdeps/unix/sysv/linux/updwtmp.c deleted file mode 100644 index 93d72e75a6..0000000000 --- a/sysdeps/unix/sysv/linux/updwtmp.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 1998-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Mark Kettenis , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP) == 0 \ - && __access (_PATH_UTMP "x", F_OK) == 0) \ - ? (_PATH_UTMP "x") \ - : ((strcmp (file_name, _PATH_WTMP) == 0 \ - && __access ( _PATH_WTMP "x", F_OK) == 0) \ - ? (_PATH_WTMP "x") \ - : ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)))) - -#include diff --git a/sysdeps/unix/sysv/linux/utmp-path.h b/sysdeps/unix/sysv/linux/utmp-path.h new file mode 100644 index 0000000000..a377bc9dba --- /dev/null +++ b/sysdeps/unix/sysv/linux/utmp-path.h @@ -0,0 +1,55 @@ +/* Handle {u,w}tmp and {u,w}tmpx file name usage. + Copyright (C) 1998-2020 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _UTMP_PATH_H +#define _UTMP_PATH_H 1 + +#include +#include + + +/* The function returns the utmp database for 32-bit utmp{x} entries based + on FILE_NAME: + + - if the default {x,w}utmp name is used but a file name ending with 'x' + exists it is returned instead + + - if the argument ends with 'x' and the file is not accessible the default + {x,w}utmp is returned instead. + + - if neither 1. nor 2. applies, the FILE_NAME is returned instead. */ +static inline const char * +utmp_file_name_time32 (const char *file_name) +{ + if (strcmp (file_name, _PATH_UTMP_BASE) == 0 + && __access (_PATH_UTMP_BASE "x", F_OK) == 0) + return _PATH_UTMP_BASE "x"; + else if (strcmp (file_name, _PATH_WTMP_BASE) == 0 + && __access (_PATH_WTMP_BASE "x", F_OK) == 0) + return _PATH_WTMP_BASE "x"; + else if (strcmp (file_name, _PATH_UTMP_BASE "x") == 0 + && __access (_PATH_UTMP_BASE "x", F_OK) != 0) + return _PATH_UTMP_BASE; + else if (strcmp (file_name, _PATH_WTMP_BASE "x") == 0 + && __access (_PATH_WTMP_BASE "x", F_OK) != 0) + return _PATH_WTMP_BASE; + + return file_name; +} + +#endif /* _UTMP_PATH_H */ diff --git a/sysdeps/unix/sysv/linux/utmp_file.c b/sysdeps/unix/sysv/linux/utmp_file.c deleted file mode 100644 index 78d10db8c8..0000000000 --- a/sysdeps/unix/sysv/linux/utmp_file.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 1998-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Mark Kettenis , 1998. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -#define TRANSFORM_UTMP_FILE_NAME(file_name) \ - ((strcmp (file_name, _PATH_UTMP) == 0 \ - && __access (_PATH_UTMP "x", F_OK) == 0) \ - ? (_PATH_UTMP "x") \ - : ((strcmp (file_name, _PATH_WTMP) == 0 \ - && __access ( _PATH_WTMP "x", F_OK) == 0) \ - ? (_PATH_WTMP "x") \ - : ((strcmp (file_name, _PATH_UTMP "x") == 0 \ - && __access (_PATH_UTMP "x", F_OK) != 0) \ - ? _PATH_UTMP \ - : ((strcmp (file_name, _PATH_WTMP "x") == 0 \ - && __access (_PATH_WTMP "x", F_OK) != 0) \ - ? _PATH_WTMP \ - : file_name)))) - -#include