mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-11 10:03:43 +00:00
better unix socket handling
This commit is contained in:
@@ -199,19 +199,25 @@ int http_server_listen(struct http_server_t *server) {
|
|||||||
|
|
||||||
if (server->unix_path[0] != '\0') {
|
if (server->unix_path[0] != '\0') {
|
||||||
struct sockaddr_un unix_addr;
|
struct sockaddr_un unix_addr;
|
||||||
int unix_fd_flags;
|
|
||||||
|
|
||||||
LOG_DEBUG("Binding HTTP to UNIX socket '%s' ...", server->unix_path);
|
LOG_DEBUG("Binding HTTP to UNIX socket '%s' ...", server->unix_path);
|
||||||
|
|
||||||
assert((server->run->unix_fd = socket(AF_UNIX, SOCK_STREAM, 0)));
|
# define MAX_SUN_PATH (sizeof(unix_addr.sun_path) - 1)
|
||||||
assert((unix_fd_flags = fcntl(server->run->unix_fd, F_GETFL)) >= 0);
|
|
||||||
unix_fd_flags |= O_NONBLOCK;
|
|
||||||
assert(fcntl(server->run->unix_fd, F_SETFL, unix_fd_flags) >= 0);
|
|
||||||
|
|
||||||
strncpy(unix_addr.sun_path, server->unix_path, 107);
|
if (strlen(server->unix_path) > MAX_SUN_PATH) {
|
||||||
unix_addr.sun_path[107] = '\0';
|
LOG_ERROR("UNIX socket path is too long, max=%zu", MAX_SUN_PATH);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
MEMSET_ZERO(unix_addr);
|
||||||
|
strncpy(unix_addr.sun_path, server->unix_path, MAX_SUN_PATH);
|
||||||
unix_addr.sun_family = AF_UNIX;
|
unix_addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
|
# undef MAX_SUN_PATH
|
||||||
|
|
||||||
|
assert((server->run->unix_fd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0);
|
||||||
|
assert(!evutil_make_socket_nonblocking(server->run->unix_fd));
|
||||||
|
|
||||||
if (server->unix_rm && unlink(server->unix_path) < 0) {
|
if (server->unix_rm && unlink(server->unix_path) < 0) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
LOG_PERROR("Can't remove old UNIX socket '%s'", server->unix_path);
|
LOG_PERROR("Can't remove old UNIX socket '%s'", server->unix_path);
|
||||||
|
|||||||
Reference in New Issue
Block a user