Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make getting the up-time more portable across unix-like systems #326

Merged
merged 3 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions internal/app/darktile/hinters/hint_dmesg_timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"regexp"
"strconv"
"strings"
"syscall"
"time"

"github.com/liamg/darktile/internal/app/darktile/termutil"
Expand Down Expand Up @@ -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)
}
23 changes: 23 additions & 0 deletions internal/app/darktile/hinters/uptime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build cgo && (freebsd || openbsd)

package hinters

/*
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/timespec.h>


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)
}
13 changes: 13 additions & 0 deletions internal/app/darktile/hinters/uptime_builtin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build cgo && (linux || netbsd)

package hinters

import (
"syscall"
)

func getUptime() int64 {
sysInfo := &syscall.Sysinfo_t{}
_ = syscall.Sysinfo(sysInfo)
return sysInfo.Uptime
}