summaryrefslogtreecommitdiff
path: root/src/basic/terminal-util.c
Commit message (Collapse)AuthorAge
* terminal-util: port some generic code over to rearrange_stdio()Lennart Poettering2018-05-30
|
* util: add new safe_close_above_stdio() wrapperLennart Poettering2018-05-30
| | | | | | At various places we only want to close fds if they are not stdin/stdout/stderr, i.e. fds 0, 1, 2. Let's add a unified helper call for that, and port everything over.
* Some comment adjustmentsZbigniew Jędrzejewski-Szmek2018-05-30
| | | | Follow up for review of #8184.
* terminal-util: make resolve_dev_console() less weirdLennart Poettering2018-05-30
| | | | | Let's normalize the behaviour: return a negative errno style error code, and return the resolved string directly as argument.
* terminal-util: modernize get_kernel_consoles() a bitLennart Poettering2018-05-30
| | | | | Also, make sure when we run in a container, we don't use the data from /sys at all, but immediately fall back to /dev/console itself.
* tty-ask-password-agent: reenable color for boot-time password promptLennart Poettering2018-05-30
| | | | | | | The password prompt used to be highlighted, and that was a good thing. Let's fix things to make the prompt highlighted again. Fixes: #3853
* terminal-util: add some explanatory commentsLennart Poettering2018-05-30
|
* terminal-util: minor, trivial fixes and improvementsLennart Poettering2018-05-30
|
* terminal-util: when making /dev/null or the console stdio, forget cached ↵Lennart Poettering2018-05-30
| | | | | | | | | | | | | terminal features Let's forget all relevant terminal features we learnt when we make a console or /dev/null stdin/stdout/stderr. Also, while we are at it, let's drop the various _unlikely_ and _likely_ annotiations around the terminal feature caches. In many cases we call the relevant functions only once in which cases the annotations are likely to do just harm and no good. After all we can't know if the specific code will call us just once or many times...
* terminal-util: rework acquire_terminal()Lennart Poettering2018-05-30
| | | | | | | | | | | | | | This modernizes acquire_terminal() in a couple of ways: 1. The three boolean arguments are replaced by a flags parameter, that should be more descriptive in what it does. 2. We now properly handle inotify queue overruns 3. We use _cleanup_ for closing the fds now, to shorten the code quite a bit. Behaviour should not be altered by this.
* tree-wide: make use of wait_for_terminate_and_check() at various placesLennart Poettering2018-05-30
| | | | | | Using wait_for_terminate_and_check() instead of wait_for_terminate() let's us simplify, shorten and unify the return value checking and logging of waitid(). Hence, let's use it all over the place.
* tree-wide: introduce new safe_fork() helper and port everything overLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds a new safe_fork() wrapper around fork() and makes use of it everywhere. The new wrapper does a couple of things we previously did manually and separately in a safer, more correct and automatic way: 1. Optionally resets signal handlers/mask in the child 2. Sets a name on all processes we fork off right after forking off (and the patch assigns useful names for all processes we fork off now, following a systematic naming scheme: always enclosed in () – in order to indicate that these are not proper, exec()ed processes, but only forked off children, and if the process is long-running with only our own code, without execve()'ing something else, it gets am "sd-" prefix.) 3. Optionally closes all file descriptors in the child 4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe way so that the parent dying before this happens being handled safely. 5. Optionally reopens the logs 6. Optionally connects stdin/stdout/stderr to /dev/null 7. Debug logs about the forked off processes.
* terminal-util: open /dev/null with O_CLOEXEC in make_stdio_null()Lennart Poettering2018-05-30
| | | | | | | | | | Ultimately, O_CLOEXEC should be off in fd 0, 1, 2, but when we open /dev/null here it's unlikely to be < 0, and after dupping the fd to 0, 1, 2 we turn off O_CLOEXEC explicitly anyway. Unless we know that what we are about to open will return 0, 1 or 2 we should always set O_CLOEXEC in order to be safe to other threads forking of subprocesses at the wrong moment.
* terminal-util: return first error, not last in make_stdio()Lennart Poettering2018-05-30
| | | | | | | | Just a minor tweak, making sure we execute as much as we can of the funciton, but return the first error instead of the last we encounter. This is usuelly how we do things when we have functions that continue on the first error, so let's do it like that here too.
* Prep v236 : Add missing SPDX-License-Identifier (2/9) src/basicSven Eden2018-03-26
|
* Remove a bunch of unused variablesZbigniew Jędrzejewski-Szmek2017-11-01
| | | | | gcc does not warn about those, because of the _cleanup_ usage. clang is smarter here.
* build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-11-23
| | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* tree-wide: use IN_SET where possibleAndreas Rammhold2017-09-29
| | | | | In addition to the changes from #6933 this handles cases that could be matched with the included cocci file.
* cgroup, unit, fragment parser: make use of new firewall functionsDaniel Mack2017-11-21
|
* Add abstraction model for BPF programsDaniel Mack2017-11-20
| | | | | This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code.
* v235: Added missing updatesSven Eden2017-11-19
|
* systemctl: don't do ANSI underlining on TERM=linux (#6778)Lennart Poettering2017-09-09
| | | | | | | The linux console apparently can't do underlining, hence let's not do it on the console. Also see: #6601
* terminal: unify code for resetting kbd utf8 mode a bit (#6692)Lennart Poettering2017-09-25
| | | | | | We have the same code at two places, let's unify that at one place. Follow-up for #6606
* terminal reset should honour default_utf8 kernel setting (#6606)g0tar2017-08-30
| | | | terminal reset should honour default_utf8 kernel setting
* tree-wide: use path_startswith() rather than startswith() where ever that's ↵Lennart Poettering2017-09-25
| | | | | | | appropriate When checking path prefixes we really should use the right APIs, just in case people add multiple slashes to their paths...
* util-lib: add a new skip_dev_prefix() helperLennart Poettering2017-09-25
| | | | | | | This new helper removes a leading /dev if there is one. We have code doing this all over the place, let's unify this, and correct it while we are at it, by using path_startswith() rather than startswith() to drop the prefix.
* Prep v235: Apply pending upstream updates in src/basic [1/4]Sven Eden2017-08-30
|
* Prep v235: Apply upstream fixes (3/10) [src/basic]Sven Eden2017-08-14
|
* core: reprint the question every 2 sec in ask_char()Franck Bui2017-07-17
| | | | | | | | | | | | | | | | | | | | | | | ask_char() now reprints the question every 2sec automatically. It prefixes its output with '\r' to to bring the cursor to the beginning of the terminal line, and then print the message, redoing it every 2sec. As long as nothing interferes with out output this logic will have no visible effect as we constantly overprint the visible text with the exact same text. However, if something is dumped in the middle, then our question won't get lost, as we'll ask soon again. This is useful if the question is asked to a terminal that is also used to dump some other status messages/logs. For example when confirmation messages are enabled during the boot (elogind.confirm_spawn=1), the question can easily be lost if the kernel logs are also enabled and both use the same console. Idea suggested by Lennart Poettering.
* core: monitor the inotify file descriptor not the console one in ↵Franck Bui2017-07-17
| | | | | | | | | | acquire_terminal() When waiting for the terminal to be release in acquire_terminal(), we were monitoring the terminal fd instead of the inotify descriptor. Therefore any write accesses would wake up the waiting process instead of being wake up when the tty is closed only.
* Prep v232: Do not listen to SYSTEMD_* environment variables to override things.Sven Eden2017-07-05
|
* terminal-util: remove unnecessary check of result of isatty() (#4000)0xAX2017-07-05
| | | | | | | | | | | | | After the call of the isatty() we check its result twice in the open_terminal(). There are no sense to check result of isatty() that it is less than zero and return -errno, because as described in documentation: isatty() returns 1 if fd is an open file descriptor referring to a terminal; otherwise 0 is returned, and errno is set to indicate the error. So it can't be less than zero.
* terminal-util: use getenv_bool for $SYSTEMD_COLORSZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | | | This changes the semantics a bit: before, SYSTEMD_COLORS= would be treated as "yes", same as SYSTEMD_COLORS=xxx and SYSTEMD_COLORS=1, and only SYSTEMD_COLORS=0 would be treated as "no". Now, only valid booleans are treated as "yes". This actually matches how $SYSTEMD_COLORS was announced in NEWS.
* elogind: ignore lack of tty when checking whether colors should be enabledZbigniew Jędrzejewski-Szmek2017-07-05
| | | | | | | | | | | When started by the kernel, we are connected to the console, and we'll set TERM properly to some value in fixup_environment(). We'll then enable or disable colors based on the value of $SYSTEMD_COLORS and $TERM. When reexecuting, TERM should be already set, so we can use this value. Effectively, behaviour is the same as before affd7ed1a was reverted, but instead of reopening the console before configuring color output, we just ignore what stdout is connected to and decide based on the variables only.
* core: inherit TERM from PID 1 for all services started on /dev/consoleLennart Poettering2017-07-05
| | | | | | | This way, invoking nspawn from a shell in the best case inherits the TERM setting all the way down into the login shell spawned in the container. Fixes: #3697
* elogind: ignore lack of tty when checking whether colors should be enabledZbigniew Jędrzejewski-Szmek2017-06-19
| | | | | | | | | | | | | When started by the kernel, we are connected to the console, and we'll set TERM properly to some value in fixup_environment(). We'll then enable or disable colors based on the value of $SYSTEMD_COLORS and $TERM. When reexecuting, TERM should be already set, so we can use this value. Effectively, behaviour is the same as before affd7ed1a was reverted, but instead of reopening the console before configuring color output, we just ignore what stdout is connected to and decide based on the variables only. (cherry picked from commit 158fbf7661912adf0f42c93155499119811dde82)
* Prep v231: Apply missing fixes from upstream (1/6) src/basicSven Eden2017-06-16
|
* treewide: use stdio_unset_cloexec() functionAlexander Kuleshov2017-06-16
|
* tree-wide: check colors_enabled() before outputting ANSI color stringsLennart Poettering2017-06-16
|
* ask-password: ask for passphrases not only on the first console of /dev/consoleWerner Fink2017-06-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | but also on all other consoles. This does help on e.g. mainframes where often a serial console together with other consoles are used. Even rack based servers attachted to both a serial console as well as having a virtual console do sometimes miss a connected monitor. To be able to ask on all terminal devices of /dev/console the devices are collected. If more than one device are found, then on each of the terminals a inquiring task for passphrase is forked and do not return to the caller. Every task has its own session and its own controlling terminal. If one of the tasks does handle a password, the remaining tasks will be terminated. Also let contradictory options on the command of elogind-tty-ask-password-agent fail. Spwan for each device of the system console /dev/console a own process. Replace the system call wait() with with system call waitid(). Use SIGTERM instead of SIGHUP to get unresponsive childs down. Port the collect_consoles() function forward to a pulbic and strv based function "get_kernel_consoles()" in terminal-util.c and use this in tty-ask-password-agent.c.
* Prep v230: Add utmp support to make wall message to work properly.Sven Eden2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.Sven Eden2017-06-16
|
* Prep v229: Add missing fixes from upstream [1/6] src/basicSven Eden2017-05-17
|
* tree-wide: check if errno is greater then zeroZbigniew Jędrzejewski-Szmek2017-05-17
| | | | | | | | | | | | | | gcc is confused by the common idiom of return errno ? -errno : -ESOMETHING and thinks a positive value may be returned. Replace this condition with errno > 0 to help gcc and avoid many spurious warnings. I filed a gcc rfe a long time ago, but it hard to say if it will ever be implemented [1]. Both conventions were used in the codebase, this change makes things more consistent. This is a follow up to bcb161b0230f. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61846
* Prep v228: Condense elogind source masks (3/5)Sven Eden2017-04-26
|
* Prep v228: Clean up the new src/basic/*-util-[hc] files:Sven Eden2017-04-26
| | | | | | | | | | | | | - src/basic/capability-util.[hc] - src/basic/cgroup-util.[hc] - src/basic/fd-util.[hc] - src/basic/fs-util.[hc] - src/basic/memfd-util.[hc] - src/basic/path-util.[hc] - src/basic/socket-util.[hc] - src/basic/terminal-util.[hc] - src/basic/user-util.[hc] - src/basic/xattr-util.[hc]
* Prep v228: Add remaining updates from upstream (2/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on libbasic.
* util: minor modernization of vt_disallocate()Lennart Poettering2017-04-26
|
* [2/5] Apply missing fixes from upstreamSven Eden2017-03-29
|
* Prep v226: Mask all unneeded functionsSven Eden2017-03-14
|