summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/cgroup-util.c137
-rw-r--r--src/shared/cgroup-util.h7
-rw-r--r--src/shared/conf-parser.c31
-rw-r--r--src/shared/conf-parser.h1
-rw-r--r--src/shared/util.c21
5 files changed, 10 insertions, 187 deletions
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 8a4eddab7a..4e0211a7a0 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -279,37 +279,6 @@ int cg_kill_recursive(const char *controller, const char *path, int sig, bool si
return ret;
}
-int cg_kill_recursive_and_wait(const char *controller, const char *path, bool rem) {
- unsigned i;
-
- assert(path);
-
- /* This safely kills all processes; first it sends a SIGTERM,
- * then checks 8 times after 200ms whether the group is now
- * empty, then kills everything that is left with SIGKILL and
- * finally checks 5 times after 200ms each whether the group
- * is finally empty. */
-
- for (i = 0; i < 15; i++) {
- int sig, r;
-
- if (i <= 0)
- sig = SIGTERM;
- else if (i == 9)
- sig = SIGKILL;
- else
- sig = 0;
-
- r = cg_kill_recursive(controller, path, sig, true, true, rem, NULL);
- if (r <= 0)
- return r;
-
- usleep(200 * USEC_PER_MSEC);
- }
-
- return 0;
-}
-
int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self) {
bool done = false;
_cleanup_set_free_ Set *s = NULL;
@@ -941,19 +910,6 @@ int cg_is_empty(const char *controller, const char *path, bool ignore_self) {
return !found;
}
-int cg_is_empty_by_spec(const char *spec, bool ignore_self) {
- _cleanup_free_ char *controller = NULL, *path = NULL;
- int r;
-
- assert(spec);
-
- r = cg_split_spec(spec, &controller, &path);
- if (r < 0)
- return r;
-
- return cg_is_empty(controller, path, ignore_self);
-}
-
int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self) {
_cleanup_closedir_ DIR *d = NULL;
char *fn;
@@ -1080,33 +1036,6 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
return 0;
}
-int cg_join_spec(const char *controller, const char *path, char **spec) {
- char *s;
-
- assert(path);
-
- if (!controller)
- controller = "systemd";
- else {
- if (!cg_controller_is_valid(controller, true))
- return -EINVAL;
-
- controller = normalize_controller(controller);
- }
-
- if (!path_is_absolute(path))
- return -EINVAL;
-
- s = strjoin(controller, ":", path, NULL);
- if (!s)
- return -ENOMEM;
-
- path_kill_slashes(s + strlen(controller) + 1);
-
- *spec = s;
- return 0;
-}
-
int cg_mangle_path(const char *path, char **result) {
_cleanup_free_ char *c = NULL, *p = NULL;
char *t;
@@ -1153,43 +1082,6 @@ int cg_get_root_path(char **path) {
return 0;
}
-char **cg_shorten_controllers(char **controllers) {
- char **f, **t;
-
- if (!controllers)
- return controllers;
-
- for (f = controllers, t = controllers; *f; f++) {
- const char *p;
- int r;
-
- p = normalize_controller(*f);
-
- if (streq(p, "systemd")) {
- free(*f);
- continue;
- }
-
- if (!cg_controller_is_valid(p, true)) {
- log_warning("Controller %s is not valid, removing from controllers list.", p);
- free(*f);
- continue;
- }
-
- r = check_hierarchy(p);
- if (r < 0) {
- log_debug("Controller %s is not available, removing from controllers list.", p);
- free(*f);
- continue;
- }
-
- *(t++) = *f;
- }
-
- *t = NULL;
- return strv_uniq(controllers);
-}
-
int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) {
_cleanup_free_ char *cg_root = NULL;
char *cg_process, *p;
@@ -1529,35 +1421,6 @@ int cg_pid_get_slice(pid_t pid, char **slice) {
return cg_path_get_slice(cgroup, slice);
}
-int cg_controller_from_attr(const char *attr, char **controller) {
- const char *dot;
- char *c;
-
- assert(attr);
- assert(controller);
-
- if (!filename_is_safe(attr))
- return -EINVAL;
-
- dot = strchr(attr, '.');
- if (!dot) {
- *controller = NULL;
- return 0;
- }
-
- c = strndup(attr, dot - attr);
- if (!c)
- return -ENOMEM;
-
- if (!cg_controller_is_valid(c, false)) {
- free(c);
- return -EINVAL;
- }
-
- *controller = c;
- return 1;
-}
-
char *cg_escape(const char *p) {
bool need_prefix = false;
diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h
index 0963450b08..b64457300a 100644
--- a/src/shared/cgroup-util.h
+++ b/src/shared/cgroup-util.h
@@ -60,14 +60,12 @@ int cg_read_subgroup(DIR *d, char **fn);
int cg_kill(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, Set *s);
int cg_kill_recursive(const char *controller, const char *path, int sig, bool sigcont, bool ignore_self, bool remove, Set *s);
-int cg_kill_recursive_and_wait(const char *controller, const char *path, bool remove);
int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self);
int cg_migrate_recursive(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self, bool remove);
int cg_migrate_recursive_fallback(const char *cfrom, const char *pfrom, const char *cto, const char *pto, bool ignore_self, bool rem);
int cg_split_spec(const char *spec, char **controller, char **path);
-int cg_join_spec(const char *controller, const char *path, char **spec);
int cg_mangle_path(const char *path, char **result);
int cg_get_path(const char *controller, const char *path, const char *suffix, char **fs);
@@ -94,7 +92,6 @@ int cg_install_release_agent(const char *controller, const char *agent);
int cg_uninstall_release_agent(const char *controller);
int cg_is_empty(const char *controller, const char *path, bool ignore_self);
-int cg_is_empty_by_spec(const char *spec, bool ignore_self);
int cg_is_empty_recursive(const char *controller, const char *path, bool ignore_self);
int cg_get_root_path(char **path);
@@ -117,10 +114,6 @@ int cg_pid_get_slice(pid_t pid, char **slice);
int cg_path_decode_unit(const char *cgroup, char **unit);
-char **cg_shorten_controllers(char **controllers);
-
-int cg_controller_from_attr(const char *attr, char **controller);
-
char *cg_escape(const char *p);
char *cg_unescape(const char *p) _pure_;
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 16c3c71eae..efd2147e79 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -517,37 +517,6 @@ int config_parse_bool(const char* unit,
return 0;
}
-int config_parse_tristate(const char *unit,
- const char *filename,
- unsigned line,
- const char *section,
- const char *lvalue,
- int ltype,
- const char *rvalue,
- void *data,
- void *userdata) {
-
- int k;
- int *b = data;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(data);
-
- /* Tristates are like booleans, but can also take the 'default' value, i.e. "-1" */
-
- k = parse_boolean(rvalue);
- if (k < 0) {
- log_syntax(unit, LOG_ERR, filename, line, -k,
- "Failed to parse boolean value, ignoring: %s", rvalue);
- return 0;
- }
-
- *b = !!k;
- return 0;
-}
-
int config_parse_string(const char *unit,
const char *filename,
unsigned line,
diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h
index f988e1c443..312315b35e 100644
--- a/src/shared/conf-parser.h
+++ b/src/shared/conf-parser.h
@@ -99,7 +99,6 @@ int config_parse_double(const char *unit, const char *filename, unsigned line, c
int config_parse_bytes_size(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_bytes_off(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_bool(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
-int config_parse_tristate(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_path(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_strv(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
diff --git a/src/shared/util.c b/src/shared/util.c
index 7d41a7ae8d..a6669c5a97 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2924,11 +2924,13 @@ int fchmod_and_fchown(int fd, mode_t mode, uid_t uid, gid_t gid) {
* first change the access mode and only then hand out
* ownership to avoid a window where access is too open. */
- if (fchmod(fd, mode) < 0)
- return -errno;
+ if (mode != (mode_t) -1)
+ if (fchmod(fd, mode) < 0)
+ return -errno;
- if (fchown(fd, uid, gid) < 0)
- return -errno;
+ if (uid != (uid_t) -1 || gid != (gid_t) -1)
+ if (fchown(fd, uid, gid) < 0)
+ return -errno;
return 0;
}
@@ -3040,13 +3042,14 @@ int status_printf(const char *status, bool ellipse, bool ephemeral, const char *
}
int status_welcome(void) {
- int r;
_cleanup_free_ char *pretty_name = NULL, *ansi_color = NULL;
+ int r;
r = parse_env_file("/etc/os-release", NEWLINE,
"PRETTY_NAME", &pretty_name,
"ANSI_COLOR", &ansi_color,
NULL);
+
if (r < 0 && r != -ENOENT)
log_warning("Failed to read /etc/os-release: %s", strerror(-r));
@@ -3700,8 +3703,7 @@ char *resolve_dev_console(char **active) {
}
bool tty_is_vc_resolve(const char *tty) {
- char *active = NULL;
- bool b;
+ _cleanup_free_ char *active = NULL;
assert(tty);
@@ -3714,10 +3716,7 @@ bool tty_is_vc_resolve(const char *tty) {
return false;
}
- b = tty_is_vc(tty);
- free(active);
-
- return b;
+ return tty_is_vc(tty);
}
const char *default_term_for_tty(const char *tty) {