From: Ladislav Michl <la...@linux-mips.org>

Coreutils date behaves this way since 1998-12-11 as done in their git commit
a17cdb11731e ("(main): Arrange to exit unsuccessfully when stime fails.")

Signed-off-by: Ladislav Michl <la...@linux-mips.org>
---
 CHANGES:
 -v2: better compatibily with coreutils, add explaining commit message

 coreutils/date.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/coreutils/date.c b/coreutils/date.c
index 3a89b6caf..09d5697dc 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -166,12 +166,13 @@ int date_main(int argc UNUSED_PARAM, char **argv)
        struct tm tm_time;
        char buf_fmt_dt2str[64];
        unsigned opt;
-       int isofmt = -1;
        char *date_str;
        char *fmt_dt2str;
        char *fmt_str2dt;
        char *filename;
        char *isofmt_arg = NULL;
+       int ret = EXIT_SUCCESS;
+       int isofmt = -1;
 
        opt = getopt32long(argv, "^"
                        "Rs:ud:r:"
@@ -287,9 +288,12 @@ int date_main(int argc UNUSED_PARAM, char **argv)
                ts.tv_sec = validate_tm_time(date_str, &tm_time);
                ts.tv_nsec = 0;
 
-               /* if setting time, set it */
+               /* if setting time, set the system clock to the specified date,
+                * then regardless of the success of that operation,
+                * format and print that date. */
                if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {
                        bb_simple_perror_msg("can't set date");
+                       ret = EXIT_FAILURE;
                }
        }
 
@@ -383,5 +387,5 @@ int date_main(int argc UNUSED_PARAM, char **argv)
        }
        puts(date_buf);
 
-       return EXIT_SUCCESS;
+       return ret;
 }
-- 
2.39.2

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to