Commit Graph

70 Commits

Author SHA1 Message Date
Egor Chelak 1b10fa0ef7 cast NULL to char * when using execl
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.

The call in newgrp.c was changed for consistency.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-10-29 19:49:07 +02:00
Alexey Gladkov 9fd01b10d0 setarch: add arm and aarch64 architectures to transition rules
Since aarch64 kernel can be configured with compat 32-bit support
enabled, extend translation rules in a way similar to x86/x86_64.

Suggested-by: "Dmitry V. Levin" <ldv@altlinux.org>
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2020-06-24 15:05:53 +02:00
Alexey Gladkov 7f48cfb0e4 setarch: make verify_arch_domain extendable
When other compatible architectures are introduced, they will also have
to be added to the verifier.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
2020-06-24 15:05:53 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07:00
Karel Zak cf5debba06 setarch: avoid NULL dereference [coverity check]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-28 13:08:21 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Andrew Savchenko 146900d411 setarch: add new e2k subarches
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-09 11:04:17 +02:00
Sami Kerola 4813a5210f various: fix 'uninitialized when used' warnings [clang]
This change fixes "warning: variable 'var' may be uninitialized when used
here [-Wconditional-uninitialized]" warnings reported in various files.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:19:24 +01:00
Andreas Schwab 33e87bf152 setarch: don't return address of automatic variable
On architectures without special personalities setarch uses the contents
of a local variable with automatic storage duration after return from
the function, causing it to report a spurious error.

$ setarch m68k
setarch: Kernel cannot set architecture to m68k

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
2019-01-22 12:02:16 +01:00
Karel Zak 3fa06e0490 setarch: fix obscure sparc32bash use-case
Reported-by: Carlos Santos <casantos@datacom.com.br>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-11-22 11:03:35 +01:00
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