From 18215381dd1013e281206d5c80af3f691ef441aa Mon Sep 17 00:00:00 2001 From: qiu-x Date: Sat, 6 Nov 2021 10:03:51 +0100 Subject: [PATCH 1/3] Make getting the up-time more portable across unix-like systems --- .../darktile/hinters/hint_dmesg_timestamp.go | 5 +---- internal/app/darktile/hinters/uptime.go | 22 +++++++++++++++++++ internal/app/darktile/hinters/uptime_linux.go | 11 ++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 internal/app/darktile/hinters/uptime.go create mode 100644 internal/app/darktile/hinters/uptime_linux.go diff --git a/internal/app/darktile/hinters/hint_dmesg_timestamp.go b/internal/app/darktile/hinters/hint_dmesg_timestamp.go index 7c481036..cb6aced8 100644 --- a/internal/app/darktile/hinters/hint_dmesg_timestamp.go +++ b/internal/app/darktile/hinters/hint_dmesg_timestamp.go @@ -4,7 +4,6 @@ import ( "regexp" "strconv" "strings" - "syscall" "time" "github.com/liamg/darktile/internal/app/darktile/termutil" @@ -52,7 +51,5 @@ func (h *DmesgTimestampHinter) Click(api HintAPI) error { } func setSysStartTime() { - sysInfo := &syscall.Sysinfo_t{} - _ = syscall.Sysinfo(sysInfo) - sysStart = time.Now().Local().Add(time.Duration(int(sysInfo.Uptime*-1)) * time.Second) + sysStart = time.Now().Local().Add(time.Duration(int(getUptime()*-1)) * time.Second) } diff --git a/internal/app/darktile/hinters/uptime.go b/internal/app/darktile/hinters/uptime.go new file mode 100644 index 00000000..e04e452d --- /dev/null +++ b/internal/app/darktile/hinters/uptime.go @@ -0,0 +1,22 @@ +//go:build cgo && (!linux || unix) +package hinters + +/* +#include +#include +#include +#include + + +time_t getuptime() { + struct timespec tp; + clock_gettime(CLOCK_UPTIME, &tp); + return tp.tv_sec; +} +*/ +import "C" + +func getUptime() int64 { + time := C.getuptime() + return int64(time) +} diff --git a/internal/app/darktile/hinters/uptime_linux.go b/internal/app/darktile/hinters/uptime_linux.go new file mode 100644 index 00000000..5b806f09 --- /dev/null +++ b/internal/app/darktile/hinters/uptime_linux.go @@ -0,0 +1,11 @@ +package hinters + +import ( + "syscall" +) + +func getUptime() int64 { + sysInfo := &syscall.Sysinfo_t{} + _ = syscall.Sysinfo(sysInfo) + return sysInfo.Uptime +} From b0aabb4cf01c374029a2ea4e7a2b90d6e318197e Mon Sep 17 00:00:00 2001 From: qiu-x Date: Sun, 14 Nov 2021 14:43:26 +0100 Subject: [PATCH 2/3] Fix the build on NetBSD --- internal/app/darktile/hinters/uptime.go | 3 ++- .../darktile/hinters/{uptime_linux.go => uptime_builtin.go} | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) rename internal/app/darktile/hinters/{uptime_linux.go => uptime_builtin.go} (80%) diff --git a/internal/app/darktile/hinters/uptime.go b/internal/app/darktile/hinters/uptime.go index e04e452d..78ba37b3 100644 --- a/internal/app/darktile/hinters/uptime.go +++ b/internal/app/darktile/hinters/uptime.go @@ -1,4 +1,5 @@ -//go:build cgo && (!linux || unix) +//go:build cgo && (freebsd || openbsd) + package hinters /* diff --git a/internal/app/darktile/hinters/uptime_linux.go b/internal/app/darktile/hinters/uptime_builtin.go similarity index 80% rename from internal/app/darktile/hinters/uptime_linux.go rename to internal/app/darktile/hinters/uptime_builtin.go index 5b806f09..484fb4dd 100644 --- a/internal/app/darktile/hinters/uptime_linux.go +++ b/internal/app/darktile/hinters/uptime_builtin.go @@ -1,3 +1,5 @@ +//go:build cgo && (linux || netbsd) + package hinters import ( From 9b8b9390e5398472cfce47f7b357bced71112337 Mon Sep 17 00:00:00 2001 From: qiu-x Date: Sun, 14 Nov 2021 14:48:49 +0100 Subject: [PATCH 3/3] Update Go version in workflows --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8ab071a0..0f4fae9c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '^1.16.6' + go-version: '^1.17' - run: go version - name: Release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9c407fa0..f280d5a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.16.x] + go-version: [1.17.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: