mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 15:38:57 +01:00
ce3b65e6dc
* abcdefghijklmnopqrstuvwxyz * accounting * additional * allowed * almost * already * appropriately * arise * bandwidth * behave * bidirectional * brackets * cached * characters * cloud * committing * concatenating * configured * constructs * current * cutoff * deferred * different * directory * disposition * dropbox * either way * error * excess * experiments * explicitly * externally * files * github * gzipped * hierarchies * huffman * hyphen * implicitly * independent * insensitive * integrity * libraries * literally * metadata * mimics * missing * modification * multipart * multiple * nightmare * nonexistent * number * obscure * ourselves * overridden * potatoes * preexisting * priority * received * remote * replacement * represents * reproducibility * response * satisfies * sensitive * separately * separator * specifying * string * successful * synchronization * syncing * šenfeld * take * temporarily * testcontents * that * the * themselves * throttling * timeout * transaction * transferred * unnecessary * using * webbrowser * which * with * workspace Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
//go:build linux || freebsd
|
|
// +build linux freebsd
|
|
|
|
package docker
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/rclone/rclone/lib/file"
|
|
)
|
|
|
|
func newUnixListener(path string, gid int) (net.Listener, string, error) {
|
|
// try systemd socket activation
|
|
fds := systemdActivationFiles()
|
|
switch len(fds) {
|
|
case 0:
|
|
// fall thru
|
|
case 1:
|
|
listener, err := net.FileListener(fds[0])
|
|
return listener, "", err
|
|
default:
|
|
return nil, "", fmt.Errorf("expected only one socket from systemd, got %d", len(fds))
|
|
}
|
|
|
|
// create socket ourselves
|
|
if filepath.Ext(path) == "" {
|
|
path += ".sock"
|
|
}
|
|
if !filepath.IsAbs(path) {
|
|
path = filepath.Join(sockDir, path)
|
|
}
|
|
|
|
if err := file.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
|
return nil, "", err
|
|
}
|
|
if err := os.Remove(path); err != nil && !os.IsNotExist(err) {
|
|
return nil, "", err
|
|
}
|
|
|
|
listener, err := net.Listen("unix", path)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
|
|
if err = os.Chmod(path, 0660); err != nil {
|
|
return nil, "", err
|
|
}
|
|
if os.Geteuid() == 0 {
|
|
if err = os.Chown(path, 0, gid); err != nil {
|
|
return nil, "", err
|
|
}
|
|
}
|
|
|
|
// we don't use spec file with unix sockets
|
|
return listener, path, nil
|
|
}
|