Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#1799 closed bug (fixed)

sh: child setpgid (216 to 215): Operation not allowed

Reported by: jonas.kirilla Owned by: bonefish
Priority: normal Milestone: R1
Component: System/Kernel Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

setpgid() often fails for shell builtin 'echo' when using pipes.

~>echo "blarg" | wc
sh: child setpgid (216 to 215): Operation not allowed
      1       1       6
~>echo "blarg" | wc
sh: child setpgid (218 to 217): Operation not allowed
      1       1       6
~>echo "blarg" | wc
      1       1       6
~>echo "blarg" | w
      1       1       6
~>echo "blarg" | wc
      1       1       6
~>echo "blarg" | wc
sh: child setpgid (226 to 225): Operation not allowed
      1       1       6
~>echo "blarg" | wc
sh: child setpgid (228 to 227): Operation not allowed
      1       1       6

Maybe it's got something to do with http://dev.haiku-os.org/changeset/22185

Change History (7)

comment:1 by bonefish, 16 years ago

Owner: changed from axeld to bonefish
Status: newassigned

comment:2 by jackburton, 16 years ago

This seems to be fixed.

comment:3 by jackburton, 16 years ago

No, sorry, I talked too fast. It's just not easily reproducible.

comment:4 by bonefish, 16 years ago

Yep, my changes in hrev24041 made it less likely (the race conditions in wait_for_child() are gone), but it won't be fixed until the TODO I added in hrev24042 is dealt with (keeping process groups with only zombies in them alive until all zombies are reaped). Will do that when I find a little more time.

comment:5 by bonefish, 16 years ago

Resolution: fixed
Status: assignedclosed

Fixed in hrev24335.

in reply to:  6 comment:7 by bonefish, 16 years ago

Replying to jonas.kirilla:

I can still reproduce it with hrev24336. :/

As it looks to me, this only happens when hitting Ctrl-C while the shell is in the middle of setting up the pipe. For the first process setpgid() has already been done and it has been given the terminal. Hitting Ctrl-C right then will cause a SIGINT to be sent to the new process group and kill all child processes that have already joined the group. Since the shell blocks SIGCHLD only while creating a child process, as soon as it is unblocked, the SIGCHLD handler is invoked, which does a waitpid() and thus causes the process group to be deleted for good. Afterwards the shell continues to create the remaining processes of the pipe and setpgid() will fail for them.

This seems to be a (design?) problem in bash rather than a bug in Haiku. At least I don't see what we could possibly be doing wrong. The original bug seems to be fixed at any rate.

Note: See TracTickets for help on using tickets.