All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Hejtmanek <xhejtman@mail.muni.cz>
To: linux-kernel@vger.kernel.org
Subject: 2.6.0-test11 - fork, dup, dup2 oddities
Date: Sun, 7 Dec 2003 22:03:05 +0100	[thread overview]
Message-ID: <20031207210305.GE13201@mail.muni.cz> (raw)

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

             reply	other threads:[~2003-12-07 21:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-07 21:03 Lukas Hejtmanek [this message]
2003-12-08  0:46 ` 2.6.0-test11 - fork, dup, dup2 oddities Greg KH
2003-12-08  1:11   ` Lukas Hejtmanek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031207210305.GE13201@mail.muni.cz \
    --to=xhejtman@mail.muni.cz \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.