[systemd-commits] src/log.c src/log.h src/manager.c
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Jun 4 10:46:00 PDT 2010
src/log.c | 21 +++++++++++++++++++++
src/log.h | 11 +++++++++++
src/manager.c | 28 +++++++++++++++++++++++++---
3 files changed, 57 insertions(+), 3 deletions(-)
New commits:
commit 2149e37c7954fd98acd54269df5f5eca78eb9d5b
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Jun 4 19:45:53 2010 +0200
manager: dump to usual debug channel on SIGUSR2, don't rely on stdin
diff --git a/src/log.c b/src/log.c
index 04ffb62..bf2382d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -357,6 +357,27 @@ static int log_dispatch(
return r;
}
+int log_dump_internal(
+ int level,
+ const char*file,
+ int line,
+ const char *func,
+ char *buffer) {
+
+ int saved_errno, r;
+
+ /* This modifies the buffer... */
+
+ if (_likely_(LOG_PRI(level) > log_max_level))
+ return 0;
+
+ saved_errno = errno;
+ r = log_dispatch(level, file, line, func, buffer);
+ errno = saved_errno;
+
+ return r;
+}
+
int log_meta(
int level,
const char*file,
diff --git a/src/log.h b/src/log.h
index 0370cb9..9d141dc 100644
--- a/src/log.h
+++ b/src/log.h
@@ -67,12 +67,23 @@ _noreturn_ void log_assert(
const char *func,
const char *format, ...) _printf_attr_(4,5);
+/* This modifies the buffer passed! */
+int log_dump_internal(
+ int level,
+ const char*file,
+ int line,
+ const char *func,
+ char *buffer);
+
#define log_debug(...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define log_info(...) log_meta(LOG_INFO, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define log_notice(...) log_meta(LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define log_warning(...) log_meta(LOG_WARNING, __FILE__, __LINE__, __func__, __VA_ARGS__)
#define log_error(...) log_meta(LOG_ERR, __FILE__, __LINE__, __func__, __VA_ARGS__)
+/* This modifies the buffer passed! */
+#define log_dump(level, buffer) log_dump_internal(level, __FILE__, __LINE__, __func__, buffer)
+
const char *log_target_to_string(LogTarget target);
LogTarget log_target_from_string(const char *s);
diff --git a/src/manager.c b/src/manager.c
index 28bc4c3..735a1aa 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -1891,10 +1891,32 @@ static int manager_process_signal_fd(Manager *m) {
break;
}
- case SIGUSR2:
- manager_dump_units(m, stdout, "\t");
- manager_dump_jobs(m, stdout, "\t");
+ case SIGUSR2: {
+ FILE *f;
+ char *dump = NULL;
+ size_t size;
+
+ if (!(f = open_memstream(&dump, &size))) {
+ log_warning("Failed to allocate memory stream.");
+ break;
+ }
+
+ manager_dump_units(m, f, "\t");
+ manager_dump_jobs(m, f, "\t");
+
+ if (ferror(f)) {
+ fclose(f);
+ free(dump);
+ log_warning("Failed to write status stream");
+ break;
+ }
+
+ fclose(f);
+ log_dump(LOG_INFO, dump);
+ free(dump);
+
break;
+ }
case SIGHUP:
m->exit_code = MANAGER_RELOAD;
More information about the systemd-commits
mailing list