install.c   install.c 
skipping to change at line 62 skipping to change at line 62
} InstallContext; } InstallContext;
static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope s cope) { static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope s cope) {
assert(paths); assert(paths);
assert(scope >= 0); assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX); assert(scope < _UNIT_FILE_SCOPE_MAX);
zero(*paths); zero(*paths);
return lookup_paths_init(paths, return lookup_paths_init(paths,
scope == UNIT_FILE_SYSTEM ? MANAGER_SYSTEM : MANAGER_USER, scope == UNIT_FILE_SYSTEM ? SYSTEMD_SYSTEM : SYSTEMD_USER,
scope == UNIT_FILE_USER, scope == UNIT_FILE_USER,
NULL, NULL, NULL); NULL, NULL, NULL);
} }
static int get_config_path(UnitFileScope scope, bool runtime, const char *r oot_dir, char **ret) { static int get_config_path(UnitFileScope scope, bool runtime, const char *r oot_dir, char **ret) {
char *p = NULL; char *p = NULL;
int r; int r;
assert(scope >= 0); assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX); assert(scope < _UNIT_FILE_SCOPE_MAX);
skipping to change at line 204 skipping to change at line 204
int fd, int fd,
const char *path, const char *path,
const char *config_path, const char *config_path,
bool *deleted, bool *deleted,
UnitFileChange **changes, UnitFileChange **changes,
unsigned *n_changes, unsigned *n_changes,
char** files) { char** files) {
int r = 0; int r = 0;
DIR *d; DIR *d;
struct dirent buffer, *de;
assert(remove_symlinks_to); assert(remove_symlinks_to);
assert(fd >= 0); assert(fd >= 0);
assert(path); assert(path);
assert(config_path); assert(config_path);
assert(deleted); assert(deleted);
d = fdopendir(fd); d = fdopendir(fd);
if (!d) { if (!d) {
close_nointr_nofail(fd); close_nointr_nofail(fd);
return -errno; return -errno;
} }
rewinddir(d); rewinddir(d);
for (;;) { for (;;) {
struct dirent *de;
union dirent_storage buf;
int k; int k;
k = readdir_r(d, &buffer, &de); k = readdir_r(d, &buf.de, &de);
if (k != 0) { if (k != 0) {
r = -errno; r = -errno;
break; break;
} }
if (!de) if (!de)
break; break;
if (ignore_file(de->d_name)) if (ignore_file(de->d_name))
continue; continue;
skipping to change at line 378 skipping to change at line 379
static int find_symlinks_fd( static int find_symlinks_fd(
const char *name, const char *name,
int fd, int fd,
const char *path, const char *path,
const char *config_path, const char *config_path,
bool *same_name_link) { bool *same_name_link) {
int r = 0; int r = 0;
DIR *d; DIR *d;
struct dirent buffer, *de;
assert(name); assert(name);
assert(fd >= 0); assert(fd >= 0);
assert(path); assert(path);
assert(config_path); assert(config_path);
assert(same_name_link); assert(same_name_link);
d = fdopendir(fd); d = fdopendir(fd);
if (!d) { if (!d) {
close_nointr_nofail(fd); close_nointr_nofail(fd);
return -errno; return -errno;
} }
for (;;) { for (;;) {
int k; int k;
struct dirent *de;
union dirent_storage buf;
k = readdir_r(d, &buffer, &de); k = readdir_r(d, &buf.de, &de);
if (k != 0) { if (k != 0) {
r = -errno; r = -errno;
break; break;
} }
if (!de) if (!de)
break; break;
if (ignore_file(de->d_name)) if (ignore_file(de->d_name))
continue; continue;
skipping to change at line 527 skipping to change at line 529
const char *config_path, const char *config_path,
bool *same_name_link) { bool *same_name_link) {
int fd; int fd;
assert(name); assert(name);
assert(config_path); assert(config_path);
assert(same_name_link); assert(same_name_link);
fd = open(config_path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_ NOFOLLOW); fd = open(config_path, O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC|O_ NOFOLLOW);
if (fd < 0) if (fd < 0) {
if (errno == ENOENT)
return 0;
return -errno; return -errno;
}
/* This takes possession of fd and closes it */ /* This takes possession of fd and closes it */
return find_symlinks_fd(name, fd, config_path, config_path, same_na me_link); return find_symlinks_fd(name, fd, config_path, config_path, same_na me_link);
} }
static int find_symlinks_in_scope( static int find_symlinks_in_scope(
UnitFileScope scope, UnitFileScope scope,
const char *root_dir, const char *root_dir,
const char *name, const char *name,
UnitFileState *state) { UnitFileState *state) {
int r; int r;
char *path; char _cleanup_free_ *path = NULL;
bool same_name_link_runtime = false, same_name_link = false; bool same_name_link_runtime = false, same_name_link = false;
assert(scope >= 0); assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX); assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name); assert(name);
if (scope == UNIT_FILE_SYSTEM || scope == UNIT_FILE_GLOBAL) { if (scope == UNIT_FILE_SYSTEM || scope == UNIT_FILE_GLOBAL) {
/* First look in runtime config path */ /* First look in runtime config path */
r = get_config_path(scope, true, root_dir, &path); r = get_config_path(scope, true, root_dir, &path);
if (r < 0) if (r < 0)
return r; return r;
r = find_symlinks(name, path, &same_name_link_runtime); r = find_symlinks(name, path, &same_name_link_runtime);
free(path);
if (r < 0) if (r < 0)
return r; return r;
else if (r > 0) { else if (r > 0) {
*state = UNIT_FILE_ENABLED_RUNTIME; *state = UNIT_FILE_ENABLED_RUNTIME;
return r; return r;
} }
} }
/* Then look in the normal config path */ /* Then look in the normal config path */
r = get_config_path(scope, false, root_dir, &path); r = get_config_path(scope, false, root_dir, &path);
if (r < 0) if (r < 0)
return r; return r;
r = find_symlinks(name, path, &same_name_link); r = find_symlinks(name, path, &same_name_link);
free(path);
if (r < 0) if (r < 0)
return r; return r;
else if (r > 0) { else if (r > 0) {
*state = UNIT_FILE_ENABLED; *state = UNIT_FILE_ENABLED;
return r; return r;
} }
/* Hmm, we didn't find it, but maybe we found the same name /* Hmm, we didn't find it, but maybe we found the same name
* link? */ * link? */
if (same_name_link_runtime) { if (same_name_link_runtime) {
skipping to change at line 603 skipping to change at line 604
int unit_file_mask( int unit_file_mask(
UnitFileScope scope, UnitFileScope scope,
bool runtime, bool runtime,
const char *root_dir, const char *root_dir,
char *files[], char *files[],
bool force, bool force,
UnitFileChange **changes, UnitFileChange **changes,
unsigned *n_changes) { unsigned *n_changes) {
char **i, *prefix; char **i;
char _cleanup_free_ *prefix;
int r; int r;
assert(scope >= 0); assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX); assert(scope < _UNIT_FILE_SCOPE_MAX);
r = get_config_path(scope, runtime, root_dir, &prefix); r = get_config_path(scope, runtime, root_dir, &prefix);
if (r < 0) if (r < 0)
return r; return r;
STRV_FOREACH(i, files) { STRV_FOREACH(i, files) {
char *path; char _cleanup_free_ *path = NULL;
if (!unit_name_is_valid(*i, true)) { if (!unit_name_is_valid(*i, true)) {
if (r == 0) if (r == 0)
r = -EINVAL; r = -EINVAL;
continue; continue;
} }
path = path_make_absolute(*i, prefix); path = path_make_absolute(*i, prefix);
if (!path) { if (!path) {
r = -ENOMEM; r = -ENOMEM;
break; break;
} }
if (symlink("/dev/null", path) >= 0) { if (symlink("/dev/null", path) >= 0) {
add_file_change(changes, n_changes, UNIT_FILE_SYMLI NK, path, "/dev/null"); add_file_change(changes, n_changes, UNIT_FILE_SYMLI NK, path, "/dev/null");
free(path);
continue; continue;
} }
if (errno == EEXIST) { if (errno == EEXIST) {
if (null_or_empty_path(path) > 0) { if (null_or_empty_path(path) > 0)
free(path);
continue; continue;
}
if (force) { if (force) {
unlink(path); unlink(path);
if (symlink("/dev/null", path) >= 0) { if (symlink("/dev/null", path) >= 0) {
add_file_change(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); add_file_change(changes, n_changes, UNIT_FILE_UNLINK, path, NULL);
add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null"); add_file_change(changes, n_changes, UNIT_FILE_SYMLINK, path, "/dev/null");
free(path);
continue; continue;
} }
} }
if (r == 0) if (r == 0)
r = -EEXIST; r = -EEXIST;
} else { } else {
if (r == 0) if (r == 0)
r = -errno; r = -errno;
} }
free(path);
} }
free(prefix);
return r; return r;
} }
int unit_file_unmask( int unit_file_unmask(
UnitFileScope scope, UnitFileScope scope,
bool runtime, bool runtime,
const char *root_dir, const char *root_dir,
char *files[], char *files[],
UnitFileChange **changes, UnitFileChange **changes,
unsigned *n_changes) { unsigned *n_changes) {
skipping to change at line 1916 skipping to change at line 1910
zero(paths); zero(paths);
if (root_dir && scope != UNIT_FILE_SYSTEM) if (root_dir && scope != UNIT_FILE_SYSTEM)
return -EINVAL; return -EINVAL;
r = lookup_paths_init_from_scope(&paths, scope); r = lookup_paths_init_from_scope(&paths, scope);
if (r < 0) if (r < 0)
return r; return r;
STRV_FOREACH(i, paths.unit_path) { STRV_FOREACH(i, paths.unit_path) {
struct dirent buffer, *de;
const char *units_dir; const char *units_dir;
free(buf); free(buf);
buf = NULL; buf = NULL;
if (root_dir) { if (root_dir) {
if (asprintf(&buf, "%s/%s", root_dir, *i) < 0) { if (asprintf(&buf, "%s/%s", root_dir, *i) < 0) {
r = -ENOMEM; r = -ENOMEM;
goto finish; goto finish;
} }
skipping to change at line 1944 skipping to change at line 1937
d = opendir(units_dir); d = opendir(units_dir);
if (!d) { if (!d) {
if (errno == ENOENT) if (errno == ENOENT)
continue; continue;
r = -errno; r = -errno;
goto finish; goto finish;
} }
for (;;) { for (;;) {
struct dirent *de;
union dirent_storage buffer;
UnitFileList *f; UnitFileList *f;
r = readdir_r(d, &buffer, &de); r = readdir_r(d, &buffer.de, &de);
if (r != 0) { if (r != 0) {
r = -r; r = -r;
goto finish; goto finish;
} }
if (!de) if (!de)
break; break;
if (ignore_file(de->d_name)) if (ignore_file(de->d_name))
continue; continue;
skipping to change at line 2005 skipping to change at line 2000
path_startswith(*i, "/run") ? path_startswith(*i, "/run") ?
UNIT_FILE_MASKED_RUNTIME : UNIT_FIL E_MASKED; UNIT_FILE_MASKED_RUNTIME : UNIT_FIL E_MASKED;
goto found; goto found;
} }
r = find_symlinks_in_scope(scope, root_dir, de->d_n ame, &f->state); r = find_symlinks_in_scope(scope, root_dir, de->d_n ame, &f->state);
if (r < 0) { if (r < 0) {
free(f->path); free(f->path);
free(f); free(f);
goto finish; goto finish;
} else if (r > 0) } else if (r > 0) {
f->state = UNIT_FILE_ENABLED;
goto found; goto found;
}
r = unit_file_can_install(&paths, root_dir, f->path , true); r = unit_file_can_install(&paths, root_dir, f->path , true);
if (r < 0) { if (r == -EINVAL || /* Invalid setting? */
r == -EBADMSG || /* Invalid format? */
r == -ENOENT /* Included file not found? */
)
f->state = UNIT_FILE_INVALID;
else if (r < 0) {
free(f->path); free(f->path);
free(f); free(f);
goto finish; goto finish;
} else if (r > 0) { } else if (r > 0)
f->state = UNIT_FILE_DISABLED; f->state = UNIT_FILE_DISABLED;
goto found; else
} else {
f->state = UNIT_FILE_STATIC; f->state = UNIT_FILE_STATIC;
goto found;
}
free(f->path);
free(f);
continue;
found: found:
r = hashmap_put(h, path_get_file_name(f->path), f); r = hashmap_put(h, path_get_file_name(f->path), f);
if (r < 0) { if (r < 0) {
free(f->path); free(f->path);
free(f); free(f);
goto finish; goto finish;
} }
} }
} }
skipping to change at line 2053 skipping to change at line 2047
} }
static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = { static const char* const unit_file_state_table[_UNIT_FILE_STATE_MAX] = {
[UNIT_FILE_ENABLED] = "enabled", [UNIT_FILE_ENABLED] = "enabled",
[UNIT_FILE_ENABLED_RUNTIME] = "enabled-runtime", [UNIT_FILE_ENABLED_RUNTIME] = "enabled-runtime",
[UNIT_FILE_LINKED] = "linked", [UNIT_FILE_LINKED] = "linked",
[UNIT_FILE_LINKED_RUNTIME] = "linked-runtime", [UNIT_FILE_LINKED_RUNTIME] = "linked-runtime",
[UNIT_FILE_MASKED] = "masked", [UNIT_FILE_MASKED] = "masked",
[UNIT_FILE_MASKED_RUNTIME] = "masked-runtime", [UNIT_FILE_MASKED_RUNTIME] = "masked-runtime",
[UNIT_FILE_STATIC] = "static", [UNIT_FILE_STATIC] = "static",
[UNIT_FILE_DISABLED] = "disabled" [UNIT_FILE_DISABLED] = "disabled",
[UNIT_FILE_INVALID] = "invalid",
}; };
DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState); DEFINE_STRING_TABLE_LOOKUP(unit_file_state, UnitFileState);
static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE _MAX] = { static const char* const unit_file_change_type_table[_UNIT_FILE_CHANGE_TYPE _MAX] = {
[UNIT_FILE_SYMLINK] = "symlink", [UNIT_FILE_SYMLINK] = "symlink",
[UNIT_FILE_UNLINK] = "unlink", [UNIT_FILE_UNLINK] = "unlink",
}; };
DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType); DEFINE_STRING_TABLE_LOOKUP(unit_file_change_type, UnitFileChangeType);
 End of changes. 30 change blocks. 
36 lines changed or deleted 32 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/