1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-28 11:55:23 +03:00

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.
This commit is contained in:
Dave Reisner 2012-06-08 22:31:19 -04:00 committed by Kay Sievers
parent 0e25e94ea7
commit 9125670f9a

View File

@ -100,6 +100,14 @@ static bool arg_remove = false;
static const char *arg_prefix = NULL; 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 #define MAX_DEPTH 256
static bool needs_glob(ItemType t) { static bool needs_glob(ItemType t) {
@ -1253,6 +1261,29 @@ static int read_config_file(const char *fn, bool ignore_enoent) {
return r; 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 main(int argc, char *argv[]) {
int r; int r;
Item *i; Item *i;
@ -1284,19 +1315,18 @@ int main(int argc, char *argv[]) {
if (optind < argc) { if (optind < argc) {
int j; int j;
for (j = optind; j < argc; j++) for (j = optind; j < argc; j++) {
if (read_config_file(argv[j], false) < 0) char *fragment = resolve_fragment(argv[j], conf_file_dirs);
if (read_config_file(fragment, false) < 0)
r = EXIT_FAILURE; r = EXIT_FAILURE;
free(fragment);
}
} else { } else {
char **files, **f; char **files, **f;
r = conf_files_list(&files, ".conf", r = conf_files_list_strv(&files, ".conf",
"/etc/tmpfiles.d", (const char **)conf_file_dirs);
"/run/tmpfiles.d",
"/usr/local/lib/tmpfiles.d",
"/usr/lib/tmpfiles.d",
NULL);
if (r < 0) { if (r < 0) {
log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r)); log_error("Failed to enumerate tmpfiles.d files: %s", strerror(-r));
r = EXIT_FAILURE; r = EXIT_FAILURE;