[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: off-topic program-Q



>>>>> Maarten Boekhold <boekhold@cindy.et.tudelft.nl> writes:

> Hi,
> I have the following piece of code (stripped down):

> ...

> 		if (execl("/bin/sh", "-c", "/usr/bin/slrn.real", "-f", buff,
> 					"-d", NULL) != -1) {
> 			sprintf(buff, "%s/tmpdsc.dsc", SLRN_DSC_DIR);
> 			sprintf(buff2, "%s/newsgroups.dsc", SLRN_DSC_DIR);
> 			execl("/bin/mv", buff, buff2);
> 		} else {
> 			perror(NULL);
> 		}

Well, one thing wrong with this code is that the execl of /bin/mv
cannot be reached because the execl of /bin/sh never returns.

You really want to wait(), in the parent, for the child to exit, and
then call rename(buff, buff2) {since it looks like the two filenames
reside in the same file system}.

-- 
Steve Preston (spreston@gte.com)


Reply to: