Commit Graph

129 Commits

Author SHA1 Message Date
Lennart Poettering 8e04444385 journalctl: port JSON output mode to new JSON API
Also, while we are at it, beef it up, by adding json-seq support (i.e.
https://tools.ietf.org/html/rfc7464). This is particularly useful in
conjunction with jq's --seq switch.
2018-10-11 17:25:27 +02:00
Yu Watanabe eda193578e bus-util: make --property= optionally take value 2018-09-12 12:11:25 +09:00
Zbigniew Jędrzejewski-Szmek 7692fed98b
Merge pull request #9783 from poettering/get-user-creds-flags
beef up get_user_creds() a bit and other improvements
2018-08-21 10:09:33 +02:00
Lennart Poettering fafff8f1ff user-util: rework get_user_creds()
Let's fold get_user_creds_clean() into get_user_creds(), and introduce a
flags argument for it to select "clean" behaviour. This flags parameter
also learns to other new flags:

- USER_CREDS_SYNTHESIZE_FALLBACK: in this mode the user records for
  root/nobody are only synthesized as fallback. Normally, the synthesized
  records take precedence over what is in the user database.  With this
  flag set this is reversed, and the user database takes precedence, and
  the synthesized records are only used if they are missing there. This
  flag should be set in cases where doing NSS is deemed safe, and where
  there's interest in knowing the correct shell, for example if the
  admin changed root's shell to zsh or suchlike.

- USER_CREDS_ALLOW_MISSING: if set, and a UID/GID is specified by
  numeric value, and there's no user/group record for it accept it
  anyway. This allows us to fix #9767

This then also ports all users to set the most appropriate flags.

Fixes: #9767

[zj: remove one isempty() call]
2018-08-20 15:58:21 +02:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Yu Watanabe 4ae25393f3 tree-wide: shorten error logging a bit
Continuation of 4027f96aa0.
2018-08-07 10:14:33 +09:00
Yu Watanabe 31d99bd172 tree-wide: do not assign values if not used 2018-06-19 08:44:55 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Zbigniew Jędrzejewski-Szmek 4d9685be5f Use const char* for timestamp strings which we don't plan to modify
Makes the intent a bit clearer.
2018-05-31 14:30:23 +02:00
Lennart Poettering 5c828e66b5 tree-wide: port various bits of the tree over to the new DUMP_STRING_TABLE() macro 2018-05-22 13:14:18 +02:00
Yu Watanabe 29a3db75fd util: rename signal_from_string_try_harder() to signal_from_string()
Also this makes the new `signal_from_string()` function reject
e.g, `SIG3` or `SIG+5`.
2018-05-03 16:52:49 +09:00
Yu Watanabe 38d7f50632 login: drop an unused variable
Follow-up for 99f1229d76.
2018-04-24 15:42:03 +09:00
Lennart Poettering 99f1229d76 loginctl: port loginctl to format-table.[ch] 2018-04-18 12:51:15 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe c75436067f tree-wide: remove unused variables (#8612) 2018-03-29 12:50:50 +02:00
Yu Watanabe a7e4861c74 bus-util: add flags for bus_map_all_properties() (#8546)
This adds flags BUS_MAP_STRDUP and BUS_MAP_BOOLEAN_AS_BOOL.
If BUS_MAP_STRDUP is set, then each "s" message is duplicated.
If BUS_MAP_BOOLEAN_AS_BOOL is set, then each "b" message is
written to a bool pointer.

Follow-up for #8488.
See https://github.com/systemd/systemd/pull/8488#discussion_r175816270.
2018-03-28 13:37:27 +02:00
Yu Watanabe 07636114b1 bus-util: introduce bus_message_print_all_properties()
Then, use it where applicable.
2018-03-20 00:44:37 +09:00
Yu Watanabe f37f8a61c0 bus-util: make bus_map_all_properties() not copy string 2018-03-20 00:42:48 +09:00
Yu Watanabe ee5324aa04 tree-wide: voidify pager_open()
Even if pager_open() fails, in general, we should continue the operations.
All erroneous cases in pager_open() show log message in the function.
So, it is not necessary to check the returned value.
2018-03-19 21:04:02 +09:00
Franck Bui 0a84daa5aa Comment the fact that some tools need to termintate their bus connect first 2018-01-12 16:20:36 +01:00
Franck Bui a3c5634573 Revert "tree-wide: use _cleanup_(sd_bus_flush_close_unrefp) at various appropriate places"
This reverts commit 0b3c84eb7d.

The removal of _cleanup_() usages was done on purpose, see
cf647b69ba.

Fixes: #3543
2018-01-12 16:09:21 +01:00
Vito Caputo 508f63b411 *: fix some inconsistent control statement style 2017-12-01 16:49:52 -08:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering 0986658d51
Merge pull request #6866 from sourcejedi/set-linger2
logind: fix `loginctl enable-linger`
2017-11-15 11:15:15 +01:00
Alan Jenkins 545f779f5c loginctl: enable-linger does not need fallback to XDG_SESSION_ID
To maintain consistency with `loginctl user-status`, drop the fallback to
XDG_SESSION_ID for `loginctl enable-linger`.  The fallback was unnecessary
and also incorrect: it passed the numeric value of the session identifier
as a UID value.
2017-11-14 18:15:33 +00:00
Lennart Poettering 3850319be5 loginctl: rework sysfs tree dump, to honour --full and friends
Let's hook up the sysfs tree output with the output flags logic,
already used when dumping log lines or process trees. This way we get
very similar output handling for line breaking/ellipsation in all three
outputs of structured data.

Fixes: #7095
2017-11-10 21:44:29 +01:00
Lennart Poettering 459b9f9ff7 merge two lines in our get_output_flags() functions
loginctl, machinectl, systemctl all have very similar implementations of
a get_output_flags() functions. Simplify it by merging two lines that
set the same flag.
2017-11-10 21:40:47 +01:00
Lennart Poettering 0b3c84eb7d tree-wide: use _cleanup_(sd_bus_flush_close_unrefp) at various appropriate places
Let's shorten the code a bit.
2017-11-10 21:15:44 +01:00
Lennart Poettering 9e29521e27 loginctl: invoke sigbus_install()
We show journal data, hence we should install the SIGBUS handler.

Similar for machinectl, where the same applies.
2017-11-10 21:09:13 +01:00
Zbigniew Jędrzejewski-Szmek 8a4b13c5cb treewide: unify identical definitions of polkit_agent_open_if_enabled() (#7187)
Follows the same pattern as pager_open() now.
2017-10-30 09:57:53 +01:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Zbigniew Jędrzejewski-Szmek 9cf8e2087b loginctl: also use $XDG_SESSION_ID for session-status 2017-05-31 22:42:50 -04:00
Zbigniew Jędrzejewski-Szmek bdb07fa5ac loginctl: use $XDG_SESSION_ID for "our" session
Instead of always letting logind guess what the caller's session is, let's
give it the value from $XDG_SESSION_ID when it is present in the caller's
environment.

Nowadays terminal emulators are often running as services under systemd --user,
and not as part of an actual session, so all loginctl calls which depend on
logind guessing the session will fail. I don't see a reason not to honour
$XDG_SESSION_ID.

This applies to LockSession, UnlockSession, TerminateSession, ActivateSession,
SetUserLinger.

Fixes #6032.
2017-05-31 22:32:14 -04:00
Ian Wienand 7e563bfc97 Add short-iso-precise for journalctl output (#5884)
This adds a short-iso-precise option for journalctl output.  It is similar to
short-iso, but includes microseconds.
2017-05-07 20:23:49 -04:00
slodki b0d08b056e loginctl: fix typo causing ignoring multiple session IDs (#5732)
Fixes #5733
2017-04-13 12:34:59 +02:00
Lennart Poettering f9e0eefc7c tree-wide: make bus_map_all_properties return a proper sd_bus_error
And then show it, to make things a bit friendlier to the user if we fail
acquiring some props.

In fact, this fixes a number of actual bugs, where we used an error
structure for output that we actually never got an error in.
2017-02-09 16:13:07 +01:00
Zbigniew Jędrzejewski-Szmek bc06be7533 shared/cgroup-show: extract funtion to query unit cgroup path
…and use it where possible.
2017-02-01 20:31:50 -05:00
Zbigniew Jędrzejewski-Szmek 5611ddebe4 loginctl: report tty in session listings
Without the tty it's really hard to tell which session is which.

New output:
$ ./loginctl
   SESSION        UID USER             SEAT             TTY
        13       1002 zbyszek          seat0            tty3
        c1         42 gdm              seat0            /dev/tty1
        11       1002 zbyszek          seat0            tty4
         3       1002 zbyszek          seat0            /dev/tty2
        17       1002 zbyszek          seat0            tty5
        18       1002 zbyszek          seat0            tty6
6 sessions listed.
2016-10-16 15:59:22 -04:00
Zbigniew Jędrzejewski-Szmek e8f215d34c loginctl: drop casts in printf 2016-10-16 15:59:22 -04:00
Lennart Poettering 43dcc86a13 sd-bus: make sure bus_map_all_properties() handle booleans right
sd-bus generally exposes bools as "int" instead of "bool" in the public API.
This is relevant when unmarshaling booleans, as the relevant functions expect
an int* pointer and no bool* pointer. Since sizeof(bool) is not necessarily the
same as sizeof(int) this is problematic and might result in memory corruption.

Let's fix this, and make sure bus_map_all_properties() handles booleans as
ints, as the rest of sd-bus, and make all users of it expect the right thing.
2016-06-21 13:20:48 +02:00
Lennart Poettering cf647b69ba systemctl: make sure we terminate the bus connection first, and then close the pager (#3550)
If "systemctl -H" is used, let's make sure we first terminate the bus
connection, and only then close the pager. If done in this order ssh will get
an EOF on stdin (as we speak D-Bus through ssh's stdin/stdout), and then
terminate. This makes sure the standard error we were invoked on is released by
ssh, and only that makes sure we don't deadlock on the pager which waits for
all clients closing its input pipe.

(Similar fixes for the various other xyzctl tools that support both pagers and
-H)

Fixes: #3543
2016-06-16 09:29:16 -04:00
Lennart Poettering 0ff308c8de shared: drop kernel_thread bool from cgroups show code
Make this an output flag instead, so that our function prototypes can lose one
parameter
2016-04-22 16:06:20 +02:00
Lennart Poettering a0e270198a loginctl,machinectl: also make use of new GetProcesses() bus call
This ports over machinectl and loginctl to also use the new GetProcesses() bus
call to show the process tree of a container or login session. This is similar
to how systemctl already has been ported over in a previous commit.
2016-04-22 16:06:20 +02:00
Zbigniew Jędrzejewski-Szmek 26e00f0e6a loginctl: show linger status in user-status
zbyszek (1002)
           Since: Tue 2016-04-12 23:11:46 EDT; 23min ago
           State: active
        Sessions: *3
          Linger: yes
            Unit: user-1002.slice
                  ├─user@1002.service
                  │ └─init.scope
                  │   ├─38 /usr/lib/systemd/systemd --user
                  │   └─39 (sd-pam)
                  └─session-3.scope
                    ├─   31 login -- zbyszek
                    ├─   44 -bash
                    ├─15076 loginctl user-status zbyszek
                    └─15077 less
2016-04-21 00:21:33 -04:00
Zbigniew Jędrzejewski-Szmek f4046fe06f loginctl: add --value option 2016-04-04 22:41:49 -04:00
Zbigniew Jędrzejewski-Szmek 4f9a91055c systemctl: add --value option
With this option, systemctl will only print the rhs in show:
$ systemctl show -p Wants,After systemd-journald --value
systemd-journald.socket ...
systemd-journald-dev-log.socket ...

This is useful in scripts, because the need to call awk or similar
is removed.
2016-04-04 22:41:49 -04:00
Alexander Kuleshov ea4b98e657 tree-wide: merge pager_open_if_enabled() to the pager_open()
Many subsystems define own pager_open_if_enabled() function which
checks '--no-pager' command line argument and open pager depends
on its value. All implementations of pager_open_if_enabled() are
the same. Let's merger this function with pager_open() from the
shared/pager.c and remove pager_open_if_enabled() from all subsytems
to prevent code duplication.
2016-02-26 01:13:23 +06:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Jan Synacek 40c9fe4c08 basic/terminal-util: introduce SYSTEMD_COLORS environment variable
... to determine if color output should be enabled. If the variable is not set,
fall back to using on_tty(). Also, rewrite existing code to use
colors_enabled() where appropriate.
2016-01-20 10:12:41 +01:00