summaryrefslogtreecommitdiff
path: root/src/basic/terminal-util.c
Commit message (Collapse)AuthorAge
* terminal-util: extra safety checks when parsing $COLUMNS or $LINES (#10314)Lennart Poettering2018-10-29
| | | | | | | | Let's make sure the integers we parse out are not larger than USHRT_MAX. This is a good idea as the kernel's TIOCSWINSZ ioctl for sizing terminals can't take larger values, and we shouldn't risk an overflow. (cherry picked from commit d09a71356e3ed78be7cef3cd7d9919dc77508b41)
* Prep v239: terminal-util.[hc] - Mask new 'urlify' functions, we do not need ↵Sven Eden2018-08-24
| | | | them.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | 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.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | 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.
* terminal-util: make file names in --cat-config output clickable linksLennart Poettering2018-08-24
|
* util: tighten on_tty() check a bit, also check stderrLennart Poettering2018-08-24
| | | | | | | Let's detect output redirection a bit better, cover both stdout and stderr. Fixes: #9192
* terminal-util: add a function that shows a pretty separator lineLennart Poettering2018-08-24
| | | | Follow-up for #8824
* basic/terminal-util: fix output of files without a final newlineZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | If the main config file or one of the drop-ins did not have the final newline, there would be no seperating empty line (or if this was the last file displayed, our own output would end without the final newline, possibly running into the subsequent prompt or such). copy_bytes() does not know anything about lines, so let's just use a normal loop with read_line() and puts().
* analyze: add 'cat-config' verbZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is used as 'systemd-analyze show-config systemd/logind.conf', which will dump /etc/systemd/system/user@.service /etc/systemd/system/user@.service.d/*.conf /run/systemd/system/user@.service.d/*.conf /usr/local/lib/systemd/system/user@.service.d/*.conf /usr/lib/systemd/system/user@.service.d/*.conf The idea is to make it easy to dump the configuration using the same locations and order that systemd programs use themselves (including masking, in the right order, etc.). This is the generic variant that works with any configuration scheme that follows the same general rules: $ systemd-analyze cat-config systemd/system.conf $ systemd-analyze cat-config systemd/user.conf $ systemd-analyze cat-config systemd/logind.conf $ systemd-analyze cat-config systemd/sleep.conf $ systemd-analyze cat-config systemd/journald.conf $ systemd-analyze cat-config systemd/journal-remote.conf $ systemd-analyze cat-config systemd/journal-upload.conf $ systemd-analyze cat-config systemd/coredump.conf $ systemd-analyze cat-config systemd/resolved.conf $ systemd-analyze cat-config systemd/timesyncd.conf $ systemd-analyze cat-config udev/udev.conf
* Move function to cat file & dropins into basic/Zbigniew Jędrzejewski-Szmek2018-08-24
| | | | | This fixes a buglet where the second and later drop-in would not be seperated properly by a newline.
* Fix typoZbigniew Jędrzejewski-Szmek2018-08-24
|
* terminal: add internal API to format URLs for display in capable terminalsLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | Newer terminals (in particular gnome-terminal) understand special escape sequence for formatting clickable links. Let's support that to make our tool output more clickable where that's appropriate. For details see this: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda The one big issue is that 'less' currently doesn't grok this, and doesn't ignore sequence like regular terminal implementations do if they don't support it. Hence for now, let's disable URL output if a pager is used. We should revisit that though as soon as less added support for it and enough time passed for it to enter various distributions.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | 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.
* macro: introduce new TAKE_FD() macroLennart Poettering2018-08-24
| | | | | | | This is similar to TAKE_PTR() but operates on file descriptors, and thus assigns -1 to the fd parameter after returning it. Removes 60 lines from our codebase. Pretty good too I think.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Prep v238: Uncomment now needed headers and unmask now needed functions in ↵Sven Eden2018-06-05
| | | | src/basic (1/6)
* 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.