summaryrefslogtreecommitdiffstats
path: root/src/basic/exec-util.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #10742 from poettering/c-utf8Zbigniew Jędrzejewski-Szmek2018-11-151-1/+1
|\ | | | | default to C.UTF-8 locale, and many improvements to env var file parsing/kernel cmdline parsing
| * fileio: drop "newline" parameter for env file parsersLennart Poettering2018-11-141-1/+1
| | | | | | | | | | | | | | 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.
* | Move LONG_LINE_MAX definition to fileio.hZbigniew Jędrzejewski-Szmek2018-11-141-1/+0
|/ | | | | | | | | | | All users of the macro (except for one, in serialize.c), use the macro in connection with read_line(), so they must include fileio.h. Let's not play libc games and require multiple header file to be included for the most common use of a function. The removal of def.h includes is not exact. I mostly went over the commits that switch over to use read_line() and add def.h at the same time and reverted the addition of def.h in those files.
* core: rework serializationLennart Poettering2018-10-261-11/+31
| | | | | | | | | | | | | | | | | 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.
* exec-util: errors are reported by non-zero, not negative by putenv()Lennart Poettering2018-10-181-1/+1
|
* exec-util: use fflush_and_check() where appropriateLennart Poettering2018-10-171-3/+4
|
* exec-util: add missing logging callLennart Poettering2018-09-251-1/+1
| | | | | This function logs about all errors, but one case was forgotten. Fix that.
* exec-util: handle putenv() errorsLennart Poettering2018-09-251-1/+2
| | | | | | | Just paranoia, as putenv() can fail and we should catch it, like we catch all other errors. Follow-up for #10073
* exec-util: in execute_directories, support initial exec environmentDimitri John Ledkov2018-09-241-4/+9
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | 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-06-141-2/+0
| | | | | | | | | | | | | | | | 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.
* conf-files: beef up conf-files.[ch] a bitLennart Poettering2018-05-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds fozr new flags: - If CONF_FILES_DIRECTORY is specified conf_file_list() and friends will look for directories only. - Similar CONF_FILES_REGULAR means we'll look only for regular files. - If CONF_FILES_BASENAME is specified the resulting list will contain only the basenames of all discovered files or directories, not the full paths. - If CONF_FILES_FILTER_MASKED is specified the resulting list will have masked entries removed (i.e. those symlinked to /dev/null and suchlike) These four flags are useful for discovering portable service profile information. While we are at it, also improve a couple of other things: - More debug logging - use path_hash_ops instead of string_hash_ops when putting together the path lists
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | 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.
* coccinelle: make use of DIV_ROUND_UP() wherever appropriateLennart Poettering2018-03-201-1/+1
| | | | Let's use our macros where we can
* tree-wide: port various places over to use new rearrange_stdio()Lennart Poettering2018-03-021-5/+2
|
* basic/exec-util: use _exit() to return from childZbigniew Jędrzejewski-Szmek2018-02-261-1/+1
|
* exec-util: cast to void when return value is ignoredYu Watanabe2018-01-101-1/+1
| | | | CID 1384262.
* process-spec: add another flag FORK_WAIT to safe_fork()Lennart Poettering2018-01-041-9/+2
| | | | | | | | | This new flag will cause safe_fork() to wait for the forked off child before returning. This allows us to unify a number of cases where we immediately wait on the forked off child, witout running any code in the parent after the fork, and without direct interest in the precise exit status of the process, except recgonizing EXIT_SUCCESS vs everything else.
* exec-util: drop redundant log message in do_spawn()Lennart Poettering2018-01-041-1/+0
| | | | safe_fork() logs that anyway, hence no need to do this twice.
* process-util: rework wait_for_terminate_and_warn() to take a flags parameterLennart Poettering2018-01-041-8/+5
| | | | | | | | | | | | | This renames wait_for_terminate_and_warn() to wait_for_terminate_and_check(), and adds a flags parameter, that controls how much to log: there's one flag that means we log about abnormal stuff, and another one that controls whether we log about non-zero exit codes. Finally, there's a shortcut flag value for logging in both cases, as that's what we usually use. All callers are accordingly updated. At three occasions duplicate logging is removed, i.e. where the old function was called but logged in the caller, too.
* process-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN loggingLennart Poettering2018-01-041-4/+4
|
* tree-wide: introduce new safe_fork() helper and port everything overLennart Poettering2017-12-251-16/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* exec-util: initialize `new` before using it (#7471)Evgeny Vereshchagin2017-11-261-1/+1
| | | CID #1383004
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* exec-util,conf-files: skip non-executable files in execute_directories()Lennart Poettering2017-09-131-1/+1
| | | | Fixes: #6787
* Tighten checking for variable validityZbigniew Jędrzejewski-Szmek2017-02-211-0/+5
| | | | | | In the future we might want to allow additional syntax (for example "unset VAR". But let's check that the data we're getting does not contain anything unexpected.
* exec-util: implement a set of callbacks to pass variables aroundZbigniew Jędrzejewski-Szmek2017-02-211-0/+102
| | | | Only tests are added, otherwise the new code is unused.
* basic/exec-util: add support for synchronous (ordered) executionZbigniew Jędrzejewski-Szmek2017-02-211-31/+118
| | | | | | | | | | | | | | | | | | | | The output of processes can be gathered, and passed back to the callee. (This commit just implements the basic functionality and tests.) After the preparation in previous commits, the change in functionality is relatively simple. For coding convenience, alarm is prepared *before* any children are executed, and not before. This shouldn't matter usually, since just forking of the children should be pretty quick. One could also argue that this is more correct, because we will also catch the case when (for whatever reason), forking itself is slow. Three callback functions and three levels of serialization are used: - from individual generator processes to the generator forker - from the forker back to the main process - deserialization in the main process v2: - replace an structure with an indexed array of callbacks
* basic/exec-util: use conf_files_list_strv to list executablesZbigniew Jędrzejewski-Szmek2017-02-121-50/+25
| | | | | | Essentially the same logic as in conf_files_list() was independently implemented in do_execute(). With previous commit, do_execute() can just call conf_files_list() to get a list of executable paths.
* basic/exec-util: split out actual execution to a different functionZbigniew Jędrzejewski-Szmek2017-02-121-25/+35
| | | | | This corrects an error in error handling: if execution fails, we should never use return, but immediately _exit().
* basic/util: move execute_directory() to separate fileZbigniew Jędrzejewski-Szmek2017-02-121-0/+181
It's a fairly specialized function. Let's make new files for it and the tests.