Re: [PATCH 06/15] copy.c: make copy_fd preserve meaningful errno
- From
Ronnie Sahlberg <sahlberg@google.com>
- Date
- Oct 23, 2014, 17:54 UTC
- Message-ID
- <CAL=YDWkatPumEM7p5Pvh6dxFgO59T-YBbjqS5nWnNpH-azzxBg@mail.gmail.com>
- In-Reply-To
- <xmqqlho6smi8.fsf@gitster.dls.corp.google.com>
On Thu, Oct 23, 2014 at 10:51 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Ronnie Sahlberg <sahlberg@google.com> writes: > >> commit 306805ccd147bfdf160b288a8d51fdf9b77ae0fa upstream. >> >> Update copy_fd to return a meaningful errno on failure. > > These two are good changes, but makes me wonder if more places > benefit from having error_errno() that does the "save away errno, > use strerror(errno) to give an error message and restore errno" > for us. > > Not meant as a suggestion for further changes in this series, but as > a future discussion item. >
That sounds like a good idea.
As a separate series once these are done, I can volunteer to go through all the errno handling in git and look into that.
Show 35 quoted lines
>>
>> Change-Id: I771f9703acc816902affcf35ff2a56d9426315ac
>> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
>> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
>> ---
>> copy.c | 15 ++++++++++-----
>> 1 file changed, 10 insertions(+), 5 deletions(-)
>>
>> diff --git a/copy.c b/copy.c
>> index f2970ec..a8d366e 100644
>> --- a/copy.c
>> +++ b/copy.c
>> @@ -8,12 +8,17 @@ int copy_fd(int ifd, int ofd)
>> if (!len)
>> break;
>> if (len < 0) {
>> - return error("copy-fd: read returned %s",
>> - strerror(errno));
>> + int save_errno = errno;
>> + error("copy-fd: read returned %s", strerror(errno));
>> + errno = save_errno;
>> + return -1;
>> + }
>> + if (write_in_full(ofd, buffer, len) < 0) {
>> + int save_errno = errno;
>> + error("copy-fd: write returned %s", strerror(errno));
>> + errno = save_errno;
>> + return -1;
>> }
>> - if (write_in_full(ofd, buffer, len) < 0)
>> - return error("copy-fd: write returned %s",
>> - strerror(errno));
>> }
>> return 0;
>> }