TIOCISATTY

From Msim

Jump to: navigation, search

ioctl(fd,TIOCISATTY) is a syscall that takes a file descriptor and checks if it is a terminal or not.

Contents

Original

                       case OSF_TIOCISATTY:
                               check_error = true;
                               regs->regs_R[MD_REG_V0] = isatty(regs->regs_R[MD_REG_A0]);
                               break;

Correction

                       case OSF_TIOCISATTY:
                               if(isatty(regs->regs_R[MD_REG_A0]))
                               {
                                       regs->regs_R[MD_REG_V0] = 0;
                               }
                               else
                               { 
                                       regs->regs_R[MD_REG_V0] = -1;
                                       regs->regs_R[MD_REG_A3] = ENOTTY;
                               }   
                               break;

Explanation

ioctl returns 0 on success. So, if the file descriptor is actually a terminal, return 0. Otherwise, it isn't a terminal. If it isn't a terminal, return -1 (for failure). However, errno is also thrown to indicate ENOTTY (not a terminal). This is a little counter-intuitive as ENOTTY would not be an error in a practical sense, however, it is just that (which follows specifications better).

Process

This was observed in the behavior of the spec2K6 gamess benchmark. Syscalls were branching on the errno variable (MD_REG_A3 or r19) instead of the return value (MD_REG_V0 or r0). The ioctl("<bench>.F10",TIOCISATTY) call in gamess was reporting not a terminal but being treated as if it was a terminal (and failing file format check - fortran error 51). ioctl's return value was never actually looked at - this provided the realization that errno was being checked instead.

Personal tools