Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 1 | From 75a193b7611bade31a150dfcc528b973e3d46231 Mon Sep 17 00:00:00 2001 |
| 2 | From: Adhemerval Zanella <adhemerval.zanella@linaro.org> |
| 3 | Date: Mon, 2 Nov 2020 16:18:29 -0300 |
| 4 | Subject: [PATCH] linux: Allow adjtime with NULL argument [BZ #26833] |
| 5 | |
| 6 | The adjtime interface allows return the amount of time remaining |
| 7 | from any previous adjustment that has not yet been completed by |
| 8 | passing a NULL as first argument. This was introduced with y2038 |
| 9 | support 0308077e3a. |
| 10 | |
| 11 | Checked on i686-linux-gnu. |
| 12 | |
| 13 | Reviewed-by: Lukasz Majewski <lukma@denx.de> |
| 14 | Upstream-Status: Backport [https://sourceware.org/git/?p=glibc.git;a=commit;h=75a193b7611bade31a150dfcc528b973e3d46231] |
| 15 | Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> |
| 16 | --- |
| 17 | sysdeps/unix/sysv/linux/adjtime.c | 11 +++++--- |
| 18 | time/Makefile | 3 ++- |
| 19 | time/tst-adjtime.c | 44 +++++++++++++++++++++++++++++++ |
| 20 | 3 files changed, 54 insertions(+), 4 deletions(-) |
| 21 | create mode 100644 time/tst-adjtime.c |
| 22 | |
| 23 | diff --git a/sysdeps/unix/sysv/linux/adjtime.c b/sysdeps/unix/sysv/linux/adjtime.c |
| 24 | index 3f9a4ea2eb..6d1d1b6af2 100644 |
| 25 | --- a/sysdeps/unix/sysv/linux/adjtime.c |
| 26 | +++ b/sysdeps/unix/sysv/linux/adjtime.c |
| 27 | @@ -68,11 +68,16 @@ libc_hidden_def (__adjtime64) |
| 28 | int |
| 29 | __adjtime (const struct timeval *itv, struct timeval *otv) |
| 30 | { |
| 31 | - struct __timeval64 itv64, otv64; |
| 32 | + struct __timeval64 itv64, *pitv64 = NULL; |
| 33 | + struct __timeval64 otv64; |
| 34 | int retval; |
| 35 | |
| 36 | - itv64 = valid_timeval_to_timeval64 (*itv); |
| 37 | - retval = __adjtime64 (&itv64, otv != NULL ? &otv64 : NULL); |
| 38 | + if (itv != NULL) |
| 39 | + { |
| 40 | + itv64 = valid_timeval_to_timeval64 (*itv); |
| 41 | + pitv64 = &itv64; |
| 42 | + } |
| 43 | + retval = __adjtime64 (pitv64, otv != NULL ? &otv64 : NULL); |
| 44 | if (otv != NULL) |
| 45 | *otv = valid_timeval64_to_timeval (otv64); |
| 46 | |
| 47 | diff --git a/time/Makefile b/time/Makefile |
| 48 | index 26aa835166..f27a75a115 100644 |
| 49 | --- a/time/Makefile |
| 50 | +++ b/time/Makefile |
| 51 | @@ -47,7 +47,8 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ |
| 52 | tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \ |
| 53 | tst-strptime3 bug-getdate1 tst-strptime-whitespace tst-ftime \ |
| 54 | tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \ |
| 55 | - tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 |
| 56 | + tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ |
| 57 | + tst-adjtime |
| 58 | |
| 59 | include ../Rules |
| 60 | |
| 61 | diff --git a/time/tst-adjtime.c b/time/tst-adjtime.c |
| 62 | new file mode 100644 |
| 63 | index 0000000000..ae2b37cdab |
| 64 | --- /dev/null |
| 65 | +++ b/time/tst-adjtime.c |
| 66 | @@ -0,0 +1,44 @@ |
| 67 | +/* Basic tests for adjtime. |
| 68 | + Copyright (C) 2020 Free Software Foundation, Inc. |
| 69 | + This file is part of the GNU C Library. |
| 70 | + |
| 71 | + The GNU C Library is free software; you can redistribute it and/or |
| 72 | + modify it under the terms of the GNU Lesser General Public |
| 73 | + License as published by the Free Software Foundation; either |
| 74 | + version 2.1 of the License, or (at your option) any later version. |
| 75 | + |
| 76 | + The GNU C Library is distributed in the hope that it will be useful, |
| 77 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 78 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 79 | + Lesser General Public License for more details. |
| 80 | + |
| 81 | + You should have received a copy of the GNU Lesser General Public |
| 82 | + License along with the GNU C Library; if not, see |
| 83 | + <https://www.gnu.org/licenses/>. */ |
| 84 | + |
| 85 | +#include <sys/time.h> |
| 86 | +#include <stdlib.h> |
| 87 | + |
| 88 | +#include <errno.h> |
| 89 | +#include <support/check.h> |
| 90 | + |
| 91 | + |
| 92 | +static int |
| 93 | +do_test (void) |
| 94 | +{ |
| 95 | + /* Check if the interface allows getting the amount of time remaining |
| 96 | + from any previous adjustment that has not yet been completed. This |
| 97 | + is a non-privileged function of adjtime. */ |
| 98 | + struct timeval tv; |
| 99 | + int r = adjtime (NULL, &tv); |
| 100 | + if (r == -1) |
| 101 | + { |
| 102 | + if (errno == ENOSYS) |
| 103 | + FAIL_UNSUPPORTED ("adjtime unsupported"); |
| 104 | + FAIL_EXIT1 ("adjtime (NULL, ...) failed: %m"); |
| 105 | + } |
| 106 | + |
| 107 | + return 0; |
| 108 | +} |
| 109 | + |
| 110 | +#include <support/test-driver.c> |