sdnotify: Send system monotonic time on reload #1314

Merged
fyrchik merged 1 commit from elebedeva/frostfs-node:fix/go-linkname-nanotime into master 2024-08-16 10:56:16 +00:00
3 changed files with 8 additions and 13 deletions

View file

@ -1,10 +0,0 @@
package sdnotify
import (
// For go:linkname to work.
_ "unsafe"
)
//go:noescape
//go:linkname nanotime runtime.nanotime
func nanotime() int64

View file

@ -1,2 +0,0 @@
// The file is intentionally empty.
// It is a workaround for https://github.com/golang/go/issues/15006

View file

@ -5,7 +5,10 @@ import (
"fmt"
"net"
"os"
"strconv"
"strings"
"golang.org/x/sys/unix"
)
const (
@ -51,7 +54,11 @@ func FlagAndStatus(status string) error {
// must be sent, containing "READY=1".
//
// For MONOTONIC_USEC format refer to https://www.man7.org/linux/man-pages/man3/sd_notify.3.html
status += fmt.Sprintf("\nMONOTONIC_USEC=%d", uint64(nanotime())/1e3 /* microseconds in nanoseconds */)
var ts unix.Timespec
if err := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err != nil {
return fmt.Errorf("clock_gettime: %w", err)
}
status += "\nMONOTONIC_USEC=" + strconv.FormatInt(ts.Nano()/1000, 10)
}
status += "\nSTATUS=" + strings.TrimSuffix(status, "=1")
return Send(status)