From patchwork Mon Nov 2 20:00:53 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: 40946 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 525DF397280C; Mon, 2 Nov 2020 20:01:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 525DF397280C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1604347262; bh=uKtQ51P4AuPX1M6iqrAM4S8eCAjoCk01D27x3KdmzNI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=h3U4kuQAhAMYGYW1hqDS0jHEJ6rRj4AJlisqTL5rkva2Uklzeknf4zdg3kej6AorO KjkZ2p3vHTpoUSISC1Y6HiaCKRj+0Tyt2gwxXY/3b9uw0RqM3CnznOI2ZK8QY/DN/d aRpAKhN9FSq67c/vztEayFjDe7P5eo2gyFtFfVEg= 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 179093894C11 for ; Mon, 2 Nov 2020 20:01:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 179093894C11 Received: by mail-qt1-x844.google.com with SMTP id h12so10104028qtu.1 for ; Mon, 02 Nov 2020 12:01:00 -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:mime-version :content-transfer-encoding; bh=uKtQ51P4AuPX1M6iqrAM4S8eCAjoCk01D27x3KdmzNI=; b=P25rAj+6YRxWR7iJ1kmkNuNogohcXB3HMFg/Ozd40qMnKzQu3LVucSpIxtko37zOzM 2WE+q+lWIkP0tE83HBgpAbJd6CgyluaVQZMPEGLxW0QJqrN+hGBMcuSk9evQ0RREzK7i pr87jE/zw3uhr9eFy1scA9XFhWFG+UmEVQHy8xXpritqv5jf30pgIDVm57B1kokaF48h PhXwI56fiLxdhJ4ZPoVw3TLARB2cBdc+kS//WjhOS8MY2v75vrUOQ8kA8DOdG2evQjVq RhQac58Co2ci3gLdql5mitXvLSreA4ctDsKrHfWCZsmaub00K/NmlkdrDxteVy+wypm+ IPTQ== X-Gm-Message-State: AOAM5314HTEaStabWbl4cHluoMQ0gZSJxbDchClUlVpvjdWhjpLf6OqH 3uB3hm76t6mBfWJFxn2Pnvbqf7CRrnlUaA== X-Google-Smtp-Source: ABdhPJwc1UqrxwiZtd2hdFsd5zhE1RQrZhQ3GFhL2e97tK+wStgMLmMX357b041BoUWJ+UDMsT7CLw== X-Received: by 2002:ac8:75d6:: with SMTP id z22mr16000972qtq.158.1604347258694; Mon, 02 Nov 2020 12:00:58 -0800 (PST) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z30sm8623590qtc.15.2020.11.02.12.00.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 12:00:58 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH] linux: Allow adjtime with NULL argument [BZ #26833] Date: Mon, 2 Nov 2020 17:00:53 -0300 Message-Id: <20201102200053.1171894-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-14.0 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 adjtime interface allows return the amount of time remaining from any previous adjustment that has not yet been completed by passing a NULL as first argument. This was introduced with y2038 support 0308077e3a. Checked on i686-linux-gnu. Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/adjtime.c | 11 ++++++-- time/Makefile | 3 +- time/tst-adjtime.c | 46 +++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 time/tst-adjtime.c diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c index 3f9a4ea2eb..6d1d1b6af2 100644 --- a/sysdeps/unix/sysv/linux/adjtime.c +++ b/sysdeps/unix/sysv/linux/adjtime.c @@ -68,11 +68,16 @@ libc_hidden_def (__adjtime64) int __adjtime (const struct timeval *itv, struct timeval *otv) { - struct __timeval64 itv64, otv64; + struct __timeval64 itv64, *pitv64 = NULL; + struct __timeval64 otv64; int retval; - itv64 = valid_timeval_to_timeval64 (*itv); - retval = __adjtime64 (&itv64, otv != NULL ? &otv64 : NULL); + if (itv != NULL) + { + itv64 = valid_timeval_to_timeval64 (*itv); + pitv64 = &itv64; + } + retval = __adjtime64 (pitv64, otv != NULL ? &otv64 : NULL); if (otv != NULL) *otv = valid_timeval64_to_timeval (otv64); diff --git a/time/Makefile b/time/Makefile index 26aa835166..f27a75a115 100644 --- a/time/Makefile +++ b/time/Makefile @@ -47,7 +47,8 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \ tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \ tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \ - tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 + tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ + tst-adjtime include ../Rules diff --git a/time/tst-adjtime.c b/time/tst-adjtime.c new file mode 100644 index 0000000000..0c39a98523 --- /dev/null +++ b/time/tst-adjtime.c @@ -0,0 +1,46 @@ +/* Test program for adjtime function. + Copyright (C) 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 +#include + + +/* This tests is a regression one that just check the non-privileged + interface provided by adjtime. */ + +static int +do_test (void) +{ + /* Check if the interface allows getting the amount of time remaining + from any previous adjustment that has not yet been completed. */ + struct timeval tv; + int r = adjtime (NULL, &tv); + if (r == -1) + { + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("adjtime unsupported"); + FAIL_EXIT1 ("adjtime (NULL, ...) failed: %m"); + } + + return 0; +} + +#include