Compare commits

...

3 Commits

Author SHA1 Message Date
f1979375cd
add sponsorship 2021-07-05 21:08:33 -07:00
4e38d03629
move panic from init to exec 2021-06-06 04:55:07 -07:00
701893ebbd
Properly return the zero time for invalid timestamps 2021-05-17 10:59:09 -07:00
3 changed files with 21 additions and 3 deletions

12
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,12 @@
# These are supported funding model platforms
github: taigrr # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@ -15,11 +15,11 @@ func GetStartTime(ctx context.Context, unit string, opts Options) (time.Time, er
value, err := Show(ctx, unit, properties.ExecMainStartTimestamp, opts) value, err := Show(ctx, unit, properties.ExecMainStartTimestamp, opts)
if err != nil { if err != nil {
return time.Unix(0, 0), err return time.Time{}, err
} }
// ExecMainStartTimestamp returns an empty string if the unit is not running // ExecMainStartTimestamp returns an empty string if the unit is not running
if value == "" { if value == "" {
return time.Unix(0, 0), ErrUnitNotActive return time.Time{}, ErrUnitNotActive
} }
return time.Parse(dateFormat, value) return time.Parse(dateFormat, value)
} }

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"log"
"os/exec" "os/exec"
"regexp" "regexp"
) )
@ -15,7 +16,9 @@ const killed = 130
func init() { func init() {
path, err := exec.LookPath("systemctl") path, err := exec.LookPath("systemctl")
if err != nil { if err != nil {
panic(ErrNotInstalled) log.Printf("%v", ErrNotInstalled)
systemctl = ""
return
} }
systemctl = path systemctl = path
} }
@ -30,6 +33,9 @@ func execute(ctx context.Context, args []string) (string, string, int, error) {
warnings string warnings string
) )
if systemctl == "" {
panic(ErrNotInstalled)
}
cmd := exec.CommandContext(ctx, systemctl, args...) cmd := exec.CommandContext(ctx, systemctl, args...)
cmd.Stdout = &stdout cmd.Stdout = &stdout
cmd.Stderr = &stderr cmd.Stderr = &stderr