diff --git a/main.c b/main.c
index 95bd7cb..5418e97 100644
--- a/main.c
+++ b/main.c
@@ -3731,7 +3731,8 @@ spawnXTerm(XtermWidget xw)
SysError(ERROR_OPPTSNAME);
}
#ifdef I_PUSH
- else if (ioctl(ptyfd, I_PUSH, "ptem") < 0) {
+ else if ((ioctl(ptyfd, I_FIND, "ptem") == 0) &&
+ (ioctl(ptyfd, I_PUSH, "ptem") < 0)) {
SysError(ERROR_PTEM);
}
#if !defined(SVR4) && !(defined(SYSV) && defined(i386))
@@ -3740,11 +3741,13 @@ spawnXTerm(XtermWidget xw)
SysError(ERROR_CONSEM);
}
#endif /* !SVR4 */
- else if (ioctl(ptyfd, I_PUSH, "ldterm") < 0) {
+ else if ((ioctl(ptyfd, I_FIND, "ldterm") == 0) &&
+ (ioctl(ptyfd, I_PUSH, "ldterm") < 0)) {
SysError(ERROR_LDTERM);
}
#ifdef SVR4 /* from Sony */
- else if (ioctl(ptyfd, I_PUSH, "ttcompat") < 0) {
+ else if ((ioctl(ptyfd, I_FIND, "ttcompat") == 0) &&
+ (ioctl(ptyfd, I_PUSH, "ttcompat") < 0)) {
SysError(ERROR_TTCOMPAT);
}
#endif /* SVR4 */