From d605ab57f51491f3fe9442a18a3ae69f1ed80241 Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Mon, 6 Nov 2023 21:23:27 +0100 Subject: [PATCH] Fixed the end-close option, it just did not work --- CHANGES | 2 ++ xio-fdnum.c | 3 ++- xio-interface.c | 3 ++- xio-ipapp.c | 6 ++++-- xio-openssl.c | 6 ++++-- xio-posixmq.c | 3 ++- xio-proxy.c | 3 ++- xio-pty.c | 3 ++- xio-rawip.c | 6 ++++-- xio-readline.c | 3 ++- xio-socket.c | 18 ++++++++++++------ xio-socks.c | 3 ++- xio-socks5.c | 3 ++- xio-stdio.c | 4 +++- xio-udp.c | 8 ++++++-- xio-unix.c | 18 ++++++++++++------ xio-vsock.c | 3 ++- xioshutdown.c | 1 + 18 files changed, 66 insertions(+), 30 deletions(-) diff --git a/CHANGES b/CHANGES index cdf4cb1..c38c787 100644 --- a/CHANGES +++ b/CHANGES @@ -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. diff --git a/xio-fdnum.c b/xio-fdnum.c index fdff75f..ddba325 100644 --- a/xio-fdnum.c +++ b/xio-fdnum.c @@ -111,7 +111,8 @@ static int xioopen_accept_fd( int xioopen_fd(struct opt *opts, int rw, struct single *sfd, int numfd) { sfd->fd = numfd; - sfd->howtoend = END_NONE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_NONE; #if WITH_TERMIOS if (Isatty(sfd->fd)) { diff --git a/xio-interface.c b/xio-interface.c index 03d6769..d870f87 100644 --- a/xio-interface.c +++ b/xio-interface.c @@ -74,7 +74,8 @@ int _xioopen_interface(const char *ifname, ifidx = 0; /* desparate attempt to continue */ } - sfd->howtoend = END_INTERFACE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_INTERFACE; retropt_int(opts, OPT_SO_TYPE, &socktype); retropt_socket_pf(opts, &pf); diff --git a/xio-ipapp.c b/xio-ipapp.c index d8b2581..faa522b 100644 --- a/xio-ipapp.c +++ b/xio-ipapp.c @@ -54,7 +54,8 @@ int xioopen_ipapp_connect( } xioinit_ip(&pf, xioparms.default_ip); - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1; @@ -367,7 +368,8 @@ int xioopen_ipapp_listen( #endif } - sfd->howtoend = END_SHUTDOWN; + 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); diff --git a/xio-openssl.c b/xio-openssl.c index 240ce4e..4ea3a51 100644 --- a/xio-openssl.c +++ b/xio-openssl.c @@ -275,7 +275,8 @@ static int xioopen_openssl_connect( } xioinit_ip(&pf, xioparms.default_ip); - sfd->howtoend = END_SHUTDOWN; + 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); @@ -592,7 +593,8 @@ static int xioopen_openssl_listen( portname = argv[1]; - sfd->howtoend = END_SHUTDOWN; + 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); diff --git a/xio-posixmq.c b/xio-posixmq.c index 7c40ebb..186e932 100644 --- a/xio-posixmq.c +++ b/xio-posixmq.c @@ -102,7 +102,8 @@ static int xioopen_posixmq( _posixmq_unlink(sfd->para.posixmq.name, E_INFO); } retropt_bool(opts, OPT_UNLINK_CLOSE, &sfd->opt_unlink_close); - sfd->howtoend = END_CLOSE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_CLOSE; sfd->dtype = XIODATA_POSIXMQ | oneshot; oflag = O_CREAT; diff --git a/xio-proxy.c b/xio-proxy.c index 29730a1..ae2027e 100644 --- a/xio-proxy.c +++ b/xio-proxy.c @@ -113,7 +113,8 @@ static int xioopen_proxy_connect( targetname = argv[2]; targetport = argv[3]; - sfd->howtoend = END_SHUTDOWN; + 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); diff --git a/xio-pty.c b/xio-pty.c index d1ff2a0..2e6f60c 100644 --- a/xio-pty.c +++ b/xio-pty.c @@ -60,7 +60,8 @@ static int xioopen_pty( return STAT_NORETRY; } - sfd->howtoend = END_CLOSE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_CLOSE; if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1; applyopts(sfd, -1, opts, PH_INIT); diff --git a/xio-rawip.c b/xio-rawip.c index e54bac3..e4d3812 100644 --- a/xio-rawip.c +++ b/xio-rawip.c @@ -106,7 +106,8 @@ int _xioopen_rawip_sendto(const char *hostname, const char *protname, /*return STAT_NORETRY;*/ } - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; retropt_int(opts, OPT_PROTOCOL_FAMILY, pf); if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1; @@ -228,7 +229,8 @@ static int xioopen_rawip_recvfrom( protname); /*return STAT_NORETRY;*/ } - sfd->howtoend = END_NONE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_NONE; retropt_socket_pf(opts, &pf); if (pf == PF_UNSPEC) { diff --git a/xio-readline.c b/xio-readline.c index b29139c..376cd26 100644 --- a/xio-readline.c +++ b/xio-readline.c @@ -75,7 +75,8 @@ static int xioopen_readline( Notice(msgbuf); xfd->stream.fd = 0; /* stdin */ - xfd->stream.howtoend = END_NONE; + if (sfd->howtoend == END_UNSPEC) + xfd->stream.howtoend = END_NONE; xfd->stream.dtype = XIODATA_READLINE; #if WITH_TERMIOS diff --git a/xio-socket.c b/xio-socket.c index 0a1af63..e162b8f 100644 --- a/xio-socket.c +++ b/xio-socket.c @@ -236,7 +236,8 @@ static int xioopen_socket_connect( retropt_socket_pf(opts, &pf); retropt_int(opts, OPT_SO_TYPE, &socktype); /*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/ - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; if (applyopts_single(sfd, opts, PH_INIT) < 0) return -1; @@ -320,7 +321,8 @@ static int xioopen_socket_listen( retropt_socket_pf(opts, &pf); retropt_int(opts, OPT_SO_TYPE, &socktype); /*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/ - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; socket_init(0, &us); ussize = 0; @@ -415,7 +417,8 @@ 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);*/ - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; sfd->peersa.soa.sa_family = pf; themsize = 0; @@ -516,7 +519,8 @@ int xioopen_socket_recvfrom( retropt_socket_pf(opts, &pf); retropt_int(opts, OPT_SO_TYPE, &socktype); /*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/ - sfd->howtoend = END_NONE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_NONE; ussize = 0; if ((result = @@ -600,7 +604,8 @@ int xioopen_socket_recv( retropt_socket_pf(opts, &pf); retropt_int(opts, OPT_SO_TYPE, &socktype); /*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/ - sfd->howtoend = END_NONE; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_NONE; ussize = 0; if ((result = @@ -673,7 +678,8 @@ static int xioopen_socket_datagram( retropt_socket_pf(opts, &pf); /*retropt_int(opts, OPT_IP_PROTOCOL, &proto);*/ - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; sfd->peersa.soa.sa_family = pf; themsize = 0; diff --git a/xio-socks.c b/xio-socks.c index 32616c8..25905c4 100644 --- a/xio-socks.c +++ b/xio-socks.c @@ -76,7 +76,8 @@ static int xioopen_socks4_connect( targetname = argv[2]; targetport = argv[3]; - sfd->howtoend = END_SHUTDOWN; + 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); diff --git a/xio-socks5.c b/xio-socks5.c index b0d9d01..1585d7a 100644 --- a/xio-socks5.c +++ b/xio-socks5.c @@ -531,7 +531,8 @@ static int xioopen_socks5( target_name = argv[3]; target_port = argv[4]; - sfd->howtoend = END_SHUTDOWN; + 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); diff --git a/xio-stdio.c b/xio-stdio.c index 1cd123c..9f8aac9 100644 --- a/xio-stdio.c +++ b/xio-stdio.c @@ -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 diff --git a/xio-udp.c b/xio-udp.c index 9925218..201d0e6 100644 --- a/xio-udp.c +++ b/xio-udp.c @@ -260,7 +260,8 @@ int _xioopen_ipdgram_listen(struct single *sfd, xiosetsockaddrenv("SOCK", us, uslen, IPPROTO_UDP); xiosetsockaddrenv("PEER", them, themlen, IPPROTO_UDP); - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; applyopts_fchown(sfd->fd, opts); applyopts(sfd, -1, opts, PH_LATE); @@ -383,7 +384,8 @@ int _xioopen_udp_sendto(const char *hostname, const char *servname, bool needbind = false; int result; - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; /* ...res_opts[] */ if (applyopts_single(sfd, opts, PH_INIT) < 0) @@ -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 diff --git a/xio-unix.c b/xio-unix.c index b1b3735..42bb2a3 100644 --- a/xio-unix.c +++ b/xio-unix.c @@ -142,7 +142,8 @@ static int xioopen_unix_listen( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; if (!(ABSTRACT && addrdesc->arg1/*abstract*/)) { /* only for non abstract because abstract do not work in file system */ @@ -239,7 +240,8 @@ static int xioopen_unix_connect( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_SHUTDOWN; + 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); applyopts_offset(sfd, opts); @@ -409,7 +411,8 @@ static int xioopen_unix_sendto( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; applyopts_offset(sfd, opts); sfd->salen = xiosetunix(pf, &sfd->peersa.un, name, addrdesc->arg1/*abstract*/, sfd->para.socket.un.tight); @@ -494,7 +497,8 @@ int xioopen_unix_recvfrom( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_NONE; + 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); applyopts_named(name, opts, PH_EARLY); /* umask! */ @@ -580,7 +584,8 @@ static int xioopen_unix_recv( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_SHUTDOWN; + 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); applyopts_named(name, opts, PH_EARLY); /* umask! */ @@ -687,7 +692,8 @@ _xioopen_unix_client( sfd->para.socket.un.tight = UNIX_TIGHTSOCKLEN; retropt_socket_pf(opts, &pf); - sfd->howtoend = END_SHUTDOWN; + 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); applyopts_offset(sfd, opts); diff --git a/xio-vsock.c b/xio-vsock.c index 2ebc5b2..fcd09bc 100644 --- a/xio-vsock.c +++ b/xio-vsock.c @@ -43,7 +43,8 @@ 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) { - sfd->howtoend = END_SHUTDOWN; + if (sfd->howtoend == END_UNSPEC) + sfd->howtoend = END_SHUTDOWN; if (applyopts_single(sfd, opts, PH_INIT) < 0) return STAT_NORETRY; diff --git a/xioshutdown.c b/xioshutdown.c index 1e8e3d0..c1ec796 100644 --- a/xioshutdown.c +++ b/xioshutdown.c @@ -79,6 +79,7 @@ int xioshutdown(xiofile_t *sock, int how) { #endif /* _WITH_SOCKET */ default: ; } + /* XIOSHUT_UNSPEC passes on */ if (false) { ;