Always check the return value of mark_fd_nonblocking().
authorAndre Noll <maan@systemlinux.org>
Sat, 19 Jan 2008 14:36:47 +0000 (15:36 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 19 Jan 2008 14:36:47 +0000 (15:36 +0100)
audiod.c
dccp_recv.c
gui.c
http_recv.c
http_send.c
stdin.c
stdout.c

index e7e368c210bd4979447eafdbd34038c7f2e43d2a..df725f96f216afe425e12ec14f0a7a9beba4178b 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -846,10 +846,11 @@ static int init_stream_io(void)
        return 1;
 }
 
        return 1;
 }
 
+/* does not unlink socket on errors */
 static int audiod_get_socket(void)
 {
        struct sockaddr_un unix_addr;
 static int audiod_get_socket(void)
 {
        struct sockaddr_un unix_addr;
-       int fd;
+       int ret, fd;
 
        if (conf.socket_given)
                socket_name = para_strdup(conf.socket_arg);
 
        if (conf.socket_given)
                socket_name = para_strdup(conf.socket_arg);
@@ -862,18 +863,22 @@ static int audiod_get_socket(void)
        PARA_NOTICE_LOG("local socket: %s\n", socket_name);
        if (conf.force_given)
                unlink(socket_name);
        PARA_NOTICE_LOG("local socket: %s\n", socket_name);
        if (conf.force_given)
                unlink(socket_name);
-       fd = create_local_socket(socket_name, &unix_addr,
-                       S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
-       if (fd < 0) {
-               PARA_EMERG_LOG("can not connect to socket\n");
-               exit(EXIT_FAILURE); /* do not unlink socket */
-       }
+       ret = create_local_socket(socket_name, &unix_addr,
+               S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
+       if (ret < 0)
+               goto err;
+       fd = ret;
        if (listen(fd , 5) < 0) {
        if (listen(fd , 5) < 0) {
-               PARA_EMERG_LOG("can not listen on socket\n");
-               exit(EXIT_FAILURE); /* do not unlink socket */
+               ret = -ERRNO_TO_PARA_ERROR(errno);
+               goto err;
        }
        }
-       mark_fd_nonblocking(fd);
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               goto err;
        return fd;
        return fd;
+err:
+       PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+       exit(EXIT_FAILURE);
 }
 
 static void signal_event_handler(struct task *t)
 }
 
 static void signal_event_handler(struct task *t)
index 64506737195de991134df0e692e897375c832e85..07f616657a7db4ca0dfe5b9d318f542c215a18c6 100644 (file)
@@ -73,12 +73,12 @@ static int dccp_recv_open(struct receiver_node *rn)
                ret = -ERRNO_TO_PARA_ERROR(errno);
                goto err;
        }
                ret = -ERRNO_TO_PARA_ERROR(errno);
                goto err;
        }
-
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0)
+               goto err;
        rn->buf = para_calloc(DCCP_BUFSIZE);
        rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
        rn->buf = para_calloc(DCCP_BUFSIZE);
        rn->private_data = pdd = para_calloc(sizeof(struct private_dccp_recv_data));
-
-       pdd->fd = ret;
-       mark_fd_nonblocking(pdd->fd);
+       pdd->fd = fd;
        return 1;
 err:
        close(fd);
        return 1;
 err:
        close(fd);
diff --git a/gui.c b/gui.c
index cf25cd4588524afa70989c4212dfecd377c8f538..c335250fee77daccc61868963e6135a220337610 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -966,8 +966,15 @@ check_return:
  */
 static int send_output(void)
 {
  */
 static int send_output(void)
 {
+       int ret;
+
        if (command_pipe < 0)
                return 0;
        if (command_pipe < 0)
                return 0;
+       ret = mark_fd_nonblocking(command_pipe);
+       if (ret < 0) {
+               close(command_pipe);
+               return ret;
+       }
        if (do_select(COMMAND_MODE) >= 0)
                PARA_INFO_LOG("%s", "command complete");
        else
        if (do_select(COMMAND_MODE) >= 0)
                PARA_INFO_LOG("%s", "command complete");
        else
@@ -988,7 +995,6 @@ static int client_cmd_cmdline(char *cmd)
        if (ret < 0)
                return -1;
        command_pipe = fds[1];
        if (ret < 0)
                return -1;
        command_pipe = fds[1];
-       mark_fd_nonblocking(command_pipe);
        return send_output();
 }
 
        return send_output();
 }
 
@@ -1004,7 +1010,6 @@ static int display_cmd(char *cmd)
        if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
                return -1;
        command_pipe = fds[1];
        if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
                return -1;
        command_pipe = fds[1];
-       mark_fd_nonblocking(command_pipe);
        return send_output();
 }
 
        return send_output();
 }
 
index 63b66d12610831ce06d362c4a533b9bc3a53e643..cb79b6436e1669a8725904b75355ef968d7dc23c 100644 (file)
@@ -168,16 +168,20 @@ static int http_recv_open(struct receiver_node *rn)
 {
        struct private_http_recv_data *phd;
        struct http_recv_args_info *conf = rn->conf;
 {
        struct private_http_recv_data *phd;
        struct http_recv_args_info *conf = rn->conf;
-       int ret = makesock(AF_UNSPEC, IPPROTO_TCP, 0, conf->host_arg, conf->port_arg);
+       int fd, ret = makesock(AF_UNSPEC, IPPROTO_TCP, 0, conf->host_arg,
+               conf->port_arg);
 
        if (ret < 0)
                return ret;
 
        if (ret < 0)
                return ret;
-
+       fd = ret;
+       ret = mark_fd_nonblocking(fd);
+       if (ret < 0) {
+               close(fd);
+               return ret;
+       }
        rn->buf = para_calloc(BUFSIZE);
        rn->private_data = phd = para_calloc(sizeof(struct private_http_recv_data));
        rn->buf = para_calloc(BUFSIZE);
        rn->private_data = phd = para_calloc(sizeof(struct private_http_recv_data));
-
-       phd->fd = ret;
-       mark_fd_nonblocking(phd->fd);
+       phd->fd = fd;
        phd->status = HTTP_CONNECTED;
        return 1;
 }
        phd->status = HTTP_CONNECTED;
        return 1;
 }
index c1a4fc6af4b72ce20122ef98ec9cf36ce11f1439..69e75ccb80eddd0badfdf49aadaadcf6e75e8417 100644 (file)
@@ -258,6 +258,9 @@ static void http_post_select(fd_set *rfds, fd_set *wfds)
                err_msg = "permission denied";
                goto err_out;
        }
                err_msg = "permission denied";
                goto err_out;
        }
+       err_msg = "failed to mark fd non-blocking";
+       if (mark_fd_nonblocking(hc->fd) < 0)
+               goto err_out;
        hc->status = HTTP_CONNECTED;
        hc->cq = cq_new(MAX_BACKLOG);
        numclients++;
        hc->status = HTTP_CONNECTED;
        hc->cq = cq_new(MAX_BACKLOG);
        numclients++;
@@ -265,7 +268,6 @@ static void http_post_select(fd_set *rfds, fd_set *wfds)
                hc->name, hc->fd);
        para_list_add(&hc->node, &clients);
        add_close_on_fork_list(hc->fd);
                hc->name, hc->fd);
        para_list_add(&hc->node, &clients);
        add_close_on_fork_list(hc->fd);
-       mark_fd_nonblocking(hc->fd);
        return;
 err_out:
        PARA_WARNING_LOG("ignoring connect request from %s (%s)\n",
        return;
 err_out:
        PARA_WARNING_LOG("ignoring connect request from %s (%s)\n",
diff --git a/stdin.c b/stdin.c
index 40f02c1cef0a945546966fef4f2cea033d54fc17..afbe35f8eaf2f74a7e04437e5c60de1a2a6a9b1b 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -90,6 +90,8 @@ static void stdin_post_select(struct sched *s, struct task *t)
  */
 void stdin_set_defaults(struct stdin_task *sit)
 {
  */
 void stdin_set_defaults(struct stdin_task *sit)
 {
+       int ret;
+
        sit->bufsize = 16 * 1024,
        sit->loaded = 0,
        sit->error = 0,
        sit->bufsize = 16 * 1024,
        sit->loaded = 0,
        sit->error = 0,
@@ -97,6 +99,10 @@ void stdin_set_defaults(struct stdin_task *sit)
        sit->task.post_select = stdin_post_select;
        sit->task.event_handler = stdin_default_event_handler;
        sit->task.private_data = sit;
        sit->task.post_select = stdin_post_select;
        sit->task.event_handler = stdin_default_event_handler;
        sit->task.private_data = sit;
-       mark_fd_nonblocking(STDIN_FILENO);
        sprintf(sit->task.status, "stdin reader");
        sprintf(sit->task.status, "stdin reader");
+       ret = mark_fd_nonblocking(STDIN_FILENO);
+       if (ret >= 0)
+               return;
+       PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+       exit(EXIT_FAILURE);
 }
 }
index 178f3eebe5cab4e8f0df1d9fdf3e03b813a14f16..2215f998abb6e1fb6e8a508df3b1ee8433fb795a 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -95,11 +95,17 @@ static void stdout_default_event_handler(struct task *t)
  */
 void stdout_set_defaults(struct stdout_task *sot)
 {
  */
 void stdout_set_defaults(struct stdout_task *sot)
 {
+       int ret;
+
        sot->task.private_data = sot;
        sot->task.pre_select = stdout_pre_select;
        sot->task.post_select = stdout_post_select;
        sot->task.event_handler = stdout_default_event_handler;
        sot->error = 0;
        sot->task.private_data = sot;
        sot->task.pre_select = stdout_pre_select;
        sot->task.post_select = stdout_post_select;
        sot->task.event_handler = stdout_default_event_handler;
        sot->error = 0;
-       mark_fd_nonblocking(STDOUT_FILENO);
        sprintf(sot->task.status, "stdout writer");
        sprintf(sot->task.status, "stdout writer");
+       ret = mark_fd_nonblocking(STDOUT_FILENO);
+       if (ret >= 0)
+               return;
+       PARA_EMERG_LOG("%s\n", para_strerror(-ret));
+       exit(EXIT_FAILURE);
 }
 }