diff options
author | Hannes Reinecke <hare@suse.de> | 2011-05-03 10:29:28 +0200 |
---|---|---|
committer | Hannes Reinecke <hare@suse.de> | 2011-05-03 10:29:28 +0200 |
commit | 54496a355dde75fbd1069a8fc0fe274b4a68a079 (patch) | |
tree | 2d85bb1c9b36b28aa20a941be5b0f06f8d6fe40f | |
parent | 34825c7a9ef60b97277834c3fda75f65eefe2fbb (diff) | |
download | multipath-tools-54496a355dde75fbd1069a8fc0fe274b4a68a079.tar.gz |
Move setup_thread_attr() to uevent.c
The function will be used by other instances, too, so move it
over to the library.
Signed-off-by: Hannes Reinecke <hare@suse.de>
-rw-r--r-- | libmultipath/uevent.c | 28 | ||||
-rw-r--r-- | libmultipath/uevent.h | 11 | ||||
-rw-r--r-- | multipathd/main.c | 24 |
3 files changed, 36 insertions, 27 deletions
diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c index d8f3647..0d68390 100644 --- a/libmultipath/uevent.c +++ b/libmultipath/uevent.c @@ -37,6 +37,7 @@ #include <linux/types.h> #include <linux/netlink.h> #include <pthread.h> +#include <limits.h> #include <sys/mman.h> #include "memory.h" @@ -59,6 +60,30 @@ int is_uevent_busy(void) return (uevqhp != NULL || servicing_uev); } +void +setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached) +{ + if (pthread_attr_init(attr)) { + fprintf(stderr, "can't initialize thread attr: %s\n", + strerror(errno)); + exit(1); + } + if (stacksize < PTHREAD_STACK_MIN) + stacksize = PTHREAD_STACK_MIN; + + if (pthread_attr_setstacksize(attr, stacksize)) { + fprintf(stderr, "can't set thread stack size to %lu: %s\n", + (unsigned long)stacksize, strerror(errno)); + exit(1); + } + if (detached && pthread_attr_setdetachstate(attr, + PTHREAD_CREATE_DETACHED)) { + fprintf(stderr, "can't set thread to detached: %s\n", + strerror(errno)); + exit(1); + } +} + static struct uevent * alloc_uevent (void) { return (struct uevent *)MALLOC(sizeof(struct uevent)); @@ -142,8 +167,7 @@ int uevent_listen(int (*uev_trigger)(struct uevent *, void * trigger_data), pthread_mutex_init(uevc_lockp, NULL); pthread_cond_init(uev_condp, NULL); - pthread_attr_init(&attr); - pthread_attr_setstacksize(&attr, 64 * 1024); + setup_thread_attr(&attr, 64 * 1024, 0); pthread_create(&uevq_thr, &attr, uevq_thread, NULL); /* diff --git a/libmultipath/uevent.h b/libmultipath/uevent.h index e1a1254..0941810 100644 --- a/libmultipath/uevent.h +++ b/libmultipath/uevent.h @@ -1,4 +1,10 @@ -/* environment buffer, the kernel's size in lib/kobject_uevent.c should fit in */ +#ifndef _UEVENT_H +#define _UEVENT_H + +/* + * buffer for environment variables, the kernel's size in + * lib/kobject_uevent.c should fit in +*/ #define HOTPLUG_BUFFER_SIZE 1024 #define HOTPLUG_NUM_ENVP 32 #define OBJECT_SIZE 512 @@ -18,3 +24,6 @@ struct uevent { int uevent_listen(int (*store_uev)(struct uevent *, void * trigger_data), void * trigger_data); int is_uevent_busy(void); +void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached); + +#endif /* _UEVENT_H */ diff --git a/multipathd/main.c b/multipathd/main.c index 229ab0b..769abb2 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1358,30 +1358,6 @@ set_oom_adj (int val) fclose(fp); } -void -setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached) -{ - if (pthread_attr_init(attr)) { - fprintf(stderr, "can't initialize thread attr: %s\n", - strerror(errno)); - exit(1); - } - if (stacksize < PTHREAD_STACK_MIN) - stacksize = PTHREAD_STACK_MIN; - - if (pthread_attr_setstacksize(attr, stacksize)) { - fprintf(stderr, "can't set thread stack size to %lu: %s\n", - (unsigned long)stacksize, strerror(errno)); - exit(1); - } - if (detached && pthread_attr_setdetachstate(attr, - PTHREAD_CREATE_DETACHED)) { - fprintf(stderr, "can't set thread to detached: %s\n", - strerror(errno)); - exit(1); - } -} - static int child (void * param) { |