Skip to content

Commit

Permalink
Merge branch 'maint-0.4.2' into release-0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Oct 20, 2019
2 parents d7c3537 + 5dbdca0 commit bcf29f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changes/bug31837
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
o Minor bugfixes (testing):
- When testing port rebinding, don't busy-wait for tor to log. Instead,
actually sleep for a short time before polling again. Also improve the
formatting of control commands and log messages.
Fixes bug 31837; bugfix on 0.3.5.1-alpha.
12 changes: 6 additions & 6 deletions src/lib/err/backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static pthread_mutex_t cb_buf_mutex = PTHREAD_MUTEX_INITIALIZER;

/** Lock and return a static stack pointer buffer that can hold up to
* MAX_DEPTH function pointers. */
static void *
static void **
lock_cb_buf(void)
{
/* Lock the mutex first, before even declaring the buffer. */
Expand All @@ -102,7 +102,7 @@ lock_cb_buf(void)

/** Unlock the static stack pointer buffer. */
static void
unlock_cb_buf(void *cb_buf)
unlock_cb_buf(void **cb_buf)
{
memset(cb_buf, 0, SIZEOF_CB_BUF);
pthread_mutex_unlock(&cb_buf_mutex);
Expand Down Expand Up @@ -149,7 +149,7 @@ log_backtrace_impl(int severity, log_domain_mask_t domain, const char *msg,
char **symbols;
size_t i;

void *cb_buf = lock_cb_buf();
void **cb_buf = lock_cb_buf();

depth = backtrace(cb_buf, MAX_DEPTH);
symbols = backtrace_symbols(cb_buf, (int)depth);
Expand Down Expand Up @@ -183,7 +183,7 @@ crash_handler(int sig, siginfo_t *si, void *ctx_)
int n_fds, i;
const int *fds = NULL;

void *cb_buf = lock_cb_buf();
void **cb_buf = lock_cb_buf();

(void) si;

Expand Down Expand Up @@ -214,7 +214,7 @@ dump_stack_symbols_to_error_fds(void)
const int *fds = NULL;
size_t depth;

void *cb_buf = lock_cb_buf();
void **cb_buf = lock_cb_buf();

depth = backtrace(cb_buf, MAX_DEPTH);

Expand Down Expand Up @@ -256,7 +256,7 @@ install_bt_handler(void)
* libc has pre-loaded the symbols we need to dump things, so that later
* reads won't be denied by the sandbox code */
char **symbols;
void *cb_buf = lock_cb_buf();
void **cb_buf = lock_cb_buf();
size_t depth = backtrace(cb_buf, MAX_DEPTH);
symbols = backtrace_symbols(cb_buf, (int) depth);
if (symbols)
Expand Down
16 changes: 9 additions & 7 deletions src/test/test_rebind.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ def wait_for_log(s):
cutoff = time.time() + LOG_TIMEOUT
while time.time() < cutoff:
l = tor_process.stdout.readline()
l = l.decode('utf8')
l = l.decode('utf8', 'backslashreplace')
if s in l:
logging.info('Tor logged: "{}"'.format(l.strip()))
return
logging.info('Tor logged: "{}", waiting for "{}"'.format(l.strip(), s))
# readline() returns a blank string when there is no output
# avoid busy-waiting
if len(s) == 0:
if len(l) == 0:
logging.debug('Tor has not logged anything, waiting for "{}"'.format(s))
time.sleep(LOG_WAIT)
else:
logging.info('Tor logged: "{}", waiting for "{}"'.format(l.strip(), s))
fail('Could not find "{}" in logs after {} seconds'.format(s, LOG_TIMEOUT))

def pick_random_port():
Expand Down Expand Up @@ -120,18 +122,18 @@ def pick_random_port():
tor_process.terminate()
fail('Cannot connect to ControlPort')

control_socket.sendall('AUTHENTICATE \r\n'.encode('utf8'))
control_socket.sendall('SETCONF SOCKSPort=0.0.0.0:{}\r\n'.format(socks_port).encode('utf8'))
control_socket.sendall('AUTHENTICATE \r\n'.encode('ascii'))
control_socket.sendall('SETCONF SOCKSPort=0.0.0.0:{}\r\n'.format(socks_port).encode('ascii'))
wait_for_log('Opened Socks listener')

try_connecting_to_socksport()

control_socket.sendall('SETCONF SOCKSPort=127.0.0.1:{}\r\n'.format(socks_port).encode('utf8'))
control_socket.sendall('SETCONF SOCKSPort=127.0.0.1:{}\r\n'.format(socks_port).encode('ascii'))
wait_for_log('Opened Socks listener')

try_connecting_to_socksport()

control_socket.sendall('SIGNAL HALT\r\n'.encode('utf8'))
control_socket.sendall('SIGNAL HALT\r\n'.encode('ascii'))

wait_for_log('exiting cleanly')
logging.info('OK')
Expand Down

0 comments on commit bcf29f4

Please sign in to comment.