From patchwork Fri Mar 5 20:14:42 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: 42297 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 0CBD5399C01F; Fri, 5 Mar 2021 20:15:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0CBD5399C01F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1614975345; bh=FekgnyVul78cdF123mU/MPpeauHlljIipJ8AMMHVyUA=; 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=xhi35u/okSEeVnI5dAWo48O1X3wm4Ev2COxVyUavp0HzMmfss+Lti/2ef/5nFb73x UrwoZXQoQniQs4/K6sxfXHqYzgPmPaI/ImhxN3qoEGKVNuDuePEV0sIepcss3MXVtD 0Kl78qQUF7f0M574h4s3kJlbWLxm/aRmtTBTCcSM= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 4E4553897807 for ; Fri, 5 Mar 2021 20:15:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4E4553897807 Received: by mail-qk1-x734.google.com with SMTP id b130so3253224qkc.10 for ; Fri, 05 Mar 2021 12:15:42 -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=FekgnyVul78cdF123mU/MPpeauHlljIipJ8AMMHVyUA=; b=HYC0JPPqNP35eR/um6wBiTk+DA+NnJDQQT5mciB7hY7GZVfIwiaNugxCMGAJYC2e4W Boub737oryUc4gay7aTup2fE2+dhtQNPOyAMQqSsblMY4A5UTCOiNYR0vVJ57RhpHJbX xdd3JEWGrH0U9dtp+4IZvkQO5E7ubxTYrJt/odx9m/Avy99yqq5VlO3n5ibgynv7eS9B Qu9NbftMI8iFVhhwBVP7E2AJvq3K6z7u1gpiWEVzaD1e7Qp+msCiWoeHZMG2G1VYwLQr H+AMicgOQEtWFWOXcJeuUrvx6eHKHhVitNHMbbGLH4Vl2KSvps+kNk9WsFoxm4wG4V4p bzJA== X-Gm-Message-State: AOAM530L9bdu+FiQnH1IhoMkMKjVBwuOpS1psdBlkC5cEnnOFNPfldNL q4u6EP6mhD+H6Q4BzUdIwZg0fox9HPI2Fw== X-Google-Smtp-Source: ABdhPJzy3vGLerNTsuO4VUYyB+rNCiSh9dOVL99U7rDBXJImGFzfGmKyyF/Ce+qzwhRKFE2nkrDVcg== X-Received: by 2002:a37:4783:: with SMTP id u125mr10994842qka.186.1614975341513; Fri, 05 Mar 2021 12:15:41 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id c5sm2526145qkl.21.2021.03.05.12.15.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 12:15:41 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 16/52] login: Move gnu utmpx to default implementation Date: Fri, 5 Mar 2021 17:14:42 -0300 Message-Id: <20210305201518.798584-17-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" 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 26ec95603f..b2947b1c13 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 f7059ac660..5e2cb1da06 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 0401e041dd..60aafb5067 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 228726a05a..839eb6826e 100644 --- a/login/getutmpx.c +++ b/login/getutmpx.c @@ -1,34 +1 @@ -/* Copyright (C) 1999-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 - . */ - -#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 0558198464..ae67cfc10a 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 4ce9d65ce0..0000000000 --- a/sysdeps/gnu/getutmp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 1999-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 - . */ - -#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 a1cb93d75d..0000000000 --- a/sysdeps/gnu/updwtmp.c +++ /dev/null @@ -1,31 +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 "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 5820701f21..6ffea2a553 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 d4aa0ce2ac..7ef8e85c00 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);