projects
/
project
/
uhttpd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
57fc4cd
)
exit if no sockets could be bound
author
Felix Fietkau
<nbd@openwrt.org>
Mon, 31 Dec 2012 16:40:23 +0000
(17:40 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Mon, 31 Dec 2012 16:40:23 +0000
(17:40 +0100)
listen.c
patch
|
blob
|
history
main.c
patch
|
blob
|
history
diff --git
a/listen.c
b/listen.c
index
7e59d1d
..
13054fb
100644
(file)
--- a/
listen.c
+++ b/
listen.c
@@
-98,7
+98,7
@@
int uh_socket_bind(const char *host, const char *port, bool tls)
if ((status = getaddrinfo(host, port, &hints, &addrs)) != 0) {
fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(status));
if ((status = getaddrinfo(host, port, &hints, &addrs)) != 0) {
fprintf(stderr, "getaddrinfo(): %s\n", gai_strerror(status));
- return
-1
;
+ return
0
;
}
/* try to bind a new socket to each found address */
}
/* try to bind a new socket to each found address */
@@
-163,6
+163,7
@@
int uh_socket_bind(const char *host, const char *port, bool tls)
l->fd.fd = sock;
l->tls = tls;
list_add_tail(&l->list, &listeners);
l->fd.fd = sock;
l->tls = tls;
list_add_tail(&l->list, &listeners);
+ bound++;
continue;
continue;
diff --git
a/main.c
b/main.c
index
1172640
..
09c66c4
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-98,7
+98,7
@@
static void uh_config_parse(void)
fclose(c);
}
fclose(c);
}
-static
void
add_listener_arg(char *arg, bool tls)
+static
int
add_listener_arg(char *arg, bool tls)
{
char *host = NULL;
char *port = arg;
{
char *host = NULL;
char *port = arg;
@@
-110,7
+110,8
@@
static void add_listener_arg(char *arg, bool tls)
port = s + 1;
*s = 0;
}
port = s + 1;
*s = 0;
}
- uh_socket_bind(host, port, tls);
+
+ return uh_socket_bind(host, port, tls);
}
static int usage(const char *name)
}
static int usage(const char *name)
@@
-174,6
+175,7
@@
int main(int argc, char **argv)
char *port;
int opt, ch;
int cur_fd;
char *port;
int opt, ch;
int cur_fd;
+ int bound = 0;
init_defaults();
signal(SIGPIPE, SIG_IGN);
init_defaults();
signal(SIGPIPE, SIG_IGN);
@@
-186,7
+188,7
@@
int main(int argc, char **argv)
tls = true;
/* fall through */
case 'p':
tls = true;
/* fall through */
case 'p':
- add_listener_arg(optarg, tls);
+
bound +=
add_listener_arg(optarg, tls);
break;
case 'h':
break;
case 'h':
@@
-289,6
+291,11
@@
int main(int argc, char **argv)
uh_config_parse();
uh_config_parse();
+ if (!bound) {
+ fprintf(stderr, "Error: No sockets bound, unable to continue\n");
+ return 1;
+ }
+
/* fork (if not disabled) */
if (!nofork) {
switch (fork()) {
/* fork (if not disabled) */
if (!nofork) {
switch (fork()) {