--- shadow-4.1.5/src/su.c~	2011-11-13 17:27:15.000000000 +0000
+++ shadow-4.1.5/src/su.c	2012-03-11 22:19:16.317844637 +0000
@@ -1089,10 +1089,12 @@
 		/* Otherwise, we cannot use setsid */
 		int fd = open ("/dev/tty", O_RDWR);
 
+		if ((isatty(fd)) == 1) {
 		if (fd >= 0) {
 			err = ioctl (fd, TIOCNOTTY, (char *) 0);
 			(void) close (fd);
 		}
+		} else {err=0;} /* we haven't a controlling terminal at all */
 #endif				/* USE_PAM */
 
 		if (-1 == err) {
