exec.Command run in background

2,566 views
Skip to first unread message

brad.rydzewski

unread,
Dec 16, 2011, 8:53:49 PM12/16/11
to golang-nuts
I'm trying to execute a command in Go
cmd := exec.Command(name, args...)
out, err := cmd.CombinedOutput()

I can execute most commands fine, but I need to execute a command that
runs in the background as a daemon

When I execute the command I get this error:
ERROR inherited fd 6 on anon_inode:[eventpoll]

I can execute from the command line and it works fine. I've tried to
execute the command from a shell script via Go, and I get the same
error. I'm looking through the code for answers, but was hoping that
perhaps someone in this group could offer suggestions

Thanks

Dave Cheney

unread,
Dec 16, 2011, 9:32:59 PM12/16/11
to brad.rydzewski, golang-nuts
Hello,

This doesn't look like a problem with exec package per se, however it
could be that a file descriptor from your Go program is leaking into
the child.

What is the program you are exec'ing ?

Cheers

Dave

Ian Lance Taylor

unread,
Dec 16, 2011, 9:40:39 PM12/16/11
to brad.rydzewski, golang-nuts
"brad.rydzewski" <brad.ry...@gmail.com> writes:

You didn't mention the OS you are using, but I'm going to guess that it
is GNU/Linux. I think the problem is that we are not marking the epoll
descriptor as CLOEXEC. Can you try
http://codereview.appspot.com/5494061 to see if it fixes your problem?

Ian

Message has been deleted

brad.rydzewski

unread,
Dec 17, 2011, 8:54:27 PM12/17/11
to golang-nuts
Ian,
Thanks for putting together a patch so quickly. I did quite a bit of
testing, and it absolutely solved the problem.
Any chance I will see this in the weekly tag any time soon? Thanks!

On Dec 16, 7:40 pm, Ian Lance Taylor <i...@google.com> wrote:

> descriptor as CLOEXEC.  Can you tryhttp://codereview.appspot.com/5494061to see if it fixes your problem?
>
> Ian

Brad Fitzpatrick

unread,
Dec 18, 2011, 2:15:02 AM12/18/11
to brad.rydzewski, golang-nuts
I'd like to understand why this bit you and it's never bit any other code that uses exec.  (at least, it's never bit me, and I've used exec for background stuff a fair bit)

Do you have a minimal case that fails?  This patch shouldn't go in without such a test in any case.

Ian Lance Taylor

unread,
Dec 19, 2011, 2:12:55 AM12/19/11
to Brad Fitzpatrick, brad.rydzewski, golang-nuts
Brad Fitzpatrick <brad...@golang.org> writes:

> I'd like to understand why this bit you and it's never bit any other code
> that uses exec. (at least, it's never bit me, and I've used exec for
> background stuff a fair bit)
>
> Do you have a minimal case that fails? This patch shouldn't go in without
> such a test in any case.

There is only going to be a problem when using the net package and
simultaneously using exec to run a command that checks for open file
descriptors other than 0, 1, and 2. That is not the common case; most
programs don't care if they are invoked with additional open file
descriptors.

Ian

Rob 'Commander' Pike

unread,
Dec 19, 2011, 11:40:13 AM12/19/11
to Ian Lance Taylor, Brad Fitzpatrick, brad.rydzewski, golang-nuts

On Dec 18, 2011, at 11:12 PM, Ian Lance Taylor wrote:

> Brad Fitzpatrick <brad...@golang.org> writes:
>
>> I'd like to understand why this bit you and it's never bit any other code
>> that uses exec. (at least, it's never bit me, and I've used exec for
>> background stuff a fair bit)
>>
>> Do you have a minimal case that fails? This patch shouldn't go in without
>> such a test in any case.
>
> There is only going to be a problem when using the net package and
> simultaneously using exec to run a command that checks for open file
> descriptors other than 0, 1, and 2. That is not the common case; most
> programs don't care if they are invoked with additional open file
> descriptors.

Perhaps the programs don't care, but I do. It's a nasty security hole. Off-topic but important.

-rob

Russ Cox

unread,
Dec 19, 2011, 11:50:14 AM12/19/11
to Ian Lance Taylor, Brad Fitzpatrick, brad.rydzewski, golang-nuts
The easiest way to test this would be to exec a program
and then open 100 files in a row and make sure you get
3-102.

Russ

Brad Fitzpatrick

unread,
Dec 19, 2011, 11:54:17 AM12/19/11
to r...@golang.org, Ian Lance Taylor, brad.rydzewski, golang-nuts
Yup, just sent out http://codereview.appspot.com/5490075

It fails currently.

Ian Lance Taylor

unread,
Dec 19, 2011, 12:09:28 PM12/19/11
to Rob 'Commander' Pike, Brad Fitzpatrick, brad.rydzewski, golang-nuts

Oh, sure, needs to be fixed, I'm just explaining why most people don't
notice this.

Ian

Reply all
Reply to author
Forward
0 new messages