Commit graph

86 commits

Author SHA1 Message Date
Lennart Poettering 8dd4c05b54 core: add support for naming file descriptors passed using socket activation
This adds support for naming file descriptors passed using socket
activation. The names are passed in a new $LISTEN_FDNAMES= environment
variable, that matches the existign $LISTEN_FDS= one and contains a
colon-separated list of names.

This also adds support for naming fds submitted to the per-service fd
store using FDNAME= in the sd_notify() message.

This also adds a new FileDescriptorName= setting for socket unit files
to set the name for fds created by socket units.

This also adds a new call sd_listen_fds_with_names(), that is similar to
sd_listen_fds(), but also returns the names of the fds.

systemd-activate gained the new --fdname= switch to specify a name for
testing socket activation.

This is based on #1247 by Maciej Wereski.

Fixes #1247.
2015-10-06 11:52:48 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Lennart Poettering ce30c8dcb4 tree-wide: whenever we fork off a foreign child process reset signal mask/handlers
Also, when the child is potentially long-running make sure to set a
death signal.

Also, ignore the result of the reset operations explicitly by casting
them to (void).
2015-06-10 01:28:58 +02:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt 23bbb0de4e treewide: more log_*_errno + return simplifications 2014-11-28 18:24:30 +01:00
Michal Schmidt eb56eb9b40 treewide: simplify log_*_errno(r,...) immediately followed by "return r" 2014-11-28 17:34:26 +01:00
Michal Schmidt c33b329709 treewide: more log_*_errno() conversions, multiline calls
Basically:

find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
 local $_=<>;
 s/log_(debug|info|notice|warning|error|emergency)\("([^"]*)%s"([^;]*),\s*strerror\(-?([->a-zA-Z_]+)\)\);/log_\1_errno(\4, "\2%m"\3);/gms;print;' \
 $f; done

Plus manual indentation fixups.
2014-11-28 17:17:51 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Philippe De Swert aa44499da1 activate: fix fd leak in do_accept()
Found with Coverity.
2014-09-11 17:47:37 +02:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Zbigniew Jędrzejewski-Szmek 73f860db98 Always prefer our headers to system headers
In practice this shouldn't make much difference, but
sometimes our headers might be newer, and we want to
test them.
2014-07-31 08:56:03 -04:00
Zbigniew Jędrzejewski-Szmek e0aa372610 activate: export make_socket_fd
Also improve logging to print out the parsed address on error.
2014-03-17 01:55:48 -04:00
Zbigniew Jędrzejewski-Szmek 892213bf1f acticate: rename --environment to --setenv
Nspawn has --setenv, and systemd itself accepts systemd.setenv.
It is nice to have the same parameter name everywhere.

Old name is accepted, but not advertised.
2013-12-30 00:17:15 -05:00
Lennart Poettering 603938e0a9 activate: fix error checking on epoll_ctl() 2013-12-17 15:42:33 +01:00
Zbigniew Jędrzejewski-Szmek c099716487 activate: clean up inherited descriptors
> [simon@troela server]$ /usr/lib/systemd/systemd-activate -l 9000 main.js
> Assertion 'fd == 3 + count' failed at src/activate/activate.c:115,
> function open_sockets(). Aborting.
> Aborted (core dumped)

> after a bit debuging i found the problem:
> slim appears to leak an fd into all of its children:
> stat /proc/14004/fd/3  (14004 is the pid a random process in my session)
>  File: '/proc/14004/fd/3' -> '/var/log/slim.log'

systemd-activate should be robust against the shell (or anything else) leaking
descriptors. Now everything except stdin/stdout/stderr and received sockets
will be closed.
2013-12-10 21:52:57 -05:00
Thomas Hindoe Paaboel Andersen d5d217eae1 remove unused variables 2013-11-18 23:04:16 +01:00
Mantas Mikulėnas ed6556920c activate: fix crash when -s is passed
getopt_long() was told to accept -s which was never implemented.
2013-11-14 00:20:43 +10:00
Mantas Mikulėnas df49ccafc0 activate: mention -E in the help text 2013-11-14 00:19:43 +10:00
Lennart Poettering 9d458c0902 clients: fix some signal handler issues 2013-11-08 14:07:27 +01:00
Lennart Poettering 2c408cb627 activate: print a nice message if no fd to listen on was specified 2013-11-07 16:53:26 +01:00
Lennart Poettering bc80136385 build-sys: add Makefile symlink for src/activate/ 2013-11-07 03:09:59 +01:00
Lennart Poettering 30374ebe5e activate: port to use new getpeername_pretty()/getsockname_pretty() calls 2013-11-07 00:13:58 +01:00
Lennart Poettering 5b84559a76 activate: fix uninitialized memory 2013-11-07 00:13:58 +01:00
Lennart Poettering 175a3d25d0 active: rework make_socket_fd() to be based on socket_address_listen()
Among other things this makes sure we set SO_REUSEADDR which is
immensely useful.
2013-11-06 23:03:12 +01:00
Lennart Poettering eceb8483e5 activate: reduce log settings to normal 2013-11-06 23:03:12 +01:00
Lennart Poettering 29a5ca9baa activate: get rid of redundant definiton of fd_cloexec() 2013-11-06 23:03:12 +01:00
Lennart Poettering eb9da376d7 clients: unify how we invoke getopt_long()
Among other things this makes sure we always expose a --version command
and show it in the help texts.
2013-11-06 18:28:39 +01:00
Jason St. John e9c1ea9de8 replace tabs with spaces in various files
The affected files in this patch had inconsistent use of tabs vs. spaces
for indentation, and this patch eliminates the stray tabs.

Also, the opening brace of sigchld_hdl() in activate.c was moved so the
opening braces are consistent throughout the file.
2013-07-02 23:06:22 -04:00
Harald Hoyer 7fd1b19bc9 move _cleanup_ attribute in front of the type
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-18 09:11:22 +02:00
Zbigniew Jędrzejewski-Szmek fff40a51cc activate: do not leak envp on error 2013-03-31 19:01:57 -04:00
Zbigniew Jędrzejewski-Szmek 23ea3dab15 activate: avoid warning from -Wshadow
src/activate/activate.c:167:51: warning: declaration shadows a variable in the global scope [-Wshadow]
static int launch(char* name, char **argv, char **environ, int fds) {
                                                  ^
/usr/include/unistd.h:546:15: note: previous declaration is here
extern char **environ;
              ^
2013-03-20 19:16:01 -04:00
Zbigniew Jędrzejewski-Szmek 5e65c93a43 systemd-activate: pass environment variables through
I need this to test half-installed socket-activated python
script, which requires PYTHONPATH and LD_LIBRARY_PATH set.
I assume that other people might find it useful to.

-E VAR passes through VAR from the environment, while
-E VAR=value sets VAR=value.

systemd-activate -E PYTHONPATH=/var/tmp/inst1/usr/lib64/python3.3/site-packages -E LD_LIBRARY_PATH=/var/tmp/inst1/usr/lib -l 2000 python3 -c 'from systemd.daemon import listen_fds; print(listen_fds())'
2013-03-15 22:55:24 -04:00
Zbigniew Jędrzejewski-Szmek 2ca0435be9 systemd-activate: add a socket-activation test tool 2013-02-27 22:10:14 -05:00