|
|
17b0f1 |
From f8fd91c9f0f1f7feabf8567bdad61f57fe922011 Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
17b0f1 |
Date: Sat, 14 Mar 2015 21:46:59 -0400
|
|
|
17b0f1 |
Subject: [PATCH] sysv-generator: initialize LookupPaths just once
|
|
|
17b0f1 |
|
|
|
17b0f1 |
With debugging on, sysv-generator would print the full set of
|
|
|
17b0f1 |
lookup paths for *every* sysv script.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
While at it, pass LookupPaths as a pointer in sysv-generator,
|
|
|
17b0f1 |
and constify it everywhere.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
(cherry picked from commit a8ffe6fbcbfdba39aef8dce8b298b3e0cb377c0e)
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
src/shared/install.c | 55 +++++++++++++++++------------
|
|
|
17b0f1 |
src/shared/install.h | 11 +++++-
|
|
|
17b0f1 |
src/shared/path-lookup.c | 1 +
|
|
|
17b0f1 |
src/shared/path-lookup.h | 3 +-
|
|
|
17b0f1 |
src/sysv-generator/sysv-generator.c | 14 ++++----
|
|
|
17b0f1 |
5 files changed, 53 insertions(+), 31 deletions(-)
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/shared/install.c b/src/shared/install.c
|
|
|
17b0f1 |
index 65f1c245c6..92b8d6e8ef 100644
|
|
|
17b0f1 |
--- a/src/shared/install.c
|
|
|
17b0f1 |
+++ b/src/shared/install.c
|
|
|
17b0f1 |
@@ -1084,7 +1084,7 @@ static int unit_file_load(
|
|
|
17b0f1 |
static int unit_file_search(
|
|
|
17b0f1 |
InstallContext *c,
|
|
|
17b0f1 |
InstallInfo *info,
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
bool allow_symlink,
|
|
|
17b0f1 |
bool load,
|
|
|
17b0f1 |
@@ -1153,7 +1153,7 @@ static int unit_file_search(
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int unit_file_can_install(
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
const char *name,
|
|
|
17b0f1 |
bool allow_symlink,
|
|
|
17b0f1 |
@@ -1317,7 +1317,7 @@ static int install_info_symlink_wants(
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int install_info_symlink_link(
|
|
|
17b0f1 |
InstallInfo *i,
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *config_path,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
bool force,
|
|
|
17b0f1 |
@@ -1345,7 +1345,7 @@ static int install_info_symlink_link(
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int install_info_apply(
|
|
|
17b0f1 |
InstallInfo *i,
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *config_path,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
bool force,
|
|
|
17b0f1 |
@@ -1377,7 +1377,7 @@ static int install_info_apply(
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int install_context_apply(
|
|
|
17b0f1 |
InstallContext *c,
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *config_path,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
bool force,
|
|
|
17b0f1 |
@@ -1424,7 +1424,7 @@ static int install_context_apply(
|
|
|
17b0f1 |
|
|
|
17b0f1 |
static int install_context_mark_for_removal(
|
|
|
17b0f1 |
InstallContext *c,
|
|
|
17b0f1 |
- LookupPaths *paths,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
Set **remove_symlinks_to,
|
|
|
17b0f1 |
const char *config_path,
|
|
|
17b0f1 |
const char *root_dir) {
|
|
|
17b0f1 |
@@ -1785,39 +1785,28 @@ int unit_file_get_default(
|
|
|
17b0f1 |
return -ENOENT;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
-UnitFileState unit_file_get_state(
|
|
|
17b0f1 |
+UnitFileState unit_file_lookup_state(
|
|
|
17b0f1 |
UnitFileScope scope,
|
|
|
17b0f1 |
const char *root_dir,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
const char *name) {
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- _cleanup_lookup_paths_free_ LookupPaths paths = {};
|
|
|
17b0f1 |
UnitFileState state = _UNIT_FILE_STATE_INVALID;
|
|
|
17b0f1 |
char **i;
|
|
|
17b0f1 |
_cleanup_free_ char *path = NULL;
|
|
|
17b0f1 |
int r;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- assert(scope >= 0);
|
|
|
17b0f1 |
- assert(scope < _UNIT_FILE_SCOPE_MAX);
|
|
|
17b0f1 |
- assert(name);
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
- if (root_dir && scope != UNIT_FILE_SYSTEM)
|
|
|
17b0f1 |
- return -EINVAL;
|
|
|
17b0f1 |
+ assert(paths);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
if (!unit_name_is_valid(name, TEMPLATE_VALID))
|
|
|
17b0f1 |
return -EINVAL;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = lookup_paths_init_from_scope(&paths, scope, root_dir);
|
|
|
17b0f1 |
- if (r < 0)
|
|
|
17b0f1 |
- return r;
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
- STRV_FOREACH(i, paths.unit_path) {
|
|
|
17b0f1 |
+ STRV_FOREACH(i, paths->unit_path) {
|
|
|
17b0f1 |
struct stat st;
|
|
|
17b0f1 |
char *partial;
|
|
|
17b0f1 |
bool also = false;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
free(path);
|
|
|
17b0f1 |
- path = NULL;
|
|
|
17b0f1 |
-
|
|
|
17b0f1 |
path = path_join(root_dir, *i, name);
|
|
|
17b0f1 |
if (!path)
|
|
|
17b0f1 |
return -ENOMEM;
|
|
|
17b0f1 |
@@ -1858,7 +1847,7 @@ UnitFileState unit_file_get_state(
|
|
|
17b0f1 |
else if (r > 0)
|
|
|
17b0f1 |
return state;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = unit_file_can_install(&paths, root_dir, partial, true, &also);
|
|
|
17b0f1 |
+ r = unit_file_can_install(paths, root_dir, partial, true, &also);
|
|
|
17b0f1 |
if (r < 0 && errno != ENOENT)
|
|
|
17b0f1 |
return r;
|
|
|
17b0f1 |
else if (r > 0)
|
|
|
17b0f1 |
@@ -1873,6 +1862,28 @@ UnitFileState unit_file_get_state(
|
|
|
17b0f1 |
return r < 0 ? r : state;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+UnitFileState unit_file_get_state(
|
|
|
17b0f1 |
+ UnitFileScope scope,
|
|
|
17b0f1 |
+ const char *root_dir,
|
|
|
17b0f1 |
+ const char *name) {
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ _cleanup_lookup_paths_free_ LookupPaths paths = {};
|
|
|
17b0f1 |
+ int r;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ assert(scope >= 0);
|
|
|
17b0f1 |
+ assert(scope < _UNIT_FILE_SCOPE_MAX);
|
|
|
17b0f1 |
+ assert(name);
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ if (root_dir && scope != UNIT_FILE_SYSTEM)
|
|
|
17b0f1 |
+ return -EINVAL;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ r = lookup_paths_init_from_scope(&paths, scope, root_dir);
|
|
|
17b0f1 |
+ if (r < 0)
|
|
|
17b0f1 |
+ return r;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ return unit_file_lookup_state(scope, root_dir, &paths, name);
|
|
|
17b0f1 |
+}
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
|
|
|
17b0f1 |
_cleanup_strv_free_ char **files = NULL;
|
|
|
17b0f1 |
char **p;
|
|
|
17b0f1 |
diff --git a/src/shared/install.h b/src/shared/install.h
|
|
|
17b0f1 |
index 357be0f92d..3ca39397e6 100644
|
|
|
17b0f1 |
--- a/src/shared/install.h
|
|
|
17b0f1 |
+++ b/src/shared/install.h
|
|
|
17b0f1 |
@@ -23,6 +23,7 @@
|
|
|
17b0f1 |
|
|
|
17b0f1 |
#include "hashmap.h"
|
|
|
17b0f1 |
#include "unit-name.h"
|
|
|
17b0f1 |
+#include "path-lookup.h"
|
|
|
17b0f1 |
|
|
|
17b0f1 |
typedef enum UnitFileScope {
|
|
|
17b0f1 |
UNIT_FILE_SYSTEM,
|
|
|
17b0f1 |
@@ -98,7 +99,15 @@ int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char
|
|
|
17b0f1 |
int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name);
|
|
|
17b0f1 |
int unit_file_add_dependency(UnitFileScope scope, bool runtime, const char *root_dir, char **files, char *target, UnitDependency dep, bool force, UnitFileChange **changes, unsigned *n_changes);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
-UnitFileState unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename);
|
|
|
17b0f1 |
+UnitFileState unit_file_lookup_state(
|
|
|
17b0f1 |
+ UnitFileScope scope,
|
|
|
17b0f1 |
+ const char *root_dir,
|
|
|
17b0f1 |
+ const LookupPaths *paths,
|
|
|
17b0f1 |
+ const char *name);
|
|
|
17b0f1 |
+UnitFileState unit_file_get_state(
|
|
|
17b0f1 |
+ UnitFileScope scope,
|
|
|
17b0f1 |
+ const char *root_dir,
|
|
|
17b0f1 |
+ const char *filename);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
|
|
|
17b0f1 |
index 291a2f4054..812730be1c 100644
|
|
|
17b0f1 |
--- a/src/shared/path-lookup.c
|
|
|
17b0f1 |
+++ b/src/shared/path-lookup.c
|
|
|
17b0f1 |
@@ -31,6 +31,7 @@
|
|
|
17b0f1 |
#include "strv.h"
|
|
|
17b0f1 |
#include "path-util.h"
|
|
|
17b0f1 |
#include "path-lookup.h"
|
|
|
17b0f1 |
+#include "install.h"
|
|
|
17b0f1 |
|
|
|
17b0f1 |
int user_config_home(char **config_home) {
|
|
|
17b0f1 |
const char *e;
|
|
|
17b0f1 |
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
|
|
|
17b0f1 |
index 2ec888da81..f1925eef69 100644
|
|
|
17b0f1 |
--- a/src/shared/path-lookup.h
|
|
|
17b0f1 |
+++ b/src/shared/path-lookup.h
|
|
|
17b0f1 |
@@ -22,7 +22,8 @@
|
|
|
17b0f1 |
***/
|
|
|
17b0f1 |
|
|
|
17b0f1 |
#include "macro.h"
|
|
|
17b0f1 |
-#include "install.h"
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+typedef enum UnitFileScope UnitFileScope;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
typedef struct LookupPaths {
|
|
|
17b0f1 |
char **unit_path;
|
|
|
17b0f1 |
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
|
|
|
17b0f1 |
index 6e39b449eb..0125ca27d9 100644
|
|
|
17b0f1 |
--- a/src/sysv-generator/sysv-generator.c
|
|
|
17b0f1 |
+++ b/src/sysv-generator/sysv-generator.c
|
|
|
17b0f1 |
@@ -723,10 +723,10 @@ static int fix_order(SysvStub *s, Hashmap *all_services) {
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
-static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
|
|
|
17b0f1 |
+static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
|
|
|
17b0f1 |
char **path;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- STRV_FOREACH(path, lp.sysvinit_path) {
|
|
|
17b0f1 |
+ STRV_FOREACH(path, lp->sysvinit_path) {
|
|
|
17b0f1 |
_cleanup_closedir_ DIR *d = NULL;
|
|
|
17b0f1 |
struct dirent *de;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -768,7 +768,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
|
|
|
17b0f1 |
if (!fpath)
|
|
|
17b0f1 |
return log_oom();
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- if (unit_file_get_state(UNIT_FILE_SYSTEM, NULL, name) >= 0) {
|
|
|
17b0f1 |
+ if (unit_file_lookup_state(UNIT_FILE_SYSTEM, NULL, lp, name) >= 0) {
|
|
|
17b0f1 |
log_debug("Native unit for %s already exists, skipping", name);
|
|
|
17b0f1 |
continue;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
@@ -793,7 +793,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
|
|
|
17b0f1 |
return 0;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
-static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
|
|
|
17b0f1 |
+static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_services) {
|
|
|
17b0f1 |
char **p;
|
|
|
17b0f1 |
unsigned i;
|
|
|
17b0f1 |
_cleanup_closedir_ DIR *d = NULL;
|
|
|
17b0f1 |
@@ -804,7 +804,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
|
|
|
17b0f1 |
_cleanup_set_free_ Set *shutdown_services = NULL;
|
|
|
17b0f1 |
int r = 0;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- STRV_FOREACH(p, lp.sysvrcnd_path)
|
|
|
17b0f1 |
+ STRV_FOREACH(p, lp->sysvrcnd_path)
|
|
|
17b0f1 |
for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
|
|
|
17b0f1 |
struct dirent *de;
|
|
|
17b0f1 |
|
|
|
17b0f1 |
@@ -954,13 +954,13 @@ int main(int argc, char *argv[]) {
|
|
|
17b0f1 |
return EXIT_FAILURE;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = enumerate_sysv(lp, all_services);
|
|
|
17b0f1 |
+ r = enumerate_sysv(&lp, all_services);
|
|
|
17b0f1 |
if (r < 0) {
|
|
|
17b0f1 |
log_error("Failed to generate units for all init scripts.");
|
|
|
17b0f1 |
return EXIT_FAILURE;
|
|
|
17b0f1 |
}
|
|
|
17b0f1 |
|
|
|
17b0f1 |
- r = set_dependencies_from_rcnd(lp, all_services);
|
|
|
17b0f1 |
+ r = set_dependencies_from_rcnd(&lp, all_services);
|
|
|
17b0f1 |
if (r < 0) {
|
|
|
17b0f1 |
log_error("Failed to read runlevels from rcnd links.");
|
|
|
17b0f1 |
return EXIT_FAILURE;
|