Commit Graph

36942 Commits

Author SHA1 Message Date
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
Zbigniew Jędrzejewski-Szmek 52d86690d6 basic/log: add concept of "synthethic errnos"
Synthetic errnos are processed like normal, and may be used in %m and become
the return value from log_*(), but they are not logged in the journal.
2018-11-22 10:45:08 +01:00
Tim Ruffing 883eb9be98 vconsole: Don't skip udev call for dummy device
Kernel 4.19 supports deferred console takeover [0], i.e., fbcon will
take over the console only when the first text is displayed on the
console. Before that event, only the dummy console is active. Our
currently udev rules call systemd-vconsole on every vtcon except for
dummy consoles. Thus the exception for dummy consoles prevents a call
to systemd-vconsole when no text is displayed on the console, and as a
consequence, the keymap will not be set in that case. This is wrong and
leads to issues when keyboard input is expected without text on the
console, e.g., when a graphical password prompt is used in the boot
process.

This reverts commit 6b169c13ec,
which introduced the exception for dummy devices to save unnecessary
udev calls.

Fixes #10826.

[0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=83d83bebf40132e2d55ec58af666713cc76f9764
2018-11-22 00:59:24 +01:00
Yann E. MORIN 66a5b5ce9b basic/user-util: properly protect use of gshadow
Commit 100d5f6ee6 (user-util: add new wrappers for [...] database
files), ammended by commit 4f07ffa8f5 (Use #if instead of #ifdef for
ENABLE_GSHADOW) moved code from sysuser to basic/user-util.

In doing so, the combination of both commits properly propagated the
ENABLE_GSHADOW conditions around the function manipulating gshadow, but
they forgot to protect the inclusion of the gshadow.h header.

Fix that to be able to build on C libraries that do not provide gshadow
(e.g. uClibc-ng, where it does not exist.)
2018-11-22 00:57:08 +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 053254e3cb generators: drop umask calls
systemd already sets the umask (see e3b8d0637d). When
running under systemd, we don't need to set it. And when *not* running under
systemd, for example during development, there is no reason to override the user
config. Let's just drop those calls.

$ git grep -e 'umask\(' -l 'src/*generator*' |xargs perl -i -0pe 's|^[^\n]*umask\([^\n]+\n\n||gms'
2018-11-21 13:40:24 +01:00
Michal Koutný aa1f95d264 core: Detect initial timer state from serialized data
We keep a mark whether a single-shot timer was triggered in the caller's
variable initial. When such a timer elapses while we are
serializing/deserializing the inner state, we consider the timer
incorrectly as elapsed and don't trigger it later.

This patch exploits last_trigger timestamp that we already serialize,
hence we can eliminate the argument initial completely.

A reproducer for OnBootSec= timers:
        cat >repro.c <<EOD
        /*
         * Compile:	gcc repro.c -o repro
         * Run:		./repro
         */
        #include <errno.h>
        #include <fcntl.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/stat.h>
        #include <sys/types.h>
        #include <time.h>
        #include <unistd.h>

        int main(int argc, char *argv[]) {
        	char command[1024];
        	int pause;

        	struct timespec now;

        	while (1) {
        		usleep(rand() % 200000); // prevent periodic repeats
               		clock_gettime(CLOCK_MONOTONIC, &now);
        		printf("%i\n", now.tv_sec);

        		system("rm -f $PWD/mark");
        		snprintf(command, 1024, "systemd-run --user --on-boot=%i --timer-property=AccuracySec=100ms "
        					"touch $PWD/mark", now.tv_sec + 1);
        		system(command);
        		system("systemctl --user list-timers");
        		pause = (1000000000 - now.tv_nsec)/1000 - 70000; // fiddle to hit the middle of reloading
        		usleep(pause > 0 ? pause : 0);
        		system("systemctl --user daemon-reload");
        		sync();
        		sleep(2);
        		if (open("./mark", 0) < 0)
        			if (errno == ENOENT) {
        				printf("mark file does not exist\n");
        				break;
        			}
        	}

        	return 0;
        }
        EOD
2018-11-21 11:28:33 +01:00
Lennart Poettering b390455cbb
Merge pull request #10866 from yuwata/libudev-util-cleanups
libudev-util: several cleanups and tests
2018-11-21 11:15:35 +01:00
Lennart Poettering 818623aca5
Merge pull request #10860 from keszybz/more-cleanup-2
Do more stuff from main macros
2018-11-21 11:07:31 +01:00
Yu Watanabe 4ec739f19f test: add tests for util_resolve_subsys_kernel() 2018-11-21 17:31:22 +09:00
Yu Watanabe 3839535a53 libudev: make util_resolve_subsys_kernel() return negative errno
This also replaces udev_device by sd_device in the function.
2018-11-21 17:31:16 +09:00
Yu Watanabe c0c591544a udev/scsi_id: fix buffer length 2018-11-21 17:30:49 +09:00
Yu Watanabe 01cbafe184 test: add tests for util_replace_whitespace() 2018-11-21 17:30:49 +09:00
Yu Watanabe df8ba4fa0e libudev-util: make util_replace_whitespace() not count leading white spaces 2018-11-21 17:30:45 +09:00
Zbigniew Jędrzejewski-Szmek 0c5a109a25 udevd: define main through macro
This removes the call to log_close(), and refactors how fork() is done. Now
the parent also goes through normal cleanup. This isn't necessary to use the
macro, but it feels cleaner this way.
2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek 138715dc12 udevadm: define main through macro
This removes a call to log_close(). I don't think this should matter.
The call to mac_selinux_init() is moved after parse_argv(). We probably
don't need selinux when printing help().
2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek 8d38b8ad56 Call mac_selinux_close() from main func macros, convert user-sessions and test-udev 2018-11-21 09:14:00 +01:00
Zbigniew Jędrzejewski-Szmek d1405af399 systemctl: define main through macro and call ask_password_agent_close() from the macro
This doesn't save us anything, but I like consistency.
2018-11-21 09:14:00 +01:00
Yu Watanabe 646acebd58 libudev-util: make util_replace_*() return size_t 2018-11-21 16:35:20 +09:00
Yu Watanabe 805a7097ee libudev-util: add assertions 2018-11-21 16:32:54 +09:00
Lennart Poettering e3b8d0637d core: run env generators with non-zero umask
For PID 1 we adjust the umask to 0, but generators should not run that
way, given that they might be implemented as shell scripts and such.
Let's hence explicitly adjust the umask for them.

We already do this for unit generators. Let's do this for env
generators, too.
2018-11-20 23:35:04 +01:00
Evgeny Vereshchagin f5f9a580dd tests: skip test_exec_ambientcapabilities on Travis CI under ASan
Let's not bother contributors with spurious failures nobody can't
seem to reproduce. There is an issue about that where we're trying
to figure out what's going on: https://github.com/systemd/systemd/issues/10696.
2018-11-20 20:23:19 +01:00
Lennart Poettering f81f8bac2c
Merge pull request #10853 from poettering/thaw-containers
main: don't freeze PID 1 in containers, exit with non-zero instead
2018-11-20 19:35:30 +01:00
Lennart Poettering 163ef57488
Merge pull request #10858 from poettering/tmpfiles-fixlets
more tmpfiles fixlets
2018-11-20 19:09:37 +01:00
Yu Watanabe 0c760322a4 portablectl: make "arg_host" const 2018-11-20 18:40:02 +01:00
Yu Watanabe f2fae6fbae mount-tool: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe c3d6fb26ed modules-load: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe f66da783fa machinectl: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Zbigniew Jędrzejewski-Szmek a6db316372 shared/main-func: also close the polkit agent automatically
The agent is closed after the static destuctors but before the pager.
No users of DEFINE_MAIN_FUNCTION* were using a polkit agent, so this makes no
functional difference.
2018-11-20 18:40:02 +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 0166c42868 machine-id: use static destructor and DEFINE_MAIN_FUNCTION() macro 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
Yu Watanabe 847da1ac1b locale: make "arg_host" const 2018-11-20 18:40:02 +01:00
Yu Watanabe 85ae63ee87 hostnamed: use DEFINE_MAIN_FUNCTION() macro
This also renames context_free() to context_clear().
2018-11-20 18:40:02 +01:00
Yu Watanabe 77182cc65e hibernate-resume-generator: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe a4ef3e4dbb fstab-generator: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe 45f394187a firstboot: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe 149afb45dc dissect: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe a8a7e5fcf2 bless-boot: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe 3a40f366b2 cryptsetup: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe 88325bf6e5 cgls: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Lennart Poettering bb25977244 main: don't freeze PID 1 in containers, exit with non-zero instead
After all we have a nice way to propagate total failures, hence let's
use it.
2018-11-20 17:04:07 +01:00
Lennart Poettering bb85a58208 main: use EXIT_EXCEPTION instead of EXIT_FAILURE at two more exceptional places 2018-11-20 17:04:07 +01:00
Lennart Poettering f2fb2ec942 nspawn: use EXIT_EXCEPTION where appropriate 2018-11-20 17:04:07 +01:00