libmultipath: Move setup_thread_attr() from uevent.c into util.c
authorBart Van Assche <bart.vanassche@sandisk.com>
Fri, 21 Oct 2016 18:42:42 +0000 (11:42 -0700)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Thu, 3 Nov 2016 13:33:19 +0000 (14:33 +0100)
The setup_thread_attr() is not called by any code in source file
uevent.c. Hence move that function to source file util.c.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
libmultipath/checkers/rbd.c
libmultipath/checkers/tur.c
libmultipath/uevent.c
libmultipath/uevent.h
libmultipath/util.c
libmultipath/util.h

index c920cbb..f60914e 100644 (file)
@@ -26,7 +26,7 @@
 #include "checkers.h"
 
 #include "../libmultipath/debug.h"
-#include "../libmultipath/uevent.h"
+#include "../libmultipath/util.h"
 #include "../libmultipath/time-util.h"
 
 struct rbd_checker_context;
index 81206e4..92200aa 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "../libmultipath/debug.h"
 #include "../libmultipath/sg_include.h"
-#include "../libmultipath/uevent.h"
+#include "../libmultipath/util.h"
 #include "../libmultipath/time-util.h"
 #include "../libmultipath/util.h"
 
index f844294..7bc5837 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/types.h>
 #include <linux/netlink.h>
 #include <pthread.h>
-#include <limits.h>
 #include <sys/mman.h>
 #include <libudev.h>
 #include <errno.h>
@@ -80,30 +79,6 @@ struct uevent * alloc_uevent (void)
        return 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);
-       }
-}
-
 void
 service_uevq(struct list_head *tmpq)
 {
index e5fdfcc..9d22dcd 100644 (file)
@@ -27,7 +27,6 @@ struct uevent {
 };
 
 int is_uevent_busy(void);
-void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached);
 
 int uevent_listen(struct udev *udev);
 int uevent_dispatch(int (*store_uev)(struct uevent *, void * trigger_data),
index ac0d1b2..0a136b4 100644 (file)
@@ -1,7 +1,10 @@
-#include <string.h>
+#include <assert.h>
 #include <ctype.h>
-#include <sys/types.h>
+#include <limits.h>
+#include <pthread.h>
+#include <string.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <unistd.h>
 
 #include "debug.h"
@@ -258,3 +261,21 @@ dev_t parse_devt(const char *dev_t)
 
        return makedev(maj, min);
 }
+
+void
+setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached)
+{
+       int ret;
+
+       ret = pthread_attr_init(attr);
+       assert(ret == 0);
+       if (stacksize < PTHREAD_STACK_MIN)
+               stacksize = PTHREAD_STACK_MIN;
+       ret = pthread_attr_setstacksize(attr, stacksize);
+       assert(ret == 0);
+       if (detached) {
+               ret = pthread_attr_setdetachstate(attr,
+                                                 PTHREAD_CREATE_DETACHED);
+               assert(ret == 0);
+       }
+}
index 8861085..f3b37ee 100644 (file)
@@ -12,6 +12,7 @@ size_t strlcat(char *dst, const char *src, size_t size);
 int devt2devname (char *, int, char *);
 dev_t parse_devt(const char *dev_t);
 char *convert_dev(char *dev, int is_path_device);
+void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached);
 
 #define safe_sprintf(var, format, args...)     \
        snprintf(var, sizeof(var), format, ##args) >= sizeof(var)