Skip to content

Commit

Permalink
parallel: Don't access the global handle from multiple threads.
Browse files Browse the repository at this point in the history
libguestfs handles are not thread safe, and it's not safe even to read
settings from the handle from multiple threads (eg. guestfs_get_trace).
Stop doing this in the parallel library.  This caused fairly
reproducible segfaults when you enabled '-x' and/or '-v'.

This fixes commit 34e77af.
  • Loading branch information
rwmjones committed Feb 28, 2013
1 parent ce7cffa commit 93feaa4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions df/parallel.c
Expand Up @@ -72,23 +72,27 @@ static void thread_failure (const char *fn, int err) __attribute__((noreturn));
static void *worker_thread (void *arg);

struct thread_data {
guestfs_h *options_handle;
int trace, verbose; /* Flags from the options_handle. */
work_fn work;
};

/* Start threads. */
void
start_threads (size_t option_P, guestfs_h *options_handle, work_fn work)
{
struct thread_data thread_data = { .options_handle = options_handle,
.work = work };
struct thread_data thread_data = { .trace = 0, .verbose = 0, .work = work };
size_t i, nr_threads;
int err;
void *status;

if (nr_domains == 0) /* Nothing to do. */
return;

if (options_handle) {
thread_data.trace = guestfs_get_trace (options_handle);
thread_data.verbose = guestfs_get_verbose (options_handle);
}

/* If the user selected the -P option, then we use up to that many threads. */
if (option_P > 0)
nr_threads = MIN (nr_domains, option_P);
Expand Down Expand Up @@ -153,11 +157,8 @@ worker_thread (void *thread_data_vp)
}

/* Copy some settings from the options guestfs handle. */
if (thread_data->options_handle) {
guestfs_set_trace (g, guestfs_get_trace (thread_data->options_handle));
guestfs_set_verbose (g,
guestfs_get_verbose (thread_data->options_handle));
}
guestfs_set_trace (g, thread_data->trace);
guestfs_set_verbose (g, thread_data->verbose);

/* Do work. */
thread_data->work (g, i, fp);
Expand Down

0 comments on commit 93feaa4

Please sign in to comment.