From patchwork Fri Mar 5 20:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42300 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 257AE399C02E; Fri, 5 Mar 2021 20:15:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 257AE399C02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975347; bh=d3ATAvcm6wwNiIzYIe/Y7ix6EvehC0yWdrSUp8hTgpU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=xTaxKL16Gf7oHQE3vDMUyi53N+IVZ8/h4ygpcY3fLPFpdN7+He1i1XrrKjh/C+Ltb hQ5u6M0FWUsiQ0Z5s8e6udLtF47CFJ0nMLAK6smiijxQV0wUsqZSmY/x3yrD/BxuQz lN2qEDwdCXpd1QNtra6G+D95AAqRNWgc1x6FY1Mg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id A0603399C01E for ; Fri, 5 Mar 2021 20:15:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A0603399C01E Received: by mail-qk1-x731.google.com with SMTP id a9so3243412qkn.13 for ; Fri, 05 Mar 2021 12:15:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=d3ATAvcm6wwNiIzYIe/Y7ix6EvehC0yWdrSUp8hTgpU=; b=uUk6NmSkmo9fzWs3++/1VQLGFK/FUxFF+LxZXOuzqiAMR/KaRjyy+m1SmmD0usZA9k 7vEirn6gBQ5r7sXws/IuwNo2xKkPoLXZ6RQ7aOJUQIaXUgKkURtAZgbuhtlsxsOgd8yJ tR+8DJAXDgwoKlc7HrnQ+Dhe9I12Igb4ASVPgOZPyGl63Y6OAPu7Ufft+bUxCYVU42ff urixVXdJW1lHKmVtUSKin6nUtt2SRkFewQe3jjer+cwB7LO4ZGnrC1nenWoivYfZLcIi 28uEejfBzrtQYyNxDYjHDZ7dHB5vYgdFuj4daCjTyw2Pi/55VhOrExEbmgquJDkehJC+ qXew== X-Gm-Message-State: AOAM53294SQGiA2CqyRyfvyq9OYBLNJJUQAUxQaLUrj+3RoVJL8En0/q ohmofwLqdltT5STSM0ikAywmGjUgu/SwsQ== X-Google-Smtp-Source: ABdhPJziNhLgXgzI4WmPWCar+xwbWL7U3tK50CkEa4HMUIKH0aSceK13S0sXfybJFjKt/2E8bs97UQ== X-Received: by 2002:a37:9b82:: with SMTP id d124mr10600254qke.489.1614975342769; Fri, 05 Mar 2021 12:15:42 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:42 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 17/52] Consolidate and simplify internal utmp definitions Date: Fri, 5 Mar 2021 17:14:43 -0300 Message-Id: <20210305201518.798584-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210305201518.798584-1-adhemerval.zanella@linaro.org> References: <20210305201518.798584-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The TRANSFORM_UTMP_FILE_NAME macro is refactored to the inline function utmp_file_name_time32 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. --- 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(-) rename sysdeps/gnu/utmp_file.c => login/utmp-path.h (50%) delete mode 100644 sysdeps/generic/utmp-equal.h delete mode 100644 sysdeps/unix/sysv/linux/updwtmp.c create mode 100644 sysdeps/unix/sysv/linux/utmp-path.h delete mode 100644 sysdeps/unix/sysv/linux/utmp_file.c 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..f39222d62f --- /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-2021 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