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

os: manually instantiated os.Process methods return EBADF #67634

Closed
prattmic opened this issue May 24, 2024 · 1 comment
Closed

os: manually instantiated os.Process methods return EBADF #67634

prattmic opened this issue May 24, 2024 · 1 comment
Assignees
Milestone

Comments

@prattmic
Copy link
Member

package main

import (
        "fmt"
        "os"
        "syscall"
)

func main() {
        p := &os.Process{Pid: os.Getpid()}
        err := p.Signal(syscall.SIGWINCH)
        fmt.Println("error:", err)
}

With 1.22 this works without issue. As of https://go.dev/cl/570036, this prints error: bad file descriptor.

The problem is that 0 is a valid value of os.Process.handle, so the Signal method tries to use it as a pidfd.

This is easy to fix with an additional field to report whether handle is initialized (N.B. that handle could really be FD 0, so we can't just look for 0). I will send a CL.

(As far as I know, this form of using os.Process has never worked on Windows, as it always uses the handle field.)

cc @kolyshkin

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/588675 mentions this issue: os: overhaul handling of PID vs pidfd within Process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants