install.c revision 49e942b2bc9fdedba79cd266a076ce9c9d91fc13
3988N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
3988N/A#include "path-lookup.h"
3988N/A#include "unit-name.h"
3988N/A#include "conf-parser.h"
3988N/Astatic int get_config_path(UnitFileScope scope, bool runtime, const char *root_dir, char **ret) {
3988N/A case UNIT_FILE_SYSTEM:
3988N/A case UNIT_FILE_GLOBAL:
3988N/A case UNIT_FILE_USER:
4001N/A r = user_config_home(&p);
4001N/Astatic int add_file_change(
3988N/Astatic int mark_symlink_for_removal(
3988N/Astatic int remove_marked_symlinks_fd(
3988N/A const char *config_path,
3988N/A q = remove_marked_symlinks_fd(remove_symlinks_to, nfd, p, config_path, deleted, changes, n_changes);
3988N/Astatic int remove_marked_symlinks(
3988N/A const char *config_path,
q = remove_marked_symlinks_fd(remove_symlinks_to, cfd, config_path, config_path, &deleted, changes, n_changes);
} while (deleted);
static int find_symlinks_fd(
const char *name,
int fd,
const char *path,
const char *config_path,
bool *same_name_link) {
DIR *d;
return -errno;
r = -errno;
if (!de)
int nfd, q;
if (nfd < 0) {
r = -errno;
r = -ENOMEM;
free(p);
char *p, *dest;
r = -ENOMEM;
free(p);
if (q == -ENOENT)
free(p);
r = -ENOMEM;
b = path_equal(t, p);
free(t);
free(p);
*same_name_link = true;
closedir(d);
static int find_symlinks(
const char *name,
const char *config_path,
bool *same_name_link) {
int fd;
if (fd < 0)
return -errno;
static int find_symlinks_in_scope(
const char *root_dir,
const char *name,
char *path;
if (same_name_link_runtime) {
} else if (same_name_link) {
int unit_file_mask(
bool runtime,
const char *root_dir,
char *files[],
bool force,
unsigned *n_changes) {
char **i, *prefix;
char *path;
if (!unit_name_is_valid_no_type(*i, true)) {
r = -EINVAL;
if (!path) {
r = -ENOMEM;
if (force) {
r = -EEXIST;
r = -errno;
int unit_file_unmask(
bool runtime,
const char *root_dir,
char *files[],
unsigned *n_changes) {
goto finish;
char *path;
if (!unit_name_is_valid_no_type(*i, true)) {
r = -EINVAL;
if (!path) {
r = -ENOMEM;
q = -errno;
if (q != -ENOENT && r == 0)
int unit_file_link(
bool runtime,
const char *root_dir,
char *files[],
bool force,
unsigned *n_changes) {
goto finish;
if (!path_is_absolute(*i) ||
r = -EINVAL;
r = -errno;
r = -ENOENT;
if (!path) {
r = -ENOMEM;
if (force) {
r = -EEXIST;
r = -errno;
UnitFileList *i;
while ((i = hashmap_steal_first(h))) {
free(i);
hashmap_free(h);
if (!changes)
for (i = 0; i < n_changes; i++) {
assert(i);
free(i);
InstallInfo *i;
while ((i = hashmap_steal_first(m)))
hashmap_free(m);
assert(c);
static int install_info_add(
InstallContext *c,
const char *name,
const char *path) {
assert(c);
if (!name)
return -EINVAL;
return -ENOMEM;
if (!i->name) {
r = -ENOMEM;
goto fail;
if (path) {
if (!i->path) {
r = -ENOMEM;
goto fail;
goto fail;
fail:
static int install_info_add_auto(
InstallContext *c,
const char *name_or_path) {
assert(c);
static int config_parse_also(
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
size_t l;
char *state;
n = strndup(w, l);
return -ENOMEM;
free(n);
free(n);
static int unit_file_load(
InstallContext *c,
const char *path,
bool allow_symlink) {
int fd;
FILE *f;
assert(c);
if (fd < 0)
return -errno;
return -ENOMEM;
fclose(f);
static int unit_file_search(
InstallContext *c,
const char *root_dir,
bool allow_symlink) {
assert(c);
if (!path)
return -ENOMEM;
return -ENOENT;
static int unit_file_can_install(
const char *root_dir,
const char *name,
bool allow_symlink) {
InstallInfo *i;
zero(c);
install_context_done(&c);
static int create_symlink(
const char *old_path,
const char *new_path,
bool force,
unsigned *n_changes) {
char *dest;
return -errno;
if (force)
return -EEXIST;
return -errno;
static int install_info_symlink_alias(
InstallInfo *i,
const char *config_path,
bool force,
unsigned *n_changes) {
assert(i);
char *alias_path;
if (!alias_path)
return -ENOMEM;
static int install_info_symlink_wants(
InstallInfo *i,
const char *config_path,
bool force,
unsigned *n_changes) {
assert(i);
char *path;
if (!unit_name_is_valid_no_type(*s, true)) {
r = -EINVAL;
return -ENOMEM;
static int install_info_symlink_link(
InstallInfo *i,
const char *config_path,
bool force,
unsigned *n_changes) {
char *path;
assert(i);
return -ENOMEM;
static int install_info_apply(
InstallInfo *i,
const char *config_path,
bool force,
unsigned *n_changes) {
assert(i);
static int install_context_apply(
InstallContext *c,
const char *config_path,
const char *root_dir,
bool force,
unsigned *n_changes) {
InstallInfo *i;
assert(c);
static int install_context_mark_for_removal(
InstallContext *c,
const char *config_path,
const char *root_dir) {
InstallInfo *i;
assert(c);
int unit_file_enable(
bool runtime,
const char *root_dir,
char *files[],
bool force,
unsigned *n_changes) {
zero(c);
goto finish;
r = install_info_add_auto(&c, *i);
goto finish;
install_context_done(&c);
int unit_file_disable(
bool runtime,
const char *root_dir,
char *files[],
unsigned *n_changes) {
zero(c);
goto finish;
r = install_info_add_auto(&c, *i);
goto finish;
install_context_done(&c);
int unit_file_reenable(
bool runtime,
const char *root_dir,
char *files[],
bool force,
unsigned *n_changes) {
zero(c);
goto finish;
goto finish;
r = install_info_add_auto(&c, *i);
goto finish;
install_context_done(&c);
const char *root_dir,
const char *name) {
return -EINVAL;
return -EINVAL;
if (root_dir)
if (!path) {
r = -ENOMEM;
goto finish;
r = -errno;
goto finish;
r = -ENOENT;
goto finish;
if (r < 0 && r != -ENOENT)
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
return r < 0 ? r : state;
char **files, **i;
"/etc/systemd/system.preset",
"/usr/local/lib/systemd/system.preset",
"/usr/lib/systemd/system.preset",
"/lib/systemd/system.preset",
NULL);
"/etc/systemd/user.preset",
"/usr/local/lib/systemd/user.preset",
"/usr/lib/systemd/user.preset",
NULL);
FILE *f;
r = -errno;
goto finish;
fclose(f);
goto finish;
fclose(f);
goto finish;
fclose(f);
int unit_file_preset(
bool runtime,
const char *root_dir,
char *files[],
bool force,
unsigned *n_changes) {
goto finish;
if (!unit_name_is_valid_no_type(*i, true)) {
r = -EINVAL;
goto finish;
goto finish;
goto finish;
int unit_file_get_list(
const char *root_dir,
Hashmap *h) {
assert(h);
return -EINVAL;
const char *units_dir;
if (root_dir) {
r = -ENOMEM;
goto finish;
units_dir = *i;
closedir(d);
r = -errno;
goto finish;
UnitFileList *f;
goto finish;
if (!de)
if (r == -ENOENT)
goto finish;
r = -ENOMEM;
goto finish;
if (!f->path) {
free(f);
r = -ENOMEM;
goto finish;
if (r < 0 && r != -ENOENT) {
free(f);
goto finish;
f->state =
goto found;
free(f);
goto finish;
goto found;
free(f);
goto finish;
goto found;
goto found;
free(f);
free(f);
goto finish;
closedir(d);