[systemd-commits] 5 commits - Makefile.am man/sd_pid_get_session.xml src/journal src/login src/logs-show.c src/logs-show.h src/systemctl.c src/util.c src/util.h
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jan 4 09:34:02 PST 2012
Makefile.am | 4 -
man/sd_pid_get_session.xml | 27 +++++-----
src/journal/journal-file.c | 3 -
src/journal/journalctl.c | 51 ++++++++-----------
src/journal/journald.c | 12 ++--
src/journal/sd-journal.c | 2
src/journal/sd-journal.h | 1
src/login/libsystemd-login.sym | 2
src/login/sd-login.c | 6 +-
src/login/sd-login.h | 6 +-
src/logs-show.c | 108 +++++++++++++++++++++++++++++++++--------
src/logs-show.h | 21 ++++---
src/systemctl.c | 40 +++++++++++++--
src/util.c | 18 ++++++
src/util.h | 2
15 files changed, 211 insertions(+), 92 deletions(-)
New commits:
commit df50185b43916926a72246ab3a80875eda7ad2a3
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 4 18:33:36 2012 +0100
journal: beef up journal output of systemctl and journalctl
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index e888990..17d6a7f 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -37,7 +37,7 @@
#include "pager.h"
#include "logs-show.h"
-static output_mode arg_output = OUTPUT_SHORT;
+static OutputMode arg_output = OUTPUT_SHORT;
static bool arg_follow = false;
static bool arg_show_all = false;
static bool arg_no_pager = false;
@@ -47,15 +47,15 @@ static bool arg_no_tail = false;
static int help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
- "Send control commands to or query the login manager.\n\n"
+ "Send control commands to or query the journal.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --no-pager Do not pipe output into a pager\n"
" -a --all Show all properties, including long and unprintable\n"
" -f --follow Follow journal\n"
- " -n --lines=INTEGER Lines to show\n"
+ " -n --lines=INTEGER Journal entries to show\n"
" --no-tail Show all lines, even in follow mode\n"
- " -o --output=STRING Change output mode (short, verbose, export, json)\n",
+ " -o --output=STRING Change journal output mode (short, verbose, export, json)\n",
program_invocation_short_name);
return 0;
@@ -109,18 +109,12 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'o':
- if (streq(optarg, "short"))
- arg_output = OUTPUT_SHORT;
- else if (streq(optarg, "verbose"))
- arg_output = OUTPUT_VERBOSE;
- else if (streq(optarg, "export"))
- arg_output = OUTPUT_EXPORT;
- else if (streq(optarg, "json"))
- arg_output = OUTPUT_JSON;
- else {
+ arg_output = output_mode_from_string(optarg);
+ if (arg_output < 0) {
log_error("Unknown output '%s'.", optarg);
return -EINVAL;
}
+
break;
case 'a':
@@ -221,8 +215,6 @@ int main(int argc, char *argv[]) {
}
for (;;) {
- struct pollfd pollfd;
-
for (;;) {
if (need_seek) {
r = sd_journal_next(j);
@@ -247,16 +239,9 @@ int main(int argc, char *argv[]) {
if (!arg_follow)
break;
- zero(pollfd);
- pollfd.fd = fd;
- pollfd.events = POLLIN;
-
- if (poll(&pollfd, 1, -1) < 0) {
- if (errno == EINTR)
- break;
-
- log_error("poll(): %m");
- r = -errno;
+ r = fd_wait_for_event(fd, POLLIN);
+ if (r < 0) {
+ log_error("Couldn't wait for event: %s", strerror(-r));
goto finish;
}
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 05c0d96..fe9208c 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1298,7 +1298,7 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
return r;
if (!sd_id128_equal(id, o->entry.boot_id))
- return -ENOENT;
+ return -ESTALE;
}
*ret = le64toh(o->entry.monotonic);
diff --git a/src/logs-show.c b/src/logs-show.c
index d44c50a..539dfed 100644
--- a/src/logs-show.c
+++ b/src/logs-show.c
@@ -22,6 +22,7 @@
#include <time.h>
#include <assert.h>
#include <errno.h>
+#include <sys/poll.h>
#include "logs-show.h"
#include "log.h"
@@ -328,44 +329,50 @@ static int (*output_funcs[_OUTPUT_MODE_MAX])(sd_journal*j, unsigned line, bool s
[OUTPUT_JSON] = output_json
};
-int output_journal(sd_journal *j, output_mode mode, unsigned line, bool show_all) {
+int output_journal(sd_journal *j, OutputMode mode, unsigned line, bool show_all) {
+ assert(mode >= 0);
assert(mode < _OUTPUT_MODE_MAX);
return output_funcs[mode](j, line, show_all);
}
-int show_journal_by_service(
- const char *service,
- output_mode mode,
+int show_journal_by_unit(
+ const char *unit,
+ OutputMode mode,
const char *prefix,
unsigned n_columns,
usec_t not_before,
unsigned how_many,
- bool show_all) {
+ bool show_all,
+ bool follow) {
char *m = NULL;
sd_journal *j;
int r;
- unsigned i;
+ int fd;
+ unsigned line = 0;
+ bool need_seek = false;
- assert(service);
+ assert(mode >= 0);
+ assert(mode < _OUTPUT_MODE_MAX);
+ assert(unit);
+
+ if (!endswith(unit, ".service") &&
+ !endswith(unit, ".socket") &&
+ !endswith(unit, ".mount") &&
+ !endswith(unit, ".swap"))
+ return 0;
- if (!endswith(service, ".service") &&
- !endswith(service, ".socket") &&
- !endswith(service, ".mount") &&
- !endswith(service, ".swap"))
+ if (how_many <= 0)
return 0;
if (n_columns <= 0)
n_columns = columns();
- if (how_many <= 0)
- how_many = 10;
-
if (!prefix)
prefix = "";
- if (asprintf(&m, "_SYSTEMD_UNIT=%s", service) < 0) {
+ if (asprintf(&m, "_SYSTEMD_UNIT=%s", unit) < 0) {
r = -ENOMEM;
goto finish;
}
@@ -374,6 +381,10 @@ int show_journal_by_service(
if (r < 0)
goto finish;
+ fd = sd_journal_get_fd(j);
+ if (fd < 0)
+ goto finish;
+
r = sd_journal_add_match(j, m, strlen(m));
if (r < 0)
goto finish;
@@ -382,23 +393,67 @@ int show_journal_by_service(
if (r < 0)
goto finish;
- for (i = 0; i < how_many; i++)
- sd_journal_previous(j);
+ r = sd_journal_previous_skip(j, how_many);
+ if (r < 0)
+ goto finish;
- for (i = 0; i < how_many; i++) {
+ if (mode == OUTPUT_JSON) {
+ fputc('[', stdout);
+ fflush(stdout);
+ }
- r = sd_journal_next(j);
- if (r < 0)
- goto finish;
+ for (;;) {
+ for (;;) {
+ usec_t usec;
+
+ if (need_seek) {
+ r = sd_journal_next(j);
+ if (r < 0)
+ goto finish;
+ }
+
+ if (r == 0)
+ break;
- if (r == 0)
+ need_seek = true;
+
+ if (not_before > 0) {
+ r = sd_journal_get_monotonic_usec(j, &usec, NULL);
+
+ /* -ESTALE is returned if the
+ timestamp is not from this boot */
+ if (r == -ESTALE)
+ continue;
+ else if (r < 0)
+ goto finish;
+
+ if (usec < not_before)
+ continue;
+ }
+
+ line ++;
+
+ r = output_journal(j, mode, line, show_all);
+ if (r < 0)
+ goto finish;
+ }
+
+ if (!follow)
break;
- r = output_journal(j, mode, i+1, show_all);
+ r = fd_wait_for_event(fd, POLLIN);
if (r < 0)
goto finish;
+
+ r = sd_journal_process(j);
+ if (r < 0)
+ goto finish;
+
}
+ if (mode == OUTPUT_JSON)
+ fputs("\n]\n", stdout);
+
finish:
if (m)
free(m);
@@ -408,3 +463,12 @@ finish:
return r;
}
+
+static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
+ [OUTPUT_SHORT] = "short",
+ [OUTPUT_VERBOSE] = "verbose",
+ [OUTPUT_EXPORT] = "export",
+ [OUTPUT_JSON] = "json"
+};
+
+DEFINE_STRING_TABLE_LOOKUP(output_mode, OutputMode);
diff --git a/src/logs-show.h b/src/logs-show.h
index f83df06..5cf1a63 100644
--- a/src/logs-show.h
+++ b/src/logs-show.h
@@ -27,23 +27,28 @@
#include "sd-journal.h"
#include "util.h"
-typedef enum output_mode {
+typedef enum OutputMode {
OUTPUT_SHORT,
OUTPUT_VERBOSE,
OUTPUT_EXPORT,
OUTPUT_JSON,
- _OUTPUT_MODE_MAX
-} output_mode;
+ _OUTPUT_MODE_MAX,
+ _OUTPUT_MODE_INVALID = -1
+} OutputMode;
-int output_journal(sd_journal *j, output_mode mode, unsigned line, bool show_all);
+int output_journal(sd_journal *j, OutputMode mode, unsigned line, bool show_all);
-int show_journal_by_service(
- const char *service,
- output_mode mode,
+int show_journal_by_unit(
+ const char *unit,
+ OutputMode mode,
const char *prefix,
unsigned n_columns,
usec_t not_before,
unsigned how_many,
- bool show_all);
+ bool show_all,
+ bool follow);
+
+const char* output_mode_to_string(OutputMode m);
+OutputMode output_mode_from_string(const char *s);
#endif
diff --git a/src/systemctl.c b/src/systemctl.c
index 6f87b06..2f03f6b 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -118,6 +118,9 @@ static enum transport {
TRANSPORT_POLKIT
} arg_transport = TRANSPORT_NORMAL;
static const char *arg_host = NULL;
+static bool arg_follow = false;
+static unsigned arg_lines = 10;
+static OutputMode arg_output = OUTPUT_SHORT;
static bool private_bus = false;
@@ -2001,6 +2004,7 @@ typedef struct UnitStatusInfo {
const char *load_error;
usec_t inactive_exit_timestamp;
+ usec_t inactive_exit_timestamp_monotonic;
usec_t active_enter_timestamp;
usec_t active_exit_timestamp;
usec_t inactive_enter_timestamp;
@@ -2264,7 +2268,7 @@ static void print_status_info(UnitStatusInfo *i) {
if (i->id && arg_transport != TRANSPORT_SSH) {
printf("\n");
- show_journal_by_service(i->id, OUTPUT_SHORT, NULL, 0, 0, 0, arg_all);
+ show_journal_by_unit(i->id, arg_output, NULL, 0, i->inactive_exit_timestamp_monotonic, arg_lines, arg_all, arg_follow);
}
if (i->need_daemon_reload)
@@ -2391,6 +2395,8 @@ static int status_property(const char *name, DBusMessageIter *iter, UnitStatusIn
i->inactive_enter_timestamp = (usec_t) u;
else if (streq(name, "InactiveExitTimestamp"))
i->inactive_exit_timestamp = (usec_t) u;
+ else if (streq(name, "InactiveExitTimestampMonotonic"))
+ i->inactive_exit_timestamp_monotonic = (usec_t) u;
else if (streq(name, "ActiveExitTimestamp"))
i->active_exit_timestamp = (usec_t) u;
else if (streq(name, "ConditionTimestamp"))
@@ -3969,7 +3975,10 @@ static int systemctl_help(void) {
" -f --force When enabling unit files, override existing symlinks\n"
" When shutting down, execute action immediately\n"
" --root=PATH Enable unit files in the specified root directory\n"
- " --runtime Enable unit files only temporarily until next reboot\n\n"
+ " --runtime Enable unit files only temporarily until next reboot\n"
+ " -n --lines=INTEGER Journal entries to show\n"
+ " --follow Follow journal\n"
+ " -o --output=STRING Change journal output mode (short, verbose, export, json)\n\n"
"Unit Commands:\n"
" list-units List loaded units\n"
" start [NAME...] Start (activate) one or more units\n"
@@ -4120,7 +4129,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
ARG_KILL_WHO,
ARG_NO_ASK_PASSWORD,
ARG_FAILED,
- ARG_RUNTIME
+ ARG_RUNTIME,
+ ARG_FOLLOW
};
static const struct option options[] = {
@@ -4153,6 +4163,9 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
{ "host", required_argument, NULL, 'H' },
{ "privileged",no_argument, NULL, 'P' },
{ "runtime", no_argument, NULL, ARG_RUNTIME },
+ { "lines", required_argument, NULL, 'n' },
+ { "follow", no_argument, NULL, ARG_FOLLOW },
+ { "output", required_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 }
};
@@ -4164,7 +4177,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
/* Only when running as systemctl we ask for passwords */
arg_ask_password = true;
- while ((c = getopt_long(argc, argv, "ht:p:aqfs:H:P", options, NULL)) >= 0) {
+ while ((c = getopt_long(argc, argv, "ht:p:aqfs:H:Pn:o:", options, NULL)) >= 0) {
switch (c) {
@@ -4302,6 +4315,25 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
arg_runtime = true;
break;
+ case 'n':
+ if (safe_atou(optarg, &arg_lines) < 0) {
+ log_error("Failed to parse lines '%s'", optarg);
+ return -EINVAL;
+ }
+ break;
+
+ case ARG_FOLLOW:
+ arg_follow = true;
+ break;
+
+ case 'o':
+ arg_output = output_mode_from_string(optarg);
+ if (arg_output < 0) {
+ log_error("Unknown output '%s'.", optarg);
+ return -EINVAL;
+ }
+ break;
+
case '?':
return -EINVAL;
diff --git a/src/util.c b/src/util.c
index de36d15..8a6c3bb 100644
--- a/src/util.c
+++ b/src/util.c
@@ -4694,6 +4694,24 @@ int pipe_eof(int fd) {
return pollfd.revents & POLLHUP;
}
+int fd_wait_for_event(int fd, int event) {
+ struct pollfd pollfd;
+ int r;
+
+ zero(pollfd);
+ pollfd.fd = fd;
+ pollfd.events = event;
+
+ r = poll(&pollfd, 1, -1);
+ if (r < 0)
+ return -errno;
+
+ if (r == 0)
+ return 0;
+
+ return pollfd.revents;
+}
+
int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
FILE *f;
char *t;
diff --git a/src/util.h b/src/util.h
index 7f25788..e285ec7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -520,4 +520,6 @@ unsigned long cap_last_cap(void);
char *format_bytes(char *buf, size_t l, off_t t);
+int fd_wait_for_event(int fd, int event);
+
#endif
commit fd8ee359a014916ac62ae2b58f6736ccb48c6d4e
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 4 18:32:50 2012 +0100
journal: it's not a problem if the realtime jumps, hence don't ensure monotonicity of realtime for entries we write
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 95a5aaf..4de1daf 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1016,9 +1016,6 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st
ts->monotonic < le64toh(f->header->tail_entry_monotonic))
return -EINVAL;
- if (ts->realtime < le64toh(f->header->tail_entry_realtime))
- return -EINVAL;
-
items = alloca(sizeof(EntryItem) * n_iovec);
for (i = 0; i < n_iovec; i++) {
commit f4fb21c1515ca882514620b2dee31ef4246be565
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 4 15:35:59 2012 +0100
systemctl: shortcut log output for non-service, non-socket, non-mount, non-swap units
diff --git a/src/logs-show.c b/src/logs-show.c
index e28fe8f..d44c50a 100644
--- a/src/logs-show.c
+++ b/src/logs-show.c
@@ -350,6 +350,12 @@ int show_journal_by_service(
assert(service);
+ if (!endswith(service, ".service") &&
+ !endswith(service, ".socket") &&
+ !endswith(service, ".mount") &&
+ !endswith(service, ".swap"))
+ return 0;
+
if (n_columns <= 0)
n_columns = columns();
commit 94fb446e55babb713fb24850455627acf30d999b
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 4 15:35:30 2012 +0100
journald: store _SYSTEMD_UNIT= instead of _SYSTEMD_SERVICE= field, since processes might also be related to mount, swap or socket units, not just services
diff --git a/Makefile.am b/Makefile.am
index 6c0fd05..21cac4e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1912,7 +1912,7 @@ MANPAGES_ALIAS += \
man/sd_session_get_uid.3 \
man/sd_session_get_seat.3 \
man/sd_pid_get_owner_uid.3 \
- man/sd_pid_get_service.3 \
+ man/sd_pid_get_unit.3 \
man/sd_uid_is_on_seat.3 \
man/sd_uid_get_sessions.3 \
man/sd_uid_get_seats.3 \
@@ -1927,7 +1927,7 @@ man/sd_login_monitor_get_fd.3: man/sd_login_monitor_new.3
man/sd_session_get_uid.3: man/sd_session_is_active.3
man/sd_session_get_seat.3: man/sd_session_is_active.3
man/sd_pid_get_owner_uid.3: man/sd_pid_get_session.3
-man/sd_pid_get_service.3: man/sd_pid_get_session.3
+man/sd_pid_get_unit.3: man/sd_pid_get_session.3
man/sd_uid_is_on_seat.3: man/sd_uid_get_state.3
man/sd_uid_get_sessions.3: man/sd_uid_get_state.3
man/sd_uid_get_seats.3: man/sd_uid_get_state.3
diff --git a/man/sd_pid_get_session.xml b/man/sd_pid_get_session.xml
index 4086c5a..bd95804 100644
--- a/man/sd_pid_get_session.xml
+++ b/man/sd_pid_get_session.xml
@@ -44,7 +44,7 @@
<refnamediv>
<refname>sd_pid_get_session</refname>
- <refname>sd_pid_get_service</refname>
+ <refname>sd_pid_get_unit</refname>
<refname>sd_pid_get_owner_uid</refname>
<refpurpose>Determine session, service or owner of a session of a specific PID</refpurpose>
</refnamediv>
@@ -60,9 +60,9 @@
</funcprototype>
<funcprototype>
- <funcdef>int <function>sd_pid_get_service</function></funcdef>
+ <funcdef>int <function>sd_pid_get_unit</function></funcdef>
<paramdef>pid_t <parameter>pid</parameter></paramdef>
- <paramdef>char** <parameter>service</parameter></paramdef>
+ <paramdef>char** <parameter>unit</parameter></paramdef>
</funcprototype>
<funcprototype>
@@ -90,15 +90,16 @@
<citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call after use.</para>
- <para><function>sd_pid_get_service()</function> may be
- used to determine the system service identifier of a
- process identified by the specified process
- identifier. The service name is a short string,
- suitable for usage in file system paths. Note that not
- all processes are part of a service (e.g. user
- processes, or kernel threads). For processes not being
- part of a system service this function will fail. The
- returned string needs to be freed with the libc
+ <para><function>sd_pid_get_unit()</function> may be
+ used to determine the systemd unit (i.e. system
+ service) identifier of a process identified by the
+ specified process identifier. The unit name is a short
+ string, suitable for usage in file system paths. Note
+ that not all processes are part of a unit/service
+ (e.g. user processes, or kernel threads). For
+ processes not being part of a systemd unit/system
+ service this function will fail. The returned string
+ needs to be freed with the libc
<citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call after use.</para>
@@ -126,7 +127,7 @@
<title>Notes</title>
<para>The <function>sd_pid_get_session()</function>,
- <function>sd_pid_get_service()</function>, and
+ <function>sd_pid_get_pid()</function>, and
<function>sd_pid_get_owner_uid()</function> interfaces
are available as shared library, which can be compiled
and linked to with the
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 47fe6ed..b029ab9 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -431,7 +431,7 @@ static void dispatch_message_real(Server *s,
*comm = NULL, *cmdline = NULL, *hostname = NULL,
*audit_session = NULL, *audit_loginuid = NULL,
*exe = NULL, *cgroup = NULL, *session = NULL,
- *owner_uid = NULL, *service = NULL;
+ *owner_uid = NULL, *unit = NULL;
char idbuf[33];
sd_id128_t id;
@@ -515,12 +515,12 @@ static void dispatch_message_real(Server *s,
IOVEC_SET_STRING(iovec[n++], session);
}
- if (sd_pid_get_service(ucred->pid, &t) >= 0) {
- service = strappend("_SYSTEMD_SERVICE=", t);
+ if (sd_pid_get_unit(ucred->pid, &t) >= 0) {
+ unit = strappend("_SYSTEMD_UNIT=", t);
free(t);
- if (service)
- IOVEC_SET_STRING(iovec[n++], service);
+ if (unit)
+ IOVEC_SET_STRING(iovec[n++], unit);
}
if (sd_pid_get_owner_uid(ucred->uid, &owner) >= 0)
@@ -596,7 +596,7 @@ retry:
free(cgroup);
free(session);
free(owner_uid);
- free(service);
+ free(unit);
}
static void dispatch_message(Server *s,
diff --git a/src/journal/sd-journal.h b/src/journal/sd-journal.h
index d7e2528..87da17d 100644
--- a/src/journal/sd-journal.h
+++ b/src/journal/sd-journal.h
@@ -35,7 +35,6 @@
* - OR of matches is borked...
* - extend hash tables table as we go
* - accelerate looking for "all hostnames" and suchlike.
- * - hookup with systemctl
* - handle incomplete header
*
* - local deserializer
diff --git a/src/login/libsystemd-login.sym b/src/login/libsystemd-login.sym
index bac46f4..15e505e 100644
--- a/src/login/libsystemd-login.sym
+++ b/src/login/libsystemd-login.sym
@@ -36,5 +36,5 @@ local:
LIBSYSTEMD_LOGIN_38 {
global:
- sd_pid_get_service;
+ sd_pid_get_unit;
} LIBSYSTEMD_LOGIN_31;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index e857ae0..8893b1d 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -121,11 +121,11 @@ _public_ int sd_pid_get_session(pid_t pid, char **session) {
return 0;
}
-_public_ int sd_pid_get_service(pid_t pid, char **service) {
+_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
int r;
char *cgroup, *p;
- if (!service)
+ if (!unit)
return -EINVAL;
r = pid_get_cgroup(pid, NULL, &cgroup);
@@ -144,7 +144,7 @@ _public_ int sd_pid_get_service(pid_t pid, char **service) {
if (!p)
return -ENOMEM;
- *service = p;
+ *unit = p;
return 0;
}
diff --git a/src/login/sd-login.h b/src/login/sd-login.h
index 1d8a55e..00de671 100644
--- a/src/login/sd-login.h
+++ b/src/login/sd-login.h
@@ -53,9 +53,9 @@ int sd_pid_get_session(pid_t pid, char **session);
* return an error for system processes. */
int sd_pid_get_owner_uid(pid_t pid, uid_t *uid);
-/* Get service name from PID. This will return an error for
- * non-service processes. */
-int sd_pid_get_service(pid_t, char **service);
+/* Get systemd unit (i.e. service) name from PID. This will return an
+ * error for non-service processes. */
+int sd_pid_get_unit(pid_t, char **unit);
/* Get state from uid. Possible states: offline, lingering, online, active */
int sd_uid_get_state(uid_t uid, char**state);
diff --git a/src/logs-show.c b/src/logs-show.c
index d178f95..e28fe8f 100644
--- a/src/logs-show.c
+++ b/src/logs-show.c
@@ -359,7 +359,7 @@ int show_journal_by_service(
if (!prefix)
prefix = "";
- if (asprintf(&m, "_SYSTEMD_SERVICE=%s", service) < 0) {
+ if (asprintf(&m, "_SYSTEMD_UNIT=%s", service) < 0) {
r = -ENOMEM;
goto finish;
}
commit e91af489a25e8bb65016a63f533ae28a505119ef
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 4 15:27:31 2012 +0100
journalctl: only output 10 most recent lines in --follow mode
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 0e1fb66..e888990 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -38,11 +38,11 @@
#include "logs-show.h"
static output_mode arg_output = OUTPUT_SHORT;
-
static bool arg_follow = false;
static bool arg_show_all = false;
static bool arg_no_pager = false;
static int arg_lines = -1;
+static bool arg_no_tail = false;
static int help(void) {
@@ -54,6 +54,7 @@ static int help(void) {
" -a --all Show all properties, including long and unprintable\n"
" -f --follow Follow journal\n"
" -n --lines=INTEGER Lines to show\n"
+ " --no-tail Show all lines, even in follow mode\n"
" -o --output=STRING Change output mode (short, verbose, export, json)\n",
program_invocation_short_name);
@@ -64,7 +65,8 @@ static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
- ARG_NO_PAGER
+ ARG_NO_PAGER,
+ ARG_NO_TAIL
};
static const struct option options[] = {
@@ -75,6 +77,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "output", required_argument, NULL, 'o' },
{ "all", no_argument, NULL, 'a' },
{ "lines", required_argument, NULL, 'n' },
+ { "no-tail", no_argument, NULL, ARG_NO_TAIL },
{ NULL, 0, NULL, 0 }
};
@@ -126,12 +129,16 @@ static int parse_argv(int argc, char *argv[]) {
case 'n':
r = safe_atoi(optarg, &arg_lines);
- if (r < 0) {
+ if (r < 0 || arg_lines < 0) {
log_error("Failed to parse lines '%s'", optarg);
return -EINVAL;
}
break;
+ case ARG_NO_TAIL:
+ arg_no_tail = true;
+ break;
+
case '?':
return -EINVAL;
@@ -141,6 +148,9 @@ static int parse_argv(int argc, char *argv[]) {
}
}
+ if (arg_follow && !arg_no_tail)
+ arg_lines = 10;
+
return 1;
}
More information about the systemd-commits
mailing list