[systemd-commits] 4 commits - src/journal
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Apr 8 06:49:27 PDT 2013
src/journal/journald-server.c | 53 ++++++++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 20 deletions(-)
New commits:
commit 7120511888321c40810a36c8da96c7d09e464f5b
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Apr 8 15:48:12 2013 +0200
journald: no need to free audit vars
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 6f283df..53e3830 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -543,10 +543,13 @@ static void dispatch_message_real(
machine_id[sizeof("_MACHINE_ID=") + 32] = "_MACHINE_ID=";
char _cleanup_free_ *comm = NULL, *cmdline = NULL, *hostname = NULL,
- *audit_session = NULL, *audit_loginuid = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
*owner_uid = NULL, *unit = NULL, *selinux_context = NULL;
+#ifdef HAVE_AUDIT
+ char _cleanup_free_ *audit_session = NULL, *audit_loginuid = NULL;
+#endif
+
sd_id128_t id;
int r;
char *t;
commit adb435bb70815461eeddf44dd5d6f1fc2ad9026d
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Apr 8 15:46:32 2013 +0200
journald: drop two more memory allocations
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 74482f1..6f283df 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -538,15 +538,15 @@ static void dispatch_message_real(
char pid[sizeof("_PID=") + DECIMAL_STR_MAX(ucred->pid)],
uid[sizeof("_UID=") + DECIMAL_STR_MAX(ucred->uid)],
gid[sizeof("_GID=") + DECIMAL_STR_MAX(ucred->gid)],
- source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=" + DECIMAL_STR_MAX(usec_t))];
+ source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=" + DECIMAL_STR_MAX(usec_t))],
+ boot_id[sizeof("_BOOT_ID=") + 32] = "_BOOT_ID=",
+ machine_id[sizeof("_MACHINE_ID=") + 32] = "_MACHINE_ID=";
- char _cleanup_free_ *boot_id = NULL, *machine_id = NULL,
- *comm = NULL, *cmdline = NULL, *hostname = NULL,
+ char _cleanup_free_ *comm = NULL, *cmdline = NULL, *hostname = NULL,
*audit_session = NULL, *audit_loginuid = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
*owner_uid = NULL, *unit = NULL, *selinux_context = NULL;
- char idbuf[33];
sd_id128_t id;
int r;
char *t;
@@ -689,14 +689,16 @@ static void dispatch_message_real(
* redundant since the entry includes this in-line
* anyway. However, we need this indexed, too. */
r = sd_id128_get_boot(&id);
- if (r >= 0)
- if (asprintf(&boot_id, "_BOOT_ID=%s", sd_id128_to_string(id, idbuf)) >= 0)
- IOVEC_SET_STRING(iovec[n++], boot_id);
+ if (r >= 0) {
+ sd_id128_to_string(id, boot_id + sizeof("_BOOT_ID=") - 1);
+ IOVEC_SET_STRING(iovec[n++], boot_id);
+ }
r = sd_id128_get_machine(&id);
- if (r >= 0)
- if (asprintf(&machine_id, "_MACHINE_ID=%s", sd_id128_to_string(id, idbuf)) >= 0)
- IOVEC_SET_STRING(iovec[n++], machine_id);
+ if (r >= 0) {
+ sd_id128_to_string(id, machine_id + sizeof("_MACHINE_ID") - 1);
+ IOVEC_SET_STRING(iovec[n++], machine_id);
+ }
t = gethostname_malloc();
if (t) {
commit a569398925430de1f8479262e8ab39502054f2e9
Author: Lennart Poettering <lennart at poettering.net>
Date: Mon Apr 8 15:38:27 2013 +0200
journald: get rid of one more memory allocation
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 2ae5624..74482f1 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -537,9 +537,10 @@ static void dispatch_message_real(
char pid[sizeof("_PID=") + DECIMAL_STR_MAX(ucred->pid)],
uid[sizeof("_UID=") + DECIMAL_STR_MAX(ucred->uid)],
- gid[sizeof("_GID=") + DECIMAL_STR_MAX(ucred->gid)];
+ gid[sizeof("_GID=") + DECIMAL_STR_MAX(ucred->gid)],
+ source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=" + DECIMAL_STR_MAX(usec_t))];
- char _cleanup_free_ *source_time = NULL, *boot_id = NULL, *machine_id = NULL,
+ char _cleanup_free_ *boot_id = NULL, *machine_id = NULL,
*comm = NULL, *cmdline = NULL, *hostname = NULL,
*audit_session = NULL, *audit_loginuid = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
@@ -678,9 +679,10 @@ static void dispatch_message_real(
}
if (tv) {
- if (asprintf(&source_time, "_SOURCE_REALTIME_TIMESTAMP=%llu",
- (unsigned long long) timeval_load(tv)) >= 0)
- IOVEC_SET_STRING(iovec[n++], source_time);
+ snprintf(source_time, sizeof(source_time) - 1, "_SOURCE_REALTIME_TIMESTAMP=%llu",
+ (unsigned long long) timeval_load(tv));
+ char_array_0(source_time);
+ IOVEC_SET_STRING(iovec[n++], source_time);
}
/* Note that strictly speaking storing the boot id here is
commit c2457105d76e3daf159f554a9bafb9751b23d756
Author: Holger Hans Peter Freyther <holger at freyther.de>
Date: Sat Apr 6 10:20:35 2013 +0200
journald: Do not dynamically allocate _UID/_GID/_PID strings
Avoid the dynamic allocation for the _UID, _GID, and _PID strings.
The maximum size of the string can be determined at compile time.
The code has only been compile tested.
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 28ce69d..2ae5624 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -535,8 +535,11 @@ static void dispatch_message_real(
const char *label, size_t label_len,
const char *unit_id) {
- char _cleanup_free_ *pid = NULL, *uid = NULL, *gid = NULL,
- *source_time = NULL, *boot_id = NULL, *machine_id = NULL,
+ char pid[sizeof("_PID=") + DECIMAL_STR_MAX(ucred->pid)],
+ uid[sizeof("_UID=") + DECIMAL_STR_MAX(ucred->uid)],
+ gid[sizeof("_GID=") + DECIMAL_STR_MAX(ucred->gid)];
+
+ char _cleanup_free_ *source_time = NULL, *boot_id = NULL, *machine_id = NULL,
*comm = NULL, *cmdline = NULL, *hostname = NULL,
*audit_session = NULL, *audit_loginuid = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
@@ -562,14 +565,17 @@ static void dispatch_message_real(
realuid = ucred->uid;
- if (asprintf(&pid, "_PID=%lu", (unsigned long) ucred->pid) >= 0)
- IOVEC_SET_STRING(iovec[n++], pid);
+ snprintf(pid, sizeof(pid) - 1, "_PID=%lu", (unsigned long) ucred->pid);
+ char_array_0(pid);
+ IOVEC_SET_STRING(iovec[n++], pid);
- if (asprintf(&uid, "_UID=%lu", (unsigned long) ucred->uid) >= 0)
- IOVEC_SET_STRING(iovec[n++], uid);
+ snprintf(uid, sizeof(uid) - 1, "_UID=%lu", (unsigned long) ucred->uid);
+ char_array_0(uid);
+ IOVEC_SET_STRING(iovec[n++], uid);
- if (asprintf(&gid, "_GID=%lu", (unsigned long) ucred->gid) >= 0)
- IOVEC_SET_STRING(iovec[n++], gid);
+ snprintf(gid, sizeof(gid) - 1, "_GID=%lu", (unsigned long) ucred->gid);
+ char_array_0(gid);
+ IOVEC_SET_STRING(iovec[n++], gid);
r = get_process_comm(ucred->pid, &t);
if (r >= 0) {
More information about the systemd-commits
mailing list