-
Notifications
You must be signed in to change notification settings - Fork 309
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
dbus: add GetUnitProcessesContext to list any unit's running processes #379
base: main
Are you sure you want to change the base?
Changes from 3 commits
c4fb696
5a40f4c
cde39f9
a338cfb
020c50b
1acf322
de54554
c6b12d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,12 @@ import ( | |
"path" | ||
"path/filepath" | ||
"reflect" | ||
"strings" | ||
"syscall" | ||
"testing" | ||
"time" | ||
|
||
"github.com/coreos/go-systemd/v22/util" | ||
"github.com/godbus/dbus/v5" | ||
) | ||
|
||
|
@@ -1657,3 +1659,41 @@ func TestFreezer(t *testing.T) { | |
|
||
runStopUnit(t, conn, TrUnitProp{target, nil}) | ||
} | ||
|
||
func TestListUnitProcesses(t *testing.T) { | ||
target, err := util.GetRunningSlice() // This test should still pass even if the cmd is spawned in a child unit (i.e. session Scope) of the current Slice | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
conn := setupConn(t) | ||
defer conn.Close() | ||
|
||
cmd := exec.Command("/bin/sleep", "400") | ||
err = cmd.Start() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer cmd.Process.Kill() | ||
|
||
pid := uint64(cmd.Process.Pid) | ||
|
||
ctx := context.Background() | ||
processes, err := conn.GetUnitProcessesContext(ctx, target) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
exists := false | ||
for _, p := range processes { | ||
if p.PID == pid && strings.HasPrefix(p.Command, "/bin/sleep") { | ||
exists = true | ||
t.Logf("Found %v\n", p) | ||
} | ||
} | ||
|
||
if !exists { | ||
t.Errorf("PID %d ('/bin/sleep 400') not found in current Slice unit's process list", pid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this test is failing on some CI runs. I suspect there is a race between spawning the child |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can directly call this
GetUnitProcesses
, plus avoid the separate*Internal
helper.