summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-08-19 15:10:38 -0400
committerDave Reisner <dreisner@archlinux.org>2012-08-19 22:04:42 -0400
commit0c93fa9ef0e014ff3504f098ed5d0cf6c23641d2 (patch)
treea98c28355ad1bcc6cf8363517849529652533e76
parent13288627b4162ea417ab0edaff81648e0df82152 (diff)
downloadfcgiwrap-0c93fa9ef0e014ff3504f098ed5d0cf6c23641d2.tar.xz
fcgiwrap-0c93fa9ef0e014ff3504f098ed5d0cf6c23641d2.zip
split listen() logic into separate function
-rw-r--r--fcgiwrap.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/fcgiwrap.c b/fcgiwrap.c
index f0bf6d5..9d87034 100644
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -638,13 +638,35 @@ static void prefork(int nchildren)
}
}
+static int listen_on_fd(int fd) {
+ int one = 1;
+
+ if (listen(fd, 511) < 0) {
+ perror("Failed to listen");
+ return -1;
+ }
+ if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one) < 0) {
+ perror("Failed to enable SO_REUSEADDR");
+ return -1;
+ }
+ if (dup2(fd, 0) < 0) {
+ perror("Failed to move socket to fd 0");
+ return -1;
+ }
+ if (close(fd) < 0) {
+ perror("Failed to close original socket");
+ return -1;
+ }
+
+ return 0;
+}
+
int setup_socket(char *url) {
char *p = url;
char *q;
int fd;
int port;
size_t sockaddr_size;
- int one = 1;
union {
struct sockaddr sa;
@@ -718,24 +740,8 @@ invalid_url:
perror("Failed to bind");
return -1;
}
- if (listen(fd, 511) < 0) {
- perror("Failed to listen");
- return -1;
- }
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one) < 0) {
- perror("Failed to enable SO_REUSEADDR");
- return -1;
- }
- if (dup2(fd, 0) < 0) {
- perror("Failed to move socket to fd 0");
- return -1;
- }
- if (close(fd) < 0) {
- perror("Failed to close original socket");
- return -1;
- }
- return 0;
+ return listen_on_fd(fd);
}
int main(int argc, char **argv)