ustcomm: improve error handling, and don't panic for nothing
[ust.git] / libustcomm / ustcomm.c
index 3b53471ac6d69c81acd1379351d985b9b8ed177b..8b459df32975499a4c1137ee379fb9d40600b231 100644 (file)
@@ -390,13 +390,24 @@ static int init_named_socket(const char *name, char **path_out)
        return -1;
 }
 
+/*
+ * Return value:
+ *   0: Success, but no reply because recv() returned 0
+ *   1: Success
+ *   -1: Error
+ *
+ * On error, the error message is printed, except on
+ * ECONNRESET, which is normal when the application dies.
+ */
+
 int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char **reply)
 {
        int result;
 
-       result = send(conn->fd, req, strlen(req), 0);
+       result = send(conn->fd, req, strlen(req), MSG_NOSIGNAL);
        if(result == -1) {
-               PERROR("send");
+               if(errno != ECONNRESET)
+                       PERROR("send");
                return -1;
        }
 
@@ -406,7 +417,8 @@ int ustcomm_send_request(struct ustcomm_connection *conn, const char *req, char
        *reply = (char *) malloc(MSG_MAX+1);
        result = recv(conn->fd, *reply, MSG_MAX, 0);
        if(result == -1) {
-               PERROR("recv");
+               if(errno != ECONNRESET)
+                       PERROR("recv");
                return -1;
        }
        else if(result == 0) {
@@ -545,7 +557,6 @@ void ustcomm_fini_app(struct ustcomm_app *handle)
        struct stat st;
 
        /* Destroy socket */
-       ERR("socket path is: %s", handle->server.socketpath);
        result = stat(handle->server.socketpath, &st);
        if(result == -1) {
                PERROR("stat (%s)", handle->server.socketpath);
This page took 0.026978 seconds and 4 git commands to generate.