summaryrefslogtreecommitdiff
path: root/src/tmpfiles
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-06-08 22:31:19 -0400
committerKay Sievers <kay@vrfy.org>2012-06-10 19:05:20 +0200
commit9125670f9a3dc34adf16b87635b460b2e4099b78 (patch)
tree229088a6a901878518ceffe9186678493fe8fc39 /src/tmpfiles
parent0e25e94ea72ca3db70484014280ddb709840f952 (diff)
tmpfiles: allow to specify basename only: systemd-tmpfiles <program.conf>
Allow passing of basename only, instead of the absolute path; letting systemd-tmpfiles perform a path lookup for the proper fragment path in the config directories. This allows distributions to call: systemd-tmpfiles <program.conf> on upgrade of a package, with respecting the possibly overriden (or even masked) tmpfile.
Diffstat (limited to 'src/tmpfiles')
-rw-r--r--src/tmpfiles/tmpfiles.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index aebc4bb088..bec73ff6cc 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -100,6 +100,14 @@ static bool arg_remove = false;
static const char *arg_prefix = NULL;
+static const char *conf_file_dirs[] = {
+ "/etc/tmpfiles.d",
+ "/run/tmpfiles.d",
+ "/usr/local/lib/tmpfiles.d",
+ "/usr/lib/tmpfiles.d",
+ NULL
+};
+
#define MAX_DEPTH 256
static bool needs_glob(ItemType t) {
@@ -1253,6 +1261,29 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
return r;
}
+static char *resolve_fragment(const char *fragment, const char **search_paths) {
+ const char **p;
+ char *resolved_path;
+
+ if (is_path(fragment))
+ return strdup(fragment);
+
+ STRV_FOREACH(p, search_paths) {
+ resolved_path = join(*p, "/", fragment, NULL);
+ if (resolved_path == NULL) {
+ log_error("Out of memory");
+ return NULL;
+ }
+
+ if (access(resolved_path, F_OK) == 0)
+ return resolved_path;
+
+ free(resolved_path);
+ }
+
+ return NULL;
+}
+
int main(int argc, char *argv[]) {
int r;
Item *i;
@@ -1284,19 +1315,18 @@ int main(int argc, char *argv[]) {
if (optind < argc) {
int j;
- for (j = optind; j < argc; j++)
- if (read_config_file(argv[j], false) < 0)
+ for (j = optind; j < argc; j++) {
+ char *fragment = resolve_fragment(argv[j], conf_file_dirs);
+ if (read_config_file(fragment, false) < 0)
r = EXIT_FAILURE;
+ free(fragment);
+ }
} else {
char **files, **f;
- r = conf_files_list(&files, ".conf",
- "/etc/tmpfiles.d",
- "/run/tmpfiles.d",
- "/usr/local/lib/tmpfiles.d",
- "/usr/lib/tmpfiles.d",
- NULL);
+ r = conf_files_list_strv(&files, ".conf",
+ (const char **)conf_file_dirs);
if (r < 0) {
log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
r = EXIT_FAILURE;