diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-10-15 23:10:35 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-10-16 12:23:55 +0100 |
commit | 492dcb2eb191b844a2fd5e51db3eed85289bea1f (patch) | |
tree | 910f93d88891b573520ebd5c812d61ddc7fbeed8 /src/id.c | |
parent | d035eacfdeba2da0134e606c8a63b2f3c0bd05bb (diff) | |
download | coreutils-492dcb2eb191b844a2fd5e51db3eed85289bea1f.tar.xz |
all: use die() rather than error(EXIT_FAILURE)
die() has the advantage of being apparent to the compiler
that it doesn't return, which will avoid warnings in some cases,
and possibly generate better code.
* cfg.mk (sc_die_EXIT_FAILURE): A new syntax check rule to
catch any new uses of error (CONSTANT, ...);
Diffstat (limited to 'src/id.c')
-rw-r--r-- | src/id.c | 40 |
1 files changed, 19 insertions, 21 deletions
@@ -26,6 +26,7 @@ #include <selinux/selinux.h> #include "system.h" +#include "die.h" #include "error.h" #include "mgetgroups.h" #include "quote.h" @@ -147,13 +148,13 @@ main (int argc, char **argv) /* politely decline if we're not on a SELinux/SMACK-enabled kernel. */ #ifdef HAVE_SMACK if (!selinux_enabled && !smack_enabled) - error (EXIT_FAILURE, 0, - _("--context (-Z) works only on " - "an SELinux/SMACK-enabled kernel")); + die (EXIT_FAILURE, 0, + _("--context (-Z) works only on " + "an SELinux/SMACK-enabled kernel")); #else if (!selinux_enabled) - error (EXIT_FAILURE, 0, - _("--context (-Z) works only on an SELinux-enabled kernel")); + die (EXIT_FAILURE, 0, + _("--context (-Z) works only on an SELinux-enabled kernel")); #endif just_context = true; break; @@ -191,11 +192,11 @@ main (int argc, char **argv) } if (n_ids && just_context) - error (EXIT_FAILURE, 0, - _("cannot print security context when user specified")); + die (EXIT_FAILURE, 0, + _("cannot print security context when user specified")); if (just_user + just_group + just_group_list + just_context > 1) - error (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice")); + die (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice")); bool default_format = ! (just_user || just_group @@ -203,12 +204,12 @@ main (int argc, char **argv) || just_context); if (default_format && (use_real || use_name)) - error (EXIT_FAILURE, 0, - _("cannot print only names or real IDs in default format")); + die (EXIT_FAILURE, 0, + _("cannot print only names or real IDs in default format")); if (default_format && opt_zero) - error (EXIT_FAILURE, 0, - _("option --zero not permitted in default format")); + die (EXIT_FAILURE, 0, + _("option --zero not permitted in default format")); /* If we are on a SELinux/SMACK-enabled kernel, no user is specified, and either --context is specified or none of (-u,-g,-G) is specified, @@ -224,7 +225,7 @@ main (int argc, char **argv) || (smack_enabled && smack_new_label_from_self (&context) < 0 && just_context)) - error (EXIT_FAILURE, 0, _("can't get process context")); + die (EXIT_FAILURE, 0, _("can't get process context")); } if (n_ids == 1) @@ -245,10 +246,7 @@ main (int argc, char **argv) } } if (pwd == NULL) - { - error (0, 0, _("%s: no such user"), quote (spec)); - exit (EXIT_FAILURE); - } + die (EXIT_FAILURE, 0, _("%s: no such user"), quote (spec)); pw_name = xstrdup (pwd->pw_name); ruid = euid = pwd->pw_uid; rgid = egid = pwd->pw_gid; @@ -267,7 +265,7 @@ main (int argc, char **argv) errno = 0; euid = geteuid (); if (euid == NO_UID && errno) - error (EXIT_FAILURE, errno, _("cannot get effective UID")); + die (EXIT_FAILURE, errno, _("cannot get effective UID")); } if (just_user ? use_real @@ -276,7 +274,7 @@ main (int argc, char **argv) errno = 0; ruid = getuid (); if (ruid == NO_UID && errno) - error (EXIT_FAILURE, errno, _("cannot get real UID")); + die (EXIT_FAILURE, errno, _("cannot get real UID")); } if (!just_user && (just_group || just_group_list || !just_context)) @@ -284,12 +282,12 @@ main (int argc, char **argv) errno = 0; egid = getegid (); if (egid == NO_GID && errno) - error (EXIT_FAILURE, errno, _("cannot get effective GID")); + die (EXIT_FAILURE, errno, _("cannot get effective GID")); errno = 0; rgid = getgid (); if (rgid == NO_GID && errno) - error (EXIT_FAILURE, errno, _("cannot get real GID")); + die (EXIT_FAILURE, errno, _("cannot get real GID")); } } |