mirror of
https://repo.or.cz/socat.git
synced 2024-12-22 23:42:34 +00:00
Corrected gettimeofday() handling
This commit is contained in:
parent
4cebaf45e4
commit
25cef1c540
6 changed files with 49 additions and 35 deletions
6
CHANGES
6
CHANGES
|
@ -68,7 +68,11 @@ Documentation:
|
||||||
Thanks to Emanuele Torre for reporting this issue.
|
Thanks to Emanuele Torre for reporting this issue.
|
||||||
|
|
||||||
Corrected more typos and added missing bug info to CHANGES, performed
|
Corrected more typos and added missing bug info to CHANGES, performed
|
||||||
some non functional corrections
|
some non functional corrections.
|
||||||
|
|
||||||
|
Porting:
|
||||||
|
Corrected building when clock_gettime() not available, with or without
|
||||||
|
gettimeofday().
|
||||||
|
|
||||||
####################### V 1.7.4.1:
|
####################### V 1.7.4.1:
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,9 @@
|
||||||
/* Define if you have the ftruncate64 function */
|
/* Define if you have the ftruncate64 function */
|
||||||
#undef HAVE_FTRUNCATE64
|
#undef HAVE_FTRUNCATE64
|
||||||
|
|
||||||
|
/* Define if you have the gettimeofday function */
|
||||||
|
#undef HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
|
|
||||||
/* Define if you have the clock_gettime function */
|
/* Define if you have the clock_gettime function */
|
||||||
#undef HAVE_CLOCK_GETTIME
|
#undef HAVE_CLOCK_GETTIME
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
dnl source: configure.in
|
dnl source: configure.ac
|
||||||
dnl Copyright Gerhard Rieger and contributors (see file CHANGES)
|
dnl Copyright Gerhard Rieger and contributors (see file CHANGES)
|
||||||
dnl Published under the GNU General Public License V.2, see file COPYING
|
dnl Published under the GNU General Public License V.2, see file COPYING
|
||||||
|
|
||||||
|
@ -1491,6 +1491,8 @@ AC_CHECK_LIB(bsd, openpty,
|
||||||
AC_CHECK_LIB(util, openpty,
|
AC_CHECK_LIB(util, openpty,
|
||||||
[LIBS="-lutil $LIBS"; AC_DEFINE(HAVE_OPENPTY)])
|
[LIBS="-lutil $LIBS"; AC_DEFINE(HAVE_OPENPTY)])
|
||||||
|
|
||||||
|
AC_CHECK_PROTOTYPE_LIB(gettimeofday)
|
||||||
|
|
||||||
AC_CHECK_LIB(rt, clock_gettime,
|
AC_CHECK_LIB(rt, clock_gettime,
|
||||||
[LIBS="-lrt $LIBS"; AC_DEFINE(HAVE_CLOCK_GETTIME)])
|
[LIBS="-lrt $LIBS"; AC_DEFINE(HAVE_CLOCK_GETTIME)])
|
||||||
|
|
||||||
|
|
12
error.c
12
error.c
|
@ -49,7 +49,7 @@ struct diag_opts diagopts =
|
||||||
static void msg2(
|
static void msg2(
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
struct timespec *now,
|
struct timespec *now,
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
struct timeval *now,
|
struct timeval *now,
|
||||||
#else
|
#else
|
||||||
time_t *now,
|
time_t *now,
|
||||||
|
@ -269,7 +269,7 @@ void msg(int level, const char *format, ...) {
|
||||||
diag_dgram.op = DIAG_OP_MSG;
|
diag_dgram.op = DIAG_OP_MSG;
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
clock_gettime(CLOCK_REALTIME, &diag_dgram.now);
|
clock_gettime(CLOCK_REALTIME, &diag_dgram.now);
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
gettimeofday(&diag_dgram.now, NULL);
|
gettimeofday(&diag_dgram.now, NULL);
|
||||||
#else
|
#else
|
||||||
diag_dgram.now = time(NULL);
|
diag_dgram.now = time(NULL);
|
||||||
|
@ -295,7 +295,7 @@ void msg(int level, const char *format, ...) {
|
||||||
void msg2(
|
void msg2(
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
struct timespec *now,
|
struct timespec *now,
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
struct timeval *now,
|
struct timeval *now,
|
||||||
#else
|
#else
|
||||||
time_t *now,
|
time_t *now,
|
||||||
|
@ -315,7 +315,7 @@ void msg2(
|
||||||
|
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
epoch = now->tv_sec;
|
epoch = now->tv_sec;
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
epoch = now->tv_sec;
|
epoch = now->tv_sec;
|
||||||
#else
|
#else
|
||||||
epoch = *now;
|
epoch = *now;
|
||||||
|
@ -329,7 +329,7 @@ void msg2(
|
||||||
if (diagopts.micros) {
|
if (diagopts.micros) {
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
micros = now->tv_nsec/1000;
|
micros = now->tv_nsec/1000;
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
micros = now->tv_usec;
|
micros = now->tv_usec;
|
||||||
#else
|
#else
|
||||||
micros = 0;
|
micros = 0;
|
||||||
|
@ -387,7 +387,7 @@ void diag_flush(void) {
|
||||||
/* we want the actual time, not when this dgram was sent */
|
/* we want the actual time, not when this dgram was sent */
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
clock_gettime(CLOCK_REALTIME, &recv_dgram.now);
|
clock_gettime(CLOCK_REALTIME, &recv_dgram.now);
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
gettimeofday(&recv_dgram.now, NULL);
|
gettimeofday(&recv_dgram.now, NULL);
|
||||||
#else
|
#else
|
||||||
recv_dgram.now = time(NULL);
|
recv_dgram.now = time(NULL);
|
||||||
|
|
2
error.h
2
error.h
|
@ -217,7 +217,7 @@ struct diag_dgram {
|
||||||
enum diag_op op;
|
enum diag_op op;
|
||||||
#if HAVE_CLOCK_GETTIME
|
#if HAVE_CLOCK_GETTIME
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
#elif HAVE_GETTIMEOFDAY
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
#else
|
#else
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
57
socat.c
57
socat.c
|
@ -1193,40 +1193,45 @@ int _socat(void) {
|
||||||
returns 0 on success or -1 if an error occurred */
|
returns 0 on success or -1 if an error occurred */
|
||||||
int gettimestamp(char *timestamp) {
|
int gettimestamp(char *timestamp) {
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
#if HAVE_GETTIMEOFDAY || 1
|
#if HAVE_CLOCK_GETTIME
|
||||||
|
struct timespec now;
|
||||||
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
int result;
|
#endif /* !HAVE_PROTOTYPE_LIB_gettimeofday */
|
||||||
time_t nowt;
|
time_t nowt;
|
||||||
#else /* !HAVE_GETTIMEOFDAY */
|
int result;
|
||||||
time_t now;
|
|
||||||
#endif /* !HAVE_GETTIMEOFDAY */
|
|
||||||
|
|
||||||
#if HAVE_GETTIMEOFDAY || 1
|
#if HAVE_CLOCK_GETTIME
|
||||||
result = gettimeofday(&now, NULL);
|
result = clock_gettime(CLOCK_REALTIME, &now);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
return result;
|
return result;
|
||||||
} else {
|
|
||||||
nowt = now.tv_sec;
|
|
||||||
#if HAVE_STRFTIME
|
|
||||||
bytes = strftime(timestamp, 20, "%Y/%m/%d %H:%M:%S", localtime(&nowt));
|
|
||||||
bytes += sprintf(timestamp+19, "."F_tv_usec" ", now.tv_usec);
|
|
||||||
#else
|
|
||||||
strcpy(timestamp, ctime(&nowt));
|
|
||||||
bytes = strlen(timestamp);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#else /* !HAVE_GETTIMEOFDAY */
|
nowt = now.tv_sec;
|
||||||
now = time(NULL); if (now == (time_t)-1) {
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
|
result = Gettimeofday(&now, NULL);
|
||||||
|
if (result < 0) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
nowt = now.tv_sec;
|
||||||
|
#else
|
||||||
|
nowt = time(NULL);
|
||||||
|
if (nowt == (time_t)-1) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
|
||||||
#if HAVE_STRFTIME
|
|
||||||
bytes = strftime(timestamp, 21, "%Y/%m/%d %H:%M:%S ", localtime(&now));
|
|
||||||
#else
|
|
||||||
strcpy(timestamp, ctime(&now));
|
|
||||||
bytes = strlen(timestamp);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif /* !HAVE_GETTIMEOFDAY */
|
#endif
|
||||||
|
#if HAVE_STRFTIME
|
||||||
|
bytes = strftime(timestamp, 20, "%Y/%m/%d %H:%M:%S", localtime(&nowt));
|
||||||
|
#if HAVE_CLOCK_GETTIME
|
||||||
|
bytes += sprintf(timestamp+19, "."F_tv_usec" ", now.tv_nsec/1000);
|
||||||
|
#elif HAVE_PROTOTYPE_LIB_gettimeofday
|
||||||
|
bytes += sprintf(timestamp+19, "."F_tv_usec" ", now.tv_usec);
|
||||||
|
#else
|
||||||
|
strncpy(×tamp[bytes++], " ", 2);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
strcpy(timestamp, ctime(&nowt));
|
||||||
|
bytes = strlen(timestamp);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue