From f6ff4f2e04325d8a465d23b72b1e3512768aeaa7 Mon Sep 17 00:00:00 2001 From: jay-mckay Date: Tue, 20 Aug 2024 17:08:56 -0600 Subject: [PATCH] allow infinity on uint properties --- control.go | 6 ++---- control_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/control.go b/control.go index 639156f..f876d6d 100644 --- a/control.go +++ b/control.go @@ -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()) @@ -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 diff --git a/control_test.go b/control_test.go index 38922f3..32a24e3 100644 --- a/control_test.go +++ b/control_test.go @@ -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()) + } +}