Skip to content

Commit

Permalink
Retry USLEEP() if EINTR
Browse files Browse the repository at this point in the history
  • Loading branch information
Fish-Git committed Aug 6, 2023
1 parent 87d04ed commit c962c5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 19 additions & 6 deletions hscutl.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,29 @@ DLL_EXPORT void list_all_symbols()
}

/* Hercules microsecond sleep */
DLL_EXPORT int herc_usleep( useconds_t usecs )
DLL_EXPORT int herc_usleep( useconds_t usecs, const char* file, int line )
{
int rc;
if ((rc = usleep( usecs )) != 0)
int rc, save_errno;

while (1
&& (rc = usleep( usecs )) != 0
&& (save_errno = errno) == EINTR
)
continue;

if (rc != 0)
{
int save_errno = errno;
char fnc[128], msg[128];

MSGBUF( fnc, "USLEEP() at %s(%d)",
TRIMLOC( file ), line);

MSGBUF( msg, "rc=%d, errno=%d: %s",
rc, save_errno, strerror( save_errno ));

// "Error in function %s: %s"
WRMSG( HHC00075, "E", "usleep()", strerror( save_errno ));
WRMSG( HHC00075, "E", fnc, msg );
errno = save_errno;
rc = -1;
}
return rc;
}
Expand Down
4 changes: 2 additions & 2 deletions hscutl.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ strlcat(char *dst, const char *src, size_t siz);
#define STRLCPY( dst, src ) strlcpy( (dst), (src), sizeof(dst) )
#define STRLCAT( dst, src ) strlcat( (dst), (src), sizeof(dst) )

#define USLEEP( _u ) herc_usleep( _u )
HUT_DLL_IMPORT int herc_usleep( useconds_t usecs );
#define USLEEP( _u ) herc_usleep( _u, __FILE__, __LINE__ )
HUT_DLL_IMPORT int herc_usleep( useconds_t usecs, const char* file, int line );

/* Subtract/add gettimeofday struct timeval */
HUT_DLL_IMPORT int timeval_subtract (struct timeval *beg_timeval, struct timeval *end_timeval, struct timeval *dif_timeval);
Expand Down

0 comments on commit c962c5d

Please sign in to comment.