Commit Graph

1129 Commits

Author SHA1 Message Date
Lennart Poettering 49fe5c0996 tree-wide: port various places over to STARTSWITH_SET() 2018-11-26 14:08:46 +01:00
Zbigniew Jędrzejewski-Szmek baaa35ad70 coccinelle: make use of SYNTHETIC_ERRNO
Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
2018-11-22 10:54:38 +01:00
Lennart Poettering 9d52a6e5a9
Merge pull request #9961 from fbuihuu/logind-fix-vt-reinit-race
Logind fix vt reinit race
2018-11-21 17:28:23 +01:00
Zbigniew Jędrzejewski-Szmek 6d176522f5 Revert 5fdf2d51c2
This reverts 5fdf2d51c2, except for one improved
log message.

Fixes #10613.

Checking if resume= is configured is a good idea, but it turns out we cannot do
it reliably:
- the code only supported boot options with sd-boot, and it's not very widely
  used. This means that for most systemd we could only check the current
  commandline, not the next one.
- Various systems resume without, e.g. Debian has
  /etc/initramfs-tools/conf.d/resume in the initramfs.

Making those checks better would be possible with enough effort, but there'll
be always new systems that boot in a slightly different way and we would need
to keep adding new cases. Longer term, we want to rely on autodetecting the
resume partition, and then checks like this will not be necessary at all. It is
quite clear from the number of bug reports that the number of poeple impacted
by this is quite high now, so let's just drop this.
2018-11-21 15:04:22 +01:00
Franck Bui adb8688b3f logind: stop managing VT switches if no sessions are registered on that VT
When no sessions are registered on a given VT (anymore), we should always let
the kernel processes VT switching (instead of simply emitting a warning)
otherwise the requests sent by the kernel are simply ignored making the VT
switch requested by users simply impossible.

Even if it shouldn't happen, this case was encountered in issue #9754, so
better to be safe than sorry.
2018-11-21 14:29:01 +01:00
Franck Bui 27dafac92b terminal-util: introduce vt_release() helper 2018-11-21 14:28:34 +01:00
Franck Bui ad96887a12 logind: become the controlling terminal process before restoring VT
Basically when a session ends, logind notices and restores VT_AUTO so the
kernel takes back VT-switching over.

logind achieves that by watching the process that took control of the session
(via the "TakeControl" D-Bus method), aka "the watched process", which can
be different from the one that initially opened the VT aka "the terminal
controlling process".

In this case the terminal controlling process can exit after the watched one
did and while logind is restoring the VT.

Even if logind took care to re-open the VT in case the VT was already in HUP
state, it wasn't enough because the terminal controlling process could have
exited right after, leaving the VT in HUP state and in VT_PROCESS mode making
further VT-switching impossible.

This patch fixes this situation by forcing logind to become the terminal
controlling process.

Fixes: #9754.
2018-11-21 14:25:10 +01:00
Franck Bui 6179ede1c5 terminal-util: introduce vt_restore() helper 2018-11-21 14:25:10 +01:00
Franck Bui 0212126c45 logind: make session_restore_vt() static
It's only used in logind-session.c.
2018-11-21 14:20:01 +01:00
Zbigniew Jędrzejewski-Szmek 294bf0c34a Split out pretty-print.c and move pager.c and main-func.h to shared/
This is high-level functionality, and fits better in shared/ (which is for
our executables), than in basic/ (which is also for libraries).
2018-11-20 18:40:02 +01:00
Yu Watanabe eae5c847f8 loginctl: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Zbigniew Jędrzejewski-Szmek a34c79d006 basic/main-func: also close the pager automatically
We generally want to close the pager last. This patch closes the pager last,
after the static destuctor calls. This means that they can do logging and such
like during normal program runtime.
2018-11-20 16:48:21 +01:00
Zbigniew Jędrzejewski-Szmek 6bc7a6ac2c inhibit: fix return value in error path 2018-11-20 16:48:20 +01:00
Lennart Poettering 6bf3c61c57 log: introduce new helper call log_setup_service()
Let's reduce the common boilerplate and have a single setup function
used by all service code to setup logging.
2018-11-20 11:18:22 +01:00
Lennart Poettering 5e332028f2 util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other
headers without this affecting everything which pulls in macro.h, which
is one of our most basic headers.

This is just refactoring, no change in behaviour, in prepartion for
later changes.
2018-11-19 21:14:34 +01:00
Lennart Poettering 2a44bf5099
Merge pull request #10811 from keszybz/define-main-through-macro
Define main through macro
2018-11-19 15:28:17 +01:00
Lennart Poettering 2675747f3c pam_systemd: suppress LOG_DEBUG log messages if debugging is off
In the PAM module we need to suppress LOG_DEBUG messages manually, if
debug logging is not on, as PAM won't do this for us. We did this
correctly for most log messages already, but two were missing. Let's fix
those too.

Fixes: #10822
2018-11-19 14:03:34 +01:00
Zbigniew Jędrzejewski-Szmek cc639ee79d user-runtime-dir: define main through macro 2018-11-17 09:13:35 +01:00
Zbigniew Jędrzejewski-Szmek c11cfa2865 logind: define main through macro 2018-11-17 09:13:35 +01:00
Zbigniew Jędrzejewski-Szmek b453c447e0 inhibit: define main through macro 2018-11-17 09:13:35 +01:00
Lennart Poettering 07be866903 logind: voidify more things 2018-11-16 21:50:37 +01:00
Lennart Poettering c282daed68 logind: when we need to execute a sleep operation we don't support, fall back to suspend
If suspend-then-hibernate, hybrid-sleep or plain hibernation is
supposed to be execute due to a key press/lid switch but is not
supported, automatically fall back to plain suspend (and log about it).

Fixes: #10558
2018-11-16 21:50:24 +01:00
Henry Tung 0c093a62ef logind: fix determination of CanHibernate() and other calls
As suggest here:

https://github.com/systemd/systemd/issues/10250#issuecomment-426788301

Fixes: #10250

(This suggested patch has been converted into a proper commit by me,
Lennart, with attribution to the original author, @henryptung)
2018-11-16 15:52:22 +01:00
Lennart Poettering c78e6f9e7b logind: imply right to reboot when user has right to set reboot-to-firmware flag
Let's reduce the number of actions the user has to acquire.
2018-11-16 15:52:22 +01:00
Lennart Poettering c57ed5735f logind: log correct error msg 2018-11-16 15:52:22 +01:00
Lennart Poettering 75100aeb9f logind: sort includes 2018-11-16 15:52:22 +01:00
Lennart Poettering 4e96eb682c logind: also expose bool prop on bus that declares whether we are on external power
The three core variables that affect idleness handling are whether we
are docked, whether we are on AC power and whether the lid is closed,
hence let's also expose the third variable on the bus, to make things
nicely debuggable.
2018-11-16 15:39:31 +01:00
Lennart Poettering e455380b18 logind: make sure that if we can't figure out whether we are on AC we presume we are
It's safer to assume that we are on AC than to assume we are on battery,
if we can't figure it out.
2018-11-16 15:39:31 +01:00
Lennart Poettering c30e0d7b6a logind: don't claim that RebootToFirmwareSetup was constant
It's not, after all, that's what SetRebootToFirmware() is about.

(I was wondering for a moment whether to make this EMITS_CHANGES, but
decided against it, given that the flag actually can be changed
externally to logind too, and we couldn't send out notifications for
that.)
2018-11-16 15:39:31 +01:00
Lennart Poettering 9b9c23daf4 logind: expose a boolean on the bus explaining whether logind thinks the lid is closed
This copies how we already expose a "Docked" boolean the reflects
whether we are in a docking station or not.
2018-11-16 15:39:31 +01:00
Zbigniew Jędrzejewski-Szmek cd5a29ce98
Merge pull request #10742 from poettering/c-utf8
default to C.UTF-8 locale, and many improvements to env var file parsing/kernel cmdline parsing
2018-11-15 12:47:17 +01:00
Lennart Poettering 042cad5737
Merge pull request #10753 from keszybz/pager-no-interrupt
Add mode in journalctl where ^C is handled by the pager
2018-11-14 20:09:39 +01:00
Lennart Poettering 13df9c398d fileio: automatically add NULL sentinel to parse_env_file()
Let's modernize things a bit.
2018-11-14 17:01:55 +01:00
Lennart Poettering aa8fbc74e3 fileio: drop "newline" parameter for env file parsers
Now that we don't (mis-)use the env file parser to parse kernel command
lines there's no need anymore to override the used newline character
set. Let's hence drop the argument and just "\n\r" always. This nicely
simplifies our code.
2018-11-14 17:01:54 +01:00
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Yu Watanabe deb2b7348e sd-device: drop priority and description from sd_device_monitor_attach_event() and sd_device_monitor_start()
Now we have sd_device_monitor_get_event_soruce(). So, it is not
necessary to include these parameters in the functions for sd_device_monitor.
2018-11-10 22:53:00 +09:00
Steven Allen 86cf4554ef logind: fix compilation without utmp (#10674) 2018-11-07 17:29:21 +01:00
Marco Trevisan (Treviño) 6260d28b8a login: Don't mark framebuffer devices as master-of-seat devices
Currently we consider any framebuffer device as enough to have a
valid graphical session, but this might lead to many false postives
like in the case of framebuffer devices that have a linked drm card
which is still in the process of being added, or for vesa fb, and
so it doesn't ensure us that we can have a proper graphical session.

Since these days we normally don't consider anything without a DRM
card able to provide a full graphical session, let's not set this
at this level.
Drivers which can provide a graphical session with the sole fb are
still free to mark any device as `master-of-seat`

Fixes #10435
2018-11-06 20:02:26 +03:00
Yu Watanabe 57512c893e tree-wide: set WRITE_STRING_FILE_DISABLE_BUFFER flag when we write files under /proc or /sys 2018-11-06 21:24:03 +09:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00
Yu Watanabe 76386309b8 login: use log_device_*() 2018-10-23 22:44:07 +09:00
Yu Watanabe 14cb109d45 tree-wide: replace 'unsigned int' with 'unsigned' 2018-10-19 22:19:12 +02:00
Lennart Poettering 849d653a4e
Merge pull request #10239 from yuwata/sd-device-monitor
sd-device: introduce sd_device_monitor
2018-10-18 18:30:38 +02:00
Lennart Poettering 8aeb1d3176
Merge pull request #10244 from poettering/nofile-bump
bump RLIMIT_NOFILE
2018-10-17 17:59:36 +02:00
Yu Watanabe eb968396bb login: replace udev_monitor by sd_device_monitor 2018-10-17 03:31:20 +09:00
Yu Watanabe 8da2f9e807
Merge pull request #10412 from poettering/sockaddr-sun-path
various fixes related to struct sockaddr_un handling
2018-10-17 01:25:58 +09:00
Lennart Poettering 1abaf4887d tree-wide: uniformly bump RLIMIT_NOFILE in all our tools that access the journal
This makes use of rlimit_nofile_bump() in all tools that access the
journal. In some cases this replaces older code to achieve this, and
others we add it in where it was missing.
2018-10-16 16:33:55 +02:00
Lennart Poettering 15a3e96f92 tree-wide: port various users over to sockaddr_un_set_path()
CID 1396140
CID 1396141
2018-10-15 19:40:51 +02:00
Lennart Poettering b921711248 logind: validate /run/user/1000 before we set it
Let's be safe than sorry, in particular as logind doesn't set it up
anymore, but user-runtime-dir@.service does, and logind doesn't really
track success of that.
2018-10-13 13:01:08 +02:00
Lennart Poettering 4e5b605af2 logind: automatically GC lingering users for who now user@.service (nor slice, not runtime dir service) is running anymore
This heavily borrows from @intelfx' PR #5546, but watches all three
units that are associated with a user now: the slice, the user@.service
and user-runtime-dir@.service.

The logic and reasoning behind it is the same though: there's no value
in keeping lingering users around if all their three services are gone.

Replaces: #5546
Fixes: #4162
2018-10-13 12:59:29 +02:00