Skip to content

Commit

Permalink
[terminal/tty] Improve check for systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed May 2, 2024
1 parent 84a11a0 commit 943922c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `[initsystem/sdnotify]` Added new package for sending messages to systemd
- `[support/deps]` Updated for compatibility with the latest version of [depsy](https://kaos.sh/depsy)
- `[terminal/tty]` Improved check for systemd

### 12.120.0

Expand Down
3 changes: 1 addition & 2 deletions terminal/tty/tty_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func IsFakeTTY() bool {

// IsSystemd returns true if process started by systemd
func IsSystemd() bool {
return os.Getenv("INVOCATION_ID") != "" ||
os.Getenv("SYSTEMCTL_IGNORE_DEPENDENCIES") != ""
return os.Getppid() == 1
}

// ////////////////////////////////////////////////////////////////////////////////// //
7 changes: 1 addition & 6 deletions terminal/tty/tty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ func (s *TTYSuite) TestIsTTY(c *C) {
}

func (s *TTYSuite) TestIsSystemd(c *C) {
os.Setenv("INVOCATION_ID", "")
os.Setenv("SYSTEMCTL_IGNORE_DEPENDENCIES", "")
c.Assert(IsSystemd(), Equals, false)
os.Setenv("INVOCATION_ID", "5d0149bfa2c34b79bccb13074001eb20")
c.Assert(IsSystemd(), Equals, true)
os.Setenv("INVOCATION_ID", "")
IsSystemd()
}

func (s *TTYSuite) TestIsTMUX(c *C) {
Expand Down

0 comments on commit 943922c

Please sign in to comment.