• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From c820da85c65c7f3aa9e9cb3ed71ada69bf9b783e Mon Sep 17 00:00:00 2001
2From: Alistair Francis <alistair.francis@wdc.com>
3Date: Tue, 19 Nov 2019 13:06:40 +0100
4Subject: [PATCH] Remove stime() function calls
5
6stime() has been deprecated in glibc 2.31 and replaced with
7clock_settime(). Let's replace the stime() function calls with
8clock_settime() in preparation.
9
10function                                             old     new   delta
11rdate_main                                           197     224     +27
12clock_settime                                          -      27     +27
13date_main                                            926     941     +15
14stime                                                 37       -     -37
15------------------------------------------------------------------------------
16(add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37)             Total: 32 bytes
17
18Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
20
21[Tom Eccles: adjust patch context to apply on top of 1.31.1-stable]
22Signed-off-by: Tom Eccles <tom.eccles@codethink.co.uk>
23---
24 coreutils/date.c         | 6 +++++-
25 libbb/missing_syscalls.c | 8 --------
26 util-linux/rdate.c       | 8 ++++++--
27 3 files changed, 11 insertions(+), 11 deletions(-)
28
29diff --git a/coreutils/date.c b/coreutils/date.c
30index 3414d38ae..4ade6abb4 100644
31--- a/coreutils/date.c
32+++ b/coreutils/date.c
33@@ -279,6 +279,9 @@ int date_main(int argc UNUSED_PARAM, char **argv)
34 		time(&ts.tv_sec);
35 #endif
36 	}
37+#if !ENABLE_FEATURE_DATE_NANO
38+	ts.tv_nsec = 0;
39+#endif
40 	localtime_r(&ts.tv_sec, &tm_time);
41
42 	/* If date string is given, update tm_time, and maybe set date */
43@@ -301,9 +304,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)
44 		if (date_str[0] != '@')
45 			tm_time.tm_isdst = -1;
46 		ts.tv_sec = validate_tm_time(date_str, &tm_time);
47+		ts.tv_nsec = 0;
48
49 		/* if setting time, set it */
50-		if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
51+		if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
52 			bb_perror_msg("can't set date");
53 		}
54 	}
55diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
56index 87cf59b3d..dc40d9155 100644
57--- a/libbb/missing_syscalls.c
58+++ b/libbb/missing_syscalls.c
59@@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)
60 	return syscall(__NR_getsid, pid);
61 }
62
63-int stime(const time_t *t)
64-{
65-	struct timeval tv;
66-	tv.tv_sec = *t;
67-	tv.tv_usec = 0;
68-	return settimeofday(&tv, NULL);
69-}
70-
71 int sethostname(const char *name, size_t len)
72 {
73 	return syscall(__NR_sethostname, name, len);
74diff --git a/util-linux/rdate.c b/util-linux/rdate.c
75index 70f829e7f..878375d78 100644
76--- a/util-linux/rdate.c
77+++ b/util-linux/rdate.c
78@@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, char **argv)
79 	if (!(flags & 2)) { /* no -p (-s may be present) */
80 		if (time(NULL) == remote_time)
81 			bb_error_msg("current time matches remote time");
82-		else
83-			if (stime(&remote_time) < 0)
84+		else {
85+			struct timespec ts;
86+			ts.tv_sec = remote_time;
87+			ts.tv_nsec = 0;
88+			if (clock_settime(CLOCK_REALTIME, &ts) < 0)
89 				bb_perror_msg_and_die("can't set time of day");
90+		}
91 	}
92
93 	if (flags != 1) /* not lone -s */
94--
952.25.1
96
97