summaryrefslogtreecommitdiff
path: root/nslcd_systemd/nslcd_systemd.go
diff options
context:
space:
mode:
Diffstat (limited to 'nslcd_systemd/nslcd_systemd.go')
-rw-r--r--nslcd_systemd/nslcd_systemd.go25
1 files changed, 9 insertions, 16 deletions
diff --git a/nslcd_systemd/nslcd_systemd.go b/nslcd_systemd/nslcd_systemd.go
index 29d49d6..91177a7 100644
--- a/nslcd_systemd/nslcd_systemd.go
+++ b/nslcd_systemd/nslcd_systemd.go
@@ -61,15 +61,6 @@ type Backend interface {
Close()
}
-type contextKey struct {
- name string
-}
-
-var (
- // ConnectionIDKey is a context key.
- ConnectionIDKey = &contextKey{"connection-id"}
-)
-
func get_socket() (socket net.Listener, err error) {
fds := sd_daemon.ListenFds(true)
if fds == nil {
@@ -106,13 +97,16 @@ func getpeercred(conn *net.UnixConn) (cred unix.Ucred, err error) {
return
}
-func handler(backend nslcd_server.Backend, limits nslcd_server.Limits, conn *net.UnixConn, ctx context.Context) {
+func handler(backend nslcd_server.Backend, limits nslcd_server.Limits, conn *net.UnixConn, cid int, ctx context.Context) {
defer conn.Close()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
- // TODO: override nslcd_server.LoggerKey with a logger that includes ConnectionIDKey
- log := nslcd_server.LoggerFromContext(ctx)
+ log := PrefixLogger{
+ Prefix: fmt.Sprintf("[%v] ", cid),
+ Logger: nslcd_server.LoggerFromContext(ctx),
+ }
+ ctx = context.WithValue(ctx, nslcd_server.LoggerKey, log)
cred, err := getpeercred(conn)
if err != nil {
@@ -195,12 +189,11 @@ func Main(backend Backend, limits nslcd_server.Limits, ctx context.Context) uint
if conn != nil {
wg.Add(1)
id++
- hctx := context.WithValue(ctx, ConnectionIDKey, id)
- go func() {
+ go func(id int) {
defer sd_daemon.Recover()
defer wg.Done()
- handler(backend, limits, conn.(*net.UnixConn), hctx)
- }()
+ handler(backend, limits, conn.(*net.UnixConn), id, ctx)
+ }(id)
}
}
}()