diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-07-30 11:51:52 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-07-30 11:51:52 -0400 |
commit | 2bd52fb107528d459dabd5929794987c01a7270e (patch) | |
tree | e01842ceb4617c06dee673c2a09dd4707ae33ab8 /src/grp-journal/journalctl | |
parent | 1ed649627c5dbf9254f325c8254bfa69c31466c9 (diff) |
stuff
Diffstat (limited to 'src/grp-journal/journalctl')
-rw-r--r-- | src/grp-journal/journalctl/Makefile | 5 | ||||
-rw-r--r-- | src/grp-journal/journalctl/journal-qrcode.c | 135 | ||||
-rw-r--r-- | src/grp-journal/journalctl/journal-qrcode.h | 27 | ||||
-rw-r--r-- | src/grp-journal/journalctl/journalctl.c | 29 |
4 files changed, 182 insertions, 14 deletions
diff --git a/src/grp-journal/journalctl/Makefile b/src/grp-journal/journalctl/Makefile index c3cdb6b27a..7fc5e64143 100644 --- a/src/grp-journal/journalctl/Makefile +++ b/src/grp-journal/journalctl/Makefile @@ -23,6 +23,9 @@ include $(dir $(lastword $(MAKEFILE_LIST)))/../../../config.mk include $(topsrcdir)/build-aux/Makefile.head.mk +rootbin_PROGRAMS += \ + journalctl + # using _CFLAGS = in the conditional below would suppress AM_CFLAGS journalctl_CFLAGS = \ $(AM_CFLAGS) @@ -46,4 +49,6 @@ journalctl_LDADD += \ $(QRENCODE_LIBS) endif # HAVE_QRENCODE +systemd.CPPFLAGS += -DCATALOG_DATABASE=\"$(catalogstatedir)/database\" + include $(topsrcdir)/build-aux/Makefile.tail.mk diff --git a/src/grp-journal/journalctl/journal-qrcode.c b/src/grp-journal/journalctl/journal-qrcode.c new file mode 100644 index 0000000000..e38730d65c --- /dev/null +++ b/src/grp-journal/journalctl/journal-qrcode.c @@ -0,0 +1,135 @@ +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <assert.h> +#include <errno.h> +#include <qrencode.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> + +#include "journal-qrcode.h" + +#define WHITE_ON_BLACK "\033[40;37;1m" +#define NORMAL "\033[0m" + +static void print_border(FILE *output, unsigned width) { + unsigned x, y; + + /* Four rows of border */ + for (y = 0; y < 4; y += 2) { + fputs(WHITE_ON_BLACK, output); + + for (x = 0; x < 4 + width + 4; x++) + fputs("\342\226\210", output); + + fputs(NORMAL "\n", output); + } +} + +int print_qr_code( + FILE *output, + const void *seed, + size_t seed_size, + uint64_t start, + uint64_t interval, + const char *hn, + sd_id128_t machine) { + + FILE *f; + char *url = NULL; + size_t url_size = 0, i; + QRcode* qr; + unsigned x, y; + + assert(seed); + assert(seed_size > 0); + + f = open_memstream(&url, &url_size); + if (!f) + return -ENOMEM; + + fputs("fss://", f); + + for (i = 0; i < seed_size; i++) { + if (i > 0 && i % 3 == 0) + fputc('-', f); + fprintf(f, "%02x", ((uint8_t*) seed)[i]); + } + + fprintf(f, "/%"PRIx64"-%"PRIx64"?machine=" SD_ID128_FORMAT_STR, + start, + interval, + SD_ID128_FORMAT_VAL(machine)); + + if (hn) + fprintf(f, ";hostname=%s", hn); + + if (ferror(f)) { + fclose(f); + free(url); + return -ENOMEM; + } + + fclose(f); + + qr = QRcode_encodeString(url, 0, QR_ECLEVEL_L, QR_MODE_8, 1); + free(url); + + if (!qr) + return -ENOMEM; + + print_border(output, qr->width); + + for (y = 0; y < (unsigned) qr->width; y += 2) { + const uint8_t *row1, *row2; + + row1 = qr->data + qr->width * y; + row2 = row1 + qr->width; + + fputs(WHITE_ON_BLACK, output); + for (x = 0; x < 4; x++) + fputs("\342\226\210", output); + + for (x = 0; x < (unsigned) qr->width; x ++) { + bool a, b; + + a = row1[x] & 1; + b = (y+1) < (unsigned) qr->width ? (row2[x] & 1) : false; + + if (a && b) + fputc(' ', output); + else if (a) + fputs("\342\226\204", output); + else if (b) + fputs("\342\226\200", output); + else + fputs("\342\226\210", output); + } + + for (x = 0; x < 4; x++) + fputs("\342\226\210", output); + fputs(NORMAL "\n", output); + } + + print_border(output, qr->width); + + QRcode_free(qr); + return 0; +} diff --git a/src/grp-journal/journalctl/journal-qrcode.h b/src/grp-journal/journalctl/journal-qrcode.h new file mode 100644 index 0000000000..34a779d5be --- /dev/null +++ b/src/grp-journal/journalctl/journal-qrcode.h @@ -0,0 +1,27 @@ +#pragma once + +/*** + This file is part of systemd. + + Copyright 2012 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <inttypes.h> +#include <stdio.h> + +#include <systemd/sd-id128.h> + +int print_qr_code(FILE *f, const void *seed, size_t seed_size, uint64_t start, uint64_t interval, const char *hn, sd_id128_t machine); diff --git a/src/grp-journal/journalctl/journalctl.c b/src/grp-journal/journalctl/journalctl.c index c673fbf78a..85a934e978 100644 --- a/src/grp-journal/journalctl/journalctl.c +++ b/src/grp-journal/journalctl/journalctl.c @@ -36,29 +36,17 @@ #include <systemd/sd-bus.h> #include <systemd/sd-journal.h> -#include "shared/acl-util.h" #include "basic/alloc-util.h" -#include "bus-error.h" -#include "shared/bus-util.h" -#include "catalog.h" #include "basic/chattr-util.h" #include "basic/fd-util.h" #include "basic/fileio.h" #include "basic/fs-util.h" -#include "fsprg.h" #include "basic/glob-util.h" #include "basic/hostname-util.h" #include "basic/io-util.h" -#include "journal-def.h" -#include "journal-internal.h" -#include "journal-qrcode.h" -#include "journal-vacuum.h" -#include "journal-verify.h" #include "basic/locale-util.h" #include "basic/log.h" -#include "shared/logs-show.h" #include "basic/mkdir.h" -#include "shared/pager.h" #include "basic/parse-util.h" #include "basic/path-util.h" #include "basic/rlimit-util.h" @@ -67,10 +55,23 @@ #include "basic/strv.h" #include "basic/syslog-util.h" #include "basic/terminal-util.h" -#include "udev.h" -#include "shared/udev-util.h" #include "basic/unit-name.h" #include "basic/user-util.h" +#include "sd-bus/bus-error.h" +#include "sd-journal/catalog.h" +#include "sd-journal/fsprg.h" +#include "sd-journal/journal-def.h" +#include "sd-journal/journal-internal.h" +#include "sd-journal/journal-vacuum.h" +#include "sd-journal/journal-verify.h" +#include "shared/acl-util.h" +#include "shared/bus-util.h" +#include "shared/logs-show.h" +#include "shared/pager.h" +#include "shared/udev-util.h" +#include "udev.h" + +#include "journal-qrcode.h" #define DEFAULT_FSS_INTERVAL_USEC (15*USEC_PER_MINUTE) |