ttcpd

Trivial tcp daemon
git clone git://git.finwo.net/app/ttcpd
Log | Files | Refs | LICENSE

commit 56481b96c2d0e23f9b362b2476c62f4552db6a0e
parent 1a1bbfc4118b87c5fae4f95fbb86b3e98f22eb67
Author: finwo <finwo@pm.me>
Date:   Mon, 14 Jun 2021 12:22:28 +0200

More stable argument passing, close original stdio before dup2

Diffstat:
Msrc/ttcpd.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/ttcpd.c b/src/ttcpd.c @@ -13,6 +13,10 @@ extern "C" { #include <sys/wait.h> #include <unistd.h> +#ifdef GNU_SOURCE +#include <fcntl.h> +#endif + void usage( char *cmd ) { fprintf(stderr, "\n"); fprintf(stderr, "Usage:\n"); @@ -65,10 +69,12 @@ int main( int argc, char *argv[] ) { } } - // Catch arguments to child + // Arguments to child + args[0] = cmd; if(strcmp(argv[optind-1],"--")==0) { - args = argv + (optind-1); - args[0] = cmd; + for(opt=0; argv[optind+opt]; opt++) { + args[opt+1] = argv[optind+opt]; + } } // Make sure we have a command set @@ -129,6 +135,8 @@ int main( int argc, char *argv[] ) { } else { // We're the child, bind the socket to stdio + close(0); + close(1); dup2(nsock,0); dup2(nsock,1);