Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
dbef0711
Commit
dbef0711
authored
Aug 09, 2010
by
Alex Brainman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: fix ForkExec() handling of envv == nil
R=golang-dev, r CC=golang-dev
https://golang.org/cl/1913047
parent
893fdbbe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
0 deletions
+26
-0
exec_test.go
src/pkg/exec/exec_test.go
+23
-0
exec.go
src/pkg/os/exec.go
+3
-0
No files found.
src/pkg/exec/exec_test.go
View file @
dbef0711
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"io"
"io"
"io/ioutil"
"io/ioutil"
"testing"
"testing"
"os"
)
)
func
TestRunCat
(
t
*
testing
.
T
)
{
func
TestRunCat
(
t
*
testing
.
T
)
{
...
@@ -84,3 +85,25 @@ func TestMergeWithStdout(t *testing.T) {
...
@@ -84,3 +85,25 @@ func TestMergeWithStdout(t *testing.T) {
t
.
Fatal
(
"close:"
,
err
)
t
.
Fatal
(
"close:"
,
err
)
}
}
}
}
func
TestAddEnvVar
(
t
*
testing
.
T
)
{
err
:=
os
.
Setenv
(
"NEWVAR"
,
"hello world"
)
if
err
!=
nil
{
t
.
Fatal
(
"setenv:"
,
err
)
}
cmd
,
err
:=
Run
(
"/bin/sh"
,
[]
string
{
"sh"
,
"-c"
,
"echo $NEWVAR"
},
nil
,
""
,
DevNull
,
Pipe
,
DevNull
)
if
err
!=
nil
{
t
.
Fatal
(
"run:"
,
err
)
}
buf
,
err
:=
ioutil
.
ReadAll
(
cmd
.
Stdout
)
if
err
!=
nil
{
t
.
Fatal
(
"read:"
,
err
)
}
if
string
(
buf
)
!=
"hello world
\n
"
{
t
.
Fatalf
(
"read: got %q"
,
buf
)
}
if
err
=
cmd
.
Close
();
err
!=
nil
{
t
.
Fatal
(
"close:"
,
err
)
}
}
src/pkg/os/exec.go
View file @
dbef0711
...
@@ -16,6 +16,9 @@ import (
...
@@ -16,6 +16,9 @@ import (
// will cause the child to have no open file descriptor with that index.
// will cause the child to have no open file descriptor with that index.
// If dir is not empty, the child chdirs into the directory before execing the program.
// If dir is not empty, the child chdirs into the directory before execing the program.
func
ForkExec
(
argv0
string
,
argv
[]
string
,
envv
[]
string
,
dir
string
,
fd
[]
*
File
)
(
pid
int
,
err
Error
)
{
func
ForkExec
(
argv0
string
,
argv
[]
string
,
envv
[]
string
,
dir
string
,
fd
[]
*
File
)
(
pid
int
,
err
Error
)
{
if
envv
==
nil
{
envv
=
Environ
()
}
// Create array of integer (system) fds.
// Create array of integer (system) fds.
intfd
:=
make
([]
int
,
len
(
fd
))
intfd
:=
make
([]
int
,
len
(
fd
))
for
i
,
f
:=
range
fd
{
for
i
,
f
:=
range
fd
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment