From: Omar Polo Subject: gotwebd: use `listen on socket' syntax for UNIX sockets too To: gameoftrees@openbsd.org Date: Mon, 02 Jan 2023 11:18:38 +0100 Currently gotwebd.conf(5) provides two way to specify where to listen for incoming connections: - `listen on ' for tcp sockets - `unix_socket' + `unix_socket_name' for unix-domain sockets with the difference being that `listen on ' may be used to more than once and unix_socket/unix_socket_name can't (each setting overwrites the previous.) Why don't unify the settings? Diff below adds `listen on socket off' to disable listening on the unix-domain socket and `listen on socket ' to specify the path. Like the unix_socket* settings these can only specified once. Does listening on multiple unix socket makes sense? Should it handle that case too or just add a note in the manpage that `listen on socket ' should only be used once? (I'm keeping the handling of unix_socket* in server context (but deleting the documentation) to provide some sort of backward compatibilty, to be deleted after the next release. Maybe should I just delete them?) diff 05791aa0b360dbff2a5212ef7babf4f96caf3940 45b81751c6adc0d549a7c908cf56adaefad2b171 commit - 05791aa0b360dbff2a5212ef7babf4f96caf3940 commit + 45b81751c6adc0d549a7c908cf56adaefad2b171 blob - b4e0de13f6815e574fd25d6bedfbc78012e4e88c blob + edb02bbb81fe636132e1112244651da491c0b4b6 --- gotwebd/gotwebd.conf.5 +++ gotwebd/gotwebd.conf.5 @@ -115,6 +115,10 @@ be ignored. will obtain the list of addresses on this interface only on startup. Any future changes to the address configuration of the interface will be ignored. +.It Ic listen on socket off +Disable use of unix socket. +.It Ic listen on socket Ar path +Set the path to the unix socket used by the server. .It Ic logo Ar path Set the path to an image file containing a logo to be displayed. .It Ic logo_url Ar url @@ -166,10 +170,6 @@ Toggle display of the site owner. Set the displayed site owner. .It Ic show_site_owner Ar on | off Toggle display of the site owner. -.It Ic unix_socket Ar on | off -Enable or disable use of unix sockets. -.It Ic unix_socket_name Ar path -Set the path to the unix socket used by the server. .El .Sh FILES .Bl -tag -width Ds -compact @@ -192,7 +192,7 @@ server "localhost-unix" { server "localhost-unix" { repos_path "/got/public" - unix_socket_name "/run/gotweb.sock" + listen on socket "/run/gotweb.sock" site_name "my public repos" site_owner "Got Owner" @@ -218,7 +218,7 @@ server "localhost-unix" { # Example server context for FCGI over TCP connections: #server "localhost-tcp" { # repos_path "/got/public" -# unix_socket off +# listen on socket off # listen on 127.0.0.1 port 9000 # listen on ::1 port 9000 #} blob - 1939f1bf7bd351ad2efa08577df37106511fd5d6 blob + eb37c2ae370fa443ae924a70fe7fd41aa97d1942 --- gotwebd/parse.y +++ gotwebd/parse.y @@ -122,7 +122,7 @@ typedef struct { %token LOGO_URL SHOW_REPO_OWNER SHOW_REPO_AGE SHOW_REPO_DESCRIPTION %token MAX_REPOS_DISPLAY REPOS_PATH MAX_COMMITS_DISPLAY ON ERROR %token SHOW_SITE_OWNER SHOW_REPO_CLONEURL PORT PREFORK RESPECT_EXPORTOK -%token UNIX_SOCKET UNIX_SOCKET_NAME SERVER CHROOT CUSTOM_CSS +%token UNIX_SOCKET UNIX_SOCKET_NAME SERVER CHROOT CUSTOM_CSS SOCKET %token STRING %type fcgiport @@ -339,6 +339,29 @@ serveropts1 : REPOS_PATH STRING { } new_srv->fcgi_socket = 1; } + | LISTEN ON SOCKET STRING { + if (!strcasecmp($4, "off") || + !strcasecmp($4, "no")) { + new_srv->unix_socket = 0; + free($4); + YYACCEPT; + } + + new_srv->unix_socket = 1; + + n = snprintf(new_srv->unix_socket_name, + sizeof(new_srv->unix_socket_name), "%s%s", + strlen(gotwebd->httpd_chroot) ? + gotwebd->httpd_chroot : D_HTTPD_CHROOT, $4); + if (n < 0 || + (size_t)n >= sizeof(new_srv->unix_socket_name)) { + yyerror("%s: unix_socket_name truncated", + __func__); + free($4); + YYERROR; + } + free($4); + } | MAX_REPOS NUMBER { if ($2 > 0) new_srv->max_repos = $2; @@ -454,6 +477,7 @@ lookup(char *s) { "site_link", SITE_LINK }, { "site_name", SITE_NAME }, { "site_owner", SITE_OWNER }, + { "socket", SOCKET }, { "unix_socket", UNIX_SOCKET }, { "unix_socket_name", UNIX_SOCKET_NAME }, };