command line may cause bugs

hi all,
 After I updated my program to  transfer everyting from src directory to dest directory by creating all hierarchy folder first ( new features) then transfer all files. I use the "system"  command to creat new folder. However, I don't know how to make sure the "system" command finish before flow of program continue .I suspect it cause bug.

Current working dir: /home/ubuntu/program
 directory is : /home/ubuntu/program/src/dir1
 directory is : /home/ubuntu/program/src/dir1/dir2a
 directory is : /home/ubuntu/program/src/dir1/dir2a/dir4
 directory is : /home/ubuntu/program/src/dir1/dir2
 directory is : /home/ubuntu/program/src/dir1/dir2/dir3

ubuntu@ubuntu:~/program$ ./server
message2-> dirname is : /home/ubuntu/program/src/dir1
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a/dir4
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2a/dir4
/home/ubuntu/program/dest/dir1/dir2a/dir4 is existed
message2-> dirname is : /home/ubuntu/program/src/dir1/dir2/dir34
 received wrong size_to_read: No such file or directory
ubuntu@ubuntu:~/program$

Tks for your advise.
PS: one idea just pop up. in this case, the quick way is to check the directory existance after "system" command????

   
client.c
server.c
BeginToLearnAsked:
Who is Participating?
 
sarabandeConnect With a Mentor Commented:
the "message2-> dirname is : /home/ubuntu/program/src/dir1/dir2/dir34" looks like you didn't clear the previous buffer after read and that's why the last '4' was added to the path.

when receiving message 2 with the filename you should add a binary zero char to the message (where you know that it was text message!).

Sara
0
 
sarabandeCommented:
if you check the man pages of system you will see that the child process which was started by system must terminate before system returns to the calling (server) process.

Sara
0
 
sarabandeConnect With a Mentor Commented:
the statement

string filenameSpacefilesize = receiveMessage(sock, sizedata);

Open in new window


would not be able to set the correct length as returned in sizedata.

do

 
char *  buf = receiveMessage(sock, sizedata);
  if (buf == NULL || sizedata <= 0)
      ... // error and return
  string filenameSpacefilesize(buf, sizedata);

Open in new window


instead.

Sara    
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
BeginToLearnAuthor Commented:
oh tks Sara. I am also rework on my get_all_files(). Testing now :)
0
 
BeginToLearnAuthor Commented:
i think it works perfect now.
client.c
server.c
0
 
sarabandeCommented:
good job :)

one last remark,

if you would clear the static buffer after each message the buffer automatically would be zero-terminated in case of text messages.

Sara
0
 
BeginToLearnAuthor Commented:
oh you mean after I receive the message, i should clear the static buffer?  Is it same effective like i use memset() to set static buffer before receving message?
0
 
sarabandeCommented:
no, my fault, you can't clear it after the message cause the buffer was returned to the caller. but you can do memset before the while loop.

because maximum message length is 2048 and the buffer is 2049 you always have at least 1 zero char left if you do proper initialisation before recv. for message 3 that is irrelevant cause it may contain binary data as well. but for string message like message 2 it makes the handling (and debug output) simpler.

Sara
0
 
BeginToLearnAuthor Commented:
I get the idea. tks. Let me close this question. I will rework to make it sending to multiple server.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.