Last active
October 3, 2018 21:37
-
-
Save alberts/4640792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package systemd | |
import ( | |
"os" | |
"strconv" | |
"syscall" | |
) | |
const ( | |
listenFdsStart = 3 | |
) | |
func ListenFds() []*os.File { | |
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID")) | |
if err != nil || pid != os.Getpid() { | |
return nil | |
} | |
nfds, err := strconv.Atoi(os.Getenv("LISTEN_FDS")) | |
if err != nil || nfds == 0 { | |
return nil | |
} | |
files := []*os.File(nil) | |
for fd := listenFdsStart; fd < listenFdsStart+nfds; fd++ { | |
syscall.CloseOnExec(fd) | |
files = append(files, os.NewFile(uintptr(fd), "")) | |
} | |
return files | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good point. I just did a direct translation of sd_listen_fds long ago. I'll update this.