diff --git a/alpine/packages/transfused/transfused.c b/alpine/packages/transfused/transfused.c index 2445fdce0..8f56cbf80 100644 --- a/alpine/packages/transfused/transfused.c +++ b/alpine/packages/transfused/transfused.c @@ -53,6 +53,8 @@ char * usage = int debug = 0; +pthread_attr_t detached; + typedef struct { char * descr; long connection; @@ -343,14 +345,10 @@ void start_reader(connection_t * connection, int fuse) { copy_state->tag = "read"; copy_state->from = read_fd; copy_state->to = fuse; - if ((errno = pthread_create(&child, NULL, + if ((errno = pthread_create(&child, &detached, copy_clean_from_thread, copy_state))) die(1, "", "couldn't create read copy thread for connection %ld: ", connection->id); - - if ((errno = pthread_detach(child))) - die(1, "", "couldn't detach read copy thread for connection %ld: ", - connection->id); } void start_writer(connection_t * connection, int fuse) { @@ -374,14 +372,10 @@ void start_writer(connection_t * connection, int fuse) { copy_state->tag = "write"; copy_state->from = fuse; copy_state->to = write_fd; - if ((errno = pthread_create(&child, NULL, + if ((errno = pthread_create(&child, &detached, copy_clean_to_thread, copy_state))) die(1, "", "Couldn't create write copy thread for connection %ld: ", connection->id); - - if ((errno = pthread_detach(child))) - die(1, "", "couldn't detach write copy thread for connection %ld: ", - connection->id); } void * mount_connection(connection_t * conn) { @@ -783,15 +777,11 @@ void process_events(char * events_path, int events, parameters * params) { die(1, NULL, "Unknown connection type '%c'", buf[0]); } - if ((errno = pthread_create(&child, NULL, + if ((errno = pthread_create(&child, &detached, connection_handler_thread, conn))) die(1, "", "Couldn't create thread for %s connection '%ld': ", conn->type_descr, conn_id); - if ((errno = pthread_detach(child))) - die(1, "", "Couldn't detach thread for %s connection '%ld': ", - conn->type_descr, conn_id); - if (debug) log_time(conn, "thread spawned\n"); } } @@ -812,6 +802,10 @@ int main(int argc, char * argv[]) { parse_parameters(argc, argv, ¶ms); setup_debug(); + if ((errno = pthread_attr_setdetachstate(&detached, + PTHREAD_CREATE_DETACHED))) + die(1, "Couldn't set pthread detach state", ""); + if (params.pidfile != NULL) write_pidfile(params.pidfile); if (params.logfile != NULL) { diff --git a/alpine/packages/transfused/transfused.h b/alpine/packages/transfused/transfused.h index ed41fe416..7e4ce149a 100644 --- a/alpine/packages/transfused/transfused.h +++ b/alpine/packages/transfused/transfused.h @@ -18,6 +18,8 @@ typedef struct { char * type_descr; } connection_t; +pthread_attr_t detached; + void * must_malloc(char *const descr, size_t size); void lock(char *const descr, pthread_mutex_t * mutex); diff --git a/alpine/packages/transfused/transfused_log.c b/alpine/packages/transfused/transfused_log.c index 2746453c5..b4fd272ae 100644 --- a/alpine/packages/transfused/transfused_log.c +++ b/alpine/packages/transfused/transfused_log.c @@ -128,14 +128,9 @@ void thread_log_time(connection_t * conn, const char * fmt, ...) { // far from ideal but fine for now as we anticipate thread-sensitive // log demand to be low. - if ((errno = pthread_create(&logger, NULL, log_time_thread, log_state))) + if ((errno = pthread_create(&logger, &detached, log_time_thread, log_state))) die(1, "", "Couldn't create log thread for %s connection '%ld': ", conn->type_descr, conn->id); - - if ((errno = pthread_detach(logger))) - die(1, "", "Couldn't detach thread for %s connection '%ld': ", - conn->type_descr, conn->id); - } void log_continue_locked(connection_t * connection, const char * fmt, ...) {