Skip to contentSkip to conversation

newrole: fix for newrole hanging on some serial consoles

PATCH In review Linda Knippers 2 participants 3 messages Feb 22, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 newrole: fix for newrole hanging on some serial consoles

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.ljk2 2007-02-20 13:32:39.000000000 -0500 renamed from newrole.c 2007-02-20 13:32:46.000000000 -0500 +8 -4
@@ -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 [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw

Reposting to fix a whitespace problem and adjust the patch location.

newrole/newrole.c +8 -4
@@ -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'. 
#2 lore raw
Quoted 3 lines · Linda Knippers

Reposting to fix a whitespace problem and adjust the patch location.

Thanks, merged into -stable and -trunk.

Quoted 39 lines
newrole/newrole.c +8 -4
@@ -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'. 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.