*/
static struct arch_domain *init_arch_domains(void)
{
- struct utsname un;
+ static struct utsname un;
size_t i;
static struct arch_domain transitions[] =
{PER_LINUX, "alphaev56", "alpha"},
{PER_LINUX, "alphaev6", "alpha"},
{PER_LINUX, "alphaev67", "alpha"},
+#endif
+#if defined(__e2k__)
+ {PER_LINUX, "e2k", "e2k"},
+ {PER_LINUX, "e2kv4", "e2k"},
+ {PER_LINUX, "e2kv5", "e2k"},
+ {PER_LINUX, "e2kv6", "e2k"},
+ {PER_LINUX, "e2k4c", "e2k"},
+ {PER_LINUX, "e2k8c", "e2k"},
+ {PER_LINUX, "e2k1cp", "e2k"},
+ {PER_LINUX, "e2k8c2", "e2k"},
+ {PER_LINUX, "e2k12c", "e2k"},
+ {PER_LINUX, "e2k16c", "e2k"},
+ {PER_LINUX, "e2k2c3", "e2k"},
#endif
/* place holder, will be filled up at runtime */
{-1, NULL, NULL},
{
struct arch_domain *d;
- for (d = doms; d->perval >= 0; d++) {
+ for (d = doms; d && d->perval >= 0; d++) {
if (!strcmp(pers, d->target_arch))
break;
}
int verbose = 0;
int archwrapper;
int c;
- struct arch_domain *doms, *target;
+ struct arch_domain *doms, *target = NULL;
unsigned long pers_value = 0;
+ char *shell = NULL, *shell_arg = NULL;
/* Options without equivalent short options */
enum {
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
if (argc < 1) {
warnx(_("Not enough arguments"));
archwrapper = strcmp(program_invocation_short_name, "setarch") != 0;
if (archwrapper) {
arch = program_invocation_short_name; /* symlinks to setarch */
-#if defined(__sparc64__) || defined(__sparc__)
+
+ /* Don't use ifdef sparc here, we get "Unrecognized architecture"
+ * error message later if necessary */
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);
- errexec("/bin/bash");
+ shell = "/bin/bash";
+ shell_arg = "";
+ goto set_arch;
}
-#endif
} else {
if (1 < argc && *argv[1] != '-') {
arch = argv[1];
while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) {
switch (c) {
- case 'h':
- usage(archwrapper);
- break;
- case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
case 'v':
verbose = 1;
break;
} else
warnx(_("unrecognized option '--list'"));
/* fallthrough */
+
default:
errtryhelp(EXIT_FAILURE);
+ case 'h':
+ usage(archwrapper);
+ case 'V':
+ print_version(EXIT_SUCCESS);
}
}
argc -= optind;
argv += optind;
+set_arch:
/* get execution domain (architecture) */
if (arch) {
doms = init_arch_domains();
if (arch)
verify_arch_domain(target, arch);
+ if (!argc) {
+ shell = "/bin/sh";
+ shell_arg = "-sh";
+ }
if (verbose) {
- printf(_("Execute command `%s'.\n"), argc ? argv[0] : "/bin/sh");
+ printf(_("Execute command `%s'.\n"), shell ? shell : argv[0]);
/* flush all output streams before exec */
fflush(NULL);
}
- if (!argc) {
- execl("/bin/sh", "-sh", NULL);
- errexec("/bin/sh");
+ /* Execute shell */
+ if (shell) {
+ execl(shell, shell_arg, NULL);
+ errexec(shell);
}
+ /* Execute on command line specified command */
execvp(argv[0], argv);
errexec(argv[0]);
}