summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/journal/journal-file.c5
-rw-r--r--src/journal/journalctl.c25
-rw-r--r--src/journal/libsystemd-journal.sym5
-rw-r--r--src/journal/sd-journal.c23
-rw-r--r--src/systemd/sd-journal.h2
5 files changed, 58 insertions, 2 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 697e7f3606..06de2acc50 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1906,6 +1906,8 @@ fail:
void journal_file_print_header(JournalFile *f) {
char a[33], b[33], c[33];
char x[FORMAT_TIMESTAMP_MAX], y[FORMAT_TIMESTAMP_MAX];
+ struct stat st;
+ char bytes[FORMAT_BYTES_MAX];
assert(f);
@@ -1970,6 +1972,9 @@ void journal_file_print_header(JournalFile *f) {
if (JOURNAL_HEADER_CONTAINS(f->header, n_entry_arrays))
printf("Entry Array Objects: %llu\n",
(unsigned long long) le64toh(f->header->n_entry_arrays));
+
+ if (fstat(f->fd, &st) >= 0)
+ printf("Disk usage: %s\n", format_bytes(bytes, sizeof(bytes), (off_t) st.st_blocks * 512ULL));
}
int journal_file_open(
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 1a6464d5e7..e2600542fc 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -72,7 +72,8 @@ static enum {
ACTION_NEW_ID128,
ACTION_PRINT_HEADER,
ACTION_SETUP_KEYS,
- ACTION_VERIFY
+ ACTION_VERIFY,
+ ACTION_DISK_USAGE,
} arg_action = ACTION_SHOW;
static int help(void) {
@@ -96,6 +97,7 @@ static int help(void) {
"Commands:\n"
" --new-id128 Generate a new 128 Bit ID\n"
" --header Show journal header information\n"
+ " --disk-usage Show total disk usage\n"
#ifdef HAVE_GCRYPT
" --setup-keys Generate new FSS key pair\n"
" --interval=TIME Time interval for changing the FSS sealing key\n"
@@ -118,7 +120,8 @@ static int parse_argv(int argc, char *argv[]) {
ARG_SETUP_KEYS,
ARG_INTERVAL,
ARG_VERIFY,
- ARG_VERIFY_KEY
+ ARG_VERIFY_KEY,
+ ARG_DISK_USAGE
};
static const struct option options[] = {
@@ -141,6 +144,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "interval", required_argument, NULL, ARG_INTERVAL },
{ "verify", no_argument, NULL, ARG_VERIFY },
{ "verify-key", required_argument, NULL, ARG_VERIFY_KEY },
+ { "disk-usage", no_argument, NULL, ARG_DISK_USAGE },
{ NULL, 0, NULL, 0 }
};
@@ -224,6 +228,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_action = ACTION_VERIFY;
break;
+ case ARG_DISK_USAGE:
+ arg_action = ACTION_DISK_USAGE;
+ break;
+
#ifdef HAVE_GCRYPT
case ARG_SETUP_KEYS:
arg_action = ACTION_SETUP_KEYS;
@@ -746,6 +754,19 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ if (arg_action == ACTION_DISK_USAGE) {
+ uint64_t bytes;
+ char sbytes[FORMAT_BYTES_MAX];
+
+ r = sd_journal_get_usage(j, &bytes);
+ if (r < 0)
+ goto finish;
+
+ printf("Journals take up %s on disk.\n", format_bytes(sbytes, sizeof(sbytes), bytes));
+ r = 0;
+ goto finish;
+ }
+
#ifdef HAVE_ACL
if (access("/var/log/journal", F_OK) < 0 && geteuid() != 0 && in_group("adm") <= 0) {
log_error("Unprivileged users can't see messages unless persistent log storage is enabled. Users in the group 'adm' can always see messages.");
diff --git a/src/journal/libsystemd-journal.sym b/src/journal/libsystemd-journal.sym
index 27fdcdda0e..7dfae2625f 100644
--- a/src/journal/libsystemd-journal.sym
+++ b/src/journal/libsystemd-journal.sym
@@ -70,3 +70,8 @@ global:
sd_journal_perror;
sd_journal_perror_with_location;
} LIBSYSTEMD_JOURNAL_187;
+
+LIBSYSTEMD_JOURNAL_190 {
+global:
+ sd_journal_get_usage;
+} LIBSYSTEMD_JOURNAL_188;
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 0f7c02ce69..b4d35eebaf 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -2062,6 +2062,29 @@ void journal_print_header(sd_journal *j) {
}
}
+_public_ int sd_journal_get_usage(sd_journal *j, uint64_t *bytes) {
+ Iterator i;
+ JournalFile *f;
+ uint64_t sum = 0;
+
+ if (!j)
+ return -EINVAL;
+ if (!bytes)
+ return -EINVAL;
+
+ HASHMAP_FOREACH(f, j->files, i) {
+ struct stat st;
+
+ if (fstat(f->fd, &st) < 0)
+ return -errno;
+
+ sum += (uint64_t) st.st_blocks * 512ULL;
+ }
+
+ *bytes = sum;
+ return 0;
+}
+
/* _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { */
/* if (!j) */
/* return -EINVAL; */
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index de1c8f38f2..6c18c89425 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -108,6 +108,8 @@ int sd_journal_get_cursor(sd_journal *j, char **cursor);
int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, uint64_t *to);
int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, const sd_id128_t boot_id, uint64_t *from, uint64_t *to);
+int sd_journal_get_usage(sd_journal *j, uint64_t *bytes);
+
/* int sd_journal_query_unique(sd_journal *j, const char *field); /\* missing *\/ */
/* int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_t *l); /\* missing *\/ */
/* void sd_journal_restart_unique(sd_journal *j); /\* missing *\/ */