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);
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)
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);
*/
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
if (ret < 0)
return -1;
command_pipe = fds[1];
- mark_fd_nonblocking(command_pipe);
return send_output();
}
if (para_exec_cmdline_pid(&cmd_pid, cmd, fds) < 0)
return -1;
command_pipe = fds[1];
- mark_fd_nonblocking(command_pipe);
return send_output();
}
{
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;
}
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->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",
*/
void stdin_set_defaults(struct stdin_task *sit)
{
+ int ret;
+
sit->bufsize = 16 * 1024,
sit->loaded = 0,
sit->error = 0,
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);
}
*/
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);
}