diff options
author | Vladislav Grishenko <themiron@mail.ru> | 2018-02-27 17:47:07 +0500 |
---|---|---|
committer | Vladislav Grishenko <themiron@mail.ru> | 2018-02-27 18:14:57 +0500 |
commit | 6f93514317953994a24e9087d44e7039e0401922 (patch) | |
tree | 5fc0d3dfdf55ba9a04a0841b73044df4a88a175c /accel-pppd/ctrl | |
parent | c2fe175d1b98ae3cc728d9254568201d45e2aeca (diff) | |
download | accel-ppp-6f93514317953994a24e9087d44e7039e0401922.tar.gz accel-ppp-6f93514317953994a24e9087d44e7039e0401922.zip |
sstp: unlink stray unix socket on init/bind error
Diffstat (limited to 'accel-pppd/ctrl')
-rw-r--r-- | accel-pppd/ctrl/sstp/sstp.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c index 5eabbfc1..b16fcaae 100644 --- a/accel-pppd/ctrl/sstp/sstp.c +++ b/accel-pppd/ctrl/sstp/sstp.c @@ -2412,8 +2412,7 @@ static void sstp_init(void) value = fcntl(serv.hnd.fd, F_GETFD); if (value < 0 || fcntl(serv.hnd.fd, F_SETFD, value | FD_CLOEXEC) < 0) { log_emerg("sstp: failed to set socket flags: %s\n", strerror(errno)); - close(serv.hnd.fd); - return; + goto error_close; } if (addr->u.sa.sa_family == AF_UNIX) { @@ -2421,25 +2420,25 @@ static void sstp_init(void) stat(addr->u.sun.sun_path, &st) == 0 && S_ISSOCK(st.st_mode)) { unlink(addr->u.sun.sun_path); } - } else - setsockopt(serv.hnd.fd, SOL_SOCKET, SO_REUSEADDR, &serv.hnd.fd, 4); + } else { + value = 1; + setsockopt(serv.hnd.fd, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(value)); + } if (bind(serv.hnd.fd, &addr->u.sa, addr->len) < 0) { log_emerg("sstp: failed to bind socket: %s\n", strerror(errno)); - close(serv.hnd.fd); - return; + goto error_close; } if (listen(serv.hnd.fd, 10) < 0) { log_emerg("sstp: failed to listen socket: %s\n", strerror(errno)); - close(serv.hnd.fd); - return; + goto error_unlink; } - if (fcntl(serv.hnd.fd, F_SETFL, O_NONBLOCK)) { + value = fcntl(serv.hnd.fd, F_GETFL); + if (fcntl(serv.hnd.fd, F_SETFL, value | O_NONBLOCK)) { log_emerg("sstp: failed to set nonblocking mode: %s\n", strerror(errno)); - close(serv.hnd.fd); - return; + goto error_unlink; } conn_pool = mempool_create(sizeof(struct sstp_conn_t)); @@ -2452,6 +2451,13 @@ static void sstp_init(void) triton_context_wakeup(&serv.ctx); triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); + return; + +error_unlink: + if (addr->u.sa.sa_family == AF_UNIX && addr->u.sun.sun_path[0]) + unlink(addr->u.sun.sun_path); +error_close: + close(serv.hnd.fd); } DEFINE_INIT(20, sstp_init); |