summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Kneschke <jan@kneschke.de>2005-11-23 10:46:21 +0000
committerJan Kneschke <jan@kneschke.de>2005-11-23 10:46:21 +0000
commit96ae6c33150571ff4488b11f19eb697d8597e365 (patch)
treebd15167d508cedd6993b279a24746e5efb014ecf /src
parent0b97fea80d50b3960930b64a9eef5f30405d0992 (diff)
downloadlighttpd-git-96ae6c33150571ff4488b11f19eb697d8597e365.tar.gz
allow to bind the server to a unix-domain socket
git-svn-id: svn+ssh://svn.lighttpd.net/lighttpd/branches/lighttpd-merge-1.4.x@878 152afb58-edef-0310-8abb-c4023f1b3aa9
Diffstat (limited to 'src')
-rw-r--r--src/base.h3
-rw-r--r--src/network.c38
2 files changed, 38 insertions, 3 deletions
diff --git a/src/base.h b/src/base.h
index 1f32d6f3..506fdad9 100644
--- a/src/base.h
+++ b/src/base.h
@@ -124,6 +124,9 @@ typedef union {
struct sockaddr_in6 ipv6;
#endif
struct sockaddr_in ipv4;
+#ifdef HAVE_SYS_UN_H
+ struct sockaddr_un un;
+#endif
struct sockaddr plain;
} sock_addr;
diff --git a/src/network.c b/src/network.c
index 22a502cc..40e9bbae 100644
--- a/src/network.c
+++ b/src/network.c
@@ -70,6 +70,7 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) {
unsigned int port = 0;
const char *host;
buffer *b;
+ int is_unix_domain_socket = 0;
#ifdef SO_ACCEPTFILTER
struct accept_filter_arg afa;
@@ -121,15 +122,34 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) {
*(sp++) = '\0';
port = strtol(sp, NULL, 10);
-
- if (port == 0 || port > 65535) {
+
+ if (host[0] == '/') {
+ /* host is a unix-domain-socket */
+ is_unix_domain_socket = 1;
+ } else if (port == 0 || port > 65535) {
log_error_write(srv, __FILE__, __LINE__, "sd", "port out of range:", port);
return -1;
}
if (*host == '\0') host = NULL;
-
+
+ if (is_unix_domain_socket) {
+#ifdef HAVE_SYS_UN_H
+
+ srv_socket->addr.plain.sa_family = AF_UNIX;
+
+ if (-1 == (srv_socket->fd = socket(srv_socket->addr.plain.sa_family, SOCK_STREAM, 0))) {
+ log_error_write(srv, __FILE__, __LINE__, "ss", "socket failed:", strerror(errno));
+ return -1;
+ }
+#else
+ log_error_write(srv, __FILE__, __LINE__, "s",
+ "ERROR: Unix Domain sockets are not supported.");
+ return -1;
+#endif
+ }
+
#ifdef HAVE_IPV6
if (s->use_ipv6) {
srv_socket->addr.plain.sa_family = AF_INET6;
@@ -223,6 +243,18 @@ int network_server_init(server *srv, buffer *host_token, specific_config *s) {
addr_len = sizeof(struct sockaddr_in);
break;
+ case AF_UNIX:
+ srv_socket->addr.un.sun_family = AF_UNIX;
+ strcpy(srv_socket->addr.un.sun_path, host);
+
+#ifdef SUN_LEN
+ addr_len = SUN_LEN(&srv_socket->addr.un);
+#else
+ /* stevens says: */
+ addr_len = strlen(host) + sizeof(srv_socket->addr.un.sun_family);
+#endif
+
+ break;
default:
addr_len = 0;