linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lsattr: return error values
@ 2009-06-18 21:59 Eric Sandeen
  2009-06-18 22:35 ` Eric Sandeen
  2009-06-18 22:51 ` [PATCH V2] " Eric Sandeen
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Sandeen @ 2009-06-18 21:59 UTC (permalink / raw)
  To: ext4 development

RH bug 489841 points out that lsattr doesn't return an error
if you point it at a file that doesn't exist.

This is slightly trickier because it can take more than one
file as an arg, but ls seems to report an error if any occurred,
so this does the same, it'll report the last error that was 
encountered.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---


diff --git a/misc/lsattr.c b/misc/lsattr.c
index 254ebb4..39fe564 100644
--- a/misc/lsattr.c
+++ b/misc/lsattr.c
@@ -74,22 +74,25 @@ static void usage(void)
 	exit(1);
 }
 
-static void list_attributes (const char * name)
+static int list_attributes (const char * name)
 {
 	unsigned long flags;
 	unsigned long generation;
+	int retval = 0;
 
 	if (fgetflags (name, &flags) == -1) {
-		com_err (program_name, errno, _("While reading flags on %s"),
+		retval = errno;
+		com_err (program_name, retval, _("While reading flags on %s"),
 			 name);
-		return;
+		return retval;
 	}
 	if (generation_opt) {
 		if (fgetversion (name, &generation) == -1) {
-			com_err (program_name, errno,
+			retval = errno;
+			com_err (program_name, retval,
 				 _("While reading version on %s"),
 				 name);
-			return;
+			return retval;
 		}
 		printf ("%5lu ", generation);
 	}
@@ -101,23 +104,27 @@ static void list_attributes (const char * name)
 		print_flags(stdout, flags, pf_options);
 		printf(" %s\n", name);
 	}
+	return retval;
 }
 
 static int lsattr_dir_proc (const char *, struct dirent *, void *);
 
-static void lsattr_args (const char * name)
+static int lsattr_args (const char * name)
 {
 	STRUCT_STAT	st;
+	int		retval = 0;
 
-	if (LSTAT (name, &st) == -1)
-		com_err (program_name, errno, _("while trying to stat %s"),
+	if (LSTAT (name, &st) == -1) {
+		retval= errno;
+		com_err (program_name, retval, _("while trying to stat %s"),
 			 name);
-	else {
+	} else {
 		if (S_ISDIR(st.st_mode) && !dirs_opt)
-			iterate_on_dir (name, lsattr_dir_proc, NULL);
+			retval = iterate_on_dir (name, lsattr_dir_proc, NULL);
 		else
-			list_attributes (name);
+			retval = list_attributes (name);
 	}
+	return retval;
 }
 
 static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
@@ -155,6 +162,7 @@ int main (int argc, char ** argv)
 {
 	int c;
 	int i;
+	int err, retval = 0;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_MESSAGES, "");
@@ -193,9 +201,12 @@ int main (int argc, char ** argv)
 		fprintf (stderr, "lsattr %s (%s)\n",
 			 E2FSPROGS_VERSION, E2FSPROGS_DATE);
 	if (optind > argc - 1)
-		lsattr_args (".");
+		retval = lsattr_args (".");
 	else
-		for (i = optind; i < argc; i++)
-			lsattr_args (argv[i]);
-	exit(0);
+		for (i = optind; i < argc; i++) {
+			err = lsattr_args (argv[i]);
+			if (err)
+				retval = err;
+		}
+	exit(retval);
 }


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lsattr: return error values
  2009-06-18 21:59 [PATCH] lsattr: return error values Eric Sandeen
@ 2009-06-18 22:35 ` Eric Sandeen
  2009-06-18 22:51 ` [PATCH V2] " Eric Sandeen
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Sandeen @ 2009-06-18 22:35 UTC (permalink / raw)
  To: ext4 development

Eric Sandeen wrote:
> RH bug 489841 points out that lsattr doesn't return an error
> if you point it at a file that doesn't exist.
> 
> This is slightly trickier because it can take more than one
> file as an arg, but ls seems to report an error if any occurred,
> so this does the same, it'll report the last error that was 
> encountered.

oops kernel on the brain, I shouldn't be exiting with the errno should
I, sigh.

I'll resend :)

-Eric

> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> 
> diff --git a/misc/lsattr.c b/misc/lsattr.c
> index 254ebb4..39fe564 100644
> --- a/misc/lsattr.c
> +++ b/misc/lsattr.c
> @@ -74,22 +74,25 @@ static void usage(void)
>  	exit(1);
>  }
>  
> -static void list_attributes (const char * name)
> +static int list_attributes (const char * name)
>  {
>  	unsigned long flags;
>  	unsigned long generation;
> +	int retval = 0;
>  
>  	if (fgetflags (name, &flags) == -1) {
> -		com_err (program_name, errno, _("While reading flags on %s"),
> +		retval = errno;
> +		com_err (program_name, retval, _("While reading flags on %s"),
>  			 name);
> -		return;
> +		return retval;
>  	}
>  	if (generation_opt) {
>  		if (fgetversion (name, &generation) == -1) {
> -			com_err (program_name, errno,
> +			retval = errno;
> +			com_err (program_name, retval,
>  				 _("While reading version on %s"),
>  				 name);
> -			return;
> +			return retval;
>  		}
>  		printf ("%5lu ", generation);
>  	}
> @@ -101,23 +104,27 @@ static void list_attributes (const char * name)
>  		print_flags(stdout, flags, pf_options);
>  		printf(" %s\n", name);
>  	}
> +	return retval;
>  }
>  
>  static int lsattr_dir_proc (const char *, struct dirent *, void *);
>  
> -static void lsattr_args (const char * name)
> +static int lsattr_args (const char * name)
>  {
>  	STRUCT_STAT	st;
> +	int		retval = 0;
>  
> -	if (LSTAT (name, &st) == -1)
> -		com_err (program_name, errno, _("while trying to stat %s"),
> +	if (LSTAT (name, &st) == -1) {
> +		retval= errno;
> +		com_err (program_name, retval, _("while trying to stat %s"),
>  			 name);
> -	else {
> +	} else {
>  		if (S_ISDIR(st.st_mode) && !dirs_opt)
> -			iterate_on_dir (name, lsattr_dir_proc, NULL);
> +			retval = iterate_on_dir (name, lsattr_dir_proc, NULL);
>  		else
> -			list_attributes (name);
> +			retval = list_attributes (name);
>  	}
> +	return retval;
>  }
>  
>  static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
> @@ -155,6 +162,7 @@ int main (int argc, char ** argv)
>  {
>  	int c;
>  	int i;
> +	int err, retval = 0;
>  
>  #ifdef ENABLE_NLS
>  	setlocale(LC_MESSAGES, "");
> @@ -193,9 +201,12 @@ int main (int argc, char ** argv)
>  		fprintf (stderr, "lsattr %s (%s)\n",
>  			 E2FSPROGS_VERSION, E2FSPROGS_DATE);
>  	if (optind > argc - 1)
> -		lsattr_args (".");
> +		retval = lsattr_args (".");
>  	else
> -		for (i = optind; i < argc; i++)
> -			lsattr_args (argv[i]);
> -	exit(0);
> +		for (i = optind; i < argc; i++) {
> +			err = lsattr_args (argv[i]);
> +			if (err)
> +				retval = err;
> +		}
> +	exit(retval);
>  }
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH V2] lsattr: return error values
  2009-06-18 21:59 [PATCH] lsattr: return error values Eric Sandeen
  2009-06-18 22:35 ` Eric Sandeen
@ 2009-06-18 22:51 ` Eric Sandeen
  2009-06-22  1:48   ` Theodore Tso
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Sandeen @ 2009-06-18 22:51 UTC (permalink / raw)
  To: ext4 development

(hastily redone before I leave for a few days, hope this
is sane, review welcome) :)

lsattr doesn't return an error if you point it at a file that 
doesn't exist.

This is slightly trickier because it can take more than one
file as an arg, but ls seems to report an error if any occurred,
so this does the same, it'll report the last error that was 
encountered.

Addresses-RedHat-Bugzilla: #489841
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---


diff --git a/misc/lsattr.c b/misc/lsattr.c

index 254ebb4..15b17ad 100644
--- a/misc/lsattr.c
+++ b/misc/lsattr.c
@@ -74,7 +74,7 @@ static void usage(void)
 	exit(1);
 }
 
-static void list_attributes (const char * name)
+static int list_attributes (const char * name)
 {
 	unsigned long flags;
 	unsigned long generation;
@@ -82,14 +82,14 @@ static void list_attributes (const char * name)
 	if (fgetflags (name, &flags) == -1) {
 		com_err (program_name, errno, _("While reading flags on %s"),
 			 name);
-		return;
+		return -1;
 	}
 	if (generation_opt) {
 		if (fgetversion (name, &generation) == -1) {
 			com_err (program_name, errno,
 				 _("While reading version on %s"),
 				 name);
-			return;
+			return -1;
 		}
 		printf ("%5lu ", generation);
 	}
@@ -101,23 +101,27 @@ static void list_attributes (const char * name)
 		print_flags(stdout, flags, pf_options);
 		printf(" %s\n", name);
 	}
+	return 0;
 }
 
 static int lsattr_dir_proc (const char *, struct dirent *, void *);
 
-static void lsattr_args (const char * name)
+static int lsattr_args (const char * name)
 {
 	STRUCT_STAT	st;
+	int retval = 0;
 
-	if (LSTAT (name, &st) == -1)
+	if (LSTAT (name, &st) == -1) {
 		com_err (program_name, errno, _("while trying to stat %s"),
 			 name);
-	else {
+		retval = -1;
+	} else {
 		if (S_ISDIR(st.st_mode) && !dirs_opt)
-			iterate_on_dir (name, lsattr_dir_proc, NULL);
+			retval = iterate_on_dir (name, lsattr_dir_proc, NULL);
 		else
-			list_attributes (name);
+			retval = list_attributes (name);
 	}
+	return retval;
 }
 
 static int lsattr_dir_proc (const char * dir_name, struct dirent * de,
@@ -155,6 +159,7 @@ int main (int argc, char ** argv)
 {
 	int c;
 	int i;
+	int err, retval = 0;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_MESSAGES, "");
@@ -192,10 +197,15 @@ int main (int argc, char ** argv)
 	if (verbose)
 		fprintf (stderr, "lsattr %s (%s)\n",
 			 E2FSPROGS_VERSION, E2FSPROGS_DATE);
-	if (optind > argc - 1)
-		lsattr_args (".");
-	else
-		for (i = optind; i < argc; i++)
-			lsattr_args (argv[i]);
-	exit(0);
+	if (optind > argc - 1) {
+		if (lsattr_args (".") == -1)
+			retval = 1;
+	} else {
+		for (i = optind; i < argc; i++) {
+			err = lsattr_args (argv[i]);
+			if (err)
+				retval = 1;
+		}
+	}
+	exit(retval);
 }


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH V2] lsattr: return error values
  2009-06-18 22:51 ` [PATCH V2] " Eric Sandeen
@ 2009-06-22  1:48   ` Theodore Tso
  0 siblings, 0 replies; 4+ messages in thread
From: Theodore Tso @ 2009-06-22  1:48 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development

On Thu, Jun 18, 2009 at 05:51:07PM -0500, Eric Sandeen wrote:
> (hastily redone before I leave for a few days, hope this
> is sane, review welcome) :)
> 
> lsattr doesn't return an error if you point it at a file that 
> doesn't exist.
> 
> This is slightly trickier because it can take more than one
> file as an arg, but ls seems to report an error if any occurred,
> so this does the same, it'll report the last error that was 
> encountered.
> 
> Addresses-RedHat-Bugzilla: #489841
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Thanks, applied.

						- Ted

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-06-22  1:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-18 21:59 [PATCH] lsattr: return error values Eric Sandeen
2009-06-18 22:35 ` Eric Sandeen
2009-06-18 22:51 ` [PATCH V2] " Eric Sandeen
2009-06-22  1:48   ` Theodore Tso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).