Commit graph

64 commits

Author SHA1 Message Date
Michael Marineau 4cf7ea556a shared: add root argument to search_and_fopen
This adds the same root argument to search_and_fopen that
conf_files_list already has. Tools that use those two functions as a
pair can now be easily modified to load configuration files from an
alternate root filesystem tree.
2014-03-14 09:31:34 -04:00
Lennart Poettering e26da2dcea tmpfiles: simplification 2014-02-19 17:53:50 +01:00
Zbigniew Jędrzejewski-Szmek 498f8a39e6 tmpfiles: fix memory leak of exclude_prefixes
Missed in 5c795114.
2014-01-30 22:53:01 -05:00
Lukas Nykryn f58ceb21e9 tmpfiles: don't allow label_fix to print ENOENT when we want to ignore it 2014-01-09 18:00:50 +01:00
Zbigniew Jędrzejewski-Szmek 8181565124 tmpfiles: rename --unsafe to --boot
As suggested by Kay, it is better to describe what is done,
not what might happen.
2013-12-30 13:01:27 -05:00
Zbigniew Jędrzejewski-Szmek c4708f1323 tmpfiles: introduce the concept of unsafe operations
Various operations done by systemd-tmpfiles may only be safely done at
boot (e.g. removal of X lockfiles in /tmp, creation of /run/nologin).
Other operations may be done at any point in time (e.g. setting the
ownership on /{run,var}/log/journal). This distinction is largely
orthogonal to the type of operation.

A new switch --unsafe is added, and operations which should only be
executed during bootup are marked with an exclamation mark in the
configuration files. systemd-tmpfiles.service is modified to use this
switch, and guards are added so it is hard to re-start it by mistake.

If we install a new version of systemd, we actually want to enforce
some changes to tmpfiles configuration immediately. This should now be
possible to do safely, so distribution packages can be modified to
execute the "safe" subset at package installation time.

/run/nologin creation is split out into a separate service, to make it
easy to override.

https://bugzilla.redhat.com/show_bug.cgi?id=1043212
https://bugzilla.redhat.com/show_bug.cgi?id=1045849
2013-12-24 15:48:06 -05:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Florian Weimer d78096b343 tmpfiles: replace readdir_r with readdir 2013-12-21 18:35:55 -05: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
Kay Sievers df28bc0836 build-sys: use -Og instead of -O0 to catch warnings
$ touch src/core/dbus.c; make CFLAGS=-O0
  make --no-print-directory all-recursive
  Making all in .
    CC       src/core/libsystemd_core_la-dbus.lo
    CCLD     libsystemd-core.la

  $ touch src/core/dbus.c; make CFLAGS=-Og
  make --no-print-directory all-recursive
  Making all in .
    CC       src/core/libsystemd_core_la-dbus.lo
  src/core/dbus.c: In function 'init_registered_system_bus':
  src/core/dbus.c:798:18: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
           dbus_free(id);
                    ^
    CCLD     libsystemd-core.la

-Og Optimize debugging experience. -Og enables optimizations that do
not interfere with debugging. It should be the optimization level of
choice for the standard edit-compile-debug cycle, offering a
reasonable level of optimization while maintaining fast compilation
and a good debugging experience.
2013-10-21 15:46:00 +02:00
Kay Sievers ca2f4176fe tmpfiles: log unaccessible FUSE mount points only as debug message 2013-10-17 03:20:46 +02:00
Lennart Poettering 14bf2c9d37 util: allow trailing semicolons on define_trivial_cleanup_func lines
Emacs C indenting really gets confused by these lines if they carry no
trailing semicolon, hence let's make this nicer for good old emacs. The
other macros which define functions already do this too, so let's copy
the scheme here.

Also, let's use an uppercase name for the macro. So far our rough rule
was that macros that are totally not function-like (like this ones,
which define a function) are uppercase. (Well, admittedly it is a rough
rule only, for example function and variable decorators are all
lower-case SINCE THE CONSTANT YELLING IN THE SOURCES WOULD SUCK, and
also they at least got underscore prefixes.) Also, the macros that
define functions that we already have are all uppercase, so let's do the
same here...
2013-10-14 06:11:19 +02:00
Zbigniew Jędrzejewski-Szmek 1ca208fb4f Introduce udev object cleanup functions 2013-10-13 17:56:55 -04:00
Lennart Poettering 265ffa1e05 tmpfiles: add a new "m" line type that adjusts user/group/mode of a file if it exists 2013-09-17 16:55:37 -05:00
Lennart Poettering 1731e34a4e tmpfiles: support simple specifier expansion for specified paths 2013-09-17 11:02:54 -05:00
Dave Reisner 5c7951141f tmpfiles: introduce --exclude-prefix
The opposite of --prefix, allows specifying path prefixes which should
be skipped when processing rules.
2013-07-24 12:04:00 -04:00
Dave Reisner a2aced4add tmpfiles: support passing --prefix multiple times 2013-07-24 11:10:05 -04:00
Maciej Wereski e2f2fb7860 tmpfiles: Fix memory leak in parse_line() 2013-07-19 09:57:04 -04:00
Lennart Poettering 96ca81944e tmpfiles: fix error check 2013-06-21 15:57:57 +02:00
Zbigniew Jędrzejewski-Szmek ef42202ac8 Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
2013-04-24 00:25:04 -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
Anatol Pomozov ab06eef810 Fix spelling errors using 'codespell' tool 2013-04-15 08:40:05 -04:00
Zbigniew Jędrzejewski-Szmek c84a948831 Add _cleanup_globfree_
Fixes a memleak in error path in exec_context_load_environment.
2013-04-05 19:58:53 -04:00
Zbigniew Jędrzejewski-Szmek b92bea5d2a Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first
by filling the structure with zeros, and then a second
time with the real values. We can let the compiler do
the job for us, avoiding one copy.

A downside of this patch is that text gets slightly
bigger. This is because all zero() calls are effectively
inlined:

$ size build/.libs/systemd
         text    data     bss     dec     hex filename
before 897737  107300    2560 1007597   f5fed build/.libs/systemd
after  897873  107300    2560 1007733   f6075 build/.libs/systemd

… actually less than 1‰.

A few asserts that the parameter is not null had to be removed. I
don't think this changes much, because first, it is quite unlikely
for the assert to fail, and second, an immediate SEGV is almost as
good as an assert.
2013-04-05 19:50:57 -04:00
Lennart Poettering 5c0d398dfc util: add a bit of syntactic sugar to run short code fragments with a different umask 2013-04-04 03:39:39 +02:00
Lennart Poettering 7f602784de util: rename parse_usec() to parse_sec() sinds the default unit is seconds
Internally we store all time values in usec_t, however parse_usec()
actually was used mostly to parse values in seconds (unless explicit
units were specified to define a different unit). Hence, be clear about
this and name the function about what we pass into it, not what we get
out of it.
2013-04-03 20:12:57 +02:00
Zbigniew Jędrzejewski-Szmek 7f2c1f4dbf tmpfiles: fix obscure leak in error path
The leak was because of the single return in midst of all
'goto finish'es. Using automatic cleanup simplifies things.
2013-03-31 19:01:57 -04:00
Zbigniew Jędrzejewski-Szmek 8333c77edf Always use errno > 0 to help gcc
gcc thinks that errno might be negative, and functions could return
something positive on error (-errno). Should not matter in practice,
but makes an -O4 build much quieter.
2013-03-29 10:12:41 -04:00
Zbigniew Jędrzejewski-Szmek d39efe744a tmpfiles: add missing missing.h include
mbiebl> src/tmpfiles/tmpfiles.c:221:13: error: ‘MAX_HANDLE_SZ’
        undeclared (first use in this function)

Fixup for 427b47c4ab.
2013-03-13 20:27:36 -04:00
Kay Sievers 99d680acf1 tmpfiles: --clean -- check for bind mounts of the same filesystem and skip them 2013-03-13 13:16:10 +01:00
Zbigniew Jędrzejewski-Szmek 19fbec1919 tmpfiles: use cleanup func. to save a few lines 2013-03-03 20:16:57 -05:00
Lukas Nykryn a6187d4ce8 tmpfiles: move exclamation mark into right place
Unary not has higher precedence than comparisons,
so the condition was bogus.
2013-03-03 20:16:57 -05:00
Lennart Poettering fabe5c0e5f binfmt,tmpfiles,modules-load,sysctl: rework the various early-boot services that work on .d/ directories
This unifies much of the logic behind them:

- All four will now ofllow the rule that the earlier file and earlier
  assignment in the .d/ directories wins. Before, sysctl was the only
  outlier, where the later setting always won.

- All four now support getopt() and --help on the command line.

- All four can now handle specification of configuration file names on
  the command line to apply. The tools will automatically find them, and
  apply them. Previously only tmpfiles could do that. This is useful for
  %post scripts in RPMs and suchlike.

- This fixes various error path issues in conf_files_list()
2013-02-11 23:54:30 +01:00
Kay Sievers 7850b3b837 shared: conf-files - add root parameter 2013-02-08 10:23:04 +01:00
Michal Sekletar 78a92a5a23 tmpfiles: introduce type X
Type X will exclude path itself from clean-up. However, if the path is a
directory systemd-tmpfiles will clean-up its content.

In contrast to type x, where path is ignored completely, type X needs some
Age parameter. In order to determine Age parameter, we will look for config
entries of type d or D and pick the best match.  Best match is either
exact match or longest prefix match.
2013-01-25 10:38:46 -05:00
Thomas Jarosch 3785ba6966 tmpfiles: Fix file descriptor leak on error
Detected by cppcheck
2013-01-03 22:42:55 +01:00
Tom Gundersen a2558205f7 tmpfiles: allow Age to be set to 0
Mostly useful for testing purposes. Setting Age to 1s works just as
well, but it is surprising that using 0s (or just 0) does not work.

Also clarify this in the documentation.
2012-10-23 21:53:20 +02:00
Kay Sievers 796b06c21b udev: add hardware database support 2012-10-23 16:43:32 +02:00
Dave Reisner 1845fdd967 tmpfiles: restore previous behavior for F/f
d4e9eb91ea changed the behavior for the F and f actions, wrongly sending
them to glob_item(). Restore the old behavior and shortcut straight to
write_one_file().
2012-09-27 20:53:05 -04:00
Lennart Poettering 7d5e9c0f60 util: define union dirent_storage and make use of it everywhere
Make sure to allocate enough space for readdir_r().

https://bugzilla.redhat.com/show_bug.cgi?id=858754
2012-09-19 22:21:09 +02:00
Dave Reisner 54693d9bfa tmpfiles: use write(2) for the 'w' action
This resolves problems with filesystems which do not implement the
aio_write file operation. In this case, the kernel will fall back using
a loop writing technique for each pointer in a received iovec. The
result is strange errors in dmesg such as:

[   31.855871] elevator: type  not found
[   31.856262] elevator: switch to
[   31.856262]  failed

It does not make sense to implement a synchronous aio_write method for
sysfs as this isn't a real filesystem where a reasonable use case for
using writev exists, nor is there an expectation that tmpfiles will be
used to write more data than can be reasonably written in a single write
syscall.

In addition, some sysfs attrs are currently buggy and will NOT reject
the second write with the newline, causing the sysfs value to be zeroed
out. This of course should be fixed in the kernel regardless of any
wrongdoing in userspace, but this simple change makes us immune to such
a bug.

This change means that we do not write a trailing newline by default, as
the expected use case of 'w' is for sysfs and procfs. In exchange, honor
C-style backslash escapes so that if the newline is really needed, the
user can add it.
2012-09-16 17:18:04 +02:00
Dave Reisner 3612fbc1e4 tmpfiles: plug file descriptor leak.
Introduced in d4e9eb91.
2012-09-13 00:10:35 +02:00
Dave Reisner d4e9eb91ea tmpfiles: support globbing for w option
Break out the write logic into a separate function and simply use it as
a callback to glob_item.

This allows users to consolidate writes to sysfs with multiple similar
pathnames, e.g.

  w /sys/class/block/sd[a-z]/queue/read_ahead_kb - - - - 1024
2012-09-12 08:46:03 +02:00
Lennart Poettering cb7ed9dfca tmpfiles: don't attempt creation of device nodes when we run in a container 2012-09-05 23:42:05 -07:00
Shawn Landden 0d0f0c50d3 log.h: new log_oom() -> int -ENOMEM, use it
also a number of minor fixups and bug fixes: spelling, oom errors
that didn't print errors, not properly forwarding error codes,
few more consistency issues, et cetera
2012-07-26 11:48:26 +02:00
Shawn Landden 669241a076 use "Out of memory." consistantly (or with "\n")
glibc/glib both use "out of memory" consistantly so maybe we should
consider that instead of this.

Eliminates one string out of a number of binaries. Also fixes extra newline
in udev/scsi_id
2012-07-25 11:23:57 +02:00
Lennart Poettering 3f2afb2914 tmpfiles: also look in /lib/tmpfiles.d on split /usr systems
https://bugs.freedesktop.org/show_bug.cgi?id=38686

I don't think the usecase case in that bug makes much sense, but all the
other tools do honour /lib in the search path so we probably should do
that here, too.
2012-07-20 16:57:13 +02:00
Lennart Poettering d05c5031ad unit: introduce %s specifier for the user shell 2012-07-16 12:34:54 +02:00
Lennart Poettering b7def68494 util: rename join() to strjoin()
This is to match strappend() and the other string related functions.
2012-07-13 13:41:01 +02:00
Lennart Poettering f56d5db919 util: rm_rf() refuse cleaning non-memory file systems, as extra paranoia 2012-07-10 19:05:58 +02:00