浏览代码

Tolerate socket creation error if port is optional

When users specify `[::]:80o` as port but the system has IPv6 disabled globally, e.g., with
```
GRUB_CMDLINE_LINUX="ipv6.disable=1"
```
then CivetWeb refuses to start even though it should skip the port if it cannot bind to it. However, when the port is specified as being optional, there is no point in treating non-availability of the protocol differently than the port already being taken. In this case, this port should simply be skipped.

Signed-off-by: DL6ER <dl6er@dl6er.de>
DL6ER 3 月之前
父节点
当前提交
267a58096b
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/civetweb.c

+ 8 - 0
src/civetweb.c

@@ -16154,6 +16154,10 @@ set_ports_option(struct mg_context *phys_ctx)
 			mg_cry_ctx_internal(phys_ctx,
 			mg_cry_ctx_internal(phys_ctx,
 			                    "cannot create socket (entry %i)",
 			                    "cannot create socket (entry %i)",
 			                    portsTotal);
 			                    portsTotal);
+			if (so.is_optional) {
+				portsOk++; /* it's okay if we couldn't create a socket,
+						this port is optional anyway */
+			}
 			continue;
 			continue;
 		}
 		}
 
 
@@ -16239,6 +16243,10 @@ set_ports_option(struct mg_context *phys_ctx)
 #else
 #else
 			mg_cry_ctx_internal(phys_ctx, "%s", "IPv6 not available");
 			mg_cry_ctx_internal(phys_ctx, "%s", "IPv6 not available");
 			closesocket(so.sock);
 			closesocket(so.sock);
+			if (so.is_optional) {
+				portsOk++; /* it's okay if we couldn't set the socket option,
+				              this port is optional anyway */
+			}
 			so.sock = INVALID_SOCKET;
 			so.sock = INVALID_SOCKET;
 			continue;
 			continue;
 #endif
 #endif