chiark / gitweb /
bring std(in|out|err) fd's in a sane state
authorKay Sievers <kay.sievers@suse.de>
Thu, 18 Aug 2005 11:07:15 +0000 (13:07 +0200)
committerKay Sievers <kay.sievers@suse.de>
Thu, 18 Aug 2005 11:07:15 +0000 (13:07 +0200)
If the kernel forks us as an usermodhelper, we don't have any of
the standard fd's and the first open() will start with fd=0.
This is inherited to all forked childs and confuses later forked
helpers where we want to read from a pipe connected to the helpers
stdout/stderr.

  # ls -l /proc/$(pidof udevd)/fd
  total 6
  dr-x------  2 root root  0 2005-08-18 12:44 .
  dr-xr-xr-x  4 root root  0 2005-08-18 12:44 ..
  lrwx------  1 root root 64 2005-08-18 12:44 0 -> /dev/null
  lrwx------  1 root root 64 2005-08-18 12:44 1 -> socket:[1274617]
  lr-x------  1 root root 64 2005-08-18 12:44 2 -> pipe:[1274618]
  l-wx------  1 root root 64 2005-08-18 12:44 3 -> pipe:[1274618]
  lrwx------  1 root root 64 2005-08-18 12:44 4 -> socket:[1274619]
  lrwx------  1 root root 64 2005-08-18 12:44 5 -> socket:[1274620]

Ouch! This will obviously not redirect sterr, it will kill the pipe
we established between the parent and the child:

  devnull = open("/dev/null", O_RDWR);
  dup2(devnull, STDERR_FILENO);

Signed-off-by: Kay Sievers <kay.sievers@suse.de>

No differences found