From patchwork Wed Aug 5 18:59:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1341374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=P3m6jDdN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BMLWy2h7zz9sTR for ; Thu, 6 Aug 2020 04:59:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 51D5D388A82B; Wed, 5 Aug 2020 18:59:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 51D5D388A82B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1596653964; bh=IwdD7Pz/ZoHwtyDzAHdisABip/XCZu3yfNXpPG/dQ0I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=P3m6jDdNTCVhPFGvT7WaGwZqoepD+Rw7iM4tVAh2pDoXmbrYHeyddTEup5qCZ7432 kHV7oCA7/JhqwFAJTz6sjfbYFTnPHGnXtiAO/FU5W+lBUeiccLiJzAlH8XCqE5Jk6I s2d9hni+7zj9vpfV1lV/VzUx9DiQuKFoOf/ekzS8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by sourceware.org (Postfix) with ESMTPS id 1F5133844034 for ; Wed, 5 Aug 2020 18:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1F5133844034 Received: by mail-qt1-x842.google.com with SMTP id h21so28101016qtp.11 for ; Wed, 05 Aug 2020 11:59:21 -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:mime-version :content-transfer-encoding; bh=IwdD7Pz/ZoHwtyDzAHdisABip/XCZu3yfNXpPG/dQ0I=; b=ZmRagjoe3kovlVGUdpoRTPFd+s5TtRSiSq1ubRFqNOSkbdF5ibV3olDed7Y3lfSsli OOOZh0aujKETGc+hIlff3kKuTqu17+qP3LGceKDBBPj+CFtkF7VV/g/8J4SCYjc6kFny hrp4KoItn+g5HYoVmVxlMBR24yG3AMzNN0/+ivAJtP3FMYgkTPlaPAXMklj0OZ06k+Ui s2+lKIjnZ1VfD5dSmXD9OBmNKWJaU/CYwHJzvO6Y3egJ9P2VDMAO1C/xIhpq2tFT3VJG JqfvF72fVn7fPco50t2TJWpgqOIAqoagX2yQPzvYBTKIJpbactc1rBDNw3di6jjPX1Y+ 9tPQ== X-Gm-Message-State: AOAM533+jiOEklgEgr5bdC3Lk2qWadFnK9ZwM55q+RLsvVo0bF+IxqAO qZit1eepObFBvphe120flAad8A1Vfw85gw== X-Google-Smtp-Source: ABdhPJx5KbCUL1cqEg6wLNdHpuA1ZPrZww5dPDsxCN7c1y3jhPxMHIN2Zcm9skY19iUX/DCqEhgKgA== X-Received: by 2002:ac8:7b9c:: with SMTP id p28mr5061367qtu.283.1596653959972; Wed, 05 Aug 2020 11:59:19 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id l13sm2610088qth.77.2020.08.05.11.59.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 11:59:19 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/7] login: Move gnu utmpx to default implementation Date: Wed, 5 Aug 2020 15:59:09 -0300 Message-Id: <20200805185915.2025314-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 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" It removes one indirection where generic implementation assumes that utmp and utmpx might differ and allows the optimize the symbol alias where getutmp is the same as getumpx. Checked with make check run-built-tests=no on all afftected ABIs. --- .../gnu/bits => bits/types}/struct_utmpx.h | 0 {sysdeps/gnu/bits => bits}/utmpx.h | 2 +- include/utmpx.h | 1 + login/Makefile | 2 +- login/getutmp.c | 34 ++++++++++++++++-- login/getutmpx.c | 35 +------------------ login/updwtmp.c | 11 +++++- {sysdeps/gnu => login}/utmpx.h | 0 sysdeps/gnu/getutmp.c | 34 ------------------ sysdeps/gnu/getutmpx.c | 1 - sysdeps/gnu/updwtmp.c | 31 ---------------- .../unix/sysv/linux/s390/s390-32/getutmp.c | 21 ++++------- .../unix/sysv/linux/s390/s390-32/updwtmp.c | 2 +- 13 files changed, 54 insertions(+), 120 deletions(-) rename {sysdeps/gnu/bits => bits/types}/struct_utmpx.h (100%) rename {sysdeps/gnu/bits => bits}/utmpx.h (98%) create mode 100644 include/utmpx.h rename {sysdeps/gnu => login}/utmpx.h (100%) delete mode 100644 sysdeps/gnu/getutmp.c delete mode 100644 sysdeps/gnu/getutmpx.c delete mode 100644 sysdeps/gnu/updwtmp.c diff --git a/sysdeps/gnu/bits/struct_utmpx.h b/bits/types/struct_utmpx.h similarity index 100% rename from sysdeps/gnu/bits/struct_utmpx.h rename to bits/types/struct_utmpx.h diff --git a/sysdeps/gnu/bits/utmpx.h b/bits/utmpx.h similarity index 98% rename from sysdeps/gnu/bits/utmpx.h rename to bits/utmpx.h index 12ee26871e..aecc433276 100644 --- a/sysdeps/gnu/bits/utmpx.h +++ b/bits/utmpx.h @@ -51,7 +51,7 @@ struct __exit_status }; -#include +#include /* Values for the `ut_type' field of a `struct utmpx'. */ diff --git a/include/utmpx.h b/include/utmpx.h new file mode 100644 index 0000000000..cfe9b7c054 --- /dev/null +++ b/include/utmpx.h @@ -0,0 +1 @@ +#include diff --git a/login/Makefile b/login/Makefile index 758899900d..c61d1950bb 100644 --- a/login/Makefile +++ b/login/Makefile @@ -26,7 +26,7 @@ include ../Makeconfig headers := utmp.h bits/utmp.h lastlog.h pty.h \ bits/types/struct_lastlog.h \ bits/types/struct_utmp.h \ - bits/struct_utmpx.h + bits/types/struct_utmpx.h routines := getlogin getlogin_r setlogin getlogin_r_chk \ getutent getutent_r getutid getutline getutid_r getutline_r \ diff --git a/login/getutmp.c b/login/getutmp.c index e9a5fe69a5..3058a93d1b 100644 --- a/login/getutmp.c +++ b/login/getutmp.c @@ -17,17 +17,47 @@ #include #include +#include +#define getutmpx __redirect_getutmpx #include +#undef getutmpx + +#define CHECK_SIZE_AND_OFFSET(field) \ + _Static_assert (sizeof ((struct utmp){0}.field) \ + == sizeof ((struct utmpx){0}.field), \ + "sizeof ((struct utmp){0}." #field " != " \ + "sizeof ((struct utmpx){0}" #field); \ + _Static_assert (offsetof (struct utmp, field) \ + == offsetof (struct utmpx, field), \ + "offsetof (struct utmp, " #field ") != " \ + "offsetof (struct utmpx, " #field ")"); + +/* This ensure the getutmp to getutmpx alias is valid. */ +_Static_assert (sizeof (struct utmp) == sizeof (struct utmpx), + "sizeof (struct utmp) != sizeof (struct utmpx)"); +CHECK_SIZE_AND_OFFSET (ut_type) +CHECK_SIZE_AND_OFFSET (ut_pid) +CHECK_SIZE_AND_OFFSET (ut_line) +CHECK_SIZE_AND_OFFSET (ut_user) +CHECK_SIZE_AND_OFFSET (ut_id) +CHECK_SIZE_AND_OFFSET (ut_host) +CHECK_SIZE_AND_OFFSET (ut_tv) + /* Copy the information in UTMPX to UTMP. */ void -getutmp (const struct utmpx *utmpx, struct utmp *utmp) +__getutmp (const struct utmpx *utmpx, struct utmp *utmp) { + memset (utmp, 0, sizeof (struct utmpx)); utmp->ut_type = utmpx->ut_type; utmp->ut_pid = utmpx->ut_pid; memcpy (utmp->ut_line, utmpx->ut_line, sizeof (utmp->ut_line)); memcpy (utmp->ut_user, utmpx->ut_user, sizeof (utmp->ut_user)); memcpy (utmp->ut_id, utmpx->ut_id, sizeof (utmp->ut_id)); memcpy (utmp->ut_host, utmpx->ut_host, sizeof (utmp->ut_host)); - utmp->ut_tv = utmpx->ut_tv; + utmp->ut_tv.tv_sec = utmpx->ut_tv.tv_sec; + utmp->ut_tv.tv_usec = utmpx->ut_tv.tv_usec; } + +weak_alias (__getutmp, getutmp) +strong_alias (__getutmp, getutmpx) diff --git a/login/getutmpx.c b/login/getutmpx.c index 250a355235..839eb6826e 100644 --- a/login/getutmpx.c +++ b/login/getutmpx.c @@ -1,34 +1 @@ -/* Copyright (C) 1999-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 - . */ - -#include -#include -#include - -/* Copy the information in UTMP to UTMPX. */ -void -getutmpx (const struct utmp *utmp, struct utmpx *utmpx) -{ - memset (utmpx, 0, sizeof (struct utmpx)); - utmpx->ut_type = utmp->ut_type; - utmpx->ut_pid = utmp->ut_pid; - memcpy (utmpx->ut_line, utmp->ut_line, sizeof (utmp->ut_line)); - memcpy (utmpx->ut_user, utmp->ut_user, sizeof (utmp->ut_user)); - memcpy (utmpx->ut_id, utmp->ut_id, sizeof (utmp->ut_id)); - memcpy (utmpx->ut_host, utmp->ut_host, sizeof (utmp->ut_host)); - utmpx->ut_tv = utmp->ut_tv; -} +/* Implemented by getutmp.c. */ diff --git a/login/updwtmp.c b/login/updwtmp.c index f6cd515ac4..489c28b553 100644 --- a/login/updwtmp.c +++ b/login/updwtmp.c @@ -17,11 +17,20 @@ . */ #include +#include +#include #include "utmp-private.h" #ifndef TRANSFORM_UTMP_FILE_NAME -# define TRANSFORM_UTMP_FILE_NAME(file_name) (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 void diff --git a/sysdeps/gnu/utmpx.h b/login/utmpx.h similarity index 100% rename from sysdeps/gnu/utmpx.h rename to login/utmpx.h diff --git a/sysdeps/gnu/getutmp.c b/sysdeps/gnu/getutmp.c deleted file mode 100644 index 95a9a4b354..0000000000 --- a/sysdeps/gnu/getutmp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1999-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 - . */ - -#include -#include -#include -#ifndef _UTMPX_H -/* This is an ugly hack but we must not see the getutmpx declaration. */ -# define getutmpx XXXgetutmpx -# include -# undef getutmpx -#endif - -void -getutmp (const struct utmpx *utmpx, struct utmp *utmp) -{ - assert (sizeof (struct utmp) == sizeof (struct utmpx)); - memcpy (utmp, utmpx, sizeof (struct utmp)); -} -strong_alias (getutmp, getutmpx) diff --git a/sysdeps/gnu/getutmpx.c b/sysdeps/gnu/getutmpx.c deleted file mode 100644 index f393734a63..0000000000 --- a/sysdeps/gnu/getutmpx.c +++ /dev/null @@ -1 +0,0 @@ -/* We don't need a separate version. it is the same as getutmp(). */ diff --git a/sysdeps/gnu/updwtmp.c b/sysdeps/gnu/updwtmp.c deleted file mode 100644 index 044091b77c..0000000000 --- a/sysdeps/gnu/updwtmp.c +++ /dev/null @@ -1,31 +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 "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/s390/s390-32/getutmp.c b/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c index 6380ae2a82..50ce8c4f5c 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/getutmp.c @@ -16,22 +16,15 @@ License along with the GNU C Library; if not, see . */ -#include -#include -/* This is an ugly hack but we must not see the getutmpx declaration. */ -#define getutmpx XXXgetutmpx -#include -#undef getutmpx +#undef weak_alias +#define weak_alias(a, b) +#undef strong_alias +#define strong_alias(a, b) -#include "utmp-compat.h" +#include -#undef weak_alias -#define weak_alias(n,a) -#define getutmp __getutmp -#define getutmpx __getutmpx -#include "sysdeps/gnu/getutmp.c" -#undef getutmp -#undef getutmpx +#include "utmp-compat.h" default_symbol_version (__getutmp, getutmp, UTMP_COMPAT_BASE); +_strong_alias (__getutmp, __getutmpx) default_symbol_version (__getutmpx, getutmpx, UTMP_COMPAT_BASE); diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c b/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c index dcd334e5a9..2079571cc1 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c +++ b/sysdeps/unix/sysv/linux/s390/s390-32/updwtmp.c @@ -25,7 +25,7 @@ # undef weak_alias # define weak_alias(n,a) #endif -#include "sysdeps/gnu/updwtmp.c" +#include #if defined SHARED default_symbol_version (__updwtmp, updwtmp, UTMP_COMPAT_BASE);