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

Properly set the controlling console #10

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

gizahNL
Copy link
Contributor

@gizahNL gizahNL commented Jun 2, 2021

Issue number:
#9

Description of changes:
Call setsid to create a new session and make the calling process the session leader, then call the SIOCSTTY ioctl on the console FD to set it as the controlling console.

Testing done:
CLI testing as is documented in the issue

Terms of contribution:

By submitting this pull request, I agree that this contribution is licensed under the terms found in the LICENSE file.

}

if ret, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), unix.TIOCSCTTY, uintptr(0)); ret != 0 || err != 0 {
return fmt.Errorf("Unable to set controlling tty")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to do something with ret and/or err here depending on which condition got us to this point?

(For example, isn't err going to be an error object? Meaning it could be wrapped with something like fmt.Errorf("Unable to set controlling tty: %w", err)?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I should ;) err is an errno, and that could be wrapped as well.
I think ret is actually safe to ignore, because I think errno would always be set when ret would be non zero

Copy link
Contributor Author

@gizahNL gizahNL Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with returning err instead of formatting, as that is what the rest of that function does as well.

For FreeBSD it's required to become session leader of the process group
before a console can be set as controlling, furthermore it's required
to call TIOCSTTY on the console FD to actually set it as controlling.
Copy link
Owner

@samuelkarp samuelkarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants