rexec() function problem


 
Thread Tools Search this Thread
Top Forums Programming rexec() function problem
# 1  
Old 01-07-2002
Question rexec() function problem

Hi folks,

I'm trying to make a reconnection algorithm using rexec(), but I noticed that when rexec() fails returning -1, it is impossible to make it run successfully again until you restart the program or the thread.

Example, I have a endless loop for connection retries, if I supply a wrong password for a given username, rexec fails, it's ok. But my program keeps trying to connect calling rexec function, so if I change the password for that user in the host to the password that rexec is giving, it should connect successfuly, but I keep getting the same login error. The curious is if I restart my program or even if I finish the thread and start the thread again it connects succesfully.

I think it's a bug in rexec, does anyone had a problem similar to that and can help me.

Due to that problem I'm writing a code just to restart the threads that failed in rexec, but it's getting much more complex than it should be.


Thanks in advance for any help.
# 2  
Old 01-07-2002
What OS are you using? Both SunOS and HP-UX have rexec man pages that say this:
Quote:
This interface is unsafe in multithreaded applications. Unsafe interfaces should be called only from the main thread.
# 3  
Old 01-07-2002
A couple of things...

First, rexec() function call is obsolete in some
environments and you should now be using rcmd().

Second, rexec() is not safe for multithreaded
programs.

When rexec() fails, the network (socket)
connection is closed. Are you creating a new
socket connection after each failure?
# 4  
Old 01-07-2002
I'm running Digital UNIX V4.0D (Rev. 878)

I looked at the man page for rexec and it does not say anything about thread problems, in fact, we are not having any problem using rexec with threads after rexec connects successfully. The only problem is when rexec fails to connect.

The code to connect is like:

do
{
*pifdComm =rexec((char **)&pszInitiatorIpAddress,ptServInfo->s_port,ptConfig->pacInitiatorUsername, ptConfig->pacInitiatorPasswd, ptConfig->pacInitiatorCommand,0);
if (0 > *pifdComm)
{
/* Connection failure message */
}
}while(0 > *pifdComm);


I do not open any socket connection, I just call rexec and use the file descriptor returned by this function to send and receive commands from the host.

I will try this rcmd() and see if it does not have this problem, I didn't try to make it in non multithreaded application, but I'll try too.


Thanks folks, if you have any suggestions let me know.
# 5  
Old 01-07-2002
I just tested rexec() in a non multthreaded application and I got the same problem, after it fails once, it does not connect successfully again, even after I change the password in host.

I tried rcmd() function, but it is for root users only, I got "permission denied" error.

Here is the code I wrote to test.

#include <stdio.h>
#include <netdb.h>

#define SERVER_NAME "server"
#define USER_NAME "username"
#define USER_PASSWD "password"
#define REXEC_CMD "command"

main()
{
struct servent *ptServInfo;
int ifdComm;
char szInitiatorIpAddress[128];
char *pszInitiatorIpAddress;

if ( (ptServInfo = getservbyname("exec", "tcp")) == NULL)
{
printf("\nFailed getservbyname\n");
return;
}
strcpy(szInitiatorIpAddress,SERVER_NAME);
pszInitiatorIpAddress = szInitiatorIpAddress;

do
{
ifdComm =rexec((char **)&pszInitiatorIpAddress,ptServInfo->s_port, USER_NAME, USER_PASSWD, REXEC_CMD,0);
if (0 > ifdComm)
{
printf("Connection failed\n");
}
}while( (0 > ifdComm));

printf("\nConnected successfully\n");
}
# 6  
Old 01-08-2002
I work on the same server as yours, and the code works perfectly fine here. Just to be sure, did you check your /etc/hosts file entry to match with your SERVER_NAME? What I mean to say is, are you changing the password on the right system?
shaik786
# 7  
Old 01-08-2002
MySQL

Hi Shaik,

Thanks for testing the code... I found out what is going wrong, but I didn't understand why.

When you said it worked there I tought "he must be kidding" Smilie, because the server I wrote in SERVER_NAME parameter was right and it was in /etc/hosts file. But to make sure I was doing the right think, I added a line in the code to print the servername before calling rexec and then for my surprise I discovered what was happening.

In the first time the server was right, the one in SERVER_NAME constant, the second time the server was diferent, it was another alias name for the same IP in the /etc/hosts, but at the third time and from there on, the servername was an alias for a different IP, so that's why it never connected again, even after I changed the password.

But I didn't understand why it is getting this servername for another IP address.

Here is a piece of my /etc/hosts.

xxx.xxx.0.1 localhost
xxx.xxx.2.20 vicunha1
xxx.xxx.72.21 sscxwin1
xxx.xxx.72.22 sscsp02
xxx.xxx.72.9 sscsp11
xxx.xxx.2.24 bscs
xxx.xxx.16.34 uatr1dfr
xxx.xxx.2.56 sdrdig14
xxx.xxx.2.56 vicunha14
xxx.xxx.72.25 sscsp05.ac.com sscsp05 #System name
xxx.xxx.72.92 AC7932CY570122


I was trying to connnect to the server "sscsp05", so at the first time it pszInitiatorIpAddress was pointing to this string, the second time it has "sscsp05.ac.com" and at a third time it has "sscxwin1", a different IP address.

I tested it trying to connect to server "sscsp02", and the same thing happened, but at the second time it already got "sscsxwin1".

So, to solve this, everytime I set pszInitiatorIpAddress to point to szInititatorIpAddress again. I also tested using 10 threads, and all of them connected successfully.

Do you have any idea why rexec is getting other server names in /etc/hosts?? I looked at the man page and it doesn't say anything about getting other servernames dinamically.



Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Slow login with rexec.

Hi all, Im replacing an old linux enterprise redhat 4.5 by a new one linux enterprise redhat 6. In both I use rexec as a communication between the front end and the user. In the old one, when the user connects, the communication establishes quickly (less than 3 sec). But in the new one, the... (1 Reply)
Discussion started by: mig28mx
1 Replies

2. UNIX for Advanced & Expert Users

Rexec Issue

Hi Team, I am executing some ksh scripts which inturn calls java files in AIX Environment. We have installed java6_64 which is in .profile. But when we execute from rexec its taking path from some different place that does not have java in $PATH variable. Can you please help me find out which... (2 Replies)
Discussion started by: balasubramani04
2 Replies

3. AIX

rexec - other options?

Rexec executes commands one at a time on a remote host. The rexec command provides an automatic login feature by checking for a $HOME/.netrc file. User and password are stored in $HOME/.netrc. I would like to log on to another host and execute a script/command but not using $HOME/.netrc file,... (4 Replies)
Discussion started by: ioniCoder
4 Replies

4. UNIX for Dummies Questions & Answers

exit codes from rexec?

how do i/is there a way to return the exit code from the remote host? echo $? from the local host only gives 0, if the rexec command itself executes successfully. But what if in the case of the remote command failiing? echo $? on the localhost still gives 0, but I'm interested in the exit code... (4 Replies)
Discussion started by: diego_sapphire
4 Replies

5. UNIX for Advanced & Expert Users

Remote commands problem using RSH & Rexec

I have enabled the RSH and Rexec command in my HP-UX server but when i try to send any command to the server it returns Execute Permission Denied except commands like ls-l C:\rsh xxx.xxx.xxx.xxx -l mpac mxpkill 12 the mxpkill command work when I log to the server using telnet with the same... (0 Replies)
Discussion started by: fhuwaidy
0 Replies

6. Shell Programming and Scripting

How can I do a rexec to execute un C exe ?

Hello, I would like to do a rexec to execute a C exe (prog.e) : rexec -l user -p password host prog.e When I execute this command, I have this error : prog.e : can not find lib.o But, When I execute prog.e directly in the remote machine : well done ! No error output. Thks for your... (4 Replies)
Discussion started by: Lika
4 Replies

7. UNIX for Advanced & Expert Users

reagrding REXEC command

Hi UNIX gurus..... have a doubt..can i run a script in a remote machine by using something like rexec add.corp.afg.com /aa/ss/remtescript I dont want to use the rsh command due to some security issues. thanx, rahul26 :) (2 Replies)
Discussion started by: rahul26
2 Replies

8. Solaris

Rexec

How is rexec enabled on a Solaris 8? How can I check if rexec is installed? (1 Reply)
Discussion started by: pmj1970
1 Replies

9. UNIX for Dummies Questions & Answers

Enabling Rexec ????

Can someone tell me how I would enable Rexec on a UNIX machine? And is the procedure different on the different systems - Solaris, HP-UX -etc. Thanks~!! mike (1 Reply)
Discussion started by: raichuu
1 Replies

10. UNIX for Dummies Questions & Answers

expect (re: rexec)

In http://forums.unix.com/showthread.php?threadid=391 there is one statement called expect. but when I issue command whereis expect, respond from o/s only EXPECT: (only one world). I try to find it at /usr/bin, no expect statement there ? is it default unix o/s command ? I am using AIX on... (1 Reply)
Discussion started by: yatno
1 Replies
Login or Register to Ask a Question

Featured Tech Videos