Import data from an old lastlog file named _file_.
Existing entries in the lastlog2 database will be overwritten.
+*-j*, *--journal* [_mode_]::
+Show the current SQLite journal mode, or set it to _mode_.
+Without an argument, displays the current journal mode.
+With an argument, sets the journal mode to the specified value.
++
+Supported modes: *WAL*, *DELETE*, *TRUNCATE*, *PERSIST*, *MEMORY*, *OFF*.
++
+*WAL* (Write-Ahead Logging) mode is recommended for high-concurrency scenarios
+as it allows readers and writers to operate concurrently without blocking each other.
+This significantly reduces database lock contention in environments with frequent
+SSH logins. The journal mode setting is persistent and only needs to be set once.
++
+See *sqlite3*(1) PRAGMA journal_mode for more details about journal modes.
+
*-r*, *--rename* _newname_::
Rename the user given with *-u* to this _newname_.
This option can only be used together with *-u* (*--user*).
include::man-common/help-version.adoc[]
+== EXAMPLES
+
+Display the current journal mode:
+----
+lastlog2 -j
+----
+
+Enable WAL mode for better concurrency (recommended for high-traffic servers):
+----
+lastlog2 -j WAL
+----
+
+Switch back to the default DELETE mode:
+----
+lastlog2 -j DELETE
+----
+
== FILES
*/var/lib/lastlog/lastlog2.db*::
fputs(_(" -C, --clear clear record of a user (requires -u)\n"), output);
fputs(_(" -d, --database FILE use FILE as lastlog2 database\n"), output);
fputs(_(" -i, --import FILE import data from old lastlog file\n"), output);
+ fputs(_(" -j, --journal [MODE] show current journal mode, or set it (WAL, DELETE, etc.)\n"), output);
fputs(_(" -r, --rename NEWNAME rename existing user to NEWNAME (requires -u)\n"), output);
fputs(_(" -s, --service display PAM service\n"), output);
fputs(_(" -S, --set set lastlog record to current time (requires -u)\n"), output);
{"database", required_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"import", required_argument, NULL, 'i'},
+ {"journal", optional_argument, NULL, 'j'},
{"rename", required_argument, NULL, 'r'},
{"service", no_argument, NULL, 's'},
{"set", no_argument, NULL, 'S'},
char *error = NULL;
int Cflg = 0;
int iflg = 0;
+ int jflg = 0;
int rflg = 0;
int Sflg = 0;
int uflg = 0;
const char *user = NULL;
const char *newname = NULL;
const char *lastlog_file = NULL;
+ const char *journal_mode = NULL;
struct ll2_context *db_context = NULL;
int c;
- while ((c = getopt_long(argc, argv, "ab:Cd:hi:r:sSt:u:vV", longopts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "ab:Cd:hi:j::r:sSt:u:vV", longopts, NULL)) != -1) {
switch (c) {
case 'a': /* active; print lastlog excluding '**Never logged in**' users */
aflg = 1;
lastlog_file = optarg;
iflg = 1;
break;
+ case 'j': /* journal [MODE]; Set or show journal mode */
+ jflg = 1;
+ if (optarg) {
+ journal_mode = optarg;
+ } else if (optind < argc && argv[optind][0] != '-') {
+ /* Check if next argument looks like a mode name */
+ journal_mode = argv[optind++];
+ }
+ break;
case 'r': /* rename <NEWNAME>; Rename existing user to NEWNAME (requires -u) */
rflg = 1;
newname = optarg;
}
}
- if ((Cflg + Sflg + iflg) > 1)
- errx(EXIT_FAILURE, _("Option -C, -i and -S cannot be used together"));
+ if ((Cflg + Sflg + iflg + jflg) > 1)
+ errx(EXIT_FAILURE, _("Option -C, -i, -j and -S cannot be used together"));
db_context = ll2_new_context(lastlog2_path);
if (!db_context)
goto done;
}
+ if (jflg) {
+ /* Journal mode operations */
+ if (journal_mode) {
+ /* Set journal mode */
+ if (ll2_set_journal_mode(db_context, journal_mode, &error) != 0) {
+ warnx(_("Couldn't set journal mode to '%s'"), journal_mode);
+ goto err;
+ }
+ printf(_("Journal mode set to '%s' successfully\n"), journal_mode);
+ } else {
+ /* Show current journal mode */
+ char *mode = NULL;
+ if (ll2_get_journal_mode(db_context, &mode, &error) != 0) {
+ warnx(_("Couldn't get journal mode"));
+ goto err;
+ }
+ printf(_("Current journal mode: %s\n"), mode);
+ free(mode);
+ }
+ goto done;
+ }
+
if (Cflg || Sflg || rflg) {
/* updating, inserting and removing entries */
if (!uflg || strlen(user) == 0) {