Navigation Menu

Skip to content

Commit

Permalink
Handle timeout values that are valid on Linux but valid on Mac
Browse files Browse the repository at this point in the history
Fixes emacs #711
  • Loading branch information
tbodt committed May 9, 2020
1 parent 2b2fc7a commit 6075b01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kernel/poll.c
Expand Up @@ -53,6 +53,8 @@ dword_t sys_select(fd_t nfds, addr_t readfds_addr, addr_t writefds_addr, addr_t
timeout_ts.tv_sec = timeout_timeval.sec;
timeout_ts.tv_nsec = timeout_timeval.usec * 1000;
}
// Emacs likes to pass invalid timeout values
timeout_ts = timespec_normalize(timeout_ts);

STRACE("select(%d, 0x%x, 0x%x, 0x%x, 0x%x {%lds %ldns}) ",
nfds, readfds_addr, writefds_addr, exceptfds_addr,
Expand Down
6 changes: 6 additions & 0 deletions util/timer.h
Expand Up @@ -43,6 +43,12 @@ static inline bool timespec_positive(struct timespec ts) {
return ts.tv_sec > 0 || (ts.tv_sec == 0 && ts.tv_nsec > 0);
}

static inline struct timespec timespec_normalize(struct timespec ts) {
ts.tv_sec += ts.tv_nsec / 1000000000;
ts.tv_nsec %= 1000000000;
return ts;
}

typedef void (*timer_callback_t)(void *data);
struct timer {
clockid_t clockid;
Expand Down

0 comments on commit 6075b01

Please sign in to comment.