Fixed the end-close option, it just did not work

This commit is contained in:
Gerhard Rieger 2023-11-06 21:23:27 +01:00
parent e610b14470
commit d605ab57f5
18 changed files with 66 additions and 30 deletions

View file

@ -210,6 +210,8 @@ Corrections:
automatically spawning new connections, however the max-children option
was not applied.
Fixed the end-close option, it just did not work.
Coding:
Introduced groups_t instead of uint32_t, for more flexibility.

View file

@ -111,6 +111,7 @@ static int xioopen_accept_fd(
int xioopen_fd(struct opt *opts, int rw, struct single *sfd, int numfd) {
sfd->fd = numfd;
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
#if WITH_TERMIOS

View file

@ -74,6 +74,7 @@ int _xioopen_interface(const char *ifname,
ifidx = 0; /* desparate attempt to continue */
}
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_INTERFACE;
retropt_int(opts, OPT_SO_TYPE, &socktype);

View file

@ -54,6 +54,7 @@ int xioopen_ipapp_connect(
}
xioinit_ip(&pf, xioparms.default_ip);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0)
@ -367,6 +368,7 @@ int xioopen_ipapp_listen(
#endif
}
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1;

View file

@ -275,6 +275,7 @@ static int xioopen_openssl_connect(
}
xioinit_ip(&pf, xioparms.default_ip);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0)
return -1;
@ -592,6 +593,7 @@ static int xioopen_openssl_listen(
portname = argv[1];
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1;
applyopts(sfd, -1, opts, PH_INIT);

View file

@ -102,6 +102,7 @@ static int xioopen_posixmq(
_posixmq_unlink(sfd->para.posixmq.name, E_INFO);
}
retropt_bool(opts, OPT_UNLINK_CLOSE, &sfd->opt_unlink_close);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_CLOSE;
sfd->dtype = XIODATA_POSIXMQ | oneshot;

View file

@ -113,6 +113,7 @@ static int xioopen_proxy_connect(
targetname = argv[2];
targetport = argv[3];
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0)
return -1;

View file

@ -60,6 +60,7 @@ static int xioopen_pty(
return STAT_NORETRY;
}
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_CLOSE;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1;

View file

@ -106,6 +106,7 @@ int _xioopen_rawip_sendto(const char *hostname, const char *protname,
/*return STAT_NORETRY;*/
}
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
retropt_int(opts, OPT_PROTOCOL_FAMILY, pf);
@ -228,6 +229,7 @@ static int xioopen_rawip_recvfrom(
protname);
/*return STAT_NORETRY;*/
}
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
retropt_socket_pf(opts, &pf);

View file

@ -75,6 +75,7 @@ static int xioopen_readline(
Notice(msgbuf);
xfd->stream.fd = 0; /* stdin */
if (sfd->howtoend == END_UNSPEC)
xfd->stream.howtoend = END_NONE;
xfd->stream.dtype = XIODATA_READLINE;

View file

@ -236,6 +236,7 @@ static int xioopen_socket_connect(
retropt_socket_pf(opts, &pf);
retropt_int(opts, OPT_SO_TYPE, &socktype);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0)
@ -320,6 +321,7 @@ static int xioopen_socket_listen(
retropt_socket_pf(opts, &pf);
retropt_int(opts, OPT_SO_TYPE, &socktype);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
socket_init(0, &us);
@ -415,6 +417,7 @@ int _xioopen_socket_sendto(const char *pfname, const char *type,
retropt_socket_pf(opts, &pf);
retropt_int(opts, OPT_SO_TYPE, &socktype);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
sfd->peersa.soa.sa_family = pf;
@ -516,6 +519,7 @@ int xioopen_socket_recvfrom(
retropt_socket_pf(opts, &pf);
retropt_int(opts, OPT_SO_TYPE, &socktype);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
ussize = 0;
@ -600,6 +604,7 @@ int xioopen_socket_recv(
retropt_socket_pf(opts, &pf);
retropt_int(opts, OPT_SO_TYPE, &socktype);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
ussize = 0;
@ -673,6 +678,7 @@ static int xioopen_socket_datagram(
retropt_socket_pf(opts, &pf);
/*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
sfd->peersa.soa.sa_family = pf;

View file

@ -76,6 +76,7 @@ static int xioopen_socks4_connect(
targetname = argv[2];
targetport = argv[3];
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1;
applyopts(sfd, 1, opts, PH_INIT);

View file

@ -531,6 +531,7 @@ static int xioopen_socks5(
target_name = argv[3];
target_port = argv[4];
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1;
applyopts(sfd, -1, opts, PH_INIT);

View file

@ -41,7 +41,9 @@ int xioopen_stdio_bi(xiofile_t *sock) {
sock->dual.stream[0]->fd = 0 /*stdin*/;
sock->dual.stream[1]->tag = XIO_TAG_WRONLY;
sock->dual.stream[1]->fd = 1 /*stdout*/;
sock->dual.stream[0]->howtoend =
if (sock->dual.stream[0]->howtoend == END_UNSPEC)
sock->dual.stream[0]->howtoend = END_NONE;
if (sock->dual.stream[1]->howtoend == END_UNSPEC)
sock->dual.stream[1]->howtoend = END_NONE;
#if WITH_TERMIOS

View file

@ -260,6 +260,7 @@ int _xioopen_ipdgram_listen(struct single *sfd,
xiosetsockaddrenv("SOCK", us, uslen, IPPROTO_UDP);
xiosetsockaddrenv("PEER", them, themlen, IPPROTO_UDP);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
applyopts_fchown(sfd->fd, opts);
applyopts(sfd, -1, opts, PH_LATE);
@ -383,6 +384,7 @@ int _xioopen_udp_sendto(const char *hostname, const char *servname,
bool needbind = false;
int result;
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
/* ...res_opts[] */
@ -539,6 +541,8 @@ static int xioopen_udp_recvfrom(
xioinit_ip(&pf, xioparms.default_ip);
sfd->howtoend = END_NONE;
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
retropt_socket_pf(opts, &pf);
if (pf == PF_UNSPEC) {
#if WITH_IP4 && WITH_IP6

View file

@ -142,6 +142,7 @@ static int xioopen_unix_listen(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (!(ABSTRACT && addrdesc->arg1/*abstract*/)) {
@ -239,6 +240,7 @@ static int xioopen_unix_connect(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return STAT_NORETRY;
applyopts(sfd, -1, opts, PH_INIT);
@ -409,6 +411,7 @@ static int xioopen_unix_sendto(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
applyopts_offset(sfd, opts);
@ -494,6 +497,7 @@ int xioopen_unix_recvfrom(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_NONE;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return STAT_NORETRY;
applyopts(sfd, -1, opts, PH_INIT);
@ -580,6 +584,7 @@ static int xioopen_unix_recv(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return STAT_NORETRY;
applyopts(sfd, -1, opts, PH_INIT);
@ -687,6 +692,7 @@ _xioopen_unix_client(
sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN;
retropt_socket_pf(opts, &pf);
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0) return STAT_NORETRY;
applyopts(sfd, -1, opts, PH_INIT);

View file

@ -43,6 +43,7 @@ static int vsock_addr_init(struct sockaddr_vm *sa, const char *cid_str,
/* Performs a few steps during opening an address of type VSOCK */
static int vsock_init(struct opt *opts, struct single *sfd) {
if (sfd->howtoend == END_UNSPEC)
sfd->howtoend = END_SHUTDOWN;
if (applyopts_single(sfd, opts, PH_INIT) < 0)

View file

@ -79,6 +79,7 @@ int xioshutdown(xiofile_t *sock, int how) {
#endif /* _WITH_SOCKET */
default: ;
}
/* XIOSHUT_UNSPEC passes on */
if (false) {
;