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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sarabandeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
sarabandeCommented:
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
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.