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

Fix reOpenDevNull #309

Merged
merged 1 commit into from
Oct 1, 2015
Merged

Fix reOpenDevNull #309

merged 1 commit into from
Oct 1, 2015

Conversation

chenchun
Copy link
Contributor

We should open /dev/null with os.O_RDWR, otherwise it won't be
possible written to it

Signed-off-by: Chun Chen ramichen@tencent.com

Found this bug when I tried to set docker containers' stdout/stderr to null if launching with --log-drive=none.
See the following simple program. It won't work without os.O_RDWR.

func main() {
    if err := reOpenDevNull(); err != nil {
        fmt.Println("Error reOpenDevNull ", err, "\n")
    }
    fmt.Println(syscall.Exec("/bin/echo", []string{"echo"}, os.Environ()))
}

func reOpenDevNull() error {
    file, err := os.Open("/dev/null")
//  file, err := os.OpenFile("/dev/null", os.O_RDWR, 0) // should open it with os.O_RDWR
    if err != nil {
        return fmt.Errorf("Failed to open /dev/null - %s", err)
    }
    defer file.Close()
    for fd := 1; fd < 3; fd++ {
        if err := syscall.Dup3(int(file.Fd()), fd, 0); err != nil {
            return err
        }
    }
    return nil
}

We should open /dev/null with os.O_RDWR, otherwise it won't be
possible writen to it

Signed-off-by: Chun Chen <ramichen@tencent.com>
@crosbymichael
Copy link
Member

LGTM

1 similar comment
@LK4D4
Copy link
Contributor

LK4D4 commented Oct 1, 2015

LGTM

LK4D4 added a commit that referenced this pull request Oct 1, 2015
@LK4D4 LK4D4 merged commit 4d5079b into opencontainers:master Oct 1, 2015
@chenchun chenchun deleted the fix_reOpenDevNull branch October 1, 2015 04:42
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
config: qualify the name of the version field
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Sep 8, 2017
This reverts commit 0f25f18, opencontainers#253.
Now that we're on to 1.0, we don't need to talk about 0.x.  And the
lack of 0.x backwards compatability is covered by SemVer 2.0 section 4
[1]:

  Major version zero (0.y.z) is for initial development.  Anything may
  change at any time.  The public API should not be considered stable.

so removing the echo from our spec doesn't actually change anything.

The conflict is due to 4e63ee0 (config: qualify the name of the
version field, 2016-01-13, opencontainers#309), and only impacted the context and
line-wrapping around the sentence I'm removing.

Conflicts:
	config.md

[1]: http://semver.org/spec/v2.0.0.html

Signed-off-by: W. Trevor King <wking@tremily.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants