setarch: reindent code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
846c7d30b3
commit
77eb13b965
|
@ -52,7 +52,6 @@ enum {
|
|||
printf(_("Switching on %s.\n"), #_flag); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#ifndef UNAME26
|
||||
# define UNAME26 0x0020000
|
||||
#endif
|
||||
|
@ -87,14 +86,12 @@ enum {
|
|||
# define ADDR_LIMIT_3GB 0x8000000
|
||||
#endif
|
||||
|
||||
static void __attribute__((__noreturn__))
|
||||
show_help(void)
|
||||
static void __attribute__((__noreturn__)) show_help(void)
|
||||
{
|
||||
fputs(USAGE_HEADER, stdout);
|
||||
printf(_(" %s%s [options] [program [program arguments]]\n"),
|
||||
program_invocation_short_name,
|
||||
!strcmp(program_invocation_short_name, "setarch") ? " <arch>" : "");
|
||||
|
||||
fputs(USAGE_OPTIONS, stdout);
|
||||
fputs(_(" -v, --verbose says what options are being switched on\n"), stdout);
|
||||
fputs(_(" -R, --addr-no-randomize disables randomization of the virtual address space\n"), stdout);
|
||||
|
@ -110,33 +107,32 @@ show_help(void)
|
|||
fputs(_(" --4gb ignored (for backward compatibility only)\n"), stdout);
|
||||
fputs(_(" --uname-2.6 turns on UNAME26\n"), stdout);
|
||||
fputs(_(" --list list settable architectures, and exit\n"), stdout);
|
||||
|
||||
fputs(USAGE_SEPARATOR, stdout);
|
||||
fputs(USAGE_HELP, stdout);
|
||||
fputs(USAGE_VERSION, stdout);
|
||||
printf(USAGE_MAN_TAIL("setarch(8)"));
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void __attribute__((__noreturn__))
|
||||
show_usage(const char *s)
|
||||
static void __attribute__((__noreturn__)) show_usage(const char *s)
|
||||
{
|
||||
if (s)
|
||||
errx(EXIT_FAILURE, _("%s\nTry `%s --help' for more information."), s, program_invocation_short_name);
|
||||
errx(EXIT_FAILURE,
|
||||
_("%s\nTry `%s --help' for more information."), s,
|
||||
program_invocation_short_name);
|
||||
else
|
||||
errx(EXIT_FAILURE, _("Try `%s --help' for more information."), program_invocation_short_name);
|
||||
errx(EXIT_FAILURE, _("Try `%s --help' for more information."),
|
||||
program_invocation_short_name);
|
||||
}
|
||||
|
||||
static void __attribute__((__noreturn__))
|
||||
show_version(void)
|
||||
show_version(void)
|
||||
{
|
||||
printf(UTIL_LINUX_VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int
|
||||
set_arch(const char *pers, unsigned long options, int list)
|
||||
static int set_arch(const char *pers, unsigned long options, int list)
|
||||
{
|
||||
struct utsname un;
|
||||
int i;
|
||||
|
@ -150,17 +146,17 @@ set_arch(const char *pers, unsigned long options, int list)
|
|||
{PER_LINUX32, "linux32", NULL},
|
||||
{PER_LINUX, "linux64", NULL},
|
||||
#if defined(__powerpc__) || defined(__powerpc64__)
|
||||
#ifdef __BIG_ENDIAN__
|
||||
# ifdef __BIG_ENDIAN__
|
||||
{PER_LINUX32, "ppc32", "ppc"},
|
||||
{PER_LINUX32, "ppc", "ppc"},
|
||||
{PER_LINUX, "ppc64", "ppc64"},
|
||||
{PER_LINUX, "ppc64pseries", "ppc64"},
|
||||
{PER_LINUX, "ppc64iseries", "ppc64"},
|
||||
#else
|
||||
{PER_LINUX32, "ppc32le", "ppcle"},
|
||||
{PER_LINUX32, "ppcle", "ppcle"},
|
||||
{PER_LINUX, "ppc64le", "ppc64le"},
|
||||
#endif
|
||||
# else
|
||||
PER_LINUX32, "ppc32le", "ppcle"},
|
||||
PER_LINUX32, "ppcle", "ppcle"},
|
||||
PER_LINUX, "ppc64le", "ppc64le"},
|
||||
# endif
|
||||
#endif
|
||||
#if defined(__x86_64__) || defined(__i386__) || defined(__ia64__)
|
||||
{PER_LINUX32, "i386", "i386"},
|
||||
|
@ -202,54 +198,48 @@ set_arch(const char *pers, unsigned long options, int list)
|
|||
{PER_LINUX, "alphaev6", "alpha"},
|
||||
{PER_LINUX, "alphaev67", "alpha"},
|
||||
#endif
|
||||
{-1, NULL, NULL}, /* place holder, eventually filled up at runtime */
|
||||
/* place holder, will be filled up at runtime */
|
||||
{-1, NULL, NULL},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
/* Add the trivial transition {PER_LINUX, machine, machine} if no such
|
||||
target_arch is hardcoded yet. */
|
||||
/* Add the trivial transition {PER_LINUX, machine, machine} if no
|
||||
* such target_arch is hardcoded yet. */
|
||||
uname(&un);
|
||||
for (i = 0; transitions[i].perval >= 0; i++)
|
||||
if(!strcmp(un.machine, transitions[i].target_arch))
|
||||
if (!strcmp(un.machine, transitions[i].target_arch))
|
||||
break;
|
||||
if (transitions[i].perval < 0) {
|
||||
unsigned long wrdsz = CHAR_BIT * sizeof(void*);
|
||||
unsigned long wrdsz = CHAR_BIT * sizeof(void *);
|
||||
if (wrdsz == 32 || wrdsz == 64) {
|
||||
/* fill up the place holder */
|
||||
transitions[i].perval = wrdsz == 32 ? PER_LINUX32 : PER_LINUX;
|
||||
transitions[i].target_arch = un.machine;
|
||||
transitions[i].result_arch = un.machine;
|
||||
}
|
||||
}
|
||||
|
||||
if (list) {
|
||||
for(i = 0; transitions[i].target_arch != NULL; i++)
|
||||
for (i = 0; transitions[i].target_arch != NULL; i++)
|
||||
printf("%s\n", transitions[i].target_arch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(i = 0; transitions[i].perval >= 0; i++)
|
||||
if(!strcmp(pers, transitions[i].target_arch))
|
||||
for (i = 0; transitions[i].perval >= 0; i++)
|
||||
if (!strcmp(pers, transitions[i].target_arch))
|
||||
break;
|
||||
|
||||
if(transitions[i].perval < 0)
|
||||
if (transitions[i].perval < 0)
|
||||
errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers);
|
||||
|
||||
pers_value = transitions[i].perval | options;
|
||||
if (set_pers(pers_value) == -EINVAL)
|
||||
return 1;
|
||||
|
||||
uname(&un);
|
||||
if(transitions[i].result_arch &&
|
||||
strcmp(un.machine, transitions[i].result_arch))
|
||||
{
|
||||
if(strcmp(transitions[i].result_arch, "i386")
|
||||
if (transitions[i].result_arch && strcmp(un.machine, transitions[i].result_arch)) {
|
||||
if (strcmp(transitions[i].result_arch, "i386")
|
||||
|| (strcmp(un.machine, "i486")
|
||||
&& strcmp(un.machine, "i586")
|
||||
&& strcmp(un.machine, "i686")
|
||||
&& strcmp(un.machine, "athlon")))
|
||||
errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), pers);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -260,26 +250,25 @@ int main(int argc, char *argv[])
|
|||
int verbose = 0;
|
||||
int c;
|
||||
|
||||
/* Options --3gb and --4gb are for compatibitity with an old Debian setarch
|
||||
implementation. */
|
||||
static const struct option longopts[] =
|
||||
{
|
||||
{ "help", 0, 0, 'h' },
|
||||
{ "version", 0, 0, 'V' },
|
||||
{ "verbose", 0, 0, 'v' },
|
||||
{ "addr-no-randomize", 0, 0, 'R' },
|
||||
{ "fdpic-funcptrs", 0, 0, 'F' },
|
||||
{ "mmap-page-zero", 0, 0, 'Z' },
|
||||
{ "addr-compat-layout", 0, 0, 'L' },
|
||||
{ "read-implies-exec", 0, 0, 'X' },
|
||||
{ "32bit", 0, 0, 'B' },
|
||||
{ "short-inode", 0, 0, 'I' },
|
||||
{ "whole-seconds", 0, 0, 'S' },
|
||||
{ "sticky-timeouts", 0, 0, 'T' },
|
||||
{ "3gb", 0, 0, '3' },
|
||||
{ "4gb", 0, 0, OPT_4GB },
|
||||
{ "uname-2.6", 0, 0, OPT_UNAME26 },
|
||||
{ NULL, 0, 0, 0 }
|
||||
/* Options --3gb and --4gb are for compatibitity with an old
|
||||
* Debian setarch implementation. */
|
||||
static const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{"addr-no-randomize", no_argument, NULL, 'R'},
|
||||
{"fdpic-funcptrs", no_argument, NULL, 'F'},
|
||||
{"mmap-page-zero", no_argument, NULL, 'Z'},
|
||||
{"addr-compat-layout", no_argument, NULL, 'L'},
|
||||
{"read-implies-exec", no_argument, NULL, 'X'},
|
||||
{"32bit", no_argument, NULL, 'B'},
|
||||
{"short-inode", no_argument, NULL, 'I'},
|
||||
{"whole-seconds", no_argument, NULL, 'S'},
|
||||
{"sticky-timeouts", no_argument, NULL, 'T'},
|
||||
{"3gb", no_argument, NULL, '3'},
|
||||
{"4gb", no_argument, NULL, OPT_4GB},
|
||||
{"uname-2.6", no_argument, NULL, OPT_UNAME26},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
@ -307,14 +296,14 @@ int main(int argc, char *argv[])
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
#if defined(__sparc64__) || defined(__sparc__)
|
||||
#if defined(__sparc64__) || defined(__sparc__)
|
||||
if (!strcmp(p, "sparc32bash")) {
|
||||
if (set_arch(p, 0L, 0))
|
||||
err(EXIT_FAILURE, _("Failed to set personality to %s"), p);
|
||||
execl("/bin/bash", NULL);
|
||||
err(EXIT_FAILURE, _("failed to execute %s"), "/bin/bash");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
|
|
Loading…
Reference in New Issue