You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.1 KiB

  1. From 402150eed057fc9fa52c8471ae645e23913a2805 Mon Sep 17 00:00:00 2001
  2. From: Philip Homburg <phomburg@ripe.net>
  3. Date: Tue, 23 Jun 2020 12:25:08 -0400
  4. Subject: [PATCH] replace stime with clock_settime
  5. ---
  6. coreutils/date.c | 5 ++++-
  7. 1 file changed, 4 insertions(+), 1 deletion(-)
  8. --- a/coreutils/date.c
  9. +++ b/coreutils/date.c
  10. @@ -246,6 +246,9 @@ int date_main(int argc UNUSED_PARAM, cha
  11. if (*argv)
  12. bb_show_usage();
  13. + /* Clear ts.tv_nsec, in case we need to set the time later */
  14. + ts.tv_nsec= 0;
  15. +
  16. /* Now we have parsed all the information except the date format
  17. * which depends on whether the clock is being set or read */
  18. @@ -310,7 +313,7 @@ int date_main(int argc UNUSED_PARAM, cha
  19. }
  20. /* if setting time, set it */
  21. - if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
  22. + if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
  23. bb_perror_msg("can't set date");
  24. }
  25. }
  26. --- a/util-linux/rdate.c
  27. +++ b/util-linux/rdate.c
  28. @@ -65,27 +65,27 @@ static time_t askremotedate(const char *
  29. int rdate_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  30. int rdate_main(int argc UNUSED_PARAM, char **argv)
  31. {
  32. - time_t remote_time;
  33. + struct timespec remote_time;
  34. unsigned flags;
  35. opt_complementary = "-1";
  36. flags = getopt32(argv, "sp");
  37. - remote_time = askremotedate(argv[optind]);
  38. + remote_time.tv_sec = askremotedate(argv[optind]);
  39. if (!(flags & 2)) { /* no -p (-s may be present) */
  40. time_t current_time;
  41. time(&current_time);
  42. - if (current_time == remote_time)
  43. + if (current_time == remote_time.tv_sec)
  44. bb_error_msg("current time matches remote time");
  45. else
  46. - if (stime(&remote_time) < 0)
  47. + if (clock_settime(CLOCK_REALTIME,&remote_time) < 0)
  48. bb_perror_msg_and_die("can't set time of day");
  49. }
  50. if (flags != 1) /* not lone -s */
  51. - printf("%s", ctime(&remote_time));
  52. + printf("%s", ctime(&remote_time.tv_sec));
  53. return EXIT_SUCCESS;
  54. }
  55. --- a/networking/httpget.c
  56. +++ b/networking/httpget.c
  57. @@ -947,8 +947,9 @@ static int eat_headers(FILE *tcp_file, i
  58. if (time_tolerance && strncmp(line, "Date: ", 6) == 0)
  59. {
  60. /* Try to set time from server */
  61. - time_t now, tim, tolerance;
  62. + time_t now, tolerance;
  63. struct tm tm;
  64. + struct timespec tim;
  65. tolerance= strtoul(time_tolerance, &cp, 10);
  66. if (cp[0] != '\0')
  67. @@ -966,16 +967,16 @@ static int eat_headers(FILE *tcp_file, i
  68. line+6);
  69. }
  70. }
  71. - tim= timegm(&tm);
  72. + tim.tv_sec= timegm(&tm);
  73. now= time(NULL);
  74. - if (now < tim-tolerance || now > tim+tolerance)
  75. + if (now < tim.tv_sec-tolerance || now > tim.tv_sec+tolerance)
  76. {
  77. if (debug)
  78. { fprintf(stderr,
  79. "setting time, time difference is %d\n",
  80. - (int)(tim-now));
  81. + (int)(tim.tv_sec-now));
  82. }
  83. - stime(&tim);
  84. + clock_settime(CLOCK_REALTIME,&tim);
  85. }
  86. }
  87. --- a/networking/httppost.c
  88. +++ b/networking/httppost.c
  89. @@ -92,13 +92,14 @@ int httppost_main(int argc, char *argv[]
  90. char *time_tolerance, *rebased_fn= NULL;
  91. char *fn_new, *fn;
  92. FILE *tcp_file, *out_file, *fh;
  93. - time_t server_time, tolerance;
  94. + time_t tolerance;
  95. + struct timespec server_time;
  96. struct stat sbF, sbH, sbS;
  97. off_t cLength, dir_length, maxpostsize;
  98. struct sigaction sa;
  99. - post_dir= NULL;
  100. - post_file= NULL;
  101. + post_dir= NULL;
  102. + post_file= NULL;
  103. post_footer=NULL;
  104. post_header=NULL;
  105. atlas_id= NULL;
  106. @@ -470,12 +471,12 @@ int httppost_main(int argc, char *argv[]
  107. if (!check_result(tcp_file))
  108. goto err;
  109. fprintf(stderr, "httppost: getting reply headers \n");
  110. - server_time= 0;
  111. + server_time.tv_sec = 0;
  112. content_length= -1;
  113. - if (!eat_headers(tcp_file, &chunked, &content_length, &server_time))
  114. + if (!eat_headers(tcp_file, &chunked, &content_length, &server_time.tv_sec))
  115. goto err;
  116. - if (tolerance && server_time > 0)
  117. + if (tolerance && server_time.tv_sec > 0)
  118. {
  119. /* Try to set time from server */
  120. int need_set_time;
  121. @@ -486,35 +487,35 @@ int httppost_main(int argc, char *argv[]
  122. rtt= now.tv_sec-start_time.tv_sec;
  123. rtt += (now.tv_usec-start_time.tv_usec)/1e6;
  124. if (rtt < 0) rtt= 0;
  125. - need_set_time= (now.tv_sec < server_time-tolerance-rtt ||
  126. - now.tv_sec > server_time+tolerance+rtt);
  127. + need_set_time= (now.tv_sec < server_time.tv_sec-tolerance-rtt ||
  128. + now.tv_sec > server_time.tv_sec+tolerance+rtt);
  129. if (need_set_time && getenv("HTTPPOST_ALLOW_STIME"))
  130. {
  131. fprintf(stderr,
  132. "setting time, time difference is %ld\n",
  133. - (long)server_time-now.tv_sec);
  134. - stime(&server_time);
  135. + (long)server_time.tv_sec-now.tv_sec);
  136. + clock_settime(CLOCK_REALTIME,&server_time);
  137. if (atlas_id)
  138. {
  139. printf(
  140. "RESULT %s ongoing %ld httppost setting time, local %ld, remote %ld\n",
  141. atlas_id, (long)time(NULL),
  142. (long)now.tv_sec,
  143. - (long)server_time);
  144. + (long)server_time.tv_sec);
  145. }
  146. }
  147. else if (need_set_time)
  148. {
  149. fprintf(stderr,
  150. "not setting time, time difference is %ld\n",
  151. - (long)server_time-now.tv_sec);
  152. + (long)server_time.tv_sec-now.tv_sec);
  153. if (atlas_id)
  154. {
  155. printf(
  156. "RESULT %s ongoing %ld httppost not in sync, local %ld, remote %ld\n",
  157. atlas_id, (long)time(NULL),
  158. (long)now.tv_sec,
  159. - (long)server_time);
  160. + (long)server_time.tv_sec);
  161. }
  162. }
  163. else if (rtt <= 1)