golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.86k stars 17.52k forks source link

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

Open songgao opened 10 years ago

songgao commented 10 years ago
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.
ianlancetaylor commented 10 years ago

Comment 1:

Labels changed: added repo-sys, release-none.

Status changed to Accepted.

songgao commented 9 years ago

Comment 2:

I'd like to at that, current form of Sysctl only supports string values. If a sysctl
value is integer (e.g. machdep.tsc_freq) , it would be interpreted (not parsed) as
string.
songgao commented 9 years ago

Kudos to the migrating robots :D

I wonder if this issue is best to be in golang/sys now?

ianlancetaylor commented 9 years ago

Yes, this is for the sys subrepo. As Andrew said in his e-mail to golang-dev, we are using this single issue tracker for the subrepos as well.

songgao commented 9 years ago

Got it. Thanks @ianlancetaylor