]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
setarch: make <arch> optional
authorKarel Zak <kzak@redhat.com>
Tue, 7 Aug 2018 09:31:14 +0000 (11:31 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 7 Aug 2018 09:31:14 +0000 (11:31 +0200)
Let's allow to change personality flags without execution domain
modification.

Old way:
  setarch `arch` --addr-no-randomize myprog

New way:
  setarch --addr-no-randomize myprog

Addresses: https://github.com/karelzak/util-linux/issues/668
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/setarch.8
sys-utils/setarch.c

index 2a701fa574c9a7de02151c91a847b7bef0712c05..d0fd5b945fbed27cbe80aa9ff9e41e0463b7d6c3 100644 (file)
@@ -1,27 +1,36 @@
 .TH SETARCH 8 "December 2017" "util-linux" "System Administration"
 .SH NAME
-setarch \- change reported architecture in new program environment and set personality flags
+setarch \- change reported architecture in new program environment and/or set personality flags
 .SH SYNOPSIS
 .B setarch
-.I arch
+.RI [ arch ]
 [options]
 .RI [ program
 .RI [ argument ...]]
 .sp
+.B setarch
+.BR \-\-list | \-h | \-V
+.sp
 .B arch
 [options]
 .RI [ program
 .RI [ argument ...]]
-.sp
-.B setarch
-.BR \-\-list | \-h | \-V
 .SH DESCRIPTION
 .B setarch
-currently only affects the output of \fBuname -m\fR.
+modifies execution domains and process personality flags.
+.PP
+The execution domains currently only affects the output of \fBuname -m\fR.
 For example, on an AMD64 system, running \fBsetarch i386 \fIprogram\fR
 will cause \fIprogram\fR to see i686 instead of x86_64 as the machine type.
 It also allows to set various personality options.
 The default \fIprogram\fR is \fB/bin/sh\fR.
+.PP
+Since version 2.33 the
+.I arch
+comnand line argument is optional and
+.B setarch
+may be used to change personality flags (ADDR_LIMIT_*, SHORT_INODE, etc) without
+modification of the execution domain.
 .SH OPTIONS
 .TP
 .B \-\-list
@@ -105,6 +114,8 @@ Display version information and exit.
 .BR \-h , " \-\-help"
 Display help text and exit.
 .SH EXAMPLES
+setarch --addr-no-randomize mytestprog
+.br
 setarch ppc32 rpmbuild --target=ppc --rebuild foo.src.rpm
 .br
 setarch ppc32 -v -vL3 rpmbuild --target=ppc --rebuild bar.src.rpm
@@ -118,6 +129,10 @@ Elliot Lee
 .MT jnovy@redhat.com
 Jindrich Novy
 .ME
+.br
+.MT kzak@redhat.com
+Karel Zak
+.ME
 .SH "SEE ALSO"
 .BR personality (2),
 .BR select (2)
index fc5764f82fae87ee4ff1f05b526db21ec3024196..a733f7b3c12cf6c1a463a8b82de881ee135a5732 100644 (file)
@@ -94,7 +94,7 @@ static void __attribute__((__noreturn__)) usage(int archwrapper)
 {
        fputs(USAGE_HEADER, stdout);
        if (!archwrapper)
-               printf(_(" %s <arch> [options] [<program> [<argument>...]]\n"), program_invocation_short_name);
+               printf(_(" %s [<arch>] [options] [<program> [<argument>...]]\n"), program_invocation_short_name);
        else
                printf(_(" %s [options] [<program> [<argument>...]]\n"), program_invocation_short_name);
 
@@ -385,19 +385,26 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (!arch)
-               errx(EXIT_FAILURE, _("no architecture argument specified"));
+       if (!arch && !options)
+               errx(EXIT_FAILURE, _("no architecture argument or personality flags specified"));
 
        argc -= optind;
        argv += optind;
 
-       doms = init_arch_domains();
+       /* get execution domain (architecture) */
+       if (arch) {
+               doms = init_arch_domains();
+               target = get_arch_domain(doms, arch);
 
-       target = get_arch_domain(doms, arch);
-       if (!target)
-               errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), arch);
+               if (!target)
+                       errx(EXIT_FAILURE, _("%s: Unrecognized architecture"), arch);
+               pers_value = target->perval;
+       }
+
+       /* add personality flags */
+       pers_value |= options;
 
-       pers_value = target->perval | options;
+       /* call kernel */
        if (personality(pers_value) < 0) {
                /*
                 * Depending on architecture and kernel version, personality
@@ -411,7 +418,9 @@ int main(int argc, char *argv[])
                        err(EXIT_FAILURE, _("failed to set personality to %s"), arch);
        }
 
-       verify_arch_domain(target, arch);
+       /* make sure architecture is set as expected */
+       if (arch)
+               verify_arch_domain(target, arch);
 
        if (verbose) {
                printf(_("Execute command `%s'.\n"), argc ? argv[0] : "/bin/sh");