[BusyBox] busybox-0.60.5 :: tcsetpgrp() returns -1 ( errno = EPERM ) in lash.c

Jayush Luniya jayush.luniya at codito.com
Fri May 7 14:15:53 UTC 2004

I am using the busybox-0.60.5 with uClinux on a processor without an MMU
with the following configuration option enabled.

Also vfork() is used instead of fork() as there is no MMU unit.
However whenever I run a command on the shell the following error message
is displayed:

 # ls
lost+found  dev         tmp         sbin        bin
ls: tcsetpgrp: Operation not permitted

This happens due to the following call in function insert_job() in lash.c
tcsetpgrp() here returns -1 and sets errno = EPERM.

if (tcsetpgrp(shell_terminal, newjob->pgrp) && errno != ENOTTY)
On further going thru the source code of busybox and the kernel source I
could figure out what the problem is.

The tcsetpgrp() here is setting shell's pgrp to that of the first process
of the new job group. But by that time the child process has terminated
and hence it sets errno to EPERM ( -1 ) .  The child process terminates
before the parent bcoz I am using vfork() instead of fork() and due to
the execve() function is not called by the child and hence the parent does
not get scheduled unless the child terminates.

So do I need to have tcsetpgrp() at this case? I think the problem can be
solved by calling waitpid() and if it does not return with errno = ECHILD
( ie Child hasnt terminated yet ) then only calling  tcsetpgrp().

if( (waitpid((newjob->pgrp), &status , WNOHANG) >= 0) && errno !=ECHILD) {
     if (tcsetpgrp(shell_terminal, newjob->pgrp) && errno != ENOTTY)

It works properly with this. I would like to know whether this is correct
solution. A similar prolem also exists in hash.c

More information about the busybox mailing list