On Thu, Oct 27, 2022 at 04:13:24PM +0200, Claudio Jeker wrote:
> So the timeout for each request is started when the command is accepted
> but the actual fork and exec of bgpctl happens later. So command_pid can
> be 0 when the timeout fires. In that case do not kill ourself but instead
> just abort this command.
> 
> I think this is the proper way to do this dance. Not sure how to really
> test this though.

The explanation and the diff certainly make sense to me.

ok tb (fwiw)

> -- 
> :wq Claudio
> 
> Index: slowcgi.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgplgd/slowcgi.c,v
> retrieving revision 1.5
> diff -u -p -r1.5 slowcgi.c
> --- slowcgi.c 27 Oct 2022 13:24:22 -0000      1.5
> +++ slowcgi.c 27 Oct 2022 14:00:52 -0000
> @@ -159,6 +159,7 @@ void              parse_begin_request(uint8_t *, uin
>  void         parse_params(uint8_t *, uint16_t, struct request *, uint16_t);
>  void         parse_stdin(uint8_t *, uint16_t, struct request *, uint16_t);
>  char         *env_get(struct request *, const char *);
> +void         error_response(struct request *, int);
>  void         exec_cgi(struct request *);
>  void         script_std_in(int, short, void *);
>  void         script_err_in(int, short, void *);
> @@ -505,6 +506,12 @@ slowcgi_timeout(int fd, short events, vo
>       if (c->script_flags & SCRIPT_DONE)
>               return;
>  
> +     if (c->command_pid == 0) {
> +             c->command_status = SIGALRM;
> +             error_response(c, 408);
> +             return;
> +     }
> +
>       ldebug("timeout fired for pid %d", c->command_pid);
>  
>       if (c->timeout_fired)
> @@ -887,7 +894,7 @@ http_error(int *res)
>       return "Internal Server Error";
>  }
>  
> -static void
> +void
>  error_response(struct request *c, int res)
>  {
>       const char *type = "text/html";
> 

Reply via email to