From: Hannes Reinecke Date: Tue, 3 May 2011 08:29:28 +0000 (+0200) Subject: Move setup_thread_attr() to uevent.c X-Git-Tag: upstream/0.5.0~106^2~74 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54496a355dde75fbd1069a8fc0fe274b4a68a079;p=platform%2Fupstream%2Fmultipath-tools.git 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 --- 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 #include #include +#include #include #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) {