ust-consumerd: fix exit race crashes
[ust.git] / libustconsumer / libustconsumer.c
index ef54fe807352bf5be8242b8bf0e205fe1aaa26c4..abf21d801ca1473fd8b1b3c1453636361fc0199a 100644 (file)
@@ -34,7 +34,7 @@
 
 #include <ust/ustconsumer.h>
 #include "lowlevel.h"
-#include "usterr.h"
+#include "usterr_signal_safe.h"
 #include "ustcomm.h"
 
 #define GET_SUBBUF_OK 1
@@ -426,6 +426,11 @@ static void destroy_buffer(struct ustconsumer_callbacks *callbacks,
 {
        int result;
 
+       result = close(buf->pipe_fd);
+       if(result == -1) {
+               WARN("problem closing the pipe fd");
+       }
+
        result = close(buf->app_sock);
        if(result == -1) {
                WARN("problem calling ustcomm_close_app");
@@ -472,6 +477,8 @@ int consumer_loop(struct ustconsumer_instance *instance, struct buffer_info *buf
                        DBG("App died while being traced");
                        finish_consuming_dead_subbuffer(instance->callbacks, buf);
                        break;
+               } else if (read_result == -1 && errno == EINTR) {
+                       continue;
                }
 
                if(instance->callbacks->on_read_subbuffer)
@@ -778,8 +785,11 @@ int ustconsumer_stop_instance(struct ustconsumer_instance *instance, int send_ms
 
        struct sockaddr_un addr;
 
+socket_again:
        result = fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if(result == -1) {
+               if (errno == EINTR)
+                       goto socket_again;
                PERROR("socket");
                return 1;
        }
@@ -789,13 +799,21 @@ int ustconsumer_stop_instance(struct ustconsumer_instance *instance, int send_ms
        strncpy(addr.sun_path, instance->sock_path, UNIX_PATH_MAX);
        addr.sun_path[UNIX_PATH_MAX-1] = '\0';
 
+connect_again:
        result = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
        if(result == -1) {
+               if (errno == EINTR)
+                       goto connect_again;
                PERROR("connect");
        }
 
-       while(bytes != sizeof(msg))
-               bytes += send(fd, msg, sizeof(msg), 0);
+       while(bytes != sizeof(msg)) {
+               int inc = send(fd, msg, sizeof(msg), 0);
+               if (inc < 0 && errno != EINTR)
+                       break;
+               else
+                       bytes += inc;
+       }
 
        close(fd);
 
@@ -841,7 +859,7 @@ static int init_ustconsumer_socket(struct ustconsumer_instance *instance)
                int result;
 
                /* Only check if socket dir exists if we are using the default directory */
-               result = ensure_dir_exists(SOCK_DIR);
+               result = ensure_dir_exists(SOCK_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
                if (result == -1) {
                        ERR("Unable to create socket directory %s", SOCK_DIR);
                        return -1;
This page took 0.027969 seconds and 4 git commands to generate.