summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-09 22:13:04 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-09 22:32:08 -0400
commit57535f4703b5de5d03ad6e35bd06247d378f46fe (patch)
tree16ae05868cc3b400fe4f04faabe79060279e0e64 /src/journal
parent6c7980093c4e39d07bf06484f96f489e236c7c29 (diff)
journald: replace new+snprintf with asprintf
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journal-file.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 81c344fe5a..78b937bb85 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2551,7 +2551,7 @@ fail:
}
int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
- char *p;
+ _cleanup_free_ char *p = NULL;
size_t l;
JournalFile *old_file, *new_file = NULL;
int r;
@@ -2568,22 +2568,15 @@ int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
return -EINVAL;
l = strlen(old_file->path);
-
- p = new(char, l + 1 + 32 + 1 + 16 + 1 + 16 + 1);
- if (!p)
+ r = asprintf(&p, "%.*s@" SD_ID128_FORMAT_STR "-%016"PRIx64"-%016"PRIx64".journal",
+ (int) l - 8, old_file->path,
+ SD_ID128_FORMAT_VAL(old_file->header->seqnum_id),
+ le64toh((*f)->header->head_entry_seqnum),
+ le64toh((*f)->header->head_entry_realtime));
+ if (r < 0)
return -ENOMEM;
- memcpy(p, old_file->path, l - 8);
- p[l-8] = '@';
- sd_id128_to_string(old_file->header->seqnum_id, p + l - 8 + 1);
- snprintf(p + l - 8 + 1 + 32, 1 + 16 + 1 + 16 + 8 + 1,
- "-%016"PRIx64"-%016"PRIx64".journal",
- le64toh((*f)->header->head_entry_seqnum),
- le64toh((*f)->header->head_entry_realtime));
-
r = rename(old_file->path, p);
- free(p);
-
if (r < 0)
return -errno;
@@ -2634,7 +2627,7 @@ int journal_file_open_reliably(
l = strlen(fname);
if (asprintf(&p, "%.*s@%016llx-%016llx.journal~",
- (int) (l-8), fname,
+ (int) l - 8, fname,
(unsigned long long) now(CLOCK_REALTIME),
random_ull()) < 0)
return -ENOMEM;