- tmx.modes = ADJ_SETOFFSET;
- d_to_tv(offset, &tmx.time);
+ tmx.modes = ADJ_SETOFFSET | ADJ_NANO;
+
+ /* ADJ_NANO uses nanoseconds in the microseconds field */
+ tmx.time.tv_sec = (long)offset;
+ tmx.time.tv_usec = (offset - tmx.time.tv_sec) * NSEC_PER_SEC;
+
+ /* the kernel expects -0.3s as {-1, 7000.000.000} */
+ if (tmx.time.tv_usec < 0) {
+ tmx.time.tv_usec -= 1;
+ tmx.time.tv_usec += NSEC_PER_SEC;
+ }