Files
nfs/cmd/nfsd/notify.go
T
petrbalvin a9b8039ef7
Test / test (push) Successful in 2m4s
Release / gates (push) Successful in 2m5s
Release / build (amd64, freebsd) (push) Successful in 1m27s
Release / build (amd64, linux) (push) Successful in 1m22s
Release / build (amd64, netbsd) (push) Successful in 1m19s
Release / build (amd64, openbsd) (push) Successful in 1m20s
Release / build (arm64, darwin) (push) Successful in 1m21s
Release / build (arm64, freebsd) (push) Successful in 1m26s
Release / build (arm64, linux) (push) Successful in 1m25s
Release / build (arm64, netbsd) (push) Successful in 1m31s
Release / build (arm64, openbsd) (push) Successful in 1m27s
Release / build (loong64, linux) (push) Successful in 1m37s
Release / build (riscv64, linux) (push) Successful in 1m21s
Release / release (push) Successful in 40s
feat: full NFSv4.2 server and client in pure Go
Assisted-by: GLM 5.3 Flash
2026-09-21 18:51:17 +02:00

42 lines
1.2 KiB
Go

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: MIT
package main
import (
"errors"
"log"
"net"
"os"
)
// notifyReady announces readiness to the service manager over
// $NOTIFY_SOCKET, the raw unix datagram socket of the sd_notify
// protocol. The message is the one READY=1 line; nothing else is sent
// and no dependency is pulled in. Without the variable, the process is
// not running under a Type=notify unit and the step is skipped quietly.
func notifyReady() error {
addr := os.Getenv("NOTIFY_SOCKET")
if addr == "" {
return nil
}
conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: addr, Net: "unixgram"})
if err != nil {
return err
}
defer conn.Close()
if _, err := conn.Write([]byte("READY=1")); err != nil {
return err
}
return nil
}
// notifyReadyOrLog announces readiness and reports a failure on the log
// without ending the service: a manager that expects the notification
// times the unit out, but the server itself is ready to serve either way.
func notifyReadyOrLog() {
if err := notifyReady(); err != nil && !errors.Is(err, os.ErrNotExist) {
log.Printf("nfsd: the readiness notification failed: %v", err)
}
}