Skip to content

x/sys/unix: Sysctl doesn't supporting writing values #8757

@songgao

Description

@songgao
Hello,

This is not really reporting defects but more like a feature request.

In syscall package, or go.sys package, Sysctl is defined as: 

func Sysctl(name string) (value string, err error)

It provides a way to read values through sysctl, but makes it impossible to write/update
values. Internally, it uses "sysctl" defined in each particular OS / ARCH. For
example, (from zsyscall_freebsd_amd64.go):

func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err
error)

It would be nice if it can be exported in some way because this is essentially the same
interface as defined in BSD systems. e.g. https://www.freebsd.org/cgi/man.cgi?sysctl(3)

int sysctl(const int *name, u_int namelen, void *oldp, size_t *oldlenp, const void
*newp, size_t newlen);
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp, const void *newp, size_t
newlen);

Can we provide a similar set of functions in go.sys that provides full sysctl support
(both read / write)? If go.sys is not frozen yet, maybe it's a good idea to use the
function names used in most BSD systems, in which case current Sysctl will need to be
renamed to, e.g., SysctlRead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions