1753434 Members
4571 Online
108793 Solutions
New Discussion юеВ

Termios is freezing

 
hem c reddy
Advisor

Termios is freezing

Hi,

I have the following small program which read password from user after echoing off. But the problem is, it is freezing for some time (not sure about the duration) before going to the next statement and I have to press "enter" multiple times (maximum 4, it is not consistent though). I am trying it on a hp-ux machine with aCC compiler.

Any pointers/help would be greatly appreciated.

#include
#include
#include
#include

int main(int argc, char *argv[])
{
struct termios oldt,
newt;
char ch;
char userpasswd[50];

printf("enter password:");
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
gets(userpasswd);
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
printf("\nPassword enetered %s\n", userpasswd);
return 0;
}


Thanks,
Reddy
Edit/Delete Message
4 REPLIES 4
Arunvijai_4
Honored Contributor

Re: Termios is freezing

HI Reddy,

You can try running your program under tusc to see where and what system call it hangs,

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-7.8/

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
A. Clay Stephenson
Acclaimed Contributor

Re: Termios is freezing

There is a function getpass() that will do all of this for you. Man getpass() for details.

I suspect that your problem stems from the use of TCSANNOW rather than TCSAFLUSH.
If it ain't broke, I can fix that.
hem c reddy
Advisor

Re: Termios is freezing

I removed ICANON from "newt.c_lflag &= ~( ICANON | ECHO )" and is not
working fine.

Thank you very much for your responses..

Regards,
Reddy
hem c reddy
Advisor

Re: Termios is freezing

I have got my problem solved