chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
service: ifdef (more) distro-specific compat logic
[elogind.git]
/
src
/
cgroup-util.c
diff --git
a/src/cgroup-util.c
b/src/cgroup-util.c
index 6abb6b549a04706336a3baa1613bce4b840c9714..4cf184ae1b34bfb6e21459e78e87417f86bd5286 100644
(file)
--- a/
src/cgroup-util.c
+++ b/
src/cgroup-util.c
@@
-166,12
+166,12
@@
int cg_rmdir(const char *controller, const char *path) {
return r < 0 ? -errno : 0;
}
return r < 0 ? -errno : 0;
}
-int cg_kill(const char *controller, const char *path, int sig, bool ignore_self) {
+int cg_kill(const char *controller, const char *path, int sig, bool ignore_self
, Set *s
) {
bool done = false;
bool done = false;
- Set *s;
int r, ret = 0;
pid_t my_pid;
FILE *f = NULL;
int r, ret = 0;
pid_t my_pid;
FILE *f = NULL;
+ Set *allocated_set = NULL;
assert(controller);
assert(path);
assert(controller);
assert(path);
@@
-181,8
+181,9
@@
int cg_kill(const char *controller, const char *path, int sig, bool ignore_self)
* is repeated until no further processes are added to the
* tasks list, to properly handle forking processes */
* is repeated until no further processes are added to the
* tasks list, to properly handle forking processes */
- if (!(s = set_new(trivial_hash_func, trivial_compare_func)))
- return -ENOMEM;
+ if (!s)
+ if (!(s = allocated_set = set_new(trivial_hash_func, trivial_compare_func)))
+ return -ENOMEM;
my_pid = getpid();
my_pid = getpid();
@@
-240,7
+241,8
@@
int cg_kill(const char *controller, const char *path, int sig, bool ignore_self)
} while (!done);
finish:
} while (!done);
finish:
- set_free(s);
+ if (allocated_set)
+ set_free(allocated_set);
if (f)
fclose(f);
if (f)
fclose(f);
@@
-248,16
+250,21
@@
finish:
return ret;
}
return ret;
}
-int cg_kill_recursive(const char *controller, const char *path, int sig, bool ignore_self, bool rem) {
+int cg_kill_recursive(const char *controller, const char *path, int sig, bool ignore_self, bool rem
, Set *s
) {
int r, ret = 0;
DIR *d = NULL;
char *fn;
int r, ret = 0;
DIR *d = NULL;
char *fn;
+ Set *allocated_set = NULL;
assert(path);
assert(controller);
assert(sig >= 0);
assert(path);
assert(controller);
assert(sig >= 0);
- ret = cg_kill(controller, path, sig, ignore_self);
+ if (!s)
+ if (!(s = allocated_set = set_new(trivial_hash_func, trivial_compare_func)))
+ return -ENOMEM;
+
+ ret = cg_kill(controller, path, sig, ignore_self, s);
if ((r = cg_enumerate_subgroups(controller, path, &d)) < 0) {
if (ret >= 0 && r != -ENOENT)
if ((r = cg_enumerate_subgroups(controller, path, &d)) < 0) {
if (ret >= 0 && r != -ENOENT)
@@
-279,7
+286,7
@@
int cg_kill_recursive(const char *controller, const char *path, int sig, bool ig
goto finish;
}
goto finish;
}
- r = cg_kill_recursive(controller, p, sig, ignore_self, rem);
+ r = cg_kill_recursive(controller, p, sig, ignore_self, rem
, s
);
free(p);
if (r != 0 && ret >= 0)
free(p);
if (r != 0 && ret >= 0)
@@
-291,7
+298,9
@@
int cg_kill_recursive(const char *controller, const char *path, int sig, bool ig
if (rem)
if ((r = cg_rmdir(controller, path)) < 0) {
if (rem)
if ((r = cg_rmdir(controller, path)) < 0) {
- if (ret >= 0 && r != -ENOENT)
+ if (ret >= 0 &&
+ r != -ENOENT &&
+ r != -EBUSY)
ret = r;
}
ret = r;
}
@@
-299,6
+308,9
@@
finish:
if (d)
closedir(d);
if (d)
closedir(d);
+ if (allocated_set)
+ set_free(allocated_set);
+
return ret;
}
return ret;
}
@@
-309,24
+321,25
@@
int cg_kill_recursive_and_wait(const char *controller, const char *path, bool re
assert(controller);
/* This safely kills all processes; first it sends a SIGTERM,
assert(controller);
/* This safely kills all processes; first it sends a SIGTERM,
- * then checks 8 times after 50ms whether the group is
- * now empty, and finally kills everything that is left with
- * SIGKILL */
+ * 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 < 1
0
; i++) {
+ for (i = 0; i < 1
5
; i++) {
int sig, r;
if (i <= 0)
sig = SIGTERM;
int sig, r;
if (i <= 0)
sig = SIGTERM;
- else if (i
>
= 9)
+ else if (i
=
= 9)
sig = SIGKILL;
else
sig = 0;
sig = SIGKILL;
else
sig = 0;
- if ((r = cg_kill_recursive(controller, path, sig, true, rem)) <= 0)
+ if ((r = cg_kill_recursive(controller, path, sig, true, rem
, NULL
)) <= 0)
return r;
return r;
- usleep(
5
0 * USEC_PER_MSEC);
+ usleep(
20
0 * USEC_PER_MSEC);
}
return 0;
}
return 0;
@@
-449,7
+462,9
@@
int cg_migrate_recursive(const char *controller, const char *from, const char *t
if (rem)
if ((r = cg_rmdir(controller, from)) < 0) {
if (rem)
if ((r = cg_rmdir(controller, from)) < 0) {
- if (ret >= 0 && r != -ENOENT)
+ if (ret >= 0 &&
+ r != -ENOENT &&
+ r != -EBUSY)
ret = r;
}
ret = r;
}