2010-09-28 02:34:02 +02:00
|
|
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
Copyright 2010 Lennart Poettering, Kay Sievers
|
2010-09-28 02:34:02 +02:00
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2010-09-28 02:34:02 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-09-28 02:34:02 +02:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
2010-10-18 22:38:41 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
2011-02-12 09:31:25 +01:00
|
|
|
#include <glob.h>
|
|
|
|
#include <fnmatch.h>
|
2012-09-06 08:39:55 +02:00
|
|
|
#include <sys/capability.h>
|
2010-09-28 02:34:02 +02:00
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2012-09-15 18:58:49 +02:00
|
|
|
#include "macro.h"
|
2013-03-14 01:20:54 +01:00
|
|
|
#include "missing.h"
|
2012-04-10 21:54:31 +02:00
|
|
|
#include "mkdir.h"
|
2012-05-07 21:36:12 +02:00
|
|
|
#include "path-util.h"
|
2010-09-28 02:34:02 +02:00
|
|
|
#include "strv.h"
|
|
|
|
#include "label.h"
|
2010-10-18 22:38:41 +02:00
|
|
|
#include "set.h"
|
2012-05-07 18:55:45 +02:00
|
|
|
#include "conf-files.h"
|
2012-09-06 08:39:55 +02:00
|
|
|
#include "capability.h"
|
2013-09-17 18:02:02 +02:00
|
|
|
#include "specifier.h"
|
2013-11-06 18:28:39 +01:00
|
|
|
#include "build.h"
|
2014-06-10 23:02:40 +02:00
|
|
|
#include "copy.h"
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-09-29 10:08:24 +02:00
|
|
|
/* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
|
2010-09-28 02:34:02 +02:00
|
|
|
* them in the file system. This is intended to be used to create
|
2011-04-04 15:33:00 +02:00
|
|
|
* properly owned directories beneath /tmp, /var/tmp, /run, which are
|
|
|
|
* volatile and hence need to be recreated on bootup. */
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2011-12-15 21:31:14 +01:00
|
|
|
typedef enum ItemType {
|
2011-02-12 09:31:25 +01:00
|
|
|
/* These ones take file names */
|
2010-10-18 22:38:41 +02:00
|
|
|
CREATE_FILE = 'f',
|
|
|
|
TRUNCATE_FILE = 'F',
|
|
|
|
CREATE_DIRECTORY = 'd',
|
|
|
|
TRUNCATE_DIRECTORY = 'D',
|
2011-07-12 03:56:56 +02:00
|
|
|
CREATE_FIFO = 'p',
|
2012-01-17 15:04:12 +01:00
|
|
|
CREATE_SYMLINK = 'L',
|
|
|
|
CREATE_CHAR_DEVICE = 'c',
|
|
|
|
CREATE_BLOCK_DEVICE = 'b',
|
2014-06-10 23:02:40 +02:00
|
|
|
COPY_FILES = 'C',
|
2011-02-12 09:31:25 +01:00
|
|
|
|
|
|
|
/* These ones take globs */
|
2014-06-10 22:50:46 +02:00
|
|
|
WRITE_FILE = 'w',
|
2010-10-18 22:38:41 +02:00
|
|
|
IGNORE_PATH = 'x',
|
2013-01-18 16:13:08 +01:00
|
|
|
IGNORE_DIRECTORY_PATH = 'X',
|
2010-10-18 22:38:41 +02:00
|
|
|
REMOVE_PATH = 'r',
|
2011-12-15 23:11:07 +01:00
|
|
|
RECURSIVE_REMOVE_PATH = 'R',
|
2014-06-10 23:42:16 +02:00
|
|
|
ADJUST_MODE = 'm', /* legacy, 'z' is identical to this */
|
2011-12-16 18:27:35 +01:00
|
|
|
RELABEL_PATH = 'z',
|
2014-06-10 23:42:16 +02:00
|
|
|
RECURSIVE_RELABEL_PATH = 'Z',
|
2011-12-15 21:31:14 +01:00
|
|
|
} ItemType;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
typedef struct Item {
|
2011-12-15 21:31:14 +01:00
|
|
|
ItemType type;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
char *path;
|
2012-01-17 15:04:12 +01:00
|
|
|
char *argument;
|
2010-09-28 02:34:02 +02:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2010-10-18 22:38:41 +02:00
|
|
|
mode_t mode;
|
|
|
|
usec_t age;
|
|
|
|
|
2012-01-17 15:04:12 +01:00
|
|
|
dev_t major_minor;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
bool uid_set:1;
|
|
|
|
bool gid_set:1;
|
|
|
|
bool mode_set:1;
|
|
|
|
bool age_set:1;
|
2014-06-11 10:14:07 +02:00
|
|
|
bool mask_perms:1;
|
2012-06-20 09:05:50 +02:00
|
|
|
|
|
|
|
bool keep_first_level:1;
|
2014-06-11 01:37:35 +02:00
|
|
|
|
2014-06-16 13:21:07 +02:00
|
|
|
bool force:1;
|
|
|
|
|
2014-06-11 01:37:35 +02:00
|
|
|
bool done:1;
|
2010-10-18 22:38:41 +02:00
|
|
|
} Item;
|
|
|
|
|
|
|
|
static bool arg_create = false;
|
|
|
|
static bool arg_clean = false;
|
|
|
|
static bool arg_remove = false;
|
2013-12-30 19:00:38 +01:00
|
|
|
static bool arg_boot = false;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
2014-06-11 01:26:28 +02:00
|
|
|
static char **arg_include_prefixes = NULL;
|
|
|
|
static char **arg_exclude_prefixes = NULL;
|
2014-03-14 05:32:13 +01:00
|
|
|
static char *arg_root = NULL;
|
2011-02-13 14:00:54 +01:00
|
|
|
|
2014-10-29 13:02:56 +01:00
|
|
|
static const char conf_file_dirs[] = CONF_DIRS_NULSTR("tmpfiles");
|
2012-06-09 04:31:19 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
#define MAX_DEPTH 256
|
|
|
|
|
2014-06-11 01:26:28 +02:00
|
|
|
static Hashmap *items = NULL, *globs = NULL;
|
|
|
|
static Set *unix_sockets = NULL;
|
|
|
|
|
2011-12-15 21:31:14 +01:00
|
|
|
static bool needs_glob(ItemType t) {
|
2014-06-10 22:50:46 +02:00
|
|
|
return IN_SET(t,
|
|
|
|
WRITE_FILE,
|
|
|
|
IGNORE_PATH,
|
|
|
|
IGNORE_DIRECTORY_PATH,
|
|
|
|
REMOVE_PATH,
|
|
|
|
RECURSIVE_REMOVE_PATH,
|
2014-06-10 23:42:16 +02:00
|
|
|
ADJUST_MODE,
|
2014-06-10 22:50:46 +02:00
|
|
|
RELABEL_PATH,
|
|
|
|
RECURSIVE_RELABEL_PATH);
|
2011-02-12 09:31:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct Item* find_glob(Hashmap *h, const char *match) {
|
|
|
|
Item *j;
|
|
|
|
Iterator i;
|
|
|
|
|
|
|
|
HASHMAP_FOREACH(j, h, i)
|
|
|
|
if (fnmatch(j->path, match, FNM_PATHNAME|FNM_PERIOD) == 0)
|
|
|
|
return j;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-14 21:55:06 +01:00
|
|
|
static void load_unix_sockets(void) {
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
2011-02-14 21:55:06 +01:00
|
|
|
char line[LINE_MAX];
|
|
|
|
|
|
|
|
if (unix_sockets)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* We maintain a cache of the sockets we found in
|
|
|
|
* /proc/net/unix to speed things up a little. */
|
|
|
|
|
2014-08-13 01:00:18 +02:00
|
|
|
unix_sockets = set_new(&string_hash_ops);
|
2012-01-11 22:07:35 +01:00
|
|
|
if (!unix_sockets)
|
2011-02-14 21:55:06 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
f = fopen("/proc/net/unix", "re");
|
|
|
|
if (!f)
|
2011-02-14 21:55:06 +01:00
|
|
|
return;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
/* Skip header */
|
|
|
|
if (!fgets(line, sizeof(line), f))
|
2011-02-14 21:55:06 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
char *p, *s;
|
|
|
|
int k;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
if (!fgets(line, sizeof(line), f))
|
2011-02-14 21:55:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
truncate_nl(line);
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
p = strchr(line, ':');
|
|
|
|
if (!p)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strlen(p) < 37)
|
2011-02-14 21:55:06 +01:00
|
|
|
continue;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
p += 37;
|
2011-02-14 21:55:06 +01:00
|
|
|
p += strspn(p, WHITESPACE);
|
2012-01-11 22:07:35 +01:00
|
|
|
p += strcspn(p, WHITESPACE); /* skip one more word */
|
2011-02-14 21:55:06 +01:00
|
|
|
p += strspn(p, WHITESPACE);
|
|
|
|
|
|
|
|
if (*p != '/')
|
|
|
|
continue;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
s = strdup(p);
|
|
|
|
if (!s)
|
2011-02-14 21:55:06 +01:00
|
|
|
goto fail;
|
|
|
|
|
2011-02-17 13:13:34 +01:00
|
|
|
path_kill_slashes(s);
|
|
|
|
|
2013-04-23 05:12:15 +02:00
|
|
|
k = set_consume(unix_sockets, s);
|
|
|
|
if (k < 0 && k != -EEXIST)
|
|
|
|
goto fail;
|
2011-02-14 21:55:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
set_free_free(unix_sockets);
|
|
|
|
unix_sockets = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool unix_socket_alive(const char *fn) {
|
|
|
|
assert(fn);
|
|
|
|
|
|
|
|
load_unix_sockets();
|
|
|
|
|
|
|
|
if (unix_sockets)
|
|
|
|
return !!set_get(unix_sockets, (char*) fn);
|
|
|
|
|
|
|
|
/* We don't know, so assume yes */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-13 13:12:36 +01:00
|
|
|
static int dir_is_mount_point(DIR *d, const char *subdir) {
|
2014-06-10 22:50:46 +02:00
|
|
|
|
|
|
|
union file_handle_union h = {
|
|
|
|
.handle.handle_bytes = MAX_HANDLE_SZ
|
|
|
|
};
|
|
|
|
|
2013-03-13 13:12:36 +01:00
|
|
|
int mount_id_parent, mount_id;
|
|
|
|
int r_p, r;
|
|
|
|
|
2014-04-19 19:22:35 +02:00
|
|
|
r_p = name_to_handle_at(dirfd(d), ".", &h.handle, &mount_id_parent, 0);
|
2013-03-13 13:12:36 +01:00
|
|
|
if (r_p < 0)
|
|
|
|
r_p = -errno;
|
|
|
|
|
2014-04-19 19:22:35 +02:00
|
|
|
h.handle.handle_bytes = MAX_HANDLE_SZ;
|
|
|
|
r = name_to_handle_at(dirfd(d), subdir, &h.handle, &mount_id, 0);
|
2013-03-13 13:12:36 +01:00
|
|
|
if (r < 0)
|
|
|
|
r = -errno;
|
|
|
|
|
|
|
|
/* got no handle; make no assumptions, return error */
|
|
|
|
if (r_p < 0 && r < 0)
|
|
|
|
return r_p;
|
|
|
|
|
|
|
|
/* got both handles; if they differ, it is a mount point */
|
|
|
|
if (r_p >= 0 && r >= 0)
|
|
|
|
return mount_id_parent != mount_id;
|
|
|
|
|
|
|
|
/* got only one handle; assume different mount points if one
|
|
|
|
* of both queries was not supported by the filesystem */
|
2014-10-12 02:35:06 +02:00
|
|
|
if (r_p == -ENOSYS || r_p == -EOPNOTSUPP || r == -ENOSYS || r == -EOPNOTSUPP)
|
2013-03-13 13:12:36 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* return error */
|
|
|
|
if (r_p < 0)
|
|
|
|
return r_p;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
static int dir_cleanup(
|
2013-01-18 16:13:08 +01:00
|
|
|
Item *i,
|
2010-10-18 22:38:41 +02:00
|
|
|
const char *p,
|
|
|
|
DIR *d,
|
|
|
|
const struct stat *ds,
|
|
|
|
usec_t cutoff,
|
|
|
|
dev_t rootdev,
|
|
|
|
bool mountpoint,
|
2012-06-20 09:05:50 +02:00
|
|
|
int maxdepth,
|
2013-09-17 23:33:30 +02:00
|
|
|
bool keep_this_level) {
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
struct dirent *dent;
|
|
|
|
struct timespec times[2];
|
|
|
|
bool deleted = false;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
while ((dent = readdir(d))) {
|
|
|
|
struct stat s;
|
|
|
|
usec_t age;
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_free_ char *sub_path = NULL;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
if (streq(dent->d_name, ".") ||
|
|
|
|
streq(dent->d_name, ".."))
|
|
|
|
continue;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
if (fstatat(dirfd(d), dent->d_name, &s, AT_SYMLINK_NOFOLLOW) < 0) {
|
2013-10-17 03:20:46 +02:00
|
|
|
if (errno == ENOENT)
|
|
|
|
continue;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2013-10-17 03:20:46 +02:00
|
|
|
/* FUSE, NFS mounts, SELinux might return EACCES */
|
|
|
|
if (errno == EACCES)
|
|
|
|
log_debug("stat(%s/%s) failed: %m", p, dent->d_name);
|
|
|
|
else
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("stat(%s/%s) failed: %m", p, dent->d_name);
|
2013-10-17 03:20:46 +02:00
|
|
|
r = -errno;
|
2010-10-18 22:38:41 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stay on the same filesystem */
|
|
|
|
if (s.st_dev != rootdev)
|
|
|
|
continue;
|
|
|
|
|
2013-03-13 13:12:36 +01:00
|
|
|
/* Try to detect bind mounts of the same filesystem instance; they
|
|
|
|
* do not differ in device major/minors. This type of query is not
|
|
|
|
* supported on all kernels or filesystem types though. */
|
|
|
|
if (S_ISDIR(s.st_mode) && dir_is_mount_point(d, dent->d_name) > 0)
|
|
|
|
continue;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
/* Do not delete read-only files owned by root */
|
|
|
|
if (s.st_uid == 0 && !(s.st_mode & S_IWUSR))
|
|
|
|
continue;
|
|
|
|
|
2014-06-10 22:50:46 +02:00
|
|
|
sub_path = strjoin(p, "/", dent->d_name, NULL);
|
|
|
|
if (!sub_path) {
|
2012-07-25 23:55:59 +02:00
|
|
|
r = log_oom();
|
2010-10-18 22:38:41 +02:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is there an item configured for this path? */
|
|
|
|
if (hashmap_get(items, sub_path))
|
|
|
|
continue;
|
|
|
|
|
2011-02-12 09:31:25 +01:00
|
|
|
if (find_glob(globs, sub_path))
|
|
|
|
continue;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
if (S_ISDIR(s.st_mode)) {
|
|
|
|
|
|
|
|
if (mountpoint &&
|
|
|
|
streq(dent->d_name, "lost+found") &&
|
|
|
|
s.st_uid == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (maxdepth <= 0)
|
|
|
|
log_warning("Reached max depth on %s.", sub_path);
|
|
|
|
else {
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_closedir_ DIR *sub_dir;
|
2010-10-18 22:38:41 +02:00
|
|
|
int q;
|
|
|
|
|
2012-04-11 21:33:12 +02:00
|
|
|
sub_dir = xopendirat(dirfd(d), dent->d_name, O_NOFOLLOW|O_NOATIME);
|
2014-06-10 22:50:46 +02:00
|
|
|
if (!sub_dir) {
|
2010-10-18 22:38:41 +02:00
|
|
|
if (errno != ENOENT) {
|
|
|
|
log_error("opendir(%s/%s) failed: %m", p, dent->d_name);
|
|
|
|
r = -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-18 16:13:08 +01:00
|
|
|
q = dir_cleanup(i, sub_path, sub_dir, &s, cutoff, rootdev, false, maxdepth-1, false);
|
2010-10-18 22:38:41 +02:00
|
|
|
if (q < 0)
|
|
|
|
r = q;
|
|
|
|
}
|
|
|
|
|
2012-06-20 09:05:50 +02:00
|
|
|
/* Note: if you are wondering why we don't
|
|
|
|
* support the sticky bit for excluding
|
|
|
|
* directories from cleaning like we do it for
|
|
|
|
* other file system objects: well, the sticky
|
|
|
|
* bit already has a meaning for directories,
|
|
|
|
* so we don't want to overload that. */
|
|
|
|
|
|
|
|
if (keep_this_level)
|
|
|
|
continue;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
/* Ignore ctime, we change it when deleting */
|
|
|
|
age = MAX(timespec_load(&s.st_mtim),
|
|
|
|
timespec_load(&s.st_atim));
|
|
|
|
if (age >= cutoff)
|
|
|
|
continue;
|
|
|
|
|
2013-03-01 18:29:59 +01:00
|
|
|
if (i->type != IGNORE_DIRECTORY_PATH || !streq(dent->d_name, p)) {
|
2013-12-24 16:39:37 +01:00
|
|
|
log_debug("rmdir '%s'", sub_path);
|
2010-10-18 22:38:41 +02:00
|
|
|
|
2013-01-18 16:13:08 +01:00
|
|
|
if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) {
|
|
|
|
if (errno != ENOENT && errno != ENOTEMPTY) {
|
|
|
|
log_error("rmdir(%s): %m", sub_path);
|
|
|
|
r = -errno;
|
|
|
|
}
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2010-11-14 20:12:51 +01:00
|
|
|
/* Skip files for which the sticky bit is
|
|
|
|
* set. These are semantics we define, and are
|
|
|
|
* unknown elsewhere. See XDG_RUNTIME_DIR
|
|
|
|
* specification for details. */
|
|
|
|
if (s.st_mode & S_ISVTX)
|
|
|
|
continue;
|
|
|
|
|
2011-02-14 21:55:06 +01:00
|
|
|
if (mountpoint && S_ISREG(s.st_mode)) {
|
2010-10-18 22:38:41 +02:00
|
|
|
if (streq(dent->d_name, ".journal") &&
|
|
|
|
s.st_uid == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (streq(dent->d_name, "aquota.user") ||
|
|
|
|
streq(dent->d_name, "aquota.group"))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-14 21:55:06 +01:00
|
|
|
/* Ignore sockets that are listed in /proc/net/unix */
|
|
|
|
if (S_ISSOCK(s.st_mode) && unix_socket_alive(sub_path))
|
|
|
|
continue;
|
|
|
|
|
2011-02-19 14:20:16 +01:00
|
|
|
/* Ignore device nodes */
|
|
|
|
if (S_ISCHR(s.st_mode) || S_ISBLK(s.st_mode))
|
|
|
|
continue;
|
|
|
|
|
2012-06-20 09:05:50 +02:00
|
|
|
/* Keep files on this level around if this is
|
|
|
|
* requested */
|
|
|
|
if (keep_this_level)
|
|
|
|
continue;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
age = MAX3(timespec_load(&s.st_mtim),
|
|
|
|
timespec_load(&s.st_atim),
|
|
|
|
timespec_load(&s.st_ctim));
|
|
|
|
|
|
|
|
if (age >= cutoff)
|
|
|
|
continue;
|
|
|
|
|
2013-12-24 16:39:37 +01:00
|
|
|
log_debug("unlink '%s'", sub_path);
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
if (unlinkat(dirfd(d), dent->d_name, 0) < 0) {
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
log_error("unlink(%s): %m", sub_path);
|
|
|
|
r = -errno;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
if (deleted) {
|
|
|
|
/* Restore original directory timestamps */
|
|
|
|
times[0] = ds->st_atim;
|
|
|
|
times[1] = ds->st_mtim;
|
|
|
|
|
|
|
|
if (futimens(dirfd(d), times) < 0)
|
|
|
|
log_error("utimensat(%s): %m", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:19:57 +02:00
|
|
|
static int item_set_perms(Item *i, const char *path) {
|
2014-08-17 09:45:00 +02:00
|
|
|
struct stat st;
|
|
|
|
bool st_valid;
|
|
|
|
|
2014-06-10 22:50:46 +02:00
|
|
|
assert(i);
|
|
|
|
assert(path);
|
|
|
|
|
2014-08-17 09:45:00 +02:00
|
|
|
st_valid = stat(path, &st) == 0;
|
|
|
|
|
2011-12-16 18:00:11 +01:00
|
|
|
/* not using i->path directly because it may be a glob */
|
2014-06-11 10:14:07 +02:00
|
|
|
if (i->mode_set) {
|
|
|
|
mode_t m = i->mode;
|
|
|
|
|
2014-08-17 09:45:00 +02:00
|
|
|
if (i->mask_perms && st_valid) {
|
|
|
|
if (!(st.st_mode & 0111))
|
|
|
|
m &= ~0111;
|
|
|
|
if (!(st.st_mode & 0222))
|
|
|
|
m &= ~0222;
|
|
|
|
if (!(st.st_mode & 0444))
|
|
|
|
m &= ~0444;
|
|
|
|
if (!S_ISDIR(st.st_mode))
|
|
|
|
m &= ~07000; /* remove sticky/sgid/suid bit, unless directory */
|
2014-06-11 10:14:07 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 09:45:00 +02:00
|
|
|
if (!st_valid || m != (st.st_mode & 07777)) {
|
|
|
|
if (chmod(path, m) < 0) {
|
|
|
|
log_error("chmod(%s) failed: %m", path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2011-12-16 18:00:11 +01:00
|
|
|
}
|
2014-06-11 10:14:07 +02:00
|
|
|
}
|
2011-12-16 18:00:11 +01:00
|
|
|
|
2014-08-17 09:45:00 +02:00
|
|
|
if ((!st_valid || (i->uid != st.st_uid || i->gid != st.st_gid)) &&
|
|
|
|
(i->uid_set || i->gid_set))
|
2011-12-16 18:00:11 +01:00
|
|
|
if (chown(path,
|
|
|
|
i->uid_set ? i->uid : (uid_t) -1,
|
|
|
|
i->gid_set ? i->gid : (gid_t) -1) < 0) {
|
|
|
|
|
2014-06-11 09:19:57 +02:00
|
|
|
log_error("chown(%s) failed: %m", path);
|
|
|
|
return -errno;
|
2011-12-16 18:00:11 +01:00
|
|
|
}
|
|
|
|
|
2014-06-11 09:19:57 +02:00
|
|
|
return label_fix(path, false, false);
|
2011-12-16 18:00:11 +01:00
|
|
|
}
|
|
|
|
|
2012-09-03 23:13:18 +02:00
|
|
|
static int write_one_file(Item *i, const char *path) {
|
2014-06-18 00:01:39 +02:00
|
|
|
_cleanup_close_ int fd = -1;
|
|
|
|
int flags, r = 0;
|
2012-09-03 23:13:18 +02:00
|
|
|
struct stat st;
|
|
|
|
|
2014-06-10 22:48:56 +02:00
|
|
|
assert(i);
|
|
|
|
assert(path);
|
|
|
|
|
2014-06-18 00:01:39 +02:00
|
|
|
flags = i->type == CREATE_FILE ? O_CREAT|O_APPEND|O_NOFOLLOW :
|
|
|
|
i->type == TRUNCATE_FILE ? O_CREAT|O_TRUNC|O_NOFOLLOW : 0;
|
2012-09-03 23:13:18 +02:00
|
|
|
|
2014-06-18 00:01:39 +02:00
|
|
|
RUN_WITH_UMASK(0000) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(path, S_IFREG);
|
2014-06-18 00:01:39 +02:00
|
|
|
fd = open(path, flags|O_NDELAY|O_CLOEXEC|O_WRONLY|O_NOCTTY, i->mode);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2013-04-04 03:39:39 +02:00
|
|
|
}
|
2012-09-03 23:13:18 +02:00
|
|
|
|
|
|
|
if (fd < 0) {
|
|
|
|
if (i->type == WRITE_FILE && errno == ENOENT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
log_error("Failed to create file %s: %m", path);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i->argument) {
|
2014-06-10 22:50:46 +02:00
|
|
|
_cleanup_free_ char *unescaped;
|
2012-09-03 23:13:18 +02:00
|
|
|
ssize_t n;
|
|
|
|
size_t l;
|
|
|
|
|
2012-09-15 18:58:49 +02:00
|
|
|
unescaped = cunescape(i->argument);
|
2014-06-18 00:01:39 +02:00
|
|
|
if (!unescaped)
|
2012-09-15 18:58:49 +02:00
|
|
|
return log_oom();
|
2012-09-03 23:13:18 +02:00
|
|
|
|
2012-09-15 18:58:49 +02:00
|
|
|
l = strlen(unescaped);
|
|
|
|
n = write(fd, unescaped, l);
|
2012-09-03 23:13:18 +02:00
|
|
|
|
|
|
|
if (n < 0 || (size_t) n < l) {
|
|
|
|
log_error("Failed to write file %s: %s", path, n < 0 ? strerror(-n) : "Short write");
|
|
|
|
return n < 0 ? n : -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 00:01:39 +02:00
|
|
|
fd = safe_close(fd);
|
2012-09-12 22:21:00 +02:00
|
|
|
|
2012-09-03 23:13:18 +02:00
|
|
|
if (stat(path, &st) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", path);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISREG(st.st_mode)) {
|
|
|
|
log_error("%s is not a file.", path);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = item_set_perms(i, path);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
static int item_set_perms_children(Item *i, const char *path) {
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_closedir_ DIR *d;
|
2014-06-10 23:42:16 +02:00
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
assert(path);
|
2011-12-15 23:11:07 +01:00
|
|
|
|
|
|
|
/* This returns the first error we run into, but nevertheless
|
|
|
|
* tries to go on */
|
|
|
|
|
|
|
|
d = opendir(path);
|
|
|
|
if (!d)
|
2014-06-10 23:42:16 +02:00
|
|
|
return errno == ENOENT || errno == ENOTDIR ? 0 : -errno;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
|
|
|
for (;;) {
|
2014-06-10 23:42:16 +02:00
|
|
|
_cleanup_free_ char *p = NULL;
|
2012-09-19 22:21:09 +02:00
|
|
|
struct dirent *de;
|
2014-06-10 23:42:16 +02:00
|
|
|
int q;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
2013-12-19 12:26:07 +01:00
|
|
|
errno = 0;
|
|
|
|
de = readdir(d);
|
2014-06-10 23:42:16 +02:00
|
|
|
if (!de) {
|
|
|
|
if (errno != 0 && r == 0)
|
|
|
|
r = -errno;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
|
|
|
break;
|
2014-06-10 23:42:16 +02:00
|
|
|
}
|
2011-12-15 23:11:07 +01:00
|
|
|
|
|
|
|
if (streq(de->d_name, ".") || streq(de->d_name, ".."))
|
|
|
|
continue;
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
p = strjoin(path, "/", de->d_name, NULL);
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
q = item_set_perms(i, p);
|
|
|
|
if (q < 0 && q != -ENOENT && r == 0)
|
|
|
|
r = q;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
if (IN_SET(de->d_type, DT_UNKNOWN, DT_DIR)) {
|
|
|
|
q = item_set_perms_children(i, p);
|
|
|
|
if (q < 0 && r == 0)
|
|
|
|
r = q;
|
2011-12-15 23:11:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
return r;
|
2011-12-15 23:11:07 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
static int item_set_perms_recursive(Item *i, const char *path) {
|
|
|
|
int r, q;
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
assert(path);
|
2011-12-15 23:11:07 +01:00
|
|
|
|
2011-12-16 18:00:11 +01:00
|
|
|
r = item_set_perms(i, path);
|
2011-12-15 23:11:07 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
q = item_set_perms_children(i, path);
|
|
|
|
if (q < 0 && r == 0)
|
|
|
|
r = q;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:45:26 +01:00
|
|
|
static int glob_item(Item *i, int (*action)(Item *, const char *)) {
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_globfree_ glob_t g = {};
|
2014-06-10 23:42:16 +02:00
|
|
|
int r = 0, k;
|
2011-12-15 23:45:26 +01:00
|
|
|
char **fn;
|
|
|
|
|
|
|
|
errno = 0;
|
2013-03-25 00:09:19 +01:00
|
|
|
k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
|
2014-06-10 23:42:16 +02:00
|
|
|
if (k != 0 && k != GLOB_NOMATCH) {
|
|
|
|
if (errno == 0)
|
|
|
|
errno = EIO;
|
2011-12-15 23:45:26 +01:00
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
log_error("glob(%s) failed: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2011-12-15 23:45:26 +01:00
|
|
|
|
2013-03-25 00:09:19 +01:00
|
|
|
STRV_FOREACH(fn, g.gl_pathv) {
|
|
|
|
k = action(i, *fn);
|
2014-06-10 23:42:16 +02:00
|
|
|
if (k < 0 && r == 0)
|
2011-12-15 23:45:26 +01:00
|
|
|
r = k;
|
2013-03-25 00:09:19 +01:00
|
|
|
}
|
2011-12-15 23:45:26 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
static int create_item(Item *i) {
|
|
|
|
struct stat st;
|
2013-10-21 15:24:18 +02:00
|
|
|
int r = 0;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
assert(i);
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
switch (i->type) {
|
|
|
|
|
|
|
|
case IGNORE_PATH:
|
2013-01-18 16:13:08 +01:00
|
|
|
case IGNORE_DIRECTORY_PATH:
|
2010-10-18 22:38:41 +02:00
|
|
|
case REMOVE_PATH:
|
|
|
|
case RECURSIVE_REMOVE_PATH:
|
|
|
|
return 0;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
case CREATE_FILE:
|
2012-01-18 16:39:04 +01:00
|
|
|
case TRUNCATE_FILE:
|
2012-09-28 02:48:13 +02:00
|
|
|
r = write_one_file(i, i->path);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
break;
|
2013-09-17 23:33:30 +02:00
|
|
|
|
2014-06-10 23:02:40 +02:00
|
|
|
case COPY_FILES:
|
2014-06-19 19:36:08 +02:00
|
|
|
r = copy_tree(i->argument, i->path, false);
|
2014-06-10 23:02:40 +02:00
|
|
|
if (r < 0) {
|
2014-06-19 19:36:08 +02:00
|
|
|
struct stat a, b;
|
|
|
|
|
|
|
|
if (r != -EEXIST) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to copy files to %s: %m", i->path);
|
2014-06-19 19:36:08 +02:00
|
|
|
return -r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(i->argument, &a) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->argument);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat(i->path, &b) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((a.st_mode ^ b.st_mode) & S_IFMT) {
|
|
|
|
log_debug("Can't copy to %s, file exists already and is of different type", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-06-10 23:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = item_set_perms(i, i->path);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-09-03 23:13:18 +02:00
|
|
|
case WRITE_FILE:
|
|
|
|
r = glob_item(i, write_one_file);
|
2011-12-15 23:44:23 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TRUNCATE_DIRECTORY:
|
|
|
|
case CREATE_DIRECTORY:
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2013-04-04 03:39:39 +02:00
|
|
|
RUN_WITH_UMASK(0000) {
|
|
|
|
mkdir_parents_label(i->path, 0755);
|
2014-06-18 00:02:08 +02:00
|
|
|
r = mkdir_label(i->path, i->mode);
|
2013-04-04 03:39:39 +02:00
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-06-19 19:36:08 +02:00
|
|
|
if (r < 0) {
|
|
|
|
if (r != -EEXIST) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to create directory %s: %m", i->path);
|
2014-06-19 19:36:08 +02:00
|
|
|
return r;
|
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-06-19 19:36:08 +02:00
|
|
|
if (stat(i->path, &st) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-06-19 19:36:08 +02:00
|
|
|
if (!S_ISDIR(st.st_mode)) {
|
|
|
|
log_debug("%s already exists and is not a directory.", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 18:00:11 +01:00
|
|
|
r = item_set_perms(i, i->path);
|
2011-12-15 23:44:23 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
break;
|
2011-07-12 03:56:56 +02:00
|
|
|
|
|
|
|
case CREATE_FIFO:
|
|
|
|
|
2013-04-04 03:39:39 +02:00
|
|
|
RUN_WITH_UMASK(0000) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, S_IFIFO);
|
2013-04-04 03:39:39 +02:00
|
|
|
r = mkfifo(i->path, i->mode);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2013-04-04 03:39:39 +02:00
|
|
|
}
|
2011-07-12 03:56:56 +02:00
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
if (r < 0) {
|
|
|
|
if (errno != EEXIST) {
|
|
|
|
log_error("Failed to create fifo %s: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2011-07-12 03:56:56 +02:00
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
if (stat(i->path, &st) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2011-07-12 03:56:56 +02:00
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
if (!S_ISFIFO(st.st_mode)) {
|
|
|
|
|
|
|
|
if (i->force) {
|
|
|
|
|
|
|
|
RUN_WITH_UMASK(0000) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, S_IFIFO);
|
2014-06-17 23:50:22 +02:00
|
|
|
r = mkfifo_atomic(i->path, i->mode);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2014-06-17 23:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to create fifo %s: %m", i->path);
|
2014-06-17 23:50:22 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log_debug("%s is not a fifo.", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2011-07-12 03:56:56 +02:00
|
|
|
}
|
|
|
|
|
2011-12-16 18:00:11 +01:00
|
|
|
r = item_set_perms(i, i->path);
|
2011-12-15 23:44:23 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2011-07-12 03:56:56 +02:00
|
|
|
|
|
|
|
break;
|
2011-12-15 23:11:07 +01:00
|
|
|
|
2014-06-16 13:21:07 +02:00
|
|
|
case CREATE_SYMLINK:
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, S_IFLNK);
|
2012-01-17 15:04:12 +01:00
|
|
|
r = symlink(i->argument, i->path);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2012-04-17 16:05:03 +02:00
|
|
|
|
2012-01-17 15:04:12 +01:00
|
|
|
if (r < 0) {
|
2014-06-16 13:21:07 +02:00
|
|
|
_cleanup_free_ char *x = NULL;
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2014-06-16 13:21:07 +02:00
|
|
|
if (errno != EEXIST) {
|
|
|
|
log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = readlink_malloc(i->path, &x);
|
|
|
|
if (r < 0 || !streq(i->argument, x)) {
|
|
|
|
|
|
|
|
if (i->force) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, S_IFLNK);
|
2014-06-16 13:21:07 +02:00
|
|
|
r = symlink_atomic(i->argument, i->path);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2014-06-16 13:21:07 +02:00
|
|
|
|
|
|
|
if (r < 0) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "symlink(%s, %s) failed: %m", i->argument, i->path);
|
2014-06-17 23:50:22 +02:00
|
|
|
return r;
|
2014-06-16 13:21:07 +02:00
|
|
|
}
|
2014-06-17 23:50:22 +02:00
|
|
|
} else {
|
2014-06-16 13:21:07 +02:00
|
|
|
log_debug("%s is not a symlink or does not point to the correct path.", i->path);
|
2014-06-17 23:50:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-06-16 13:21:07 +02:00
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CREATE_BLOCK_DEVICE:
|
|
|
|
case CREATE_CHAR_DEVICE: {
|
2012-09-06 08:39:55 +02:00
|
|
|
mode_t file_type;
|
|
|
|
|
|
|
|
if (have_effective_cap(CAP_MKNOD) == 0) {
|
|
|
|
/* In a container we lack CAP_MKNOD. We
|
2013-04-15 04:37:54 +02:00
|
|
|
shouldn't attempt to create the device node in
|
2012-09-06 08:39:55 +02:00
|
|
|
that case to avoid noise, and we don't support
|
|
|
|
virtualized devices in containers anyway. */
|
|
|
|
|
|
|
|
log_debug("We lack CAP_MKNOD, skipping creation of device node %s.", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
file_type = i->type == CREATE_BLOCK_DEVICE ? S_IFBLK : S_IFCHR;
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2013-04-04 03:39:39 +02:00
|
|
|
RUN_WITH_UMASK(0000) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, file_type);
|
2013-04-04 03:39:39 +02:00
|
|
|
r = mknod(i->path, i->mode | file_type, i->major_minor);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2013-04-04 03:39:39 +02:00
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2014-06-13 04:11:11 +02:00
|
|
|
if (r < 0) {
|
|
|
|
if (errno == EPERM) {
|
|
|
|
log_debug("We lack permissions, possibly because of cgroup configuration; "
|
|
|
|
"skipping creation of device node %s.", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno != EEXIST) {
|
|
|
|
log_error("Failed to create device node %s: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
if (stat(i->path, &st) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2014-06-17 23:50:22 +02:00
|
|
|
if ((st.st_mode & S_IFMT) != file_type) {
|
|
|
|
|
|
|
|
if (i->force) {
|
|
|
|
|
|
|
|
RUN_WITH_UMASK(0000) {
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_prepare(i->path, file_type);
|
2014-06-17 23:50:22 +02:00
|
|
|
r = mknod_atomic(i->path, i->mode | file_type, i->major_minor);
|
2014-10-23 19:41:27 +02:00
|
|
|
mac_selinux_create_file_clear();
|
2014-06-17 23:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r < 0) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to create device node %s: %m", i->path);
|
2014-06-17 23:50:22 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log_debug("%s is not a device node.", i->path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
r = item_set_perms(i, i->path);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
case ADJUST_MODE:
|
2011-12-16 18:27:35 +01:00
|
|
|
case RELABEL_PATH:
|
|
|
|
|
|
|
|
r = glob_item(i, item_set_perms);
|
|
|
|
if (r < 0)
|
2013-06-21 15:57:42 +02:00
|
|
|
return r;
|
2011-12-16 18:27:35 +01:00
|
|
|
break;
|
|
|
|
|
2011-12-15 23:11:07 +01:00
|
|
|
case RECURSIVE_RELABEL_PATH:
|
|
|
|
|
2014-06-10 23:42:16 +02:00
|
|
|
r = glob_item(i, item_set_perms_recursive);
|
2011-12-15 23:11:07 +01:00
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-06-10 23:42:16 +02:00
|
|
|
|
|
|
|
break;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
log_debug("%s created successfully.", i->path);
|
|
|
|
|
2011-12-15 23:44:23 +01:00
|
|
|
return 0;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
2011-12-15 21:32:50 +01:00
|
|
|
static int remove_item_instance(Item *i, const char *instance) {
|
2010-10-18 22:38:41 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
|
|
|
|
switch (i->type) {
|
|
|
|
|
|
|
|
case CREATE_FILE:
|
|
|
|
case TRUNCATE_FILE:
|
|
|
|
case CREATE_DIRECTORY:
|
2011-07-12 03:56:56 +02:00
|
|
|
case CREATE_FIFO:
|
2012-01-17 15:04:12 +01:00
|
|
|
case CREATE_SYMLINK:
|
|
|
|
case CREATE_BLOCK_DEVICE:
|
|
|
|
case CREATE_CHAR_DEVICE:
|
2010-10-18 22:38:41 +02:00
|
|
|
case IGNORE_PATH:
|
2013-01-18 16:13:08 +01:00
|
|
|
case IGNORE_DIRECTORY_PATH:
|
2014-06-10 23:42:16 +02:00
|
|
|
case ADJUST_MODE:
|
2011-12-16 18:27:35 +01:00
|
|
|
case RELABEL_PATH:
|
2011-12-15 23:11:07 +01:00
|
|
|
case RECURSIVE_RELABEL_PATH:
|
2012-01-18 16:39:04 +01:00
|
|
|
case WRITE_FILE:
|
2014-06-10 23:02:40 +02:00
|
|
|
case COPY_FILES:
|
2010-10-18 22:38:41 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOVE_PATH:
|
2011-02-12 09:31:25 +01:00
|
|
|
if (remove(instance) < 0 && errno != ENOENT) {
|
|
|
|
log_error("remove(%s): %m", instance);
|
2010-10-18 22:38:41 +02:00
|
|
|
return -errno;
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRUNCATE_DIRECTORY:
|
|
|
|
case RECURSIVE_REMOVE_PATH:
|
2012-06-20 14:31:00 +02:00
|
|
|
/* FIXME: we probably should use dir_cleanup() here
|
|
|
|
* instead of rm_rf() so that 'x' is honoured. */
|
2012-07-10 19:05:58 +02:00
|
|
|
r = rm_rf_dangerous(instance, false, i->type == RECURSIVE_REMOVE_PATH, false);
|
2012-01-17 15:04:12 +01:00
|
|
|
if (r < 0 && r != -ENOENT) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "rm_rf(%s): %m", instance);
|
2010-10-18 22:38:41 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-15 21:32:50 +01:00
|
|
|
static int remove_item(Item *i) {
|
2011-12-15 23:45:26 +01:00
|
|
|
int r = 0;
|
|
|
|
|
2011-02-12 09:31:25 +01:00
|
|
|
assert(i);
|
|
|
|
|
|
|
|
switch (i->type) {
|
|
|
|
|
|
|
|
case CREATE_FILE:
|
|
|
|
case TRUNCATE_FILE:
|
|
|
|
case CREATE_DIRECTORY:
|
2011-07-12 03:56:56 +02:00
|
|
|
case CREATE_FIFO:
|
2012-01-17 15:04:12 +01:00
|
|
|
case CREATE_SYMLINK:
|
|
|
|
case CREATE_CHAR_DEVICE:
|
|
|
|
case CREATE_BLOCK_DEVICE:
|
2011-02-12 09:31:25 +01:00
|
|
|
case IGNORE_PATH:
|
2013-01-18 16:13:08 +01:00
|
|
|
case IGNORE_DIRECTORY_PATH:
|
2014-06-10 23:42:16 +02:00
|
|
|
case ADJUST_MODE:
|
2011-12-16 18:27:35 +01:00
|
|
|
case RELABEL_PATH:
|
2011-12-15 23:11:07 +01:00
|
|
|
case RECURSIVE_RELABEL_PATH:
|
2012-01-18 16:39:04 +01:00
|
|
|
case WRITE_FILE:
|
2014-06-10 23:02:40 +02:00
|
|
|
case COPY_FILES:
|
2011-02-12 09:31:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case REMOVE_PATH:
|
|
|
|
case TRUNCATE_DIRECTORY:
|
2011-12-15 23:45:26 +01:00
|
|
|
case RECURSIVE_REMOVE_PATH:
|
|
|
|
r = glob_item(i, remove_item_instance);
|
|
|
|
break;
|
2011-02-12 09:31:25 +01:00
|
|
|
}
|
|
|
|
|
2011-12-15 23:45:26 +01:00
|
|
|
return r;
|
2011-02-12 09:31:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 16:13:08 +01:00
|
|
|
static int clean_item_instance(Item *i, const char* instance) {
|
2013-04-18 09:11:22 +02:00
|
|
|
_cleanup_closedir_ DIR *d = NULL;
|
2013-01-18 16:13:08 +01:00
|
|
|
struct stat s, ps;
|
|
|
|
bool mountpoint;
|
|
|
|
int r;
|
|
|
|
usec_t cutoff, n;
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
|
|
|
|
if (!i->age_set)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
n = now(CLOCK_REALTIME);
|
|
|
|
if (n < i->age)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cutoff = n - i->age;
|
|
|
|
|
|
|
|
d = opendir(instance);
|
|
|
|
if (!d) {
|
|
|
|
if (errno == ENOENT || errno == ENOTDIR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
log_error("Failed to open directory %s: %m", i->path);
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fstat(dirfd(d), &s) < 0) {
|
|
|
|
log_error("stat(%s) failed: %m", i->path);
|
2013-03-04 00:42:52 +01:00
|
|
|
return -errno;
|
2013-01-18 16:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISDIR(s.st_mode)) {
|
|
|
|
log_error("%s is not a directory.", i->path);
|
2013-03-04 00:42:52 +01:00
|
|
|
return -ENOTDIR;
|
2013-01-18 16:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fstatat(dirfd(d), "..", &ps, AT_SYMLINK_NOFOLLOW) != 0) {
|
|
|
|
log_error("stat(%s/..) failed: %m", i->path);
|
2013-03-04 00:42:52 +01:00
|
|
|
return -errno;
|
2013-01-18 16:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mountpoint = s.st_dev != ps.st_dev ||
|
|
|
|
(s.st_dev == ps.st_dev && s.st_ino == ps.st_ino);
|
|
|
|
|
2013-03-04 00:42:52 +01:00
|
|
|
r = dir_cleanup(i, instance, d, &s, cutoff, s.st_dev, mountpoint,
|
|
|
|
MAX_DEPTH, i->keep_first_level);
|
2013-01-18 16:13:08 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int clean_item(Item *i) {
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
assert(i);
|
|
|
|
|
|
|
|
switch (i->type) {
|
|
|
|
case CREATE_DIRECTORY:
|
|
|
|
case TRUNCATE_DIRECTORY:
|
|
|
|
case IGNORE_PATH:
|
2014-06-10 23:02:40 +02:00
|
|
|
case COPY_FILES:
|
2013-01-18 16:13:08 +01:00
|
|
|
clean_item_instance(i, i->path);
|
|
|
|
break;
|
|
|
|
case IGNORE_DIRECTORY_PATH:
|
|
|
|
r = glob_item(i, clean_item_instance);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
static int process_item(Item *i) {
|
|
|
|
int r, q, p;
|
2014-10-01 14:33:22 +02:00
|
|
|
_cleanup_free_ char *prefix = NULL;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
assert(i);
|
|
|
|
|
2014-06-11 01:37:35 +02:00
|
|
|
if (i->done)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
i->done = true;
|
|
|
|
|
2014-10-01 14:33:22 +02:00
|
|
|
prefix = malloc(strlen(i->path) + 1);
|
|
|
|
if (!prefix)
|
|
|
|
return log_oom();
|
|
|
|
|
2014-06-11 01:37:35 +02:00
|
|
|
PATH_FOREACH_PREFIX(prefix, i->path) {
|
|
|
|
Item *j;
|
|
|
|
|
|
|
|
j = hashmap_get(items, prefix);
|
|
|
|
if (j)
|
|
|
|
process_item(j);
|
|
|
|
}
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
r = arg_create ? create_item(i) : 0;
|
2011-12-15 21:32:50 +01:00
|
|
|
q = arg_remove ? remove_item(i) : 0;
|
2010-10-18 22:38:41 +02:00
|
|
|
p = arg_clean ? clean_item(i) : 0;
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (q < 0)
|
|
|
|
return q;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void item_free(Item *i) {
|
2014-06-12 23:07:17 +02:00
|
|
|
|
|
|
|
if (!i)
|
|
|
|
return;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
free(i->path);
|
2012-01-17 15:04:12 +01:00
|
|
|
free(i->argument);
|
2010-10-18 22:38:41 +02:00
|
|
|
free(i);
|
|
|
|
}
|
|
|
|
|
2013-10-14 04:59:26 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(Item*, item_free);
|
2013-07-19 15:43:12 +02:00
|
|
|
|
2011-04-08 04:49:43 +02:00
|
|
|
static bool item_equal(Item *a, Item *b) {
|
|
|
|
assert(a);
|
|
|
|
assert(b);
|
|
|
|
|
|
|
|
if (!streq_ptr(a->path, b->path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->type != b->type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->uid_set != b->uid_set ||
|
|
|
|
(a->uid_set && a->uid != b->uid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->gid_set != b->gid_set ||
|
|
|
|
(a->gid_set && a->gid != b->gid))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->mode_set != b->mode_set ||
|
|
|
|
(a->mode_set && a->mode != b->mode))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (a->age_set != b->age_set ||
|
|
|
|
(a->age_set && a->age != b->age))
|
|
|
|
return false;
|
|
|
|
|
2012-01-18 16:39:04 +01:00
|
|
|
if ((a->type == CREATE_FILE ||
|
|
|
|
a->type == TRUNCATE_FILE ||
|
|
|
|
a->type == WRITE_FILE ||
|
2014-06-10 23:02:40 +02:00
|
|
|
a->type == CREATE_SYMLINK ||
|
|
|
|
a->type == COPY_FILES) &&
|
2012-01-22 18:19:24 +01:00
|
|
|
!streq_ptr(a->argument, b->argument))
|
2012-01-17 15:04:12 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((a->type == CREATE_CHAR_DEVICE ||
|
|
|
|
a->type == CREATE_BLOCK_DEVICE) &&
|
|
|
|
a->major_minor != b->major_minor)
|
|
|
|
return false;
|
|
|
|
|
2011-04-08 04:49:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-24 17:10:05 +02:00
|
|
|
static bool should_include_path(const char *path) {
|
|
|
|
char **prefix;
|
|
|
|
|
2014-06-11 10:14:07 +02:00
|
|
|
STRV_FOREACH(prefix, arg_exclude_prefixes)
|
2013-07-24 17:19:24 +02:00
|
|
|
if (path_startswith(path, *prefix))
|
|
|
|
return false;
|
2013-07-24 17:10:05 +02:00
|
|
|
|
2014-06-11 10:14:07 +02:00
|
|
|
STRV_FOREACH(prefix, arg_include_prefixes)
|
2013-07-24 17:10:05 +02:00
|
|
|
if (path_startswith(path, *prefix))
|
|
|
|
return true;
|
|
|
|
|
2013-07-24 17:19:24 +02:00
|
|
|
/* no matches, so we should include this path only if we
|
|
|
|
* have no whitelist at all */
|
2014-06-11 01:26:28 +02:00
|
|
|
return strv_length(arg_include_prefixes) == 0;
|
2013-07-24 17:10:05 +02:00
|
|
|
}
|
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
static int parse_line(const char *fname, unsigned line, const char *buffer) {
|
2013-09-17 18:02:02 +02:00
|
|
|
|
|
|
|
static const Specifier specifier_table[] = {
|
|
|
|
{ 'm', specifier_machine_id, NULL },
|
|
|
|
{ 'b', specifier_boot_id, NULL },
|
|
|
|
{ 'H', specifier_host_name, NULL },
|
|
|
|
{ 'v', specifier_kernel_release, NULL },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2014-06-10 22:50:46 +02:00
|
|
|
_cleanup_free_ char *action = NULL, *mode = NULL, *user = NULL, *group = NULL, *age = NULL, *path = NULL;
|
|
|
|
_cleanup_(item_freep) Item *i = NULL;
|
2013-03-31 22:29:46 +02:00
|
|
|
Item *existing;
|
2011-12-15 21:31:14 +01:00
|
|
|
char type;
|
2011-04-08 04:49:43 +02:00
|
|
|
Hashmap *h;
|
2012-01-18 16:39:04 +01:00
|
|
|
int r, n = -1;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
assert(fname);
|
|
|
|
assert(line >= 1);
|
|
|
|
assert(buffer);
|
|
|
|
|
2013-03-04 00:42:52 +01:00
|
|
|
r = sscanf(buffer,
|
2013-12-21 02:25:39 +01:00
|
|
|
"%ms %ms %ms %ms %ms %ms %n",
|
|
|
|
&action,
|
2013-09-17 18:02:02 +02:00
|
|
|
&path,
|
2011-01-22 02:18:59 +01:00
|
|
|
&mode,
|
|
|
|
&user,
|
|
|
|
&group,
|
2012-01-17 15:04:12 +01:00
|
|
|
&age,
|
2013-03-04 00:42:52 +01:00
|
|
|
&n);
|
|
|
|
if (r < 2) {
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("[%s:%u] Syntax error.", fname, line);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EIO;
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 13:21:07 +02:00
|
|
|
if (isempty(action)) {
|
|
|
|
log_error("[%s:%u] Command too short '%s'.", fname, line, action);
|
2013-12-21 02:25:39 +01:00
|
|
|
return -EINVAL;
|
2014-06-16 13:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(action) > 1 && !in_charset(action+1, "!+")) {
|
|
|
|
log_error("[%s:%u] Unknown modifiers in command '%s'", fname, line, action);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr(action+1, '!') && !arg_boot)
|
2013-12-21 02:25:39 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
type = action[0];
|
|
|
|
|
2013-09-17 18:02:02 +02:00
|
|
|
i = new0(Item, 1);
|
|
|
|
if (!i)
|
|
|
|
return log_oom();
|
|
|
|
|
2014-06-16 13:21:07 +02:00
|
|
|
i->force = !!strchr(action+1, '+');
|
|
|
|
|
2013-09-17 18:02:02 +02:00
|
|
|
r = specifier_printf(path, specifier_table, NULL, &i->path);
|
|
|
|
if (r < 0) {
|
|
|
|
log_error("[%s:%u] Failed to replace specifiers: %s", fname, line, path);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-01-18 16:39:04 +01:00
|
|
|
if (n >= 0) {
|
|
|
|
n += strspn(buffer+n, WHITESPACE);
|
|
|
|
if (buffer[n] != 0 && (buffer[n] != '-' || buffer[n+1] != 0)) {
|
|
|
|
i->argument = unquote(buffer+n, "\"");
|
2012-07-25 23:55:59 +02:00
|
|
|
if (!i->argument)
|
|
|
|
return log_oom();
|
2012-01-18 16:39:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-12 23:07:17 +02:00
|
|
|
switch (type) {
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2011-12-16 18:27:35 +01:00
|
|
|
case CREATE_FILE:
|
|
|
|
case TRUNCATE_FILE:
|
|
|
|
case CREATE_DIRECTORY:
|
|
|
|
case TRUNCATE_DIRECTORY:
|
|
|
|
case CREATE_FIFO:
|
|
|
|
case IGNORE_PATH:
|
2013-01-18 16:13:08 +01:00
|
|
|
case IGNORE_DIRECTORY_PATH:
|
2011-12-16 18:27:35 +01:00
|
|
|
case REMOVE_PATH:
|
|
|
|
case RECURSIVE_REMOVE_PATH:
|
2014-06-10 23:42:16 +02:00
|
|
|
case ADJUST_MODE:
|
2011-12-16 18:27:35 +01:00
|
|
|
case RELABEL_PATH:
|
|
|
|
case RECURSIVE_RELABEL_PATH:
|
|
|
|
break;
|
2012-01-17 15:04:12 +01:00
|
|
|
|
|
|
|
case CREATE_SYMLINK:
|
|
|
|
if (!i->argument) {
|
2014-06-20 15:57:43 +02:00
|
|
|
i->argument = strappend("/usr/share/factory", i->path);
|
|
|
|
if (!i->argument)
|
|
|
|
return log_oom();
|
2012-01-17 15:04:12 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-01-18 16:39:04 +01:00
|
|
|
case WRITE_FILE:
|
|
|
|
if (!i->argument) {
|
|
|
|
log_error("[%s:%u] Write file requires argument.", fname, line);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2012-01-18 16:39:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-06-10 23:02:40 +02:00
|
|
|
case COPY_FILES:
|
|
|
|
if (!i->argument) {
|
2014-06-20 15:57:43 +02:00
|
|
|
i->argument = strappend("/usr/share/factory", i->path);
|
|
|
|
if (!i->argument)
|
|
|
|
return log_oom();
|
2014-06-10 23:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!path_is_absolute(i->argument)) {
|
|
|
|
log_error("[%s:%u] Source path is not absolute.", fname, line);
|
|
|
|
return -EBADMSG;
|
|
|
|
}
|
|
|
|
|
|
|
|
path_kill_slashes(i->argument);
|
|
|
|
break;
|
|
|
|
|
2012-01-17 15:04:12 +01:00
|
|
|
case CREATE_CHAR_DEVICE:
|
|
|
|
case CREATE_BLOCK_DEVICE: {
|
|
|
|
unsigned major, minor;
|
|
|
|
|
|
|
|
if (!i->argument) {
|
|
|
|
log_error("[%s:%u] Device file requires argument.", fname, line);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2012-01-17 15:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(i->argument, "%u:%u", &major, &minor) != 2) {
|
|
|
|
log_error("[%s:%u] Can't parse device file major/minor '%s'.", fname, line, i->argument);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2012-01-17 15:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
i->major_minor = makedev(major, minor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 18:27:35 +01:00
|
|
|
default:
|
2014-06-12 23:07:17 +02:00
|
|
|
log_error("[%s:%u] Unknown command type '%c'.", fname, line, type);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
2012-01-17 15:04:12 +01:00
|
|
|
|
2011-12-15 23:11:07 +01:00
|
|
|
i->type = type;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
if (!path_is_absolute(i->path)) {
|
|
|
|
log_error("[%s:%u] Path '%s' not absolute.", fname, line, i->path);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
path_kill_slashes(i->path);
|
|
|
|
|
2013-07-24 17:10:05 +02:00
|
|
|
if (!should_include_path(i->path))
|
2013-03-31 22:29:46 +02:00
|
|
|
return 0;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-03-14 05:32:13 +01:00
|
|
|
if (arg_root) {
|
2014-06-10 22:50:46 +02:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strappend(arg_root, i->path);
|
2014-03-14 05:32:13 +01:00
|
|
|
if (!p)
|
|
|
|
return log_oom();
|
|
|
|
|
|
|
|
free(i->path);
|
|
|
|
i->path = p;
|
|
|
|
}
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
if (user && !streq(user, "-")) {
|
2011-07-23 01:17:59 +02:00
|
|
|
const char *u = user;
|
|
|
|
|
2012-07-16 12:34:54 +02:00
|
|
|
r = get_user_creds(&u, &i->uid, NULL, NULL, NULL);
|
2011-07-23 01:17:59 +02:00
|
|
|
if (r < 0) {
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("[%s:%u] Unknown user '%s'.", fname, line, user);
|
2013-03-31 22:29:46 +02:00
|
|
|
return r;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
i->uid_set = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group && !streq(group, "-")) {
|
2011-07-23 01:17:59 +02:00
|
|
|
const char *g = group;
|
|
|
|
|
|
|
|
r = get_group_creds(&g, &i->gid);
|
|
|
|
if (r < 0) {
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("[%s:%u] Unknown group '%s'.", fname, line, group);
|
2013-03-31 22:29:46 +02:00
|
|
|
return r;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
i->gid_set = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode && !streq(mode, "-")) {
|
2014-06-11 10:14:07 +02:00
|
|
|
const char *mm = mode;
|
2010-10-18 22:38:41 +02:00
|
|
|
unsigned m;
|
|
|
|
|
2014-06-11 10:14:07 +02:00
|
|
|
if (*mm == '~') {
|
|
|
|
i->mask_perms = true;
|
|
|
|
mm++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(mm, "%o", &m) != 1) {
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("[%s:%u] Invalid mode '%s'.", fname, line, mode);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -ENOENT;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
i->mode = m;
|
|
|
|
i->mode_set = true;
|
|
|
|
} else
|
2012-01-17 15:04:12 +01:00
|
|
|
i->mode =
|
|
|
|
i->type == CREATE_DIRECTORY ||
|
|
|
|
i->type == TRUNCATE_DIRECTORY ? 0755 : 0644;
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
if (age && !streq(age, "-")) {
|
2012-06-20 09:05:50 +02:00
|
|
|
const char *a = age;
|
|
|
|
|
|
|
|
if (*a == '~') {
|
|
|
|
i->keep_first_level = true;
|
|
|
|
a++;
|
|
|
|
}
|
|
|
|
|
2013-04-02 20:38:16 +02:00
|
|
|
if (parse_sec(a, &i->age) < 0) {
|
2010-10-18 22:38:41 +02:00
|
|
|
log_error("[%s:%u] Invalid age '%s'.", fname, line, age);
|
2013-03-31 22:29:46 +02:00
|
|
|
return -EBADMSG;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
i->age_set = true;
|
|
|
|
}
|
|
|
|
|
2011-04-08 04:49:43 +02:00
|
|
|
h = needs_glob(i->type) ? globs : items;
|
|
|
|
|
2012-01-17 15:04:12 +01:00
|
|
|
existing = hashmap_get(h, i->path);
|
|
|
|
if (existing) {
|
2011-04-08 04:49:43 +02:00
|
|
|
|
|
|
|
/* Two identical items are fine */
|
|
|
|
if (!item_equal(existing, i))
|
2011-01-05 16:11:15 +01:00
|
|
|
log_warning("Two or more conflicting lines for %s configured, ignoring.", i->path);
|
|
|
|
|
2013-03-31 22:29:46 +02:00
|
|
|
return 0;
|
2011-04-08 04:49:43 +02:00
|
|
|
}
|
|
|
|
|
2012-01-17 15:04:12 +01:00
|
|
|
r = hashmap_put(h, i->path, i);
|
|
|
|
if (r < 0) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to insert item %s: %m", i->path);
|
2013-03-31 22:29:46 +02:00
|
|
|
return r;
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
2013-03-31 22:29:46 +02:00
|
|
|
i = NULL; /* avoid cleanup */
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2013-03-31 22:29:46 +02:00
|
|
|
return 0;
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|
|
|
|
|
2014-08-02 17:12:21 +02:00
|
|
|
static void help(void) {
|
2011-02-13 15:08:15 +01:00
|
|
|
printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
|
|
|
|
"Creates, deletes and cleans up volatile and temporary files and directories.\n\n"
|
2013-07-24 17:19:24 +02:00
|
|
|
" -h --help Show this help\n"
|
2013-11-06 18:28:39 +01:00
|
|
|
" --version Show package version\n"
|
2013-07-24 17:19:24 +02:00
|
|
|
" --create Create marked files/directories\n"
|
|
|
|
" --clean Clean up marked directories\n"
|
|
|
|
" --remove Remove marked files/directories\n"
|
2013-12-30 19:00:38 +01:00
|
|
|
" --boot Execute actions only safe at boot\n"
|
2013-07-24 17:19:24 +02:00
|
|
|
" --prefix=PATH Only apply rules that apply to paths with the specified prefix\n"
|
2014-03-14 05:32:13 +01:00
|
|
|
" --exclude-prefix=PATH Ignore rules that apply to paths with the specified prefix\n"
|
|
|
|
" --root=PATH Operate on an alternate filesystem root\n",
|
2010-10-18 22:38:41 +02:00
|
|
|
program_invocation_short_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parse_argv(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
enum {
|
2013-11-06 18:28:39 +01:00
|
|
|
ARG_VERSION = 0x100,
|
2010-10-18 22:38:41 +02:00
|
|
|
ARG_CREATE,
|
|
|
|
ARG_CLEAN,
|
2011-02-13 14:00:54 +01:00
|
|
|
ARG_REMOVE,
|
2013-12-30 19:00:38 +01:00
|
|
|
ARG_BOOT,
|
2013-07-24 17:19:24 +02:00
|
|
|
ARG_PREFIX,
|
|
|
|
ARG_EXCLUDE_PREFIX,
|
2014-03-14 05:32:13 +01:00
|
|
|
ARG_ROOT,
|
2010-10-18 22:38:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct option options[] = {
|
2013-07-24 17:19:24 +02:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
2013-11-06 18:28:39 +01:00
|
|
|
{ "version", no_argument, NULL, ARG_VERSION },
|
2013-07-24 17:19:24 +02:00
|
|
|
{ "create", no_argument, NULL, ARG_CREATE },
|
|
|
|
{ "clean", no_argument, NULL, ARG_CLEAN },
|
|
|
|
{ "remove", no_argument, NULL, ARG_REMOVE },
|
2013-12-30 19:00:38 +01:00
|
|
|
{ "boot", no_argument, NULL, ARG_BOOT },
|
2013-07-24 17:19:24 +02:00
|
|
|
{ "prefix", required_argument, NULL, ARG_PREFIX },
|
|
|
|
{ "exclude-prefix", required_argument, NULL, ARG_EXCLUDE_PREFIX },
|
2014-03-14 05:32:13 +01:00
|
|
|
{ "root", required_argument, NULL, ARG_ROOT },
|
2013-11-06 18:28:39 +01:00
|
|
|
{}
|
2010-10-18 22:38:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
assert(argc >= 0);
|
|
|
|
assert(argv);
|
|
|
|
|
2014-08-02 17:12:21 +02:00
|
|
|
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
|
2010-10-18 22:38:41 +02:00
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
|
|
|
case 'h':
|
2014-08-02 17:12:21 +02:00
|
|
|
help();
|
|
|
|
return 0;
|
2013-11-06 18:28:39 +01:00
|
|
|
|
|
|
|
case ARG_VERSION:
|
|
|
|
puts(PACKAGE_STRING);
|
|
|
|
puts(SYSTEMD_FEATURES);
|
2010-10-18 22:38:41 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case ARG_CREATE:
|
|
|
|
arg_create = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_CLEAN:
|
|
|
|
arg_clean = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ARG_REMOVE:
|
|
|
|
arg_remove = true;
|
|
|
|
break;
|
|
|
|
|
2013-12-30 19:00:38 +01:00
|
|
|
case ARG_BOOT:
|
|
|
|
arg_boot = true;
|
2013-12-21 02:25:39 +01:00
|
|
|
break;
|
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
case ARG_PREFIX:
|
2014-06-11 01:26:28 +02:00
|
|
|
if (strv_push(&arg_include_prefixes, optarg) < 0)
|
2013-07-24 17:10:05 +02:00
|
|
|
return log_oom();
|
2011-02-13 14:00:54 +01:00
|
|
|
break;
|
|
|
|
|
2013-07-24 17:19:24 +02:00
|
|
|
case ARG_EXCLUDE_PREFIX:
|
2014-06-11 01:26:28 +02:00
|
|
|
if (strv_push(&arg_exclude_prefixes, optarg) < 0)
|
2013-07-24 17:19:24 +02:00
|
|
|
return log_oom();
|
|
|
|
break;
|
|
|
|
|
2014-03-14 05:32:13 +01:00
|
|
|
case ARG_ROOT:
|
2014-06-12 23:07:17 +02:00
|
|
|
free(arg_root);
|
2014-03-14 05:32:13 +01:00
|
|
|
arg_root = path_make_absolute_cwd(optarg);
|
|
|
|
if (!arg_root)
|
|
|
|
return log_oom();
|
2014-06-12 23:07:17 +02:00
|
|
|
|
2014-03-14 05:32:13 +01:00
|
|
|
path_kill_slashes(arg_root);
|
|
|
|
break;
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
case '?':
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
default:
|
2013-11-06 18:28:39 +01:00
|
|
|
assert_not_reached("Unhandled option");
|
2010-10-18 22:38:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg_clean && !arg_create && !arg_remove) {
|
2011-02-21 15:32:17 +01:00
|
|
|
log_error("You need to specify at least one of --clean, --create or --remove.");
|
2010-10-18 22:38:41 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
static int read_config_file(const char *fn, bool ignore_enoent) {
|
2013-09-17 18:02:02 +02:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
char line[LINE_MAX];
|
2013-01-18 16:13:08 +01:00
|
|
|
Iterator iterator;
|
2013-09-17 18:02:02 +02:00
|
|
|
unsigned v = 0;
|
2013-01-18 16:13:08 +01:00
|
|
|
Item *i;
|
2013-09-17 18:02:02 +02:00
|
|
|
int r;
|
2011-02-13 14:00:54 +01:00
|
|
|
|
|
|
|
assert(fn);
|
|
|
|
|
2014-03-14 05:32:13 +01:00
|
|
|
r = search_and_fopen_nulstr(fn, "re", arg_root, conf_file_dirs, &f);
|
2013-02-11 23:48:36 +01:00
|
|
|
if (r < 0) {
|
|
|
|
if (ignore_enoent && r == -ENOENT)
|
2011-02-13 14:00:54 +01:00
|
|
|
return 0;
|
|
|
|
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to open '%s', ignoring: %m", fn);
|
2013-02-11 23:48:36 +01:00
|
|
|
return r;
|
2011-02-13 14:00:54 +01:00
|
|
|
}
|
|
|
|
|
2013-09-17 18:02:02 +02:00
|
|
|
FOREACH_LINE(line, f, break) {
|
|
|
|
char *l;
|
2011-02-13 14:00:54 +01:00
|
|
|
int k;
|
|
|
|
|
|
|
|
v++;
|
|
|
|
|
|
|
|
l = strstrip(line);
|
|
|
|
if (*l == '#' || *l == 0)
|
|
|
|
continue;
|
|
|
|
|
2013-09-17 18:02:02 +02:00
|
|
|
k = parse_line(fn, v, l);
|
|
|
|
if (k < 0 && r == 0)
|
|
|
|
r = k;
|
2011-02-13 14:00:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-18 16:13:08 +01:00
|
|
|
/* we have to determine age parameter for each entry of type X */
|
|
|
|
HASHMAP_FOREACH(i, globs, iterator) {
|
|
|
|
Iterator iter;
|
|
|
|
Item *j, *candidate_item = NULL;
|
|
|
|
|
|
|
|
if (i->type != IGNORE_DIRECTORY_PATH)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
HASHMAP_FOREACH(j, items, iter) {
|
|
|
|
if (j->type != CREATE_DIRECTORY && j->type != TRUNCATE_DIRECTORY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (path_equal(j->path, i->path)) {
|
|
|
|
candidate_item = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!candidate_item && path_startswith(i->path, j->path)) ||
|
|
|
|
(candidate_item && path_startswith(j->path, candidate_item->path) && (fnmatch(i->path, j->path, FNM_PATHNAME | FNM_PERIOD) == 0)))
|
|
|
|
candidate_item = j;
|
|
|
|
}
|
|
|
|
|
2014-09-09 11:09:37 +02:00
|
|
|
if (candidate_item && candidate_item->age_set) {
|
2013-01-18 16:13:08 +01:00
|
|
|
i->age = candidate_item->age;
|
|
|
|
i->age_set = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
if (ferror(f)) {
|
|
|
|
log_error("Failed to read from file %s: %m", fn);
|
|
|
|
if (r == 0)
|
|
|
|
r = -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:34:02 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2013-02-11 23:48:36 +01:00
|
|
|
int r, k;
|
2010-10-18 22:38:41 +02:00
|
|
|
Item *i;
|
|
|
|
Iterator iterator;
|
|
|
|
|
2012-01-11 22:07:35 +01:00
|
|
|
r = parse_argv(argc, argv);
|
|
|
|
if (r <= 0)
|
2014-06-12 23:07:17 +02:00
|
|
|
goto finish;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2011-02-12 09:31:38 +01:00
|
|
|
log_set_target(LOG_TARGET_AUTO);
|
2010-09-28 02:34:02 +02:00
|
|
|
log_parse_environment();
|
|
|
|
log_open();
|
|
|
|
|
2011-08-01 20:52:18 +02:00
|
|
|
umask(0022);
|
|
|
|
|
2014-10-23 10:23:46 +02:00
|
|
|
mac_selinux_init(NULL);
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-08-13 01:00:18 +02:00
|
|
|
items = hashmap_new(&string_hash_ops);
|
|
|
|
globs = hashmap_new(&string_hash_ops);
|
2011-02-12 09:31:25 +01:00
|
|
|
|
|
|
|
if (!items || !globs) {
|
2013-02-11 23:48:36 +01:00
|
|
|
r = log_oom();
|
2010-10-18 22:38:41 +02:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2013-02-11 23:48:36 +01:00
|
|
|
r = 0;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
if (optind < argc) {
|
|
|
|
int j;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2012-06-09 04:31:19 +02:00
|
|
|
for (j = optind; j < argc; j++) {
|
2013-02-11 23:48:36 +01:00
|
|
|
k = read_config_file(argv[j], false);
|
|
|
|
if (k < 0 && r == 0)
|
|
|
|
r = k;
|
2012-06-09 04:31:19 +02:00
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2011-02-13 14:00:54 +01:00
|
|
|
} else {
|
2013-02-11 23:48:36 +01:00
|
|
|
_cleanup_strv_free_ char **files = NULL;
|
|
|
|
char **f;
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-03-14 05:32:13 +01:00
|
|
|
r = conf_files_list_nulstr(&files, ".conf", arg_root, conf_file_dirs);
|
2011-04-28 23:51:24 +02:00
|
|
|
if (r < 0) {
|
2014-11-28 13:19:16 +01:00
|
|
|
log_error_errno(r, "Failed to enumerate tmpfiles.d files: %m");
|
2011-04-28 23:51:24 +02:00
|
|
|
goto finish;
|
|
|
|
}
|
2010-10-18 22:38:41 +02:00
|
|
|
|
2011-04-25 21:38:21 +02:00
|
|
|
STRV_FOREACH(f, files) {
|
2013-02-11 23:48:36 +01:00
|
|
|
k = read_config_file(*f, true);
|
|
|
|
if (k < 0 && r == 0)
|
|
|
|
r = k;
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|
2011-04-25 21:38:21 +02:00
|
|
|
}
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2011-02-12 09:31:25 +01:00
|
|
|
HASHMAP_FOREACH(i, globs, iterator)
|
2011-07-02 01:44:49 +02:00
|
|
|
process_item(i);
|
2011-02-12 09:31:25 +01:00
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
HASHMAP_FOREACH(i, items, iterator)
|
2011-07-02 01:44:49 +02:00
|
|
|
process_item(i);
|
2010-10-18 22:38:41 +02:00
|
|
|
|
2010-09-28 02:34:02 +02:00
|
|
|
finish:
|
2010-10-18 22:38:41 +02:00
|
|
|
while ((i = hashmap_steal_first(items)))
|
|
|
|
item_free(i);
|
|
|
|
|
2011-02-14 21:55:06 +01:00
|
|
|
while ((i = hashmap_steal_first(globs)))
|
|
|
|
item_free(i);
|
|
|
|
|
2010-10-18 22:38:41 +02:00
|
|
|
hashmap_free(items);
|
2011-02-12 09:31:25 +01:00
|
|
|
hashmap_free(globs);
|
2010-09-28 02:34:02 +02:00
|
|
|
|
2014-06-11 01:26:28 +02:00
|
|
|
free(arg_include_prefixes);
|
|
|
|
free(arg_exclude_prefixes);
|
2014-03-14 05:32:13 +01:00
|
|
|
free(arg_root);
|
2013-07-24 17:10:05 +02:00
|
|
|
|
2011-02-14 21:55:06 +01:00
|
|
|
set_free_free(unix_sockets);
|
|
|
|
|
2014-10-23 10:23:46 +02:00
|
|
|
mac_selinux_finish();
|
2010-10-19 19:36:45 +02:00
|
|
|
|
2013-02-11 23:48:36 +01:00
|
|
|
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
2010-09-28 02:34:02 +02:00
|
|
|
}
|