Move setup_thread_attr() to uevent.c
authorHannes Reinecke <hare@suse.de>
Tue, 3 May 2011 08:29:28 +0000 (10:29 +0200)
committerHannes Reinecke <hare@suse.de>
Tue, 3 May 2011 08:29:28 +0000 (10:29 +0200)
The function will be used by other instances, too, so move it
over to the library.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/uevent.c
libmultipath/uevent.h
multipathd/main.c

index d8f3647..0d68390 100644 (file)
@@ -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);
 
        /*
index e1a1254..0941810 100644 (file)
@@ -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 */
index 229ab0b..769abb2 100644 (file)
@@ -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)
 {