From: Andre Noll Date: Sat, 19 Jan 2008 14:36:47 +0000 (+0100) Subject: Always check the return value of mark_fd_nonblocking(). X-Git-Tag: v0.3.1~73 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=8d7bdabd22ed7750086ca660754d8d881dae3832;p=paraslash.git Always check the return value of mark_fd_nonblocking(). --- diff --git a/audiod.c b/audiod.c index e7e368c2..df725f96 100644 --- a/audiod.c +++ b/audiod.c @@ -846,10 +846,11 @@ static int init_stream_io(void) return 1; } +/* does not unlink socket on errors */ 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); @@ -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); - 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) { - 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; +err: + PARA_EMERG_LOG("%s\n", para_strerror(-ret)); + exit(EXIT_FAILURE); } static void signal_event_handler(struct task *t) diff --git a/dccp_recv.c b/dccp_recv.c index 64506737..07f61665 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -73,12 +73,12 @@ static int dccp_recv_open(struct receiver_node *rn) 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)); - - pdd->fd = ret; - mark_fd_nonblocking(pdd->fd); + pdd->fd = fd; return 1; err: close(fd); diff --git a/gui.c b/gui.c index cf25cd45..c335250f 100644 --- a/gui.c +++ b/gui.c @@ -966,8 +966,15 @@ check_return: */ static int send_output(void) { + int ret; + 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 @@ -988,7 +995,6 @@ static int client_cmd_cmdline(char *cmd) if (ret < 0) return -1; command_pipe = fds[1]; - mark_fd_nonblocking(command_pipe); 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]; - mark_fd_nonblocking(command_pipe); return send_output(); } diff --git a/http_recv.c b/http_recv.c index 63b66d12..cb79b643 100644 --- a/http_recv.c +++ b/http_recv.c @@ -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; - 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; - + 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)); - - phd->fd = ret; - mark_fd_nonblocking(phd->fd); + phd->fd = fd; phd->status = HTTP_CONNECTED; return 1; } diff --git a/http_send.c b/http_send.c index c1a4fc6a..69e75ccb 100644 --- a/http_send.c +++ b/http_send.c @@ -258,6 +258,9 @@ static void http_post_select(fd_set *rfds, fd_set *wfds) 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++; @@ -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); - mark_fd_nonblocking(hc->fd); return; err_out: PARA_WARNING_LOG("ignoring connect request from %s (%s)\n", diff --git a/stdin.c b/stdin.c index 40f02c1c..afbe35f8 100644 --- 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) { + int ret; + 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; - mark_fd_nonblocking(STDIN_FILENO); 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); } diff --git a/stdout.c b/stdout.c index 178f3eeb..2215f998 100644 --- 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) { + 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; - mark_fd_nonblocking(STDOUT_FILENO); 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); }