Commit Graph

60 Commits

Author SHA1 Message Date
Karel Zak 0554182555 setarch: make <arch> optional
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>
2018-08-07 11:31:14 +02:00
Karel Zak 1db8bf9378 setarch: split set_arch() function to small functions
It seems better to keep the code more flexibile by small one-purpose
functions than by one huge monster.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-06 16:32:36 +02:00
Karel Zak e60b6df54e setarch: add another PER_LINUX32 aliases for ppcle
The big-endian version maps generic "ppc" and "ppc32" aliases to
PER_LINUX32.  It seems that we can do the same for little-endian.

Note that SYS_personality does not care about LE/BE, it's 32 or 64 bit.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-14 13:05:00 +02:00
Karel Zak fd777151bf sys-utils: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:44:25 +01:00
Sami Kerola cbfa144276 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>
2017-12-04 13:04:16 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 7a87a774af setarch: use errtryhelp()
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:34:47 +02:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak 9a8fada18b setarch: let's keep analyzer happy [coverity scan] 2016-10-05 11:12:45 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Ruediger Meier 9508e2972b setarch: add "exec" message to --verbose
Also we don't need fflush() in non-verbose case.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-22 14:13:33 +01:00
Dmitry V. Levin ae7065760d setarch: fix personality syscall return code check
Depending on architecture and kernel version, personality
syscall is either capable or incapable of returning an error.
If the return value is not an error, then it's the previous
personality value, which can be an arbitrary value
undistinguishable from an error value.
To make things clear, a second call is needed.

For more details about personality syscall peculiarities see
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=glibc-2.22-637-ge0043e17dfc5

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2016-03-07 14:23:21 +01:00
Waldemar Brodkorb fcca5f1e18 setarch: fix regression for sparc builds
With following commit:
5edb0ea6bb

Sparc cross-compile fails.

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
2015-03-30 11:50:01 +02:00
Sami Kerola 00b5ef70e2 setarch: print error when command runs without arguments
$ ./setarch
Segmentation fault (core dumped)
$ coredumpctl gdb
...
Program terminated with signal SIGSEGV, Segmentation fault.
301                     if (*argv[1] != '-') {

Reference: 5edb0ea6bb
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-02-19 10:55:10 +01:00
Ruediger Meier d9ca5dd442 setarch: fix typo (missing braces) for ppcle
Introduced in 77eb13b9, noticed on ppc64le.

CC: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2015-02-10 11:18:51 +01:00
Karel Zak b2b5b502d2 setarch: fix --list
$ ./setarch --list
.
.
setarch: no architecture argument specified

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 08:26:09 +01:00
Karel Zak 5edb0ea6bb setarch: cleanup options usage
* call --help, --verbose and --list from one place only
* add 'archwrapper' variable to detect when called by symplink
* make --list available only got setchar(8) (but no for symlinks)

Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-12 12:22:10 +01:00
Benno Schulenberg 1e098672f4 setarch: differentiate between "unrecognized" and "cannot set"
When the provided string does not match any architecture that
setarch knows about, the response stays "Unrecognized architecture",
but when trying to set the specified architecture does not have any
effect, then respond with "Kernel cannot set architecture to...".

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-12 11:28:21 +01:00
Benno Schulenberg 26b0b857c9 textual: list the options of setarch in a more alphabetical order
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:43:16 +01:00
Benno Schulenberg 682430494c setarch: make the usage synopsis comprehensible for translators
Use two separate strings for the two different forms of setarch,
instead of filling in an untranslated word into a single string.
Also use the standard angular brackets for nonliteral arguments.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:42:41 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola 9ed11cc260 setarch: use personality() system call when it is available
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:02 +01:00
Sami Kerola 77eb13b965 setarch: reindent code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-09-19 19:31:02 +01:00
Ruediger Meier ae2c3b5bee setarch: add generic support for setarch $(uname -m) ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-05-29 09:52:26 +02:00
Ruediger Meier f6eb160c6e setarch: add shortcut binary uname26
There are some uname26 binaries flying around. Let's make it available
everywhere.

Internal SUSE references: fate313476, sr226509

CC: Stanislav Brabec <sbrabec@suse.cz>
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-22 09:25:12 +00:00
Ruediger Meier 34c265f01c setarch: flush output streams before exec
This fixes the following (non-deterministic) discrepancy:

$ setarch x86_64 -RFZLvXBIST3 --uname-2.6 echo success
Switching on READ_IMPLIES_EXEC.
Switching on ADDR_LIMIT_32BIT.
Switching on SHORT_INODE.
Switching on WHOLE_SECONDS.
Switching on STICKY_TIMEOUTS.
Switching on ADDR_LIMIT_3GB.
Switching on UNAME26.
success

$ setarch x86_64 -RFZLvXBIST3 --uname-2.6 echo success  &> /tmp/bla; cat /tmp/bla
success

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2014-05-22 09:41:24 +02:00
Anton Blanchard 95bf26fd68 setarch: Fix ppc64le architectures
setarch currently fails on ppc64le because it tries to
use big endian architecture names. Fix it.

Signed-off-by: Anton Blanchard <anton@samba.org>
2014-04-07 12:38:22 +02:00
Sami Kerola f29a3d1868 setarch: prefer preprocessor rather than autotools check
It seems to be pointless to spend time in ./configure phase when
preprocessor has to perform #ifndef check anyway.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-01 13:35:26 +02:00
Sami Kerola 69d00b75df setarch: clean up usage()
Requested-by: Karel Zak <kzak@redhat.com>
References: http://marc.info/?l=util-linux-ng&m=136516351523680&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:17:05 +02:00
Sami Kerola 5d1607e260 setarch: add option to list settable architectures
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-05 14:03:07 +02:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06 11:51:17 +01:00
Karel Zak 5b90f817d8 setarch: fix compiler warning [-Wmissing-prototypes]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-16 18:51:27 +02:00
Sami Kerola edf1cf0af5 setarch: disallow unknown command line options
Exit with instruction to run --help if unknown option is encountered.
Before the following example printed error, but resulted to an attempt
to run argument.

$ x86_64 -x ls

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-17 17:59:59 +02:00
Sami Kerola 50f32c363a setarch: do not use -1 as array index [cppcheck]
Negative array index does technically work, but looks awkward and
can confuse static analyser such as cppcheck.

[sys-utils/setarch.c:267]: (error) Array index -1 is out of bounds

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-09 22:51:10 +02:00
Sami Kerola efb8854f4c sys-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:49:40 +02:00
Karel Zak b7fcd7ab6a setarch: minor changes to usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-09-27 13:26:59 +02:00
Sami Kerola b446402b79 setarch: add version printing
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-10 21:33:47 +02:00
Sami Kerola cf1377a431 setarch: use program_invocation_short_name
Trust that the c.h is setting program name correctly.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-10 19:37:37 +02:00
Sami Kerola 745627993b setarch: move options struct to function scope
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-10 19:37:19 +02:00
Ben Hutchings 70eebc40e2 setarch: add --uname-2.6 option for personality flag UNAME26
[kzak@redhat.com: - minor change in usage()]

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-29 11:16:25 +02:00
Karel Zak cfe2d24951 setarch: fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 13:16:21 +02:00
Francesco Cosoleto c60103a9f3 fstrim, setarch: replace error() with err()
This should improve a bit the portability as error() is a GNU extension and
util-linux provides fallbacks for err.h functions.

Fix compilation with icc, broken due to a reference to `__builtin_va_arg_pack'
in error.h using the -gcc default option.

Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
2011-06-08 13:09:18 +02:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00
Karel Zak 601d12fb10 rename util-linux-ng back to util-linux
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-30 11:41:59 +01:00
Karel Zak 2d281745d9 setarch: add fallback for linux/personality
setarch.c:248: error: 'ADDR_NO_RANDOMIZE' undeclared (first use in this function)
setarch.c:248: error: (Each undeclared identifier is reported only once
setarch.c:248: error: for each function it appears in.)
setarch.c:251: error: 'FDPIC_FUNCPTRS' undeclared (first use in this function)
setarch.c:257: error: 'ADDR_COMPAT_LAYOUT' undeclared (first use in this function)
setarch.c:260: error: 'READ_IMPLIES_EXEC' undeclared (first use in this function)

Linux gzp1 2.4.36.1-gzp1 #1 SMP Tue Feb 19 10:23:48 CET 2008 i686 GNU/Linux

Reported-By: Gabor Z. Papp <gzp@papp.hu>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-05-13 14:00:39 +02:00
Dmitry V. Levin 3c52010c68 setarch: provide backwards compatibility
The getopt_long(3) use introduced by commit
8df90dec2b
broke backwards compatibility.

Old behavior:
$ i386 uname -m
i686

New behavior:
$ i386 uname -m
i386: invalid option -- m
Linux

Traditional method to fix it is to disable program arguments reordering
by prefixing getopt_long's optstring with '+' character.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2008-04-16 11:20:09 +02:00
Oliver Falk adf88e666a setarch: add missing alpha subarchs
Signed-off-by: Oliver Falk <oliver@linux-kernel.at>
Signed-off-by: Karel Zak <kzak@redhat.com>
2007-12-03 13:34:42 +01:00
Benno Schulenberg 2e2d3ff6a3 setarch: tweak the help text, and gettextize a forgotten message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2007-11-06 01:09:04 +01:00
LaMont Jones 0901c3a467 setarch: fix compiler warning
NULL is not 0L.  It's (void*)0.  Passing that as a parameter to a function
that takes an unsigned long results in a warning about the lack of a cast.

Signed-off-by: LaMont Jones <lamont@debian.org>
2007-09-23 21:34:33 +02:00