From patchwork Wed Aug 5 18:59:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 40215 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 66B6C388C005; Wed, 5 Aug 2020 18:59:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66B6C388C005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1596653966; bh=xgADF7nu6vJUleaKkTX7t96sKb8AZwmg40609JR/8mk=; 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=BhX6f5Y7XcX+Lfv/bjaqeUd40q5SE8np8REOz5PcfHeS68xo8x2e7L9MDgqrz9lVl NOgGs47R3J7qVuPqALj8sD02Ymvhq2mutXFPa10LZHHqfVtKJb/PI8a4kh9PZEH4J8 93uyCXxmptCjPuCyH8OBhwkPRGeP3rxnr8VH0Ffw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id 5BB91383E833 for ; Wed, 5 Aug 2020 18:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5BB91383E833 Received: by mail-qk1-x742.google.com with SMTP id l64so35883301qkb.8 for ; Wed, 05 Aug 2020 11:59:22 -0700 (PDT) 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=xgADF7nu6vJUleaKkTX7t96sKb8AZwmg40609JR/8mk=; b=AT6Iu4xMBVOmp2YP+V+K7NjOKayPSKX68kTwdtXJric0RU6lmHHTEk9OCcp95HuyFR aAgGLDC3P5QZtbft3VszycbZSbTGwDK5GuJ6RD3H6If6Lmvl5kw1fToUon+trXag9HN7 we0vIU30P4YbKeJ0tIkBPd1IC/Uq7BTar/7MxB5/qafx/4qS3kAZHcsWGkB/nvQQhIZK dUEC3fZc7Ut/YgSRxhOWXFt2nPRVaZopY84QBFpIBeM1y1DeIX16lLAyS8/itkayQjLX j2w2iyGRAEhyXFBOaiklMXSk+FrHqFYMO8YF+2HkNKpxu/QCJMKsqLULwpU35k6DmtED cutQ== X-Gm-Message-State: AOAM531a8n00EkQNr/vTZpZqL47AlOgPx8Tbfufk/t6SAGUd+mGuDuY7 5MzwChWgaA90Le5iGCel3MUC2Q3kfPnP5A== X-Google-Smtp-Source: ABdhPJwsYsl/GiAtCLJMOVBevrnDrniyASrj6Xir0IAe+4/Rp4cjJuym+KMz5L4TdJqo1K4KJu+s1Q== X-Received: by 2002:a05:620a:7e7:: with SMTP id k7mr4634590qkk.420.1596653961310; Wed, 05 Aug 2020 11:59:21 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id l13sm2610088qth.77.2020.08.05.11.59.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 11:59:20 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 2/7] Consolidate and simplify internal utmp definitions Date: Wed, 5 Aug 2020 15:59:10 -0300 Message-Id: <20200805185915.2025314-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200805185915.2025314-1-adhemerval.zanella@linaro.org> References: <20200805185915.2025314-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 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 Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. --- 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 489c28b553..42a2152b60 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 25ceaa897c..c284c8c398 100644 --- a/sysdeps/gnu/utmp_file.c +++ b/login/utmp-path.h @@ -1,6 +1,6 @@ -/* Copyright (C) 1998-2020 Free Software Foundation, Inc. +/* 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. - 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 f095139c51..4f4f0cf4e4 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 cd0e3e79a0..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-2020 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 333317bfe2..0000000000 --- a/sysdeps/unix/sysv/linux/updwtmp.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 1998-2020 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 71da027a5f..0000000000 --- a/sysdeps/unix/sysv/linux/utmp_file.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 1998-2020 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