2.6.0-test11 - fork, dup, dup2 oddities

From: Lukas Hejtmanek
Date: Sun Dec 07 2003 - 16:14:57 EST


Hello,

I have 2.6.0-test11 kernel. I try to run pppd with pppd call gprs. In gprs
I have device /dev/ttyUSB0. It fails. I've found that it happened ONLY if I use
detach option.

I have tried /dev/ircomm0 as well with the same result. However with /dev/ttySL0
(that is symlink to pty created by modem driver) it works ok with or withoud
detach option.

I've tried to debug pppd and discovered failing code:

/* make sure fds 0, 1, 2 are occupied */
while ((fd = dup(in)) >= 0) {
if (fd > 2) {
close(fd);
break;
}
}

/* dup in and out to fds > 2 */
{
int fd1 = in, fd2 = out, fd3 = log_to_fd;

in = dup(in);
out = dup(out);
if (log_to_fd >= 0) {
errfd = dup(log_to_fd);
} else {
errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600);
}
close(fd1);
close(fd2);
close(fd3);
}

/* close fds 0 - 2 and any others we can think of */
close(0);
close(1);
close(2);
if (the_channel->close)
(*the_channel->close)();
closelog();
close(fd_devnull);

/* dup the in, out, err fds to 0, 1, 2 */
dup2(in, 0);
close(in);
dup2(out, 1);
close(out);
if (errfd >= 0) {
dup2(errfd, 2);
close(errfd);
}

setuid(uid);
if (getuid() != uid) {
error("setuid failed");
exit(1);
}
setgid(getgid());
execl("/bin/sh", "sh", "-c", program, (char *)0);
error("could not exec /bin/sh: %m");
exit(99);

execl exit with code 02.

program is equal to:
/usr/sbin/chat -V -s '' ATZ OK 'AT+CGDCONT=1,\"IP\",\"ointernet\"' OK 'ATD*99***1#' CONNECT

in=10, out=10 (it is opened /dev/ttyUSB0)

It works OK with 2.4.22 or if do not use previous fork.

--
Lukáš Hejtmánek
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/