summaryrefslogtreecommitdiffstats
path: root/sys-utils/setarch.c
diff options
context:
space:
mode:
authorSami Kerola2017-12-03 13:51:17 +0100
committerKarel Zak2017-12-04 13:04:16 +0100
commitcbfa1442761d5b85acd0652f2e7f0e21bf675cd4 (patch)
tree7bb57bb4fd5943a96365b3e33983baceccfe9812 /sys-utils/setarch.c
parentrename: use access(3) to check if a file exists (diff)
downloadkernel-qcow2-util-linux-cbfa1442761d5b85acd0652f2e7f0e21bf675cd4.tar.gz
kernel-qcow2-util-linux-cbfa1442761d5b85acd0652f2e7f0e21bf675cd4.tar.xz
kernel-qcow2-util-linux-cbfa1442761d5b85acd0652f2e7f0e21bf675cd4.zip
setarch: minor code clean up
Remove global variable, skip unnecessary comparison, and remove version printing function when a simple printf() can do the job. In same go fix compiler warning. sys-utils/setarch.c:296:4: warning: null argument where non-null required (argument 2) [-Wnonnull] execl("/bin/bash", NULL); Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/setarch.c')
-rw-r--r--sys-utils/setarch.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index 6673825c8..6f5c8d6b3 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -82,9 +82,8 @@
# define ADDR_LIMIT_3GB 0x8000000
#endif
-static int archwrapper;
-static void __attribute__((__noreturn__)) usage(void)
+static void __attribute__((__noreturn__)) usage(int archwrapper)
{
fputs(USAGE_HEADER, stdout);
if (!archwrapper)
@@ -120,13 +119,6 @@ static void __attribute__((__noreturn__)) usage(void)
exit(EXIT_SUCCESS);
}
-static void __attribute__((__noreturn__))
- show_version(void)
-{
- printf(UTIL_LINUX_VERSION);
- exit(EXIT_SUCCESS);
-}
-
static int set_arch(const char *pers, unsigned long options, int list)
{
struct utsname un;
@@ -253,6 +245,7 @@ int main(int argc, char *argv[])
const char *arch = NULL;
unsigned long options = 0;
int verbose = 0;
+ int archwrapper;
int c;
/* Options without equivalent short options */
@@ -294,9 +287,17 @@ int main(int argc, char *argv[])
errtryhelp(EXIT_FAILURE);
}
archwrapper = strcmp(program_invocation_short_name, "setarch") != 0;
- if (archwrapper)
+ if (archwrapper) {
arch = program_invocation_short_name; /* symlinks to setarch */
- else {
+#if defined(__sparc64__) || defined(__sparc__)
+ if (strcmp(arch, "sparc32bash") == 0) {
+ if (set_arch(arch, 0L, 0))
+ err(EXIT_FAILURE, _("Failed to set personality to %s"), arch);
+ execl("/bin/bash", "", NULL);
+ err(EXIT_FAILURE, _("failed to execute %s"), "/bin/bash");
+ }
+#endif
+ } else {
if (1 < argc && *argv[1] != '-') {
arch = argv[1];
argv[1] = argv[0]; /* for getopt_long() to get the program name */
@@ -305,23 +306,14 @@ int main(int argc, char *argv[])
}
}
-#if defined(__sparc64__) || defined(__sparc__)
- if (archwrapper && strcmp(arch, "sparc32bash") == 0) {
- if (set_arch(arch, 0L, 0))
- err(EXIT_FAILURE, _("Failed to set personality to %s"), arch);
- execl("/bin/bash", NULL);
- err(EXIT_FAILURE, _("failed to execute %s"), "/bin/bash");
- }
-#endif
-
while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) {
switch (c) {
case 'h':
- usage();
+ usage(archwrapper);
break;
case 'V':
- show_version();
- break;
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
case 'v':
verbose = 1;
break;