|
@@ -33,6 +33,12 @@
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
#include <sys/stat.h>
|
|
|
#endif
|
|
|
+#ifdef HAVE_UTIME_H
|
|
|
+#include <utime.h>
|
|
|
+#endif
|
|
|
+#ifdef HAVE_SYS_UTIME_H
|
|
|
+#include <sys/utime.h>
|
|
|
+#endif
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
#include <unistd.h>
|
|
|
#endif
|
|
@@ -89,12 +95,6 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
|
|
|
#include "tor_readpassphrase.h"
|
|
|
#endif
|
|
|
|
|
|
-#ifndef HAVE_GETTIMEOFDAY
|
|
|
-#ifdef HAVE_FTIME
|
|
|
-#include <sys/timeb.h>
|
|
|
-#endif
|
|
|
-#endif
|
|
|
-
|
|
|
/* Includes for the process attaching prevention */
|
|
|
#if defined(HAVE_SYS_PRCTL_H) && defined(__linux__)
|
|
|
/* Only use the linux prctl; the IRIX prctl is totally different */
|
|
@@ -116,12 +116,6 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
#include <signal.h>
|
|
|
#endif
|
|
|
-#ifdef HAVE_UTIME_H
|
|
|
-#include <utime.h>
|
|
|
-#endif
|
|
|
-#ifdef HAVE_SYS_UTIME_H
|
|
|
-#include <sys/utime.h>
|
|
|
-#endif
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
#include <sys/mman.h>
|
|
|
#endif
|
|
@@ -131,12 +125,6 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
|
|
|
#ifdef HAVE_SYS_FILE_H
|
|
|
#include <sys/file.h>
|
|
|
#endif
|
|
|
-#ifdef TOR_UNIT_TESTS
|
|
|
-#if !defined(HAVE_USLEEP) && defined(HAVE_SYS_SELECT_H)
|
|
|
-/* as fallback implementation for tor_sleep_msec */
|
|
|
-#include <sys/select.h>
|
|
|
-#endif
|
|
|
-#endif
|
|
|
|
|
|
#include "torlog.h"
|
|
|
#include "util.h"
|
|
@@ -2836,53 +2824,6 @@ compute_num_cpus(void)
|
|
|
return num_cpus;
|
|
|
}
|
|
|
|
|
|
-/** Set *timeval to the current time of day. On error, log and terminate.
|
|
|
- * (Same as gettimeofday(timeval,NULL), but never returns -1.)
|
|
|
- */
|
|
|
-void
|
|
|
-tor_gettimeofday(struct timeval *timeval)
|
|
|
-{
|
|
|
-#ifdef _WIN32
|
|
|
- /* Epoch bias copied from perl: number of units between windows epoch and
|
|
|
- * Unix epoch. */
|
|
|
-#define EPOCH_BIAS U64_LITERAL(116444736000000000)
|
|
|
-#define UNITS_PER_SEC U64_LITERAL(10000000)
|
|
|
-#define USEC_PER_SEC U64_LITERAL(1000000)
|
|
|
-#define UNITS_PER_USEC U64_LITERAL(10)
|
|
|
- union {
|
|
|
- uint64_t ft_64;
|
|
|
- FILETIME ft_ft;
|
|
|
- } ft;
|
|
|
- /* number of 100-nsec units since Jan 1, 1601 */
|
|
|
- GetSystemTimeAsFileTime(&ft.ft_ft);
|
|
|
- if (ft.ft_64 < EPOCH_BIAS) {
|
|
|
- /* LCOV_EXCL_START */
|
|
|
- log_err(LD_GENERAL,"System time is before 1970; failing.");
|
|
|
- exit(1);
|
|
|
- /* LCOV_EXCL_STOP */
|
|
|
- }
|
|
|
- ft.ft_64 -= EPOCH_BIAS;
|
|
|
- timeval->tv_sec = (unsigned) (ft.ft_64 / UNITS_PER_SEC);
|
|
|
- timeval->tv_usec = (unsigned) ((ft.ft_64 / UNITS_PER_USEC) % USEC_PER_SEC);
|
|
|
-#elif defined(HAVE_GETTIMEOFDAY)
|
|
|
- if (gettimeofday(timeval, NULL)) {
|
|
|
- /* LCOV_EXCL_START */
|
|
|
- log_err(LD_GENERAL,"gettimeofday failed.");
|
|
|
- /* If gettimeofday dies, we have either given a bad timezone (we didn't),
|
|
|
- or segfaulted.*/
|
|
|
- exit(1);
|
|
|
- /* LCOV_EXCL_STOP */
|
|
|
- }
|
|
|
-#elif defined(HAVE_FTIME)
|
|
|
- struct timeb tb;
|
|
|
- ftime(&tb);
|
|
|
- timeval->tv_sec = tb.time;
|
|
|
- timeval->tv_usec = tb.millitm * 1000;
|
|
|
-#else
|
|
|
-#error "No way to get time."
|
|
|
-#endif
|
|
|
- return;
|
|
|
-}
|
|
|
|
|
|
#if !defined(_WIN32)
|
|
|
/** Defined iff we need to add locks when defining fake versions of reentrant
|
|
@@ -3441,26 +3382,6 @@ get_total_system_memory(size_t *mem_out)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-#ifdef TOR_UNIT_TESTS
|
|
|
-/** Delay for <b>msec</b> milliseconds. Only used in tests. */
|
|
|
-void
|
|
|
-tor_sleep_msec(int msec)
|
|
|
-{
|
|
|
-#ifdef _WIN32
|
|
|
- Sleep(msec);
|
|
|
-#elif defined(HAVE_USLEEP)
|
|
|
- sleep(msec / 1000);
|
|
|
- /* Some usleep()s hate sleeping more than 1 sec */
|
|
|
- usleep((msec % 1000) * 1000);
|
|
|
-#elif defined(HAVE_SYS_SELECT_H)
|
|
|
- struct timeval tv = { msec / 1000, (msec % 1000) * 1000};
|
|
|
- select(0, NULL, NULL, NULL, &tv);
|
|
|
-#else
|
|
|
- sleep(CEIL_DIV(msec, 1000));
|
|
|
-#endif
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
/** Emit the password prompt <b>prompt</b>, then read up to <b>buflen</b>
|
|
|
* bytes of passphrase into <b>output</b>. Return the number of bytes in
|
|
|
* the passphrase, excluding terminating NUL.
|