All of lore.kernel.org
 help / color / mirror / Atom feed
* 2.6.0-test11 - fork, dup, dup2 oddities
@ 2003-12-07 21:03 Lukas Hejtmanek
  2003-12-08  0:46 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Lukas Hejtmanek @ 2003-12-07 21:03 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-12-08  1:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-07 21:03 2.6.0-test11 - fork, dup, dup2 oddities Lukas Hejtmanek
2003-12-08  0:46 ` Greg KH
2003-12-08  1:11   ` Lukas Hejtmanek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.