Termios is freezing
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Termios is freezing




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Termios is freezing  
Reddy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

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 <stdio.h>
#include <termios.h>
#include <unistd.h>
#include<string.h>

int main()
{
struct termios oldt, newt;
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






[ Post a follow-up to this message ]



    Re: Termios is freezing  
Brian Bebeau


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

Reddy wrote:
> 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.
>

> int main()
> {
> struct termios oldt, newt;
> char userpasswd[50];
>
> printf("enter password:");
>
> tcgetattr( STDIN_FILENO, &oldt );
> newt = oldt;
> newt.c_lflag &= ~( ICANON | ECHO );

Common problem. If you're going to turn off ICANON,
you have to set VMIN and VTIME. Read the termios man
page more carefully. On many machines, c_cc[VMIN] is
the same value as c_cc[VEOF]. VMIN is for non-canonical\
processing and VEOF is for canonical processing. VEOF is
ususally set to Ctrl-D, which is 4, so if you don't change
VMIN when turning off ICANON, it'll wait for 4 chars to be
input.

> tcsetattr( STDIN_FILENO, TCSANOW, &newt );
> gets(userpasswd);
> tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
> printf("\nPassword enetered %s\n", userpasswd);
> return 0;
>
> }

If all you're doing is getting a password, why not just use
the getpass(2) routine? It does the same thing.

--
Brian Bebeau
SecurePipe, Inc.
http://www.securepipe.com





[ Post a follow-up to this message ]



    Re: Termios is freezing  
Kirill Kuvaldin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

Brian Bebeau <bbebeau@unspammed-computer.org> wrote:
> If all you're doing is getting a password, why not just use
> the getpass(2) routine? It does the same thing.

According to the getpass(2) man page, this function is obsolete and
shouldn't be used.

Regards,
Kirill


Inviato da X-Privat.Org - Registrazione gratuita [url]http://www.x-privat.org/join.php[
/url]





[ Post a follow-up to this message ]



    Re: Termios is freezing  
Reddy


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-27-06 12:56 PM

Hi Brain,

Thanks for your reply.

I need to port the same code on multiple operatinsystems. As Solaris
limits getpass() to eight characters I do not have other go.

Please let me know your comments.

Thanks,
Reddy






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 02:28 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register