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/windows: add ExitWindowsEx #34271

Closed
bruceadowns opened this issue Sep 12, 2019 · 12 comments
Closed

x/sys/windows: add ExitWindowsEx #34271

bruceadowns opened this issue Sep 12, 2019 · 12 comments

Comments

@bruceadowns
Copy link

What version of Go are you using (go version)?

C:\Users\Bruce Downs>go version
go version go1.13 windows/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
C:\Users\Bruce Downs>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Bruce Downs\AppData\Local\go-build
set GOENV=C:\Users\Bruce Downs\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Bruce Downs\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\BRUCED~1\AppData\Local\Temp\go-build181801726=/tmp/go-build -gno-record-gcc-switches

What did you do?

Tried to find windows reboot functionality in the standard library, but it was only found for linux.

What did you expect to see?

For Windows to have parity capability as linux.

import "golang.org/x/sys/unix"
unix.Reboot(...)

What did you see instead?

Mention of ExitWindowsEx is missing in the standard library.

The following api will need to be added to /x/sys/windows:
ExitWindowsEx

The following apis will need to be moved from internal/syscall/windows:
LookupPrivilegeValue
AdjustTokenPrivileges

along with their various const dependencies.

@mdempsky mdempsky changed the title Add parity reboot support on windows as on linux x/sys/windows: add ExitWindowsEx Sep 12, 2019
@gopherbot gopherbot added this to the Unreleased milestone Sep 12, 2019
@mdempsky
Copy link
Member

Not sure to what extent x/sys/windows hopes to cover the entire Windows API. /cc @alexbrainman

Can't you use something like windows.NewLazySystemDLL("user32.dll").NewProc("ExitWindowsEx")?

@bruceadowns
Copy link
Author

Can't you use something like windows.NewLazySystemDLL("user32.dll").NewProc("ExitWindowsEx")?

Yup, I could certainly do something like that.

I was looking to extend the standard library for the better on windows.

Currently, I have to do a hodgepodge of the following to accomplish my goal:

windows.OpenProcessToken()
LookupPrivilegeValue.Call()
AdjustTokenPrivileges.Call()
syscall.GetLastError()
ExitWindowsEx.Call()

@alexbrainman
Copy link
Member

I was looking to extend the standard library for the better on windows.

Sounds good to me. What exactly do you propose?

Adding @zx2c4, because he makes most changes to golang.org/x/sys/windows lately.

Alex

@zx2c4
Copy link
Contributor

zx2c4 commented Sep 15, 2019

I've got some plans to add some token manipulation functions. I'll try to add ExitWindowsEx too.

@bruceadowns
Copy link
Author

I was looking to extend the standard library for the better on windows.

Sounds good to me. What exactly do you propose?

Thanks @alexbrainman and @zx2c4!

My initial plan was to take the following calls:

windows.OpenProcessToken()
LookupPrivilegeValue.Call()
AdjustTokenPrivileges.Call()
syscall.GetLastError()
ExitWindowsEx.Call()

And make them look more like:

windows.OpenProcessToken()
windows.LookupPrivilegeValue()
windows.AdjustTokenPrivileges()
windows.GetLastError()
windows.ExitWindowsEx()

Some would need to be added and some would need to be ported from internal/syscall/windows. This would also include adding/moving the relevant constants.

This will offer a more streamline experience similar to https://docs.microsoft.com/en-us/windows/win32/shutdown/how-to-shut-down-the-system.

@zx2c4
Copy link
Contributor

zx2c4 commented Sep 15, 2019

windows.GetLastError()

This is already returned by syscall.SyscallN as one of its return values.

@alexbrainman
Copy link
Member

My initial plan was to take the following calls:

Try and write it yourself. And show your code, if you are not sure. We will correct it, if need be.

Maybe we could put it all into golang.org/x/sys/windows.Reboot function (or similar name). Maybe we could even put it into golang.org/x/sys.Reboot function, if there is enough interest.

Alex

@gopherbot
Copy link

Change https://golang.org/cl/195497 mentions this issue: windows: add various functions for shutting down and logging out

@zx2c4
Copy link
Contributor

zx2c4 commented Sep 15, 2019

@bruceadowns let me know if that implementation is suitable.

@zx2c4
Copy link
Contributor

zx2c4 commented Sep 15, 2019

Maybe we could put it all into golang.org/x/sys/windows.Reboot function (or similar name).

This is hard to do because different contexts require different calls. We could probably detect an interactive session and try to convert the arguments between the different types of calls, but that doesn't seem trivial.

Maybe we could even put it into golang.org/x/sys.Reboot function, if there is enough interest.

Also a cool idea, but isn't shutdown somewhat different on different platforms, which have different notions of sessions and window stations and shutdown states and stuff?

@bruceadowns
Copy link
Author

@bruceadowns let me know if that implementation is suitable.

Sweet! I'll look at it later today.

@alexbrainman
Copy link
Member

but isn't shutdown somewhat different on different platforms, which have different notions of sessions and window stations and shutdown states and stuff?

I would not know. I am not really a Windows expert. Forget my suggestion.

Alex

@golang golang locked and limited conversation to collaborators Sep 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants