}
if ((istty = isatty(fd))) {
- n = t;
- /* Disable echo */
- n.c_lflag &= ~(ECHO);
- tcsetattr(fd, TCSANOW, &n);
- printf("%sassword for group %s:", update ? "New p" : "P",
- grp->gr_name);
- fflush(stdout);
+ if (tcgetattr(fd, &t) == -1)
+ istty = 0;
+ else {
+ n = t;
+ /* Disable echo */
+ n.c_lflag &= ~(ECHO);
+ tcsetattr(fd, TCSANOW, &n);
+ printf("%sassword for group %s:",
+ update ? "New p" : "P",
+ grp->gr_name);
+ fflush(stdout);
+ }
}
b = read(fd, line, sizeof(line) - 1);
if (istty) { /* Restore state */