#include <signal.h>
#include <sys/timex.h>
-#ifndef UTIME_NOW
-#define UTIME_NOW ((1l << 30) - 1l)
-#endif
-#ifndef UTIME_OMIT
-#define UTIME_OMIT ((1l << 30) - 2l)
-#endif
-
-#if SUPPORTED_PERSONALITIES > 1
-# if defined X86_64 || defined X32
-# define current_time_t_is_compat (current_personality == 1)
-# else
-# define current_time_t_is_compat (current_wordsize == 4)
-# endif
-#else
-# define current_time_t_is_compat 0
-#endif
-
-struct timeval32
-{
- u_int32_t tv_sec, tv_usec;
-};
-
-void
-printtv_bitness(struct tcb *tcp, long addr, enum bitness_t bitness, int special)
-{
- char buf[TIMEVAL_TEXT_BUFSIZE];
- sprinttv(buf, tcp, addr, bitness, special);
- tprints(buf);
-}
-
-static char *
-do_sprinttv(char *buf, const uintmax_t sec, const uintmax_t usec,
- const int special)
-{
- if (special) {
- switch (usec) {
- case UTIME_NOW:
- return stpcpy(buf, "UTIME_NOW");
- case UTIME_OMIT:
- return stpcpy(buf, "UTIME_OMIT");
- }
- }
- return buf + sprintf(buf, "{%ju, %ju}", sec, usec);
-}
-
-char *
-sprinttv(char *buf, struct tcb *tcp, long addr, enum bitness_t bitness, int special)
+static void
+print_timezone(struct tcb *tcp, const long addr)
{
- if (addr == 0)
- return stpcpy(buf, "NULL");
-
- if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
- return buf + sprintf(buf, "%#lx", addr);
+ struct timezone tz;
- if (bitness == BITNESS_32 || current_time_t_is_compat)
- {
- struct timeval32 tv;
+ if (umove_or_printaddr(tcp, addr, &tz))
+ return;
- if (umove(tcp, addr, &tv) >= 0)
- return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
- } else {
- struct timeval tv;
-
- if (umove(tcp, addr, &tv) >= 0)
- return do_sprinttv(buf, tv.tv_sec, tv.tv_usec, special);
- }
-
- return buf + sprintf(buf, "%#lx", addr);
-}
-
-void
-print_timespec(struct tcb *tcp, long addr)
-{
- char buf[TIMESPEC_TEXT_BUFSIZE];
- sprint_timespec(buf, tcp, addr);
- tprints(buf);
-}
-
-void
-sprint_timespec(char *buf, struct tcb *tcp, long addr)
-{
- if (addr == 0)
- strcpy(buf, "NULL");
- else if (!verbose(tcp))
- sprintf(buf, "%#lx", addr);
- else {
- int rc;
-
-#if SUPPORTED_PERSONALITIES > 1
- if (current_time_t_is_compat) {
- struct timeval32 tv;
-
- rc = umove(tcp, addr, &tv);
- if (rc >= 0)
- sprintf(buf, "{%u, %u}",
- tv.tv_sec, tv.tv_usec);
- } else
-#endif
- {
- struct timespec ts;
-
- rc = umove(tcp, addr, &ts);
- if (rc >= 0)
- sprintf(buf, "{%ju, %ju}",
- (uintmax_t) ts.tv_sec,
- (uintmax_t) ts.tv_nsec);
- }
- if (rc < 0)
- strcpy(buf, "{...}");
- }
+ tprintf("{tz_minuteswest=%d, tz_dsttime=%d}",
+ tz.tz_minuteswest, tz.tz_dsttime);
}
SYS_FUNC(gettimeofday)
{
if (exiting(tcp)) {
- printtv(tcp, tcp->u_arg[0]);
+ print_timeval(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timezone(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(osf_gettimeofday)
{
if (exiting(tcp)) {
- printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
+ print_timeval32(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
+ print_timezone(tcp, tcp->u_arg[1]);
}
return 0;
}
SYS_FUNC(settimeofday)
{
- printtv(tcp, tcp->u_arg[0]);
+ print_timeval(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timezone(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
#ifdef ALPHA
SYS_FUNC(osf_settimeofday)
{
- printtv_bitness(tcp, tcp->u_arg[0], BITNESS_32, 0);
+ print_timeval32(tcp, tcp->u_arg[0]);
tprints(", ");
- printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
+ print_timezone(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
#endif
-SYS_FUNC(adjtime)
-{
- if (entering(tcp)) {
- printtv(tcp, tcp->u_arg[0]);
- tprints(", ");
- } else {
- printtv(tcp, tcp->u_arg[1]);
- }
- return 0;
-}
-
SYS_FUNC(nanosleep)
{
if (entering(tcp)) {
print_timespec(tcp, tcp->u_arg[0]);
tprints(", ");
} else {
- /* Second (returned) timespec is only significant
- * if syscall was interrupted. On success, we print
- * only its address, since kernel doesn't modify it,
+
+ /*
+ * Second (returned) timespec is only significant if syscall
+ * was interrupted. On success and in case of other errors we
+ * print only its address, since kernel doesn't modify it,
* and printing the value may show uninitialized data.
*/
- switch (tcp->u_error) {
- default:
- /* Not interrupted (slept entire interval) */
- printaddr(tcp->u_arg[1]);
- break;
- case ERESTARTSYS:
- case ERESTARTNOINTR:
- case ERESTARTNOHAND:
- case ERESTART_RESTARTBLOCK:
- /* Interrupted */
+ if (is_erestart(tcp)) {
+ temporarily_clear_syserror(tcp);
print_timespec(tcp, tcp->u_arg[1]);
+ restore_cleared_syserror(tcp);
+ } else {
+ printaddr(tcp->u_arg[1]);
}
}
return 0;
{
printclockname(tcp->u_arg[0]);
tprints(", ");
- printtv(tcp, tcp->u_arg[1]);
+ print_timespec(tcp, tcp->u_arg[1]);
return RVAL_DECODED;
}
printclockname(tcp->u_arg[0]);
tprints(", ");
} else {
- printtv(tcp, tcp->u_arg[1]);
+ print_timespec(tcp, tcp->u_arg[1]);
}
return 0;
}
tprints(", ");
printflags(clockflags, tcp->u_arg[1], "TIMER_???");
tprints(", ");
- printtv(tcp, tcp->u_arg[2]);
+ print_timespec(tcp, tcp->u_arg[2]);
tprints(", ");
} else {
- printtv(tcp, tcp->u_arg[3]);
+ /*
+ * Second (returned) timespec is only significant
+ * if syscall was interrupted and flags is not TIMER_ABSTIME.
+ */
+ if (!tcp->u_arg[1] && is_erestart(tcp)) {
+ temporarily_clear_syserror(tcp);
+ print_timespec(tcp, tcp->u_arg[3]);
+ restore_cleared_syserror(tcp);
+ } else {
+ printaddr(tcp->u_arg[3]);
+ }
}
return 0;
}