slang-users mailing list

[2007 Date Index] [2007 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Re: mc sets process group differently from shell; forgets to close fd# 3


On Fri, 20 Apr 2007, Denis Vlasenko wrote:

Hi mc people,

If you compile and run the following program
under shell and under mc...

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
       int i, numfd = open("/dev/null", O_RDONLY);

       printf("pid=%d\n", getpid());
       printf("ppid=%d\n", getppid());
       printf("tty_pgrp=%d\n", (int)tcgetpgrp(0));
       printf("task_pgrp=%d\n", (int)getpgrp());
       for (i = 0; i < numfd; i++) {
               printf("fd# %d: '%s'\n", i, ttyname(i));
       }
       return 0;
}

you will see the following:

bash-3.2# ./z
pid=8183
ppid=8181
tty_pgrp=8183    <========== child is in its own process group
task_pgrp=8183   <==========
fd# 0: '/dev/pts/4'
fd# 1: '/dev/pts/4'
fd# 2: '/dev/pts/4'

bash-3.2# echo $$ ; exec mc
8181

# ./z
pid=8212
ppid=8181
tty_pgrp=8181    <========== child is in mc's process group
task_pgrp=8181   <========== child is in mc's process group
fd# 0: '/dev/pts/4'
fd# 1: '/dev/pts/4'
fd# 2: '/dev/pts/4'
fd# 3: '/dev/tty'  <=== ??!

[...]

Big one (actually, I think it's a bug): stray fd# opened
to controlling terminal.

The descriptor to /dev/tty is created by S-Lang in SLang_init_tty().
Maybe it would make sense to mark it FD_CLOEXEC ?

Thanks!



[2007 date index] [2007 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]