Skip to content

Commit 3223c51

Browse files
committed
Handle relative unix socket paths
Make relative unix sockets absolute by making them absolute against the AppWorkPath Fix go-gitea#17833 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 04c55e9 commit 3223c51

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
247247
- `HTTP_ADDR`: **0.0.0.0**: HTTP listen address.
248248
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
249249
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.
250-
- If `PROTOCOL` is set to `unix` or `fcgi+unix`, this should be the name of the Unix socket file to use.
250+
- If `PROTOCOL` is set to `unix` or `fcgi+unix`, this should be the name of the Unix socket file to use. Relative paths will be made absolute against the AppWorkPath.
251251
- `HTTP_PORT`: **3000**: HTTP listen port.
252252
- If `PROTOCOL` is set to `fcgi`, Gitea will listen for FastCGI requests on TCP socket
253253
defined by `HTTP_ADDR` and `HTTP_PORT` configuration settings.

modules/setting/setting.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,10 @@ func NewContext() {
583583
sec := Cfg.Section("server")
584584
AppName = Cfg.Section("").Key("APP_NAME").MustString("Gitea: Git with a cup of tea")
585585

586+
Domain = sec.Key("DOMAIN").MustString("localhost")
587+
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
588+
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
589+
586590
Protocol = HTTP
587591
switch sec.Key("PROTOCOL").String() {
588592
case "https":
@@ -605,6 +609,9 @@ func NewContext() {
605609
log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
606610
}
607611
UnixSocketPermission = uint32(UnixSocketPermissionParsed)
612+
if !filepath.IsAbs(HTTPAddr) {
613+
HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr)
614+
}
608615
case "unix":
609616
Protocol = UnixSocket
610617
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
@@ -613,6 +620,9 @@ func NewContext() {
613620
log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
614621
}
615622
UnixSocketPermission = uint32(UnixSocketPermissionParsed)
623+
if !filepath.IsAbs(HTTPAddr) {
624+
HTTPAddr = filepath.Join(AppWorkPath, HTTPAddr)
625+
}
616626
}
617627
EnableLetsEncrypt = sec.Key("ENABLE_LETSENCRYPT").MustBool(false)
618628
LetsEncryptTOS = sec.Key("LETSENCRYPT_ACCEPTTOS").MustBool(false)
@@ -626,9 +636,6 @@ func NewContext() {
626636
SSLMaximumVersion = sec.Key("SSL_MAX_VERSION").MustString("")
627637
SSLCurvePreferences = sec.Key("SSL_CURVE_PREFERENCES").Strings(",")
628638
SSLCipherSuites = sec.Key("SSL_CIPHER_SUITES").Strings(",")
629-
Domain = sec.Key("DOMAIN").MustString("localhost")
630-
HTTPAddr = sec.Key("HTTP_ADDR").MustString("0.0.0.0")
631-
HTTPPort = sec.Key("HTTP_PORT").MustString("3000")
632639
GracefulRestartable = sec.Key("ALLOW_GRACEFUL_RESTARTS").MustBool(true)
633640
GracefulHammerTime = sec.Key("GRACEFUL_HAMMER_TIME").MustDuration(60 * time.Second)
634641
StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(0 * time.Second)

0 commit comments

Comments
 (0)