All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linda Knippers <linda.knippers@hp.com>
To: selinux@tycho.nsa.gov
Subject: [PATCH] newrole: fix for newrole hanging on some serial consoles
Date: Thu, 22 Feb 2007 09:47:10 -0500	[thread overview]
Message-ID: <45DDACEE.20205@hp.com> (raw)


The following patch addresses a problem I experienced with newrole hanging
when run from a serial console when the console is configured using the
default /etc/inittab settings.  newrole would hang when re-opening the
tty device.  This patch causes newrole to mimic the behavior of agetty,
which opens the device with O_NONBLOCK and then turns the bit off before
execing the next program.  Changing /etc/inittab to use the -L option for
agetty will avoid the problem but that solution won't be obvious to anyone
experiencing the problem and it may introduce other issues.

This patch was tested with policycoreutils-newrole-1.33.12-5.el5 on RHEL5 RC1.

-- ljk


--- newrole.c   2007-02-20 13:32:46.000000000 -0500
+++ newrole.c.ljk2      2007-02-20 13:32:39.000000000 -0500
@@ -636,11 +636,12 @@ static int relabel_tty(const char *ttyn,
        }

        /* Re-open TTY descriptor */
-       fd = open(ttyn, O_RDWR);
+       fd = open(ttyn, O_RDWR|O_NONBLOCK);
        if (fd < 0) {
                fprintf(stderr, _("Error!  Could not open %s.\n"), ttyn);
                return fd;
        }
+       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);

        if (fgetfilecon(fd, &tty_con) < 0) {
                fprintf(stderr, _("%s!  Could not get current context "
@@ -1127,15 +1128,18 @@ int main(int argc, char *argv[])
                fprintf(stderr, _("Could not close descriptors.\n"));
                goto err_close_pam;
        }
-       fd = open(ttyn, O_RDONLY);
+       fd = open(ttyn, O_RDONLY|O_NONBLOCK);
        if (fd != 0)
                goto err_close_pam;
-       fd = open(ttyn, O_RDWR);
+       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
+       fd = open(ttyn, O_RDWR|O_NONBLOCK);
        if (fd != 1)
                goto err_close_pam;
-       fd = open(ttyn, O_RDWR);
+       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
+       fd = open(ttyn, O_RDWR|O_NONBLOCK);
        if (fd != 2)
                goto err_close_pam;
+       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);

        /*
         * Step 5:  Execute a new shell with the new context in `new_context'.


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

             reply	other threads:[~2007-02-22 14:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-22 14:47 Linda Knippers [this message]
2007-02-22 15:20 ` [PATCH] newrole: fix for newrole hanging on some serial consoles Linda Knippers
2007-02-22 16:07   ` Stephen Smalley

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=45DDACEE.20205@hp.com \
    --to=linda.knippers@hp.com \
    --cc=selinux@tycho.nsa.gov \
    /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.