001-remove-stime-function-calls.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. From d3539be8f27b8cbfdfee460fe08299158f08bcd9 Mon Sep 17 00:00:00 2001
  2. From: Alistair Francis <[email protected]>
  3. Date: Tue, 19 Nov 2019 13:06:40 +0100
  4. Subject: Remove stime() function calls
  5. stime() has been deprecated in glibc 2.31 and replaced with
  6. clock_settime(). Let's replace the stime() function calls with
  7. clock_settime() in preperation.
  8. function old new delta
  9. rdate_main 197 224 +27
  10. clock_settime - 27 +27
  11. date_main 926 941 +15
  12. stime 37 - -37
  13. ------------------------------------------------------------------------------
  14. (add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37) Total: 32 bytes
  15. Signed-off-by: Alistair Francis <[email protected]>
  16. Signed-off-by: Denys Vlasenko <[email protected]>
  17. ---
  18. coreutils/date.c | 6 +++++-
  19. libbb/missing_syscalls.c | 8 --------
  20. util-linux/rdate.c | 8 ++++++--
  21. 3 files changed, 11 insertions(+), 11 deletions(-)
  22. --- a/coreutils/date.c
  23. +++ b/coreutils/date.c
  24. @@ -279,6 +279,9 @@ int date_main(int argc UNUSED_PARAM, cha
  25. time(&ts.tv_sec);
  26. #endif
  27. }
  28. +#if !ENABLE_FEATURE_DATE_NANO
  29. + ts.tv_nsec = 0;
  30. +#endif
  31. localtime_r(&ts.tv_sec, &tm_time);
  32. /* If date string is given, update tm_time, and maybe set date */
  33. @@ -301,9 +304,10 @@ int date_main(int argc UNUSED_PARAM, cha
  34. if (date_str[0] != '@')
  35. tm_time.tm_isdst = -1;
  36. ts.tv_sec = validate_tm_time(date_str, &tm_time);
  37. + ts.tv_nsec = 0;
  38. /* if setting time, set it */
  39. - if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
  40. + if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
  41. bb_perror_msg("can't set date");
  42. }
  43. }
  44. --- a/libbb/missing_syscalls.c
  45. +++ b/libbb/missing_syscalls.c
  46. @@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)
  47. return syscall(__NR_getsid, pid);
  48. }
  49. -int stime(const time_t *t)
  50. -{
  51. - struct timeval tv;
  52. - tv.tv_sec = *t;
  53. - tv.tv_usec = 0;
  54. - return settimeofday(&tv, NULL);
  55. -}
  56. -
  57. int sethostname(const char *name, size_t len)
  58. {
  59. return syscall(__NR_sethostname, name, len);
  60. --- a/util-linux/rdate.c
  61. +++ b/util-linux/rdate.c
  62. @@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, ch
  63. if (!(flags & 2)) { /* no -p (-s may be present) */
  64. if (time(NULL) == remote_time)
  65. bb_error_msg("current time matches remote time");
  66. - else
  67. - if (stime(&remote_time) < 0)
  68. + else {
  69. + struct timespec ts;
  70. + ts.tv_sec = remote_time;
  71. + ts.tv_nsec = 0;
  72. + if (clock_settime(CLOCK_REALTIME, &ts) < 0)
  73. bb_perror_msg_and_die("can't set time of day");
  74. + }
  75. }
  76. if (flags != 1) /* not lone -s */