Commit graph

501 commits

Author SHA1 Message Date
Lennart Poettering 7e9d36e06b systemctl: fix how we decode types and states
There was a bad memory access among other smaller issues.
2015-10-01 14:27:20 +02:00
reverendhomer bc6c18fef1 systemctl: fix memory leak in systemctl_parse_argv
This commit fixes Coverity #1325228
2015-10-01 12:09:00 +03:00
Lennart Poettering 32c6d387bf Merge pull request #1422 from keszybz/sd-daemon-mq-badf
sd-daemon: fix return value for sd_is_mq
2015-09-30 22:33:50 +02:00
Lennart Poettering 23a749f285 Merge pull request #1419 from keszybz/shell-completion
Shell completion tweaks
2015-09-30 22:32:09 +02:00
Zbigniew Jędrzejewski-Szmek 7bbb5359c0 systemctl: do not set variable to be immediately overwritten 2015-09-30 12:33:31 -04:00
Lennart Poettering a4420f7b8e systemctl: when reading legacy -t argument for shutdown, don't drop following parameter
We currently completely ignore the following parameter, but we really
should not, as that is actually the time to shut down on.
2015-09-30 12:23:33 +02:00
Lennart Poettering 45519fd630 systemctl: various modernizations 2015-09-30 12:23:32 +02:00
Daniel Mack 5cfee41459 tree-wide: use strempty() where possible
Also add a Coccinell patch to detect such locations in the future.
2015-09-30 11:41:03 +02:00
Lennart Poettering 7f96539d45 systemctl: when a shutdown is scheduled, always go via logind 2015-09-29 21:55:53 +02:00
Lennart Poettering 19578bb26b systemctl: minor modernizations 2015-09-29 21:55:53 +02:00
Lennart Poettering e449de8777 systemctl: port verb dispatching to generic verbs.[ch] code
Let's parse the command line the same way in our various tools.
2015-09-29 21:55:53 +02:00
Lennart Poettering 7089051f67 systemctl: prefer shutting down through logind even as root
Otherwise, wall messages will not be generated for root.
2015-09-29 21:55:53 +02:00
Lennart Poettering 57ab90065d systemctl: split out code invoking SetExitCode() into function of its own 2015-09-29 21:55:53 +02:00
Lennart Poettering 4057e12315 systemctl: don't assert on the arguments array unnecessarily
In most verbs it's fine to treat the arguments array being NULL is empty
array, hence do so.
2015-09-29 21:55:53 +02:00
Lennart Poettering 14b316ebf8 systemctl: make use of strv_skip() where appropriate 2015-09-29 21:55:53 +02:00
Lennart Poettering 691395d84c systemctl: make use of log_error_errno() where we can
Also adds a couple of "return" statements, where they are missing.
2015-09-29 21:55:52 +02:00
Lennart Poettering 4fbd7192c5 systemctl: rework how we connect to busses
Sometimes we have to connect to the system manager directly (early boot,
initrd, late boot, ...), sometimes through the system bus (unprivileged,
remote, logind, ...). Instead of guessing in advance, which kind of
connection we require (and sometimes guessing incorrectly), let's make
sure each time we need  bus connection we request the right bus
explicitly.

This way, we set up exactly the bus connections require, never guess
incorrectly, and do so only immediately when necessary.

As effect this reworks avoid_bus() into install_client_side(), since
that's all it determines now: whether to install unit files client-side
or server-side (i.e. in PID 1).
2015-09-29 21:55:52 +02:00
Lennart Poettering 266f3e269d bus-util: rename bus_open_transport() to bus_connect_transport()
In sd-bus, the sd_bus_open_xyz() family of calls allocates a new bus,
while sd_bus_default_xyz() family tries to reuse the thread's default
bus. bus_open_transport() sometimes internally uses the former,
sometimes the latter family, but suggests it only calls the former via
its name. Hence, let's avoid this confusion, and generically rename the
call to bus_connect_transport().

Similar for all related calls.

And while we are at it, also change cgls + cgtop to do direct systemd
connections where possible, since all they do is talk to systemd itself.
2015-09-29 21:55:52 +02:00
Lennart Poettering 2cc7b0a25f systemctl: rename parse_time_spec() to parse_shutdown_time_spec()
Let's clarify that this function is specific to shutdown time
specifications, nothing else.
2015-09-29 21:55:52 +02:00
Lennart Poettering eca830bee9 systemctl: conditionalize /dev/initctl fallback on HAVE_SYSV_COMPAT 2015-09-29 21:55:52 +02:00
Lennart Poettering 172d7abfea systemctl: allocate arg_wall only on the heap
Previously, we'd allocate it sometimes from the heap, but otherwise let
it point directly int argv[]. Let's clean this up, so that we know
exactly how to release its resources, and do so at the end.
2015-09-29 21:55:52 +02:00
Lennart Poettering fc2ffaf17d systemctl: add 'const' where appropriate 2015-09-29 21:55:52 +02:00
Lennart Poettering 48ec22bc02 systemctl: remove client-side wall message support
logind sends out wall messages now, let's remove this from the systemctl
client side hence. If people build systemd without logind support they
won't get wall messages now, but that's OK.
2015-09-29 21:55:52 +02:00
Lennart Poettering e3ead6bb42 systemctl: move strv_skip_first() out of systemctl.c
Make it generic, call it strv_skip() and move it to strv.[ch]
2015-09-29 21:55:52 +02:00
Lennart Poettering 56a730fa56 systemctl: split out code that schedules shutdowsn into its own function 2015-09-29 21:55:52 +02:00
Lennart Poettering 2cf05793f2 systemctl: rename all logind-specific functions to logind_xyz() 2015-09-29 21:55:52 +02:00
Lennart Poettering 949d9ce954 systemctl: move shutdown cancelling code into its own function
Let's make sure the main switch statement only invokes functions, but
doesn't do anything real on its own.
2015-09-29 21:55:52 +02:00
Lennart Poettering 4f16c1f479 systemctl: don't special case ACTION_RUNLEVEL anymore
Let's move its dispatching to the main switch statement.
2015-09-29 21:55:51 +02:00
Lennart Poettering f2d11d35e9 systemctl: introduce a single function to set the wall message
Let's not have the same code three times, but reduce it to one function.
2015-09-29 21:55:51 +02:00
Lennart Poettering 94f099d813 systemctl: make "systemctl is-system-running" return "offline" if we are not booted with systemd
This sounds like the better place to expose this than in "systemd-notify
--booted".

Also document the so far undocumented "unknown" state the command might
return. And rearrange the table of states documented to be more like the
one for "is-running".

Also, don't document the precise exit code of this function, just say
errors are reported != 0 or > 0...
2015-09-29 21:55:51 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Zbigniew Jędrzejewski-Szmek 7e55de3b96 Move all unit states to basic/ and extend systemctl --state=help 2015-09-28 15:09:34 -04:00
Zbigniew Jędrzejewski-Szmek e16972e626 systemctl: add --state=help
This mirrors --type=help and simplifies completion scripts.

The array of states is dense, so the is no need to check if the string is null.
2015-09-28 15:09:34 -04:00
David Herrmann 840cdfcd81 Merge pull request #1334 from poettering/sd-bus-default-flush-close
sd-bus: introduce new sd_bus_default_flush_close() call
2015-09-22 17:33:58 +02:00
Lennart Poettering 1fc464f6fb cgtop: underline table header
Let's underline the header line of the table shown by cgtop, how it is
customary for tables. In order to do this, let's introduce new ANSI
underline macros, and clean up the existing ones as side effect.
2015-09-22 16:30:42 +02:00
Lennart Poettering fa2f8973ad sd-bus: introduce new sd_bus_default_flush_close() call
If code enqueues a message on one of the default busses, but doesn't
sync on it, and immediately drops the reference to the bus again, it
will stay queued and consume memory. Intrdouce a new call
sd_bus_default_flush_close() that can be invoked at the end of programs
(or threads) and flushes out all unsent messages on any of the default
busses.
2015-09-22 16:29:10 +02:00
Alban Crequy 287419c119 containers: systemd exits with non-zero code
When a systemd service running in a container exits with a non-zero
code, it can be useful to terminate the container immediately and get
the exit code back to the host, when systemd-nspawn returns. This was
not possible to do. This patch adds the following to make it possible:

- Add a read-only "ExitCode" property on PID 1's "Manager" bus object.
  By default, it is 0 so the behaviour stays the same as previously.
- Add a method "SetExitCode" on the same object. The method fails when
  called on baremetal: it is only allowed in containers or in user
  session.
- Add support in systemctl to call "systemctl exit 42". It reuses the
  existing code for user session.
- Add exit.target and systemd-exit.service to the system instance.
- Change main() to actually call systemd-shutdown to exit() with the
  correct value.
- Add verb 'exit' in systemd-shutdown with parameter --exit-code
- Update systemctl manpage.

I used the following to test it:

| $ sudo rkt --debug --insecure-skip-verify run \
|            --mds-register=false --local docker://busybox \
|            --exec=/bin/chroot -- /proc/1/root \
|            systemctl --force exit 42
| ...
| Container rkt-895a0cba-5c66-4fa5-831c-e3f8ddc5810d failed with error code 42.
| $ echo $?
| 42

Fixes https://github.com/systemd/systemd/issues/1290
2015-09-21 17:32:45 +02:00
Jan Synacek ac5e3a505e core: extend KillUnit() to return error when no unit was killed 2015-09-21 10:05:49 +02:00
Lennart Poettering 3227b2bced Merge pull request #1227 from intelfx/systemctl-legacy-tools-polkit
systemctl: fix various aspects of polkit authorization in legacy tools.
2015-09-10 19:53:31 +02:00
Daniel Mack a18f3caa56 Merge pull request #1239 from poettering/cgroup-pids
core: add support for the "pids" cgroup controller
2015-09-10 19:11:29 +02:00
Daniel Mack 786c5bf957 Merge pull request #1242 from poettering/no-off_t
Drop usage of off_t
2015-09-10 19:01:25 +02:00
Lennart Poettering 03a7b521e3 core: add support for the "pids" cgroup controller
This adds support for the new "pids" cgroup controller of 4.3 kernels.
It allows accounting the number of tasks in a cgroup and enforcing
limits on it.

This adds two new setting TasksAccounting= and TasksMax= to each unit,
as well as a gloabl option DefaultTasksAccounting=.

This also updated "cgtop" to optionally make use of the new
kernel-provided accounting.

systemctl has been updated to show the number of tasks for each service
if it is available.

This patch also adds correct support for undoing memory limits for units
using a MemoryLimit=infinity syntax. We do the same for TasksMax= now
and hence keep things in sync here.
2015-09-10 18:41:06 +02:00
Lennart Poettering 59f448cf15 tree-wide: never use the off_t unless glibc makes us use it
off_t is a really weird type as it is usually 64bit these days (at least
in sane programs), but could theoretically be 32bit. We don't support
off_t as 32bit builds though, but still constantly deal with safely
converting from off_t to other types and back for no point.

Hence, never use the type anymore. Always use uint64_t instead. This has
various benefits, including that we can expose these values directly as
D-Bus properties, and also that the values parse the same in all cases.
2015-09-10 18:16:18 +02:00
Evgeny Vereshchagin 1143adf722 systemctl: add RequisiteOf* as inverses of Requisite and RequisiteOverridable 2015-09-10 14:49:29 +03:00
Ivan Shapovalov 58158dc765 systemctl: improve clarity of error messages in the logind path 2015-09-10 14:45:00 +03:00
Ivan Shapovalov 2ac3930f5b systemctl: relax permission checks in halt_main()
Thus we allow (non-interactive) polkit auth to kick in for legacy commands
(halt, poweroff, reboot, telinit) as well.

Fixes (another aspect of) issue #213.
2015-09-10 14:45:00 +03:00
Ivan Shapovalov a9085ea356 systemctl: fix logind bus call error handling in halt_main()
Handle -EOPNOTSUPP and -EINPROGRESS like in start_special().
2015-09-10 14:44:59 +03:00
Ivan Shapovalov 4c315c2c7c systemctl: minor: use IN_SET() instead of repeated equality checks. 2015-09-10 14:39:46 +03:00
Ivan Shapovalov 16f017fa6e systemctl: legacy tools shall never be interactive
Fixes (the main concern of) issue #213.
2015-09-10 01:14:07 +03:00
Daniel Mack 7681f5b889 systemctl: add dry-run support for scheduled shutdowns
Prefix the action parameter with "dry-" in case the --dry-run command
line switch was passed.
2015-09-09 17:52:12 +02:00