commit 2be11cdeee0c210d3273b3724e924de0422d9f67 from: Omar Polo date: Tue Jan 03 14:38:01 2023 UTC gotd: allow to express timeouts using minutes/hours This allows to use a suffix to indicate the unit of measure, such as "1h" for one hour or "30m" for 30 minutes. The suffix "s" for seconds is also accepted for completeness. ok stsp commit - 46e48ac738ef3d714f4258bd513bca84369a457d commit + 2be11cdeee0c210d3273b3724e924de0422d9f67 blob - ba00f127e7a704c7c95a42f2210fd109af6de5a3 blob + a45eb65170386548a9b8a2b7812f7309eebdc6f6 --- gotd/gotd.conf.5 +++ gotd/gotd.conf.5 @@ -55,7 +55,19 @@ Specify the inactivity timeout for operations between If this timeout is exceeded while a Git protocol request is being processed, the request will be aborted and the connection will be terminated. .Pp -The default timeout is 3600 seconds (1 hour). +The timeout value may also have a suffix indicating its unit of measure. +Supported suffixes are: +.Pp +.Bl -tag -compact -width tenletters +.It Ar s No or Ar S +seconds +.It Ar m No or Ar M +minutes +.It Ar h No or Ar H +hours +.El +.Pp +The default timeout is 1h (3600 seconds, one hour). This should only be changed if legitimate requests are exceeding the default timeout for some reason, such as the server spending an extraordinary amount of time generating a pack file. @@ -205,7 +217,7 @@ repository "openbsd/ports" { } # Use a larger request timeout value: -connection request timeout 7200 # 2 hours +connection request timeout 2h # Some users are granted a higher concurrent connection limit: connection { blob - bdbdd8744b35a0c889d8572b46ec471cd7d8d159 blob + a157b990e93fe1cb15f7ba00f0d218349adca5a2 --- gotd/parse.y +++ gotd/parse.y @@ -148,6 +148,57 @@ timeout : NUMBER { $$.tv_sec = $1; $$.tv_usec = 0; } + | STRING { + const char *errstr; + const char *type = "seconds"; + size_t len; + int mul = 1; + + if (*$1 == '\0') { + yyerror("invalid number of seconds: %s", $1); + free($1); + YYERROR; + } + + len = strlen($1); + switch ($1[len - 1]) { + case 'S': + case 's': + $1[len - 1] = '\0'; + break; + case 'M': + case 'm': + type = "minutes"; + mul = 60; + $1[len - 1] = '\0'; + break; + case 'H': + case 'h': + type = "hours"; + mul = 60 * 60; + $1[len - 1] = '\0'; + break; + } + + $$.tv_usec = 0; + $$.tv_sec = strtonum($1, 0, INT_MAX, &errstr); + if (errstr) { + yyerror("number of %s is %s: %s", type, + errstr, $1); + free($1); + YYERROR; + } + + if ($$.tv_sec > INT_MAX / mul) { + yyerror("number of %s is too too large: %s", + type, $1); + free($1); + YYERROR; + } + + $$.tv_sec *= mul; + free($1); + } ; main : UNIX_SOCKET STRING {