func testSetfilecon(t *testing.T) { if selinux.SelinuxEnabled() { tmp := "selinux_test" out, _ := os.OpenFile(tmp, os.O_WRONLY, 0) out.Close() err := selinux.Setfilecon(tmp, "system_u:object_r:bin_t:s0") if err != nil { t.Log("Setfilecon failed") t.Fatal(err) } os.Remove(tmp) } }
// SetFileLabel modifies the "path" label to the specified file label func SetFileLabel(path string, fileLabel string) error { if selinux.SelinuxEnabled() && fileLabel != "" { return selinux.Setfilecon(path, fileLabel) } return nil }