Subject: Re: [PATCH 3/5] git-cherry-pick: Add ignore-if-made-empty option [v2]

From: Johannes Sixt <[email-masked]>
Date: Fri, 06 Apr 2012 20:30:19 +0200

Am 05.04.2012 21:39, schrieb Neil Horman:
> +	if (pipe2(pipefd, 0) < 0)
> +		return 0;
> +	output = xfdopen(pipefd[0], "r");
> +	memset(&cp, 0, sizeof(struct child_process));
> +	... setup cp ...
> +	if (start_command(&cp) < 0)
> +		goto out;
> +	if (fscanf(output, "%s\n", ptree)<  1)
> +		goto out;
> +	finish_command(&cp);
> +	fclose(output);
> +	close(pipefd[0]);

Instead of this sequence (I quoted only the relevant pieces), use the 
following:

	memset(&cp, 0, sizeof(struct child_process));
	cp.out = -1;
	... set other pieces in cp ...
	if (start_command(&cp) < 0)
		goto out;
	read_in_full(cp.out, ptree, sizeof(ptree));
	/* add suitable error reporting above */
	close(cp.out);
	if (!finish_command(&cp))
		goto out;

i.e.,

1. let start_command create the pipe for you by setting cp.out = -1,
2. avoid fscanf() if read_in_full() is equally simple to use,
3. close the pipe before finish_command(),
4. check the return code of finish_command().

-- Hannes