Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/unix: unix.Klogctl does not allow access to len arg #34672

Closed
hugelgupf opened this issue Oct 3, 2019 · 5 comments
Closed

x/sys/unix: unix.Klogctl does not allow access to len arg #34672

hugelgupf opened this issue Oct 3, 2019 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Milestone

Comments

@hugelgupf
Copy link
Contributor

Linux sys_syslog looks like this:

int syslog(int type, char *buf, int len);

In Go's x/sys/unix, it's this

func Klogctl(typ int, buf []byte) (n int, err error)
// = syslog(typ, buf, len(buf))

That's kinda lame, because the len arg is not only used for the length, as you can see in the man page:

SYSLOG_ACTION_CONSOLE_LEVEL (8)
              The call sets console_loglevel to the value given in len,
              which must be an integer between 1 and 8 (inclusive).  The
              kernel silently enforces a minimum value of
              minimum_console_loglevel for len.  See the log level section
              for details.  The bufp argument is ignored.

So now you, either you gotta construct the unix.Syscall yourself or trick Klogctl into passing the right length:

unix.Klogctl(8, []byte{1, 2}) // Set console level 2!
// Yah ok this is silly

Perhaps there should be another function like this?

func Klogset(typ int, arg int) error
// = syslog(typ, nullptr, arg)
@gopherbot gopherbot added this to the Unreleased milestone Oct 3, 2019
@hugelgupf
Copy link
Contributor Author

Also, unix is missing const declarations for the typ argument:

const (                                                                                                                                                               
         SYSLOG_ACTION_READ_ALL      = 3                                                                                                                              
         SYSLOG_ACTION_READ_CLEAR    = 4                                                                                                                              
         SYSLOG_ACTION_CLEAR         = 5               
// etc                                                                                                               
         SYSLOG_ACTION_CONSOLE_LEVEL = 8                                                                                                                              
)   

@tklauser
Copy link
Member

tklauser commented Oct 3, 2019

Adding Klogset (and the missing const declarations) as suggested sounds good to me. Want to send a CL?

@tklauser tklauser added NeedsFix The path to resolution is known, but the work has not been done. OS-Linux labels Oct 3, 2019
@clickyotomy
Copy link

Hello! Is this up for grabs? I'd like to take it up, if that's OK.

@hugelgupf
Copy link
Contributor Author

Do it!

@gopherbot
Copy link

Change https://golang.org/cl/199278 mentions this issue: x/sys/unix: Add Klogset and related SYSLOG_ACTION_ constants

@golang golang locked and limited conversation to collaborators Oct 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Linux
Projects
None yet
Development

No branches or pull requests

4 participants