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
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

# ./z
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 ?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]