From patchwork Wed Jul 29 20:51:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 40188 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 F225F3851C18; Wed, 29 Jul 2020 20:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F225F3851C18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1596055889; bh=JRy8grM1VIykdKlGuz5pWWu5RNa84bWZrms+7dOkVI4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=gOlB3KCHXGsTDciqBAjeD0wyRZBFqmWDHqB7OtVFkTbQSModStn4fzNjz/2BPhBct Ie0Koxm8pKK84J4Tg8x5PuHKuWCwO5cWTV7kmz0qVXwtXpxOQ+6KG45bVbMPOdz9Eh w6/5Fea1kzgfzLQ3/9x9gkKwYRYid6AMxXf5LgRA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by sourceware.org (Postfix) with ESMTPS id 5617E3857C42 for ; Wed, 29 Jul 2020 20:51:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5617E3857C42 Received: by mail-qt1-x844.google.com with SMTP id s23so18715385qtq.12 for ; Wed, 29 Jul 2020 13:51:24 -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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JRy8grM1VIykdKlGuz5pWWu5RNa84bWZrms+7dOkVI4=; b=r2Zp1ZyeapOGthZhBDi4J0+NIMpyWwUtErd/KcBVF5hxUyhi6YZvAFkWgkktYO7V1X W1Mwt0t7hqixvS7/+L/82XpQdFYxoV6JhJqnMnqgQTHIAZ0qjRGWe4ifvozDpBOw1Edj wEjOUdW7by3CKOywFtqDItzo1KdYtV2WgUBX6mMPAZ4Dfu3f6V/tToZ6BxHw9hEI7Ks6 HhtSvCKc/dEPuUgzq6IMnyIfDgY3zDj5x9OCr0L1qv9NKox50NzltjNNlLks92K9t3Y6 lPlzI/UL2xsnwNHIz3r85/XwmgHGAKIIEdcto4i3dWUCue9EsdGBAjvGpOjbCPps7EgM AYvA== X-Gm-Message-State: AOAM531sG9abSye8W5lvz975tBpi5QlyoikoNjFLSbTP8I63iC8kRKdA 7c7if4y5+8Lz3II3hWra2MOSs9uAPcg= X-Google-Smtp-Source: ABdhPJympRGuQOry166pVwGJBuxku0QIhDubWjx8MT42qOPzDwqNh+W+AqdlACa8Snw3HZp9k+USqQ== X-Received: by 2002:ac8:346c:: with SMTP id v41mr251622qtb.262.1596055883546; Wed, 29 Jul 2020 13:51:23 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id v58sm2827230qtj.56.2020.07.29.13.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2020 13:51:23 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/5] login: Move gnu utmpx to default implementaion Date: Wed, 29 Jul 2020 17:51:14 -0300 Message-Id: <20200729205117.2925113-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200729205117.2925113-1-adhemerval.zanella@linaro.org> References: <20200729205117.2925113-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 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 Cc: Alistair Francis 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 on all afftected ABIs. Reviewed-by: Lukasz Majewski --- {sysdeps/gnu/bits => bits}/struct_utmpx.h | 0 {sysdeps/gnu/bits => bits}/utmpx.h | 0 include/utmpx.h | 1 + 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 +- 12 files changed, 52 insertions(+), 118 deletions(-) rename {sysdeps/gnu/bits => bits}/struct_utmpx.h (100%) rename {sysdeps/gnu/bits => bits}/utmpx.h (100%) 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/struct_utmpx.h similarity index 100% rename from sysdeps/gnu/bits/struct_utmpx.h rename to bits/struct_utmpx.h diff --git a/sysdeps/gnu/bits/utmpx.h b/bits/utmpx.h similarity index 100% rename from sysdeps/gnu/bits/utmpx.h rename to bits/utmpx.h 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/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);