URI: 
       Change from system() to execl() for user agent script. - bitreich-httpd - Bitreich HTTPD service
  HTML git clone git://bitreich.org/bitreich-httpd git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/bitreich-httpd
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit d91240a05f9f9ccb93d93e7bea44fc7cbf79e779
   DIR parent 19ed00841160bf4661c1a2533ce9008eef47090e
  HTML Author: Christoph Lohmann <20h@r-36.net>
       Date:   Sun,  3 Sep 2023 20:55:01 +0200
       
       Change from system() to execl() for user agent script.
       
       Diffstat:
         M bitreich-httpd.c                    |      26 ++++++++++++++++++++------
       
       1 file changed, 20 insertions(+), 6 deletions(-)
       ---
   DIR diff --git a/bitreich-httpd.c b/bitreich-httpd.c
       @@ -13,6 +13,7 @@
        #include <string.h>
        #include <strings.h>
        #include <sys/socket.h>
       +#include <sys/wait.h>
        #include <netdb.h>
        #include <time.h>
        
       @@ -138,12 +139,13 @@ main(int argc, char *argv[])
                char *wwwbase, *wwwindex, *request, *ctype, *path, *le_file,
                        *le_base, clienth[NI_MAXHOST], clientp[NI_MAXSERV], *zuccbase,
                        *requested, *header, *headerval, *hosthdr;
       -        int rlen, i;
       +        int rlen, i, user_agent_script_pid;
                struct sockaddr_storage clt;
                socklen_t cltlen = sizeof(clt);
                time_t tim;
        
                hosthdr = NULL;
       +        user_agent_script_pid = -1;
        
                wwwbase = "/bitreich/www";
                wwwindex = "index.html";
       @@ -194,11 +196,16 @@ main(int argc, char *argv[])
                                continue;
                        }
                        if (!strcasecmp(header, "user-agent")) {
       -                        asprintf(&path,
       -                                "/home/annna/bin/modules/http-user-agent/add-user-agent.sh '%s'",
       -                                headerval);
       -                        system(path);
       -                        free(path);
       +                        user_agent_script_pid = fork();
       +                        switch (user_agent_script_pid) {
       +                        case -1:
       +                                perror("fork");
       +                                return 1;
       +                        case 0:
       +                                return execl("add-user-agent.sh",
       +                                        "/home/annna/bin/modules/http-user-agent/add-user-agent.sh",
       +                                        headerval, 0);
       +                        }
                        }
                        if (!strcasecmp(header, "host")) {
                                rlen = strlen(headerval);
       @@ -279,6 +286,13 @@ main(int argc, char *argv[])
                rlen = servefile(path, ctype, 1);
                free(path);
        
       +        if (user_agent_script_pid != -1) {
       +                if (waitpid(user_agent_script_pid, NULL, 0) < 0) {
       +                        perror("waitpid");
       +                        return 1;
       +                }
       +        }
       +
                return rlen;
        }