Unix Programming - Termios is freezing

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2006 > Termios is freezing





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Termios is freezing
Reddy

2006-04-27, 7:56 am

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

Brian Bebeau

2006-04-27, 7:56 am

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
Kirill Kuvaldin

2006-04-27, 7:56 am

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 http://www.x-privat.org/join.php
Reddy

2006-04-27, 7:56 am

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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com