# [PATCH] entry.c: Use strerror() to print error info when possible

5 messages from 2007-04-15 to 2007-04-15. Participants: Luiz Fernando N. Capitulino, Junio C Hamano, Alex Riesen.
Thread: https://gitlist.dev/t/7665

## Luiz Fernando N. Capitulino, 2007-04-15 21:56

Subject: [PATCH] entry.c: Use strerror() to print error info when possible
Message-ID: <20070415185619.3fa90f3a@gnut>
URL: https://gitlist.dev/e/20070415185619.3fa90f3a%40gnut

```

Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
---
 entry.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/entry.c b/entry.c
index d72f811..c36c09d 100644
--- a/entry.c
+++ b/entry.c
@@ -19,7 +19,8 @@ static void create_directories(const char *path, struct checkout *state)
 				if (!stat(buf, &st) && S_ISDIR(st.st_mode))
 					continue; /* ok */
 			}
-			die("cannot create directory at %s", buf);
+			die("cannot create directory at %s (%s)", buf,
+			    strerror(errno));
 		}
 	}
 	free(buf);
@@ -33,7 +34,7 @@ static void remove_subtree(const char *path)
 	char *name;
 	
 	if (!dir)
-		die("cannot opendir %s", path);
+		die("cannot opendir %s (%s)", path, strerror(errno));
 	strcpy(pathbuf, path);
 	name = pathbuf + strlen(path);
 	*name++ = '/';
@@ -45,15 +46,15 @@ static void remove_subtree(const char *path)
 			continue;
 		strcpy(name, de->d_name);
 		if (lstat(pathbuf, &st))
-			die("cannot lstat %s", pathbuf);
+			die("cannot lstat %s (%s)", pathbuf, strerror(errno));
 		if (S_ISDIR(st.st_mode))
 			remove_subtree(pathbuf);
 		else if (unlink(pathbuf))
-			die("cannot unlink %s", pathbuf);
+			die("cannot unlink %s (%s)", pathbuf, strerror(errno));
 	}
 	closedir(dir);
 	if (rmdir(path))
-		die("cannot rmdir %s", path);
+		die("cannot rmdir %s (%s)", path, strerror(errno));
 }
 
 static int create_file(const char *path, unsigned int mode)
-- 
1.5.1.1.85.geed2-dirty

```

## Junio C Hamano, 2007-04-15 22:54

Subject: Re: [PATCH] entry.c: Use strerror() to print error info when possible
Message-ID: <7v7isd2qq0.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v7isd2qq0.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20070415185619.3fa90f3a@gnut>

```
"Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br>
writes:

> Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
> ---
>  entry.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/entry.c b/entry.c
> index d72f811..c36c09d 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -19,7 +19,8 @@ static void create_directories(const char *path, struct checkout *state)
>  				if (!stat(buf, &st) && S_ISDIR(st.st_mode))
>  					continue; /* ok */
>  			}
> -			die("cannot create directory at %s", buf);
> +			die("cannot create directory at %s (%s)", buf,
> +			    strerror(errno));
>  		}
>  	}
>  	free(buf);

This hunk is wrong; stat() you see in the context could have
been what failed the last before this die().

I do not think other places you patched do not share the issue.

```

## Alex Riesen, 2007-04-15 23:00

Subject: Re: [PATCH] entry.c: Use strerror() to print error info when possible
Message-ID: <20070415230020.GC4417@steel.home>
URL: https://gitlist.dev/e/20070415230020.GC4417%40steel.home
In-Reply-To: <20070415185619.3fa90f3a@gnut>

```
Luiz Fernando N. Capitulino, Sun, Apr 15, 2007 23:56:19 +0200:
> 
> Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
> ---
>  entry.c |   11 ++++++-----
>  1 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/entry.c b/entry.c
> index d72f811..c36c09d 100644
> --- a/entry.c
> +++ b/entry.c
> @@ -19,7 +19,8 @@ static void create_directories(const char *path, struct checkout *state)
>  				if (!stat(buf, &st) && S_ISDIR(st.st_mode))
>  					continue; /* ok */
>  			}
> -			die("cannot create directory at %s", buf);
> +			die("cannot create directory at %s (%s)", buf,
> +			    strerror(errno));

This errno is not very useful, as it may come from the stat above, and
you provided no way to figure out what was the syscall (the mkdir or
the stat) which failed. Also, the errnos of unlink or mkdir just above
the stat are just lost.

It is not worse than before, but not very much better either, and
probably confusing. I suggest you just leave this one as it is.

```

## Luiz Fernando N. Capitulino, 2007-04-15 23:54

Subject: Re: [PATCH] entry.c: Use strerror() to print error info when possible
Message-ID: <20070415205433.3b475f60@gnut>
URL: https://gitlist.dev/e/20070415205433.3b475f60%40gnut
In-Reply-To: <7v7isd2qq0.fsf@assigned-by-dhcp.cox.net>

```
Em Sun, 15 Apr 2007 15:54:47 -0700
Junio C Hamano <junkio@cox.net> escreveu:

| "Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br>
| writes:
| 
| > Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
| > ---
| >  entry.c |   11 ++++++-----
| >  1 files changed, 6 insertions(+), 5 deletions(-)
| >
| > diff --git a/entry.c b/entry.c
| > index d72f811..c36c09d 100644
| > --- a/entry.c
| > +++ b/entry.c
| > @@ -19,7 +19,8 @@ static void create_directories(const char *path, struct checkout *state)
| >  				if (!stat(buf, &st) && S_ISDIR(st.st_mode))
| >  					continue; /* ok */
| >  			}
| > -			die("cannot create directory at %s", buf);
| > +			die("cannot create directory at %s (%s)", buf,
| > +			    strerror(errno));
| >  		}
| >  	}
| >  	free(buf);
| 
| This hunk is wrong; stat() you see in the context could have
| been what failed the last before this die().

 You right, will try to read the code more carefully before
patching.

| I do not think other places you patched do not share the issue.

 Other places seems ok, I'll review and re-send along with other
patches I'm working on.

 Thanks a lot for the feedback.

```

## Luiz Fernando N. Capitulino, 2007-04-15 23:57

Subject: Re: [PATCH] entry.c: Use strerror() to print error info when possible
Message-ID: <20070415205709.27d7e475@gnut>
URL: https://gitlist.dev/e/20070415205709.27d7e475%40gnut
In-Reply-To: <20070415230020.GC4417@steel.home>

```
Em Mon, 16 Apr 2007 01:00:20 +0200
Alex Riesen <raa.lkml@gmail.com> escreveu:

| Luiz Fernando N. Capitulino, Sun, Apr 15, 2007 23:56:19 +0200:
| > 
| > Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
| > ---
| >  entry.c |   11 ++++++-----
| >  1 files changed, 6 insertions(+), 5 deletions(-)
| > 
| > diff --git a/entry.c b/entry.c
| > index d72f811..c36c09d 100644
| > --- a/entry.c
| > +++ b/entry.c
| > @@ -19,7 +19,8 @@ static void create_directories(const char *path, struct checkout *state)
| >  				if (!stat(buf, &st) && S_ISDIR(st.st_mode))
| >  					continue; /* ok */
| >  			}
| > -			die("cannot create directory at %s", buf);
| > +			die("cannot create directory at %s (%s)", buf,
| > +			    strerror(errno));
| 
| This errno is not very useful, as it may come from the stat above, and
| you provided no way to figure out what was the syscall (the mkdir or
| the stat) which failed. Also, the errnos of unlink or mkdir just above
| the stat are just lost.
| 
| It is not worse than before, but not very much better either, and
| probably confusing. I suggest you just leave this one as it is.

 Will do, thanks for reviewing Alex.

```
