Skip to content

Commit

Permalink
allow infinity on uint properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-mckay committed Aug 20, 2024
1 parent ee5bbc0 commit f6ff4f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ func controlHandler() http.HandlerFunc {

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(http.StatusOK)
response := controlResponse{Unit: unit, Username: username, Property: request.Property}
response.Property = request.Property
err = json.NewEncoder(w).Encode(response)
if err != nil {
slog.Error("unable to send encode response", "error", err.Error())
Expand Down Expand Up @@ -152,8 +150,8 @@ func transform(controlProp controlProperty) (systemd.Property, error) {
return systemd.Property{Name: controlProp.Name, Value: dbus.MakeVariant(val)}, err

case CPUQuotaPerSecUSec, MemoryMax, MemoryHigh:
if controlProp.Value == "-1" {
return systemd.Property{Name: controlProp.Name, Value: dbus.MakeVariant("-1")}, nil
if controlProp.Value == "infinity" {
return systemd.Property{Name: controlProp.Name, Value: dbus.MakeVariant("infinity")}, nil
}
val, err := strconv.ParseUint(controlProp.Value, 10, 64)
return systemd.Property{Name: controlProp.Name, Value: dbus.MakeVariant(val)}, err
Expand Down
19 changes: 19 additions & 0 deletions control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,22 @@ func TestGetUnit(t *testing.T) {
t.Fail()
}
}

func TestSetMemoryAccounting(t *testing.T) {
tc := controlProperty{Name: "CPUQuotaPerSecUSec", Value: "infinity"}

sysconn, err := newSystemdConn()
if err != nil {
t.Fatal(err.Error())
}
defer sysconn.conn.Close()
unit := "user-1000.slice"
property, err := transform(tc)
if err != nil {
t.Fatal(err.Error())
}
err = sysconn.conn.SetUnitPropertiesContext(sysconn.ctx, unit, true, property)
if err != nil {
t.Fatal(err.Error())
}
}

0 comments on commit f6ff4f2

Please sign in to comment.