tag 40220 + notabug close 40220 thanks shy wrote: > I use command date -s "1970-01-20 00:00:00" to set date, but it > failed. there is error message "date: can't set date: Invalid > argument". > It's UTC time and no timezone.
This is most likely a limitation of your kernel. I can recreate this problem on a Linux 4.9 system for example. TZ=UTC strace -o /tmp/out -v date -s "1970-01-01 00:00:00" ... clock_settime(CLOCK_REALTIME, {tv_sec=0, tv_nsec=0}) = -1 EINVAL (Invalid argument) settimeofday({tv_sec=0, tv_usec=0}, NULL) = -1 EINVAL (Invalid argument) ... And the documented possible returns of EINVAL for clock_settime(). EINVAL The clk_id specified is not supported on this system. EINVAL (clock_settime()): tp.tv_sec is negative or tp.tv_nsec is outside the range [0..999,999,999]. EINVAL (since Linux 4.3) A call to clock_settime() with a clk_id of CLOCK_REALTIME attempted to set the time to a value less than the current value of the CLOCK_MONOTONIC clock. And for settimeofday(). EINVAL (settimeofday()): timezone is invalid. EINVAL (settimeofday()): tv.tv_sec is negative or tv.tv_usec is outside the range [0..999,999]. EINVAL (since Linux 4.3) (settimeofday()): An attempt was made to set the time to a value less than the current value of the CLOCK_MONOTONIC clock (see clock_gettime(2)). EPERM The calling process has insufficient privilege to call settimeofday(); under Linux the CAP_SYS_TIME capability is required. But this is not a bug in GNU date. This is likely the effect of CLOCK_MONOTONIC in the Linux kernel. CLOCK_MONOTONIC Clock that cannot be set and represents monotonic time since--as described by POSIX--"some unspecified point in the past". On Linux, that point corresponds to the number of seconds that the system has been running since it was booted. The CLOCK_MONOTONIC clock is not affected by discontinuous jumps in the system time (e.g., if the system administrator manually changes the clock), but is affected by the incremental adjustments performed by adjtime(3) and NTP. This clock does not count time that the system is suspended. I am not familiar with CLOCK_MONOTONIC but reading the documentation points me to it as being the most likely reason this is not allowing that time to be set. I tested this in a victim system and if I was very quick I was able to log in and set the time to :10 seconds but no earlier. > I test with stime or settimeofday to set seconds 0, they are all have the > problem. > 1. I use buildroot-2013.05, the busybox is in 1.21.1, the linux kernel is in > version 4.4.39. That multiple frontends, GNU date and busybox date, all have the same problem speaks that the problem is not with the frontend but with the kernel handling the system call. > 3.When set date command, the busybox uses function "stime" to set > time, I use stime to set time around linux epoch time, > but the stime seems not work well. > int ret = 0; > time_t time = 20; > ret = stime(&time); > printf("ret %d %d\r\n",ret, errno); > perror("stime:"); > and the results are as follows: > ret -1 22 > stime:: Invalid argument And also confirmed by your independent test the the problem is not a bug in GNU date. Therefore I mark this GNU date bug ticket as closed for our own accounting. But please continue to discuss the issue here. Bob