s->cached_available_space_timestamp = 0;
}
-static char *shortened_cgroup_path(pid_t pid) {
- int r;
- char _cleanup_free_ *process_path = NULL, *init_path = NULL;
- char *path;
-
- assert(pid > 0);
-
- r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &process_path);
- if (r < 0)
- return NULL;
-
- r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &init_path);
- if (r < 0)
- return NULL;
-
- if (endswith(init_path, "/system"))
- init_path[strlen(init_path) - 7] = 0;
- else if (streq(init_path, "/"))
- init_path[0] = 0;
-
- if (startswith(process_path, init_path)) {
- path = strdup(process_path + strlen(init_path));
- } else {
- path = process_path;
- process_path = NULL;
- }
-
- return path;
-}
-
bool shall_try_append_again(JournalFile *f, int r) {
/* -E2BIG Hit configured limit
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)],
+ boot_id[sizeof("_BOOT_ID=") + 32] = "_BOOT_ID=",
+ machine_id[sizeof("_MACHINE_ID=") + 32] = "_MACHINE_ID=";
- char _cleanup_free_ *source_time = NULL, *boot_id = NULL, *machine_id = NULL,
- *comm = NULL, *cmdline = NULL, *hostname = NULL,
- *audit_session = NULL, *audit_loginuid = NULL,
+ char _cleanup_free_ *comm = NULL, *cmdline = NULL, *hostname = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
*owner_uid = NULL, *unit = NULL, *selinux_context = NULL;
- char idbuf[33];
+#ifdef HAVE_AUDIT
+ char _cleanup_free_ *audit_session = NULL, *audit_loginuid = NULL;
+#endif
+
sd_id128_t id;
int r;
char *t;
IOVEC_SET_STRING(iovec[n++], audit_loginuid);
#endif
- t = shortened_cgroup_path(ucred->pid);
- if (t) {
+ r = cg_pid_get_path(NULL, ucred->pid, &t);
+ if (r >= 0) {
cgroup = strappend("_SYSTEMD_CGROUP=", t);
free(t);
}
#ifdef HAVE_LOGIND
- if (sd_pid_get_session(ucred->pid, &t) >= 0) {
+ r = cg_pid_get_session(ucred->pid, &t);
+ if (r >= 0) {
session = strappend("_SYSTEMD_SESSION=", t);
free(t);
}
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
* 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) {
const char *unit_id,
int priority) {
- int rl;
+ int rl, r;
char _cleanup_free_ *path = NULL;
char *c;
if (!ucred)
goto finish;
- path = shortened_cgroup_path(ucred->pid);
- if (!path)
+ r = cg_pid_get_path_shifted(ucred->pid, NULL, &path);
+ if (r < 0)
goto finish;
/* example: /user/lennart/3/foobar
return -errno;
}
- r = config_parse(fn, f, "Journal\0", config_item_perf_lookup,
+ r = config_parse(NULL, fn, f, "Journal\0", config_item_perf_lookup,
(void*) journald_gperf_lookup, false, s);
if (r < 0)
log_warning("Failed to parse configuration file: %s", strerror(-r));