commit 1a1bbfc4118b87c5fae4f95fbb86b3e98f22eb67
parent c63e52c9107c5e2bd48eeee09be4ff20ef6e87f7
Author: finwo <finwo@pm.me>
Date: Mon, 14 Jun 2021 11:57:33 +0200
Fix passed arguments to command
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/ttcpd.c b/src/ttcpd.c
@@ -37,7 +37,7 @@ int main( int argc, char *argv[] ) {
// Initialize
int opt=0,port = 8080;
char *cmd = 0;
- char **args = 0;
+ char **args = calloc(argc,sizeof(void*));
// Detect port by environment variables
if(getenv("PORT")) {
@@ -67,7 +67,8 @@ int main( int argc, char *argv[] ) {
// Catch arguments to child
if(strcmp(argv[optind-1],"--")==0) {
- args = argv + optind;
+ args = argv + (optind-1);
+ args[0] = cmd;
}
// Make sure we have a command set
@@ -92,6 +93,10 @@ int main( int argc, char *argv[] ) {
inet_aton(inaddr, &saddr.sin_addr);
+ // Allow socket re-use
+ int optval = 1;
+ setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
+
// Bind socket to port
if(bind(sockfd,(struct sockaddr *) &saddr, sizeof(saddr))<0) {
fprintf( stderr, "Could not bind to %s:%d\n", inet_ntoa(saddr.sin_addr), port );