Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/wtmpdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ extern int64_t wtmpdb_login (const char *db_path, int type,
const char *service, char **error);
extern int wtmpdb_logout (const char *db_path, int64_t id,
uint64_t usec_logout, char **error);
extern int wtmpdb_read_all (const char *db_path,
extern int wtmpdb_read_all (const char *db_path, int uniq,
int (*cb_func) (void *unused, int argc,
char **argv, char **azColName),
char **error);
extern int wtmpdb_read_all_v2 (const char *db_path,
extern int wtmpdb_read_all_v2 (const char *db_path, int uniq,
int (*cb_func) (void *unused, int argc,
char **argv, char **azColName),
void *userdata, char **error);
Expand Down
12 changes: 6 additions & 6 deletions lib/libwtmpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ wtmpdb_get_id (const char *db_path, const char *tty, char **error)
each entry.
Returns 0 on success, -1 on failure. */
int
wtmpdb_read_all (const char *db_path,
wtmpdb_read_all (const char *db_path, int uniq,
int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
char **error)
Expand All @@ -168,7 +168,7 @@ wtmpdb_read_all (const char *db_path,
#if WITH_WTMPDBD
int r;

r = varlink_read_all (cb_func, NULL, error);
r = varlink_read_all (uniq, cb_func, NULL, error);
if (r >= 0)
return r;

Expand All @@ -185,11 +185,11 @@ wtmpdb_read_all (const char *db_path,
#endif
}

return sqlite_read_all (db_path?db_path:_PATH_WTMPDB, cb_func, NULL, error);
return sqlite_read_all (db_path?db_path:_PATH_WTMPDB, uniq, cb_func, NULL, error);
}

int
wtmpdb_read_all_v2 (const char *db_path,
wtmpdb_read_all_v2 (const char *db_path, int uniq,
int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
void *userdata, char **error)
Expand All @@ -199,7 +199,7 @@ wtmpdb_read_all_v2 (const char *db_path,
#if WITH_WTMPDBD
int r;

r = varlink_read_all (cb_func, userdata, error);
r = varlink_read_all (uniq, cb_func, userdata, error);
if (r >= 0)
return r;

Expand All @@ -216,7 +216,7 @@ wtmpdb_read_all_v2 (const char *db_path,
#endif
}

return sqlite_read_all (db_path?db_path:_PATH_WTMPDB, cb_func, userdata, error);
return sqlite_read_all (db_path?db_path:_PATH_WTMPDB, uniq, cb_func, userdata, error);
}


Expand Down
8 changes: 6 additions & 2 deletions lib/sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ sqlite_get_id (const char *db_path, const char *tty, char **error)
each entry.
Returns 0 on success, -1 on failure. */
int
sqlite_read_all (const char *db_path,
sqlite_read_all (const char *db_path, int uniq,
int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
void *userdata, char **error)
Expand All @@ -471,7 +471,11 @@ sqlite_read_all (const char *db_path,
if (r != 0)
return -r;

char *sql = "SELECT * FROM wtmp ORDER BY Login DESC, Logout ASC";
char *sql = uniq
? "SELECT ID, Type, User, Login, Logout, TTY, RemoteHost, Service FROM ("
"SELECT *,ROW_NUMBER() OVER (PARTITION BY User ORDER BY Login DESC) AS rn "
"FROM wtmp WHERE Login IS NOT NULL AND TTY != '~') WHERE rn = 1"
: "SELECT * FROM wtmp ORDER BY Login DESC, Logout ASC";

r = sqlite3_exec (db, sql, cb_func, userdata, &err_msg);
sqlite3_close (db);
Expand Down
2 changes: 1 addition & 1 deletion lib/sqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern int sqlite_logout (const char *db_path, int64_t id,
uint64_t usec_logout, char **error);
extern int64_t sqlite_get_id (const char *db_path, const char *tty,
char **error);
extern int sqlite_read_all (const char *db_path,
extern int sqlite_read_all (const char *db_path, int uniq,
int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
void *userdata, char **error);
Expand Down
15 changes: 13 additions & 2 deletions lib/varlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ wtmpdb_entry_free (struct wtmpdb_entry *var)
}

int
varlink_read_all (int (*cb_func)(void *unused, int argc, char **argv,
varlink_read_all (int uniq, int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
void *userdata, char **error)
{
Expand All @@ -539,15 +539,26 @@ varlink_read_all (int (*cb_func)(void *unused, int argc, char **argv,
{}
};
_cleanup_(sd_varlink_unrefp) sd_varlink *link = NULL;
_cleanup_(sd_json_variant_unrefp) sd_json_variant *params = NULL;
sd_json_variant *result;
int r;

r = connect_to_wtmpdbd(&link, _VARLINK_WTMPDB_SOCKET, error);
if (r < 0)
return r;

r = sd_json_buildo(&params, SD_JSON_BUILD_PAIR("Uniq", SD_JSON_BUILD_INTEGER(uniq)));
if (r < 0)
{
if (error)
if (asprintf (error, "Failed to build JSON data: %s",
strerror(-r)) < 0)
*error = strdup ("Out of memory");
return r;
}

const char *error_id;
r = sd_varlink_call(link, "org.openSUSE.wtmpdb.ReadAll", NULL, &result, &error_id);
r = sd_varlink_call(link, "org.openSUSE.wtmpdb.ReadAll", params, &result, &error_id);
if (r < 0)
{
if (error)
Expand Down
2 changes: 1 addition & 1 deletion lib/varlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern int64_t varlink_login (int type, const char *user,
char **error);
extern int varlink_logout (int64_t id, uint64_t usec_logout, char **error);
extern int64_t varlink_get_id (const char *tty, char **error);
extern int varlink_read_all (int (*cb_func)(void *unused, int argc, char **argv,
extern int varlink_read_all (int uniq, int (*cb_func)(void *unused, int argc, char **argv,
char **azColName),
void *userdata, char **error);
extern int varlink_get_boottime (uint64_t *boottime, char **error);
Expand Down
128 changes: 72 additions & 56 deletions man/wtmpdb.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,25 @@
</varlistentry>
<varlistentry>
<term>
<option>-d, --dns</option>
<option>-c, --compact</option>
</term>
<listitem>
<para>
Translate IP addresses into a hostname.
Hide the logout column and set the time format for the login
column to <constant>compact</constant>. One may still overwrite the
time format by using the <option>--time-format</option> option after
this one. If the environment variable <envar>LAST_COMPACT</envar>
is set, this option is applied before any others are processed.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
<option>-d, --dns</option>
</term>
<listitem>
<para>
Use <replaceable>FILE</replaceable> as wtmpdb database.
Translate IP addresses into a hostname.
</para>
</listitem>
</varlistentry>
Expand All @@ -111,6 +115,17 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-L, --legacy</option>
</term>
<listitem>
<para>
Display session duration with precision in minutes instead of seconds,
which is the default setting for the legacy 'last' command.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-n, --limit</option> <replaceable>N</replaceable>
Expand All @@ -124,6 +139,16 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-o, --open</option>
</term>
<listitem>
<para>
Display only sessions that are still open, i.e. no end of session has been recorded since last boot.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-p, --present</option> <replaceable>TIME</replaceable>
Expand Down Expand Up @@ -175,6 +200,19 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-u, --unique</option>
</term>
<listitem>
<para>
Display only the most recent log entry for each user.
This is the default when called as lastlog or wlastlog.
In contrast to the legacy lastlog tool, users without any log entries
will not be shown.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-w, --fullnames</option>
Expand Down Expand Up @@ -204,14 +242,16 @@
<para>
Display timestamps in the specified
<replaceable>FORMAT</replaceable>. The format can be
<replaceable>notime</replaceable>,
<replaceable>short</replaceable>,
<replaceable>full</replaceable>, or
<replaceable>iso</replaceable>.
<replaceable>notime</replaceable> will not display times at
all, <replaceable>short</replaceable> is the default option,
<replaceable>full</replaceable> will display the full times
and dates, and <replaceable>iso</replaceable> will display
<constant>notime</constant>,
<constant>short</constant>,
<constant>compact</constant>,
<constant>full</constant>, or
<constant>iso</constant>.
<constant>notime</constant> will not display times at
all, <constant>short</constant> is the default option,
<constant>compact</constant> format is "YYYY-mm-dd HH:MM:SS",
<constant>full</constant> will display the full times
and dates, and <constant>iso</constant> will display
times in ISO-8601 format.
</para>
</listitem>
Expand Down Expand Up @@ -242,16 +282,6 @@
to the <filename>/var/lib/wtmpdb/wtmp.db</filename> database.
</para>
<title>boot options</title>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
</term>
<listitem>
<para>
Use <replaceable>FILE</replaceable> as wtmpdb database.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-q, --quiet</option>
Expand All @@ -264,6 +294,16 @@
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term>
<command>boottime</command>
<optional><replaceable>option</replaceable>…</optional>
</term>
<listitem>
<para><command>wtmpdb boottime</command> shows the time of the
last boot.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><command>shutdown</command>
<optional><replaceable>option</replaceable>…</optional></term>
Expand All @@ -273,17 +313,6 @@
requests to the <filename>/var/lib/wtmpdb/wtmp.db</filename>
database.
</para>
<title>shutdown options</title>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
</term>
<listitem>
<para>
Use <replaceable>FILE</replaceable> as wtmpdb database.
</para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
Expand All @@ -296,17 +325,6 @@
database and removes these entries from the original one.
</para>
<title>rotate options</title>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
</term>
<listitem>
<para>
Use <replaceable>FILE</replaceable> as wtmpdb database.
The exported DB file will be on the same location.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-d, --days</option> <replaceable>DAYS</replaceable>
Expand All @@ -331,22 +349,20 @@
files to the <filename>/var/lib/wtmpdb/wtmp.db</filename>
database.
</para>
<title>import options</title>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
</term>
<listitem>
<para>
Use <replaceable>FILE</replaceable> as wtmpdb database.
</para>
</listitem>
</varlistentry>
</listitem>
</varlistentry>
<varlistentry>
<term>global options</term>
<term>common options</term>
<title>global options</title>
<varlistentry>
<term>
<option>-f, --file</option> <replaceable>FILE</replaceable>
</term>
<listitem>
<para>Use <replaceable>FILE</replaceable> as wtmpdb
database.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-h, --help</option>
Expand Down
1 change: 1 addition & 0 deletions src/varlink-org.openSUSE.wtmpdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static SD_VARLINK_DEFINE_METHOD(
static SD_VARLINK_DEFINE_METHOD(
ReadAll,
SD_VARLINK_FIELD_COMMENT("Get all entries from the database"),
SD_VARLINK_DEFINE_INPUT(Uniq, SD_VARLINK_INT, 0),
SD_VARLINK_DEFINE_OUTPUT(Success, SD_VARLINK_BOOL, 0),
SD_VARLINK_DEFINE_OUTPUT_BY_TYPE(Data, WtmpdbEntry, SD_VARLINK_ARRAY | SD_VARLINK_NULLABLE),
SD_VARLINK_DEFINE_OUTPUT(ErrorMsg, SD_VARLINK_STRING, SD_VARLINK_NULLABLE));
Expand Down
Loading