[systemd-commits] 5 commits - src/journal src/libsystemd-bus src/shared src/test units/systemd-readahead-done.service.in units/systemd-readahead-done.timer
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Dec 11 14:49:24 PST 2013
src/journal/journal-internal.h | 1
src/journal/journald-server.c | 11 ++++++--
src/journal/journald-server.h | 3 ++
src/journal/journald-stream.c | 4 ++-
src/journal/sd-journal.c | 28 ++++++++++++---------
src/libsystemd-bus/sd-event.c | 16 ++++++++++--
src/shared/cgroup-util.c | 42 ++++++++++++++++----------------
src/shared/cgroup-util.h | 2 -
src/test/test-cgroup-util.c | 7 ++---
units/systemd-readahead-done.service.in | 1
units/systemd-readahead-done.timer | 1
11 files changed, 72 insertions(+), 44 deletions(-)
New commits:
commit ba276c8153e510a6741dc8a9492f5bed2b375825
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 11 23:41:21 2013 +0100
sd-event: try to move each wakeup to the same spot within every 10s
In addition to the same spot within every 1min, every 1s, every 250s
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 9fceb7b..462dd41 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1379,8 +1379,9 @@ static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
We implement this by waking up everywhere at the same time
within any given minute if we can, synchronised via the
perturbation value determined from the boot ID. If we can't,
- then we try to find the same spot in every 1s and then 250ms
- step. Otherwise, we pick the last possible time to wake up.
+ then we try to find the same spot in every 10s, then 1s and
+ then 250ms step. Otherwise, we pick the last possible time
+ to wake up.
*/
c = (b / USEC_PER_MINUTE) * USEC_PER_MINUTE + e->perturb;
@@ -1394,6 +1395,17 @@ static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
if (c >= a)
return c;
+ c = (b / (USEC_PER_SEC*10)) * (USEC_PER_SEC*10) + (e->perturb % (USEC_PER_SEC*10));
+ if (c >= b) {
+ if (_unlikely_(c < USEC_PER_SEC*10))
+ return b;
+
+ c -= USEC_PER_SEC*10;
+ }
+
+ if (c >= a)
+ return c;
+
c = (b / USEC_PER_SEC) * USEC_PER_SEC + (e->perturb % USEC_PER_SEC);
if (c >= b) {
if (_unlikely_(c < USEC_PER_SEC))
commit 21c6dc33a6fc0e8617247fc12123bc667dcde92b
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 11 23:36:59 2013 +0100
journald: make sure the stdout/stderr stream fd is removed from epoll before we close it
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index b2291a2..8958c7f 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -334,8 +334,10 @@ void stdout_stream_free(StdoutStream *s) {
LIST_REMOVE(stdout_stream, s->server->stdout_streams, s);
}
- if (s->event_source)
+ if (s->event_source) {
+ sd_event_source_set_enabled(s->event_source, SD_EVENT_OFF);
s->event_source = sd_event_source_unref(s->event_source);
+ }
if (s->fd >= 0)
close_nointr_nofail(s->fd);
commit b3de50cb07bb49c4e24287002eca1e95c490f90d
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 11 23:31:34 2013 +0100
units: don't run readahead done timers in containers
We don't run the collector in the container either, hence we don't need
to stop it either.
diff --git a/units/systemd-readahead-done.service.in b/units/systemd-readahead-done.service.in
index c3b2ac5..e0d9579 100644
--- a/units/systemd-readahead-done.service.in
+++ b/units/systemd-readahead-done.service.in
@@ -12,6 +12,7 @@ DefaultDependencies=no
Conflicts=shutdown.target
After=default.target
Before=shutdown.target
+ConditionVirtualization=no
[Service]
Type=oneshot
diff --git a/units/systemd-readahead-done.timer b/units/systemd-readahead-done.timer
index bdfd465..c58e096 100644
--- a/units/systemd-readahead-done.timer
+++ b/units/systemd-readahead-done.timer
@@ -12,6 +12,7 @@ DefaultDependencies=no
Conflicts=shutdown.target
After=default.target
Before=shutdown.target
+ConditionVirtualization=no
[Timer]
OnActiveSec=30s
commit e9174f29c7e3ee45137537b126458718913a3ec5
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 11 23:31:07 2013 +0100
journald: cache cgroup root path, instead of querying it on every incoming log message
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index a4fa394..0f67fb8 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -622,7 +622,7 @@ static void dispatch_message_real(
}
#endif
- r = cg_pid_get_path_shifted(ucred->pid, NULL, &c);
+ r = cg_pid_get_path_shifted(ucred->pid, s->cgroup_root, &c);
if (r >= 0) {
char *session = NULL;
@@ -743,7 +743,7 @@ static void dispatch_message_real(
}
#endif
- r = cg_pid_get_path_shifted(object_pid, NULL, &c);
+ r = cg_pid_get_path_shifted(object_pid, s->cgroup_root, &c);
if (r >= 0) {
x = strappenda("OBJECT_SYSTEMD_CGROUP=", c);
IOVEC_SET_STRING(iovec[n++], x);
@@ -878,7 +878,7 @@ void server_dispatch_message(
if (!ucred)
goto finish;
- r = cg_pid_get_path_shifted(ucred->pid, NULL, &path);
+ r = cg_pid_get_path_shifted(ucred->pid, s->cgroup_root, &path);
if (r < 0)
goto finish;
@@ -1563,6 +1563,10 @@ int server_init(Server *s) {
if (!s->rate_limit)
return -ENOMEM;
+ r = cg_get_root_path(&s->cgroup_root);
+ if (r < 0)
+ return r;
+
server_cache_hostname(s);
server_cache_boot_id(s);
server_cache_machine_id(s);
@@ -1643,6 +1647,7 @@ void server_done(Server *s) {
free(s->buffer);
free(s->tty_path);
+ free(s->cgroup_root);
if (s->mmap)
mmap_cache_unref(s->mmap);
diff --git a/src/journal/journald-server.h b/src/journal/journald-server.h
index 86c4be4..2a81061 100644
--- a/src/journal/journald-server.h
+++ b/src/journal/journald-server.h
@@ -136,6 +136,9 @@ typedef struct Server {
char machine_id_field[sizeof("_MACHINE_ID=") + 32];
char boot_id_field[sizeof("_BOOT_ID=") + 32];
char *hostname_field;
+
+ /* Cached cgroup root, so that we don't have to query that all the time */
+ char *cgroup_root;
} Server;
#define N_IOVEC_META_FIELDS 20
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index dda9351..bb116df 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1616,8 +1616,8 @@ static int add_current_paths(sd_journal *j) {
* treat them as fatal. */
HASHMAP_FOREACH(f, j->files, i) {
- int r;
_cleanup_free_ char *dir;
+ int r;
dir = dirname_malloc(f->path);
if (!dir)
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 88bc33e..2c2ffc5 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -1082,42 +1082,42 @@ int cg_get_root_path(char **path) {
return 0;
}
-int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup) {
+int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
_cleanup_free_ char *cg_root = NULL;
char *cg_process, *p;
int r;
- r = cg_get_root_path(&cg_root);
- if (r < 0)
- return r;
+ assert(pid >= 0);
+ assert(cgroup);
+
+ if (!root) {
+ /* If the root was specified let's use that, otherwise
+ * let's determine it from PID 1 */
+
+ r = cg_get_root_path(&cg_root);
+ if (r < 0)
+ return r;
+
+ root = cg_root;
+ }
r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cg_process);
if (r < 0)
return r;
- p = path_startswith(cg_process, cg_root);
- if (p)
- p--;
- else
- p = cg_process;
+ p = path_startswith(cg_process, root);
+ if (p) {
+ char *c;
- if (cgroup) {
- char* c;
+ c = strdup(p - 1);
+ free(cg_process);
- c = strdup(p);
- if (!c) {
- free(cg_process);
+ if (!c)
return -ENOMEM;
- }
*cgroup = c;
- }
-
- if (root) {
- cg_process[p-cg_process] = 0;
- *root = cg_process;
} else
- free(cg_process);
+ *cgroup = cg_process;
return 0;
}
diff --git a/src/shared/cgroup-util.h b/src/shared/cgroup-util.h
index b644573..3e6a3f6 100644
--- a/src/shared/cgroup-util.h
+++ b/src/shared/cgroup-util.h
@@ -103,7 +103,7 @@ int cg_path_get_user_unit(const char *path, char **unit);
int cg_path_get_machine_name(const char *path, char **machine);
int cg_path_get_slice(const char *path, char **slice);
-int cg_pid_get_path_shifted(pid_t pid, char **root, char **cgroup);
+int cg_pid_get_path_shifted(pid_t pid, const char *cached_root, char **cgroup);
int cg_pid_get_session(pid_t pid, char **session);
int cg_pid_get_owner_uid(pid_t pid, uid_t *uid);
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index 4d802d4..eae6739 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -140,7 +140,7 @@ static void test_proc(void) {
assert_se(d);
FOREACH_DIRENT(de, d, break) {
- _cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *prefix = NULL, *slice = NULL;
+ _cleanup_free_ char *path = NULL, *path_shifted = NULL, *session = NULL, *unit = NULL, *user_unit = NULL, *machine = NULL, *slice = NULL;
pid_t pid;
uid_t uid = (uid_t) -1;
@@ -156,7 +156,7 @@ static void test_proc(void) {
continue;
cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &path);
- cg_pid_get_path_shifted(pid, &prefix, &path_shifted);
+ cg_pid_get_path_shifted(pid, NULL, &path_shifted);
cg_pid_get_owner_uid(pid, &uid);
cg_pid_get_session(pid, &session);
cg_pid_get_unit(pid, &unit);
@@ -164,10 +164,9 @@ static void test_proc(void) {
cg_pid_get_machine_name(pid, &machine);
cg_pid_get_slice(pid, &slice);
- printf("%lu\t%s\t%s\t%s\t%lu\t%s\t%s\t%s\t%s\t%s\n",
+ printf("%lu\t%s\t%s\t%lu\t%s\t%s\t%s\t%s\t%s\n",
(unsigned long) pid,
path,
- prefix,
path_shifted,
(unsigned long) uid,
session,
commit 897395791f53064d8c9a18cf6b6567404fbedf15
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Dec 11 23:10:36 2013 +0100
journal: when listing logs of a container make sure we don't accidentally show messages from host too
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index 3355fca..2c401e3 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -98,6 +98,7 @@ struct Directory {
struct sd_journal {
char *path;
+ char *prefix;
Hashmap *files;
MMapCache *mmap;
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index b55cf37..dda9351 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1466,7 +1466,7 @@ static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
return 0;
}
-static int add_root_directory(sd_journal *j, const char *p, const char *prefix) {
+static int add_root_directory(sd_journal *j, const char *p) {
_cleanup_closedir_ DIR *d = NULL;
Directory *m;
int r;
@@ -1478,8 +1478,8 @@ static int add_root_directory(sd_journal *j, const char *p, const char *prefix)
!path_startswith(p, "/run"))
return -EINVAL;
- if (prefix)
- p = strappenda(prefix, p);
+ if (j->prefix)
+ p = strappenda(j->prefix, p);
d = opendir(p);
if (!d)
@@ -1580,7 +1580,7 @@ static int remove_directory(sd_journal *j, Directory *d) {
return 0;
}
-static int add_search_paths(sd_journal *j, const char *prefix) {
+static int add_search_paths(sd_journal *j) {
int r;
const char search_paths[] =
"/run/log/journal\0"
@@ -1593,7 +1593,7 @@ static int add_search_paths(sd_journal *j, const char *prefix) {
* what's actually accessible, and ignore the rest. */
NULSTR_FOREACH(p, search_paths) {
- r = add_root_directory(j, p, prefix);
+ r = add_root_directory(j, p);
if (r < 0 && r != -ENOENT) {
r = set_put_error(j, r);
if (r < 0)
@@ -1623,7 +1623,7 @@ static int add_current_paths(sd_journal *j) {
if (!dir)
return -ENOMEM;
- r = add_root_directory(j, dir, NULL);
+ r = add_root_directory(j, dir);
if (r < 0) {
set_put_error(j, r);
return r;
@@ -1694,7 +1694,7 @@ _public_ int sd_journal_open(sd_journal **ret, int flags) {
if (!j)
return -ENOMEM;
- r = add_search_paths(j, NULL);
+ r = add_search_paths(j);
if (r < 0)
goto fail;
@@ -1734,7 +1734,10 @@ _public_ int sd_journal_open_container(sd_journal **ret, const char *machine, in
if (!j)
return -ENOMEM;
- r = add_search_paths(j, root);
+ j->prefix = root;
+ root = NULL;
+
+ r = add_search_paths(j);
if (r < 0)
goto fail;
@@ -1758,7 +1761,7 @@ _public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int f
if (!j)
return -ENOMEM;
- r = add_root_directory(j, path, NULL);
+ r = add_root_directory(j, path);
if (r < 0) {
set_put_error(j, r);
goto fail;
@@ -1836,6 +1839,7 @@ _public_ void sd_journal_close(sd_journal *j) {
}
free(j->path);
+ free(j->prefix);
free(j->unique_field);
set_free(j->errors);
free(j);
@@ -2121,9 +2125,9 @@ _public_ int sd_journal_get_fd(sd_journal *j) {
if (j->no_new_files)
r = add_current_paths(j);
else if (j->path)
- r = add_root_directory(j, j->path, NULL);
+ r = add_root_directory(j, j->path);
else
- r = add_search_paths(j, NULL);
+ r = add_search_paths(j);
if (r < 0)
return r;
More information about the systemd-commits
mailing list