ftp application behaving erratically

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ftp application behaving erratically
# 1  
Old 12-29-2004
ftp application behaving erratically


I am working on a custom made FTP application. The application is behaving erratically for the "ls" command. Wild card character passed to the "ls" command (like "ls *temp") is giving inconsistent results. On debuggin I have found that the "ls" command is implemented as shown below in the code of the ftp application,
FILE* fin;
char line[1024];
//line will contain something like "/bin/ls -l *temp" at this point
fin = popen (line, "r");
//fin is used to get the result of the ls command...
//sockets are used to send the data to the client side

The problem is that "line" gets truncated to "/bin/ls" just after the call to popen. So the result is, sometimes all the files are listed, sometimes nothing at all. If I hard code the value of "line" while calling popen (like popen ("/bin/ls -l *temp", "r") ), the application just gets killed.

Also, socket creation is also failing mysteriously in some cases. While debugging I found that the application is getting some junk IP ( : 20) for creating the socket and hence it is failing. This behaviour is totally inconsistent and is not reproducible all the time.

The code works fine in AIX. The problem seems to be in Solaris only. There are some subtle differences in the application running on AIX and Solaris plateform. But the code where I found the bug is common to both the plateforms.

Can anyone give me any idea how to go ahead to solve this problem?

# 2  
Old 12-30-2004
can u show the code before popen(). the signature for popen is

FILE* popen( const char * , const char *);

since it takes only const char * there is no way the popen command can change the contents of what is being passed. We need to make sure that 'line' is valid before calling popen - maybe printf before and after popen would help checking that.
# 3  
Old 12-30-2004
Agreed that popen cannot modify "line". But somehow that is what is happening. We cannot use printf here as the application is running as a deamon. I have called a function just before and after popen that will do the task of printf but it will write to a file. The code snippet is like,

gen_log("Value of line is %s", line); //10
popen (line, "r"); //11
gen_log("Value of line is %s", line); //12

At line 10 the value of line is "/bin/ls -l *temp" (lets assume we passed *temp as the argument to ls).
At line 12 the value of line is "/bin/ls". The rest gets truncated. Again if we hard code the value of line, the application just crashes.
# 4  
Old 12-30-2004
are u sure ur gen_log fn doesn't spoil line. Check it by calling gen_log twice before popen and running it a few times as u say the problem occurs occasionally.
# 5  
Old 12-30-2004
I am pretty sure gen_log() is not modifying "line". It is a generic fn. we use in most of our applications for generating error logs. I have tested it. It is not modifying "line".
# 6  
Old 12-30-2004
If u r sure gen_log is fine, I suggest u take a copy of line in a another array and pass that to popen.

like ..

char tempLine[200];
strcpy( tempLine , line );
gen_log( both line and tempLine )
popen( ..)
gen_log( again both);

This might solve the problem if line is pointing to a location that was created as a temporary in a previous expression.

I still feel u must call gen_log twice and run it a few times , as u never know . There could be a dormant problem in gen_log implementation.
# 7  
Old 12-30-2004
I have tried copying "line" to another variable and passing it to popen. I have tried printing "line" and the temp variable also. I have even tried printing "line" twice by calling gen_log() also. But still, only the variable that is passed to popen is getting corrupted.

Also, why is the application failing when we hard code the command passed to popen (line popen ("/bin/ls -l", "r") ).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read command acting erratically

I have been trying to use read in a script with issues so I tried some things on the command line. $ echo "testing 123" | read x ; echo $xand $ echo "testing 123" | read -r x ; echo $xare only producing any output after being invoked the first time after rebooting the machine. I also got into... (14 Replies)
Discussion started by: Michael Stora
14 Replies

2. UNIX for Advanced & Expert Users

[Solved] wc behaving weirdly

Can anyone explain why wc is behaving weirdly? Their are only 2 occurrences but wc thinks their are 7 occurrences. I have even manually checked this. $ grep -i base * lit: base xx lit.lst:003- 00103 BASE XX $ grep -i base * | wc -w ... (2 Replies)
Discussion started by: cokedude
2 Replies

3. Shell Programming and Scripting

awk not behaving as expected

Hi, Immediate help on below will be appreciated. I have to read a file (max of 10MB) which will have no new line characters, i.e. data in single line. and have to inster '\n' at every 100 characters. and if record starts with 'BUCA' then need to pick value of length 10 at position 71 and... (7 Replies)
Discussion started by: maks475
7 Replies

4. Programming

Application behaving in 3 different ways on 3 different machines

Hello. During the holidays I've been developing an application on my desktop computer at home. I setup a repository on github, so when I got back to work I cloned the repo to my laptop. It wouldn't work. The app is comprised of a client and a server, strangely enough the server would segfault... (10 Replies)
Discussion started by: erupter
10 Replies

5. Red Hat

nslookup behaving strangely

I have two servers on same domain. one can nslookup other cannot Psu100 can lookup to psu000, psu010 & psu011 Psu110 can NOT lookup to psu000, psu010 & psu011 I verified resolv.conf entries on both psu000 and psu010 and it contains both name servers ( & am... (1 Reply)
Discussion started by: scorohan
1 Replies

6. UNIX and Linux Applications

Firefox35 displays pngs erratically

I have been using firefox3.5 now for some months and noticed that some images, notably in the png format, do not display correctly: the images are not displayed at all or display in part whereby the rest of the image shows a black rectangle. Does anybody else suffer from this problem? Desktop:... (0 Replies)
Discussion started by: figaro
0 Replies

7. UNIX for Advanced & Expert Users

FTP behaving erraneous way

Hi Gurus, I tried FTP one file to UNIX which got values like wel^come If I see the content in unix, it shows like wel^Zcome ^ coverted into ^Z (Control + Z ) Can someone please share what is happening here? Thanks, Shahnaz (5 Replies)
Discussion started by: shahnazurs
5 Replies

8. Shell Programming and Scripting

tr command behaving unexpectedly

Im trying to execute the below command on our server to list files and replace the newline in the file list with spaces, but the character 'n' is getting replaced with a space, is there any environment variable that needs to be set in UNIX? sh -c 'ls -trx... (1 Reply)
Discussion started by: rameshrr3
1 Replies

9. UNIX for Advanced & Expert Users

csplit not behaving

I have a large file with the first 2 characters of each line determining the type of record. type 03 being a subheader and then it will have multiple 04 records. eg: 03,xxx,xxxx,xxxx 04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx 04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx 03,xxx,xxx,xxx ... (2 Replies)
Discussion started by: badg3r
2 Replies

10. Programming

ftp application using socket programming

i have made a ftp application in socket programming which uses TCP/IP .. i have the problem runing the only problem is on the client side i take the user input for the file to be downloaded from the command promt. write(s, argv, strlen(argv)+1); // this is how i write in client side argv is... (1 Reply)
Discussion started by: toughguy2handle
1 Replies
Login or Register to Ask a Question

Featured Tech Videos