exit(EXIT_FAILURE);
}
socket_fd = ret;
- if (listen(socket_fd , 5) < 0) {
- PARA_EMERG_LOG("can not listen on socket\n");
- exit(EXIT_FAILURE);
- }
- ret = mark_fd_nonblocking(socket_fd);
- if (ret < 0) {
- close(socket_fd);
- return ret;
- }
PARA_INFO_LOG("listening on socket %s (fd %d)\n", socket_name,
socket_fd);
return socket_fd;
/* does not unlink socket on errors */
static int audiod_get_socket(void)
{
- int ret, fd;
+ int ret;
if (conf.socket_given)
socket_name = para_strdup(conf.socket_arg);
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH);
if (ret < 0)
goto err;
- fd = ret;
- if (listen(fd , 5) < 0) {
- ret = -ERRNO_TO_PARA_ERROR(errno);
- goto err;
- }
- ret = mark_fd_nonblocking(fd);
- if (ret < 0)
- goto err;
- return fd;
+ return ret;
err:
PARA_EMERG_LOG("%s\n", para_strerror(-ret));
exit(EXIT_FAILURE);
}
/**
- * Prepare, create, and bind a socket for local communication.
+ * Create a socket for local communication and listen on it.
*
* \param name The socket pathname.
* \param mode The desired permissions of the socket.
*
- * This function creates a local socket for sequenced, reliable,
- * two-way, connection-based byte streams.
+ * This function creates a passive local socket for sequenced, reliable,
+ * two-way, connection-based byte streams. The socket file descriptor is set to
+ * nonblocking mode and listen(2) is called to prepare the socket for
+ * accepting incoming connection requests.
*
- * \return The file descriptor, on success, negative on errors.
+ * \return The file descriptor on success, negative error code on failure.
*
- * \sa socket(2)
- * \sa bind(2)
- * \sa chmod(2)
+ * \sa socket(2), \sa bind(2), \sa chmod(2), listen(2), unix(7).
*/
int create_local_socket(const char *name, mode_t mode)
{
if (ret < 0)
return -ERRNO_TO_PARA_ERROR(errno);
fd = ret;
+ ret = mark_fd_nonblocking(fd);
+ if (ret < 0)
+ goto err;
ret = bind(fd, (struct sockaddr *)&unix_addr, UNIX_PATH_MAX);
if (ret < 0) {
ret = -ERRNO_TO_PARA_ERROR(errno);
ret = -E_CHMOD;
if (chmod(name, mode) < 0)
goto err;
+ if (listen(fd , 5) < 0) {
+ ret = -ERRNO_TO_PARA_ERROR(errno);
+ goto err;
+ }
return fd;
err:
close(fd);