Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package wtmpdb for openSUSE:Factory checked 
in at 2023-06-14 16:28:34
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/wtmpdb (Old)
 and      /work/SRC/openSUSE:Factory/.wtmpdb.new.15902 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "wtmpdb"

Wed Jun 14 16:28:34 2023 rev:4 rq:1092602 version:0.6.0

Changes:
--------
--- /work/SRC/openSUSE:Factory/wtmpdb/wtmpdb.changes    2023-04-26 
17:26:28.370012288 +0200
+++ /work/SRC/openSUSE:Factory/.wtmpdb.new.15902/wtmpdb.changes 2023-06-14 
16:28:39.950219812 +0200
@@ -1,0 +2,6 @@
+Wed Jun  7 15:18:21 UTC 2023 - Thorsten Kukuk <[email protected]>
+
+- Update to version 0.6.0
+  - wtmpdb rotate: move old log entries into wtmpdb_<yyyymmdd>.db
+
+-------------------------------------------------------------------
@@ -7 +12,0 @@
-

Old:
----
  wtmpdb-0.5.0.tar.xz

New:
----
  wtmpdb-0.6.0.tar.xz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ wtmpdb.spec ++++++
--- /var/tmp/diff_new_pack.2BB6rY/_old  2023-06-14 16:28:40.794224999 +0200
+++ /var/tmp/diff_new_pack.2BB6rY/_new  2023-06-14 16:28:40.794224999 +0200
@@ -18,7 +18,7 @@
 
 %define lname   libwtmpdb0
 Name:           wtmpdb
-Version:        0.5.0
+Version:        0.6.0
 Release:        0
 Summary:        Reports last logged in users and system reboots
 License:        BSD-2-Clause
@@ -64,21 +64,21 @@
 %meson_test
 
 %pre
-%service_add_pre wtmpdb-update-boot.service
+%service_add_pre wtmpdb-update-boot.service wtmpdb-rotate.timer
 
 %preun
-%service_del_preun wtmpdb-update-boot.service
+%service_del_preun wtmpdb-update-boot.service wtmpdb-rotate.timer
 
 %post
 %tmpfiles_create wtmpdb.conf
-%service_add_post wtmpdb-update-boot.service
+%service_add_post wtmpdb-update-boot.service wtmpdb-rotate.timer
 pam-config -a --wtmpdb --wtmpdb-skip_if=sshd
 
 %postun
 if [ "$1" -eq 0 ]; then
     pam-config -d --wtmpdb
 fi
-%service_del_postun_without_restart wtmpdb-update-boot.service
+%service_del_postun_without_restart wtmpdb-update-boot.service 
wtmpdb-rotate.timer
 
 %post   -n %{lname} -p /sbin/ldconfig
 %postun -n %{lname} -p /sbin/ldconfig
@@ -87,6 +87,8 @@
 %license LICENSE
 %{_bindir}/wtmpdb
 %{_unitdir}/wtmpdb-update-boot.service
+%{_unitdir}/wtmpdb-rotate.service
+%{_unitdir}/wtmpdb-rotate.timer
 %{_tmpfilesdir}/wtmpdb.conf
 %{_pam_moduledir}/pam_wtmpdb.so
 %ghost %{_localstatedir}/lib/wtmpdb

++++++ wtmpdb-0.5.0.tar.xz -> wtmpdb-0.6.0.tar.xz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/INSTALL.md new/wtmpdb-0.6.0/INSTALL.md
--- old/wtmpdb-0.5.0/INSTALL.md 1970-01-01 01:00:00.000000000 +0100
+++ new/wtmpdb-0.6.0/INSTALL.md 2023-06-12 16:15:30.000000000 +0200
@@ -0,0 +1,17 @@
+# Building and installing wtmpdb
+
+## Building with Meson
+
+wtmpdb requires a relatively recent version of Meson.
+
+Building with Meson is quite simple:
+
+```shell
+$ meson setup build
+$ meson compile -C build
+$ meson compile -C build test
+$ sudo meson install -C build
+```
+
+If you want to build with the address sanitizer enabled, add
+`-Db_sanitize=address` as an argument to `meson build`.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/NEWS new/wtmpdb-0.6.0/NEWS
--- old/wtmpdb-0.5.0/NEWS       2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/NEWS       2023-06-12 16:15:30.000000000 +0200
@@ -1,6 +1,9 @@
+Version 0.6.0
+* wtmpdb rotate: move old log entries into wtmpdb_<yyyymmdd>.db
+
 Version 0.5.0
 * Use uint64_t instead of usec_t to avoid conflicts with other projects
-* wtmpdb boot: ore accurate calculation of boot time
+* wtmpdb boot: more accurate calculation of boot time
 
 Version 0.4.0
 * libwtmpdb: Use project version for library version
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/README.md new/wtmpdb-0.6.0/README.md
--- old/wtmpdb-0.5.0/README.md  2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/README.md  2023-06-12 16:15:30.000000000 +0200
@@ -18,7 +18,7 @@
 
 * It's using sqlite3 as database backend.
 * Data is mainly collected via a PAM module, so that every tools can make use 
of it, without modifying existing packages. For cases where this is not 
possible, there is a library `libwtmpdb`.
-* The `wtmpdb last` output is as compatible as possible with the old `last` 
implementation, but not all options are yet supported.
+* The `wtmpdb last` output is as compatible as possible with the old `last` 
implementation, but not all options are yet supported. For compatibility 
reasons, a symlink `last` pointing to `wtmpdb` can be created.
 
 **IMPORTANT** To be Y2038 safe on 32bit architectures, the binaries needs to 
be build with a **64bit time_t**. This should be the standard on 64bit 
architectures.
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/include/wtmpdb.h 
new/wtmpdb-0.6.0/include/wtmpdb.h
--- old/wtmpdb-0.5.0/include/wtmpdb.h   2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/include/wtmpdb.h   2023-06-12 16:15:30.000000000 +0200
@@ -54,6 +54,9 @@
                            int (*cb_func) (void *unused, int argc,
                                            char **argv, char **azColName),
                            char **error);
+extern int wtmpdb_logrotate  (const char *db_path,
+                            const int days,
+                           char **error);
 
 /* helper function */
 extern int64_t wtmpdb_get_id (const char *db_path, const char *tty,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/lib/libwtmpdb.map 
new/wtmpdb-0.6.0/lib/libwtmpdb.map
--- old/wtmpdb-0.5.0/lib/libwtmpdb.map  2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/lib/libwtmpdb.map  2023-06-12 16:15:30.000000000 +0200
@@ -4,6 +4,7 @@
        wtmpdb_login;
        wtmpdb_logout;
        wtmpdb_read_all;
+       wtmpdb_logrotate;
        wtmpdb_timespec2usec;
        wtmpdb_get_id;
   local: *;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/lib/sqlite.c 
new/wtmpdb-0.6.0/lib/sqlite.c
--- old/wtmpdb-0.5.0/lib/sqlite.c       2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/lib/sqlite.c       2023-06-12 16:15:30.000000000 +0200
@@ -29,6 +29,7 @@
 #include <time.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <libgen.h>
 #include <string.h>
 #include <limits.h>
 #include <sys/stat.h>
@@ -36,6 +37,40 @@
 
 #include "wtmpdb.h"
 
+/* Begin - local helper functions */
+
+static void
+mkdir_p(const char *pathname, mode_t mode)
+{
+  if (mkdir(pathname, mode) == 0 || errno == EEXIST || errno != ENOENT)
+    return;
+
+  char *buf = strdup(pathname);
+  mkdir_p(dirname(buf), mode);
+  free(buf);
+
+  mkdir(pathname, mode);
+}
+
+static void strip_extension(char *in_str)
+{
+    static const int name_min_len = 1;
+    static const int max_ext_len = 4;
+
+    /* Check chars starting at end of string to find last '.' */
+    for (ssize_t i = strlen(in_str); i > (name_min_len + max_ext_len); i--)
+    {
+        if (in_str[i] == '.')
+        {
+            in_str[i] = '\0';
+            return;
+        }
+    }
+}
+
+/* End - local helper functions */
+
+
 static sqlite3 *
 open_database_ro (const char *path, char **error)
 {
@@ -59,6 +94,10 @@
 {
   sqlite3 *db;
 
+  char *buf = strdup(path);
+  mkdir_p(dirname(buf), 0644);
+  free(buf);
+
   if (sqlite3_open (path, &db) != SQLITE_OK)
     {
       if (error)
@@ -401,3 +440,162 @@
 
   return 0;
 }
+
+static int logrotate_callback(void *data, int argc, char **argv, char 
**azColName) {
+  (void)argc;
+  (void)azColName;
+  sqlite3 *db_dest = (sqlite3*)data;
+  char *error = NULL;
+  char *endptr;
+
+  const int type = atoi (argv[1]);
+  const char *user = argv[2];
+  const char *tty = argv[5];
+  const char *host = argv[6];
+  const char *service = argv[7];
+  uint64_t login_t = strtoul(argv[3], &endptr, 10);
+  if ((errno == ERANGE && login_t == UINT64_MAX)
+      || (endptr == argv[1]) || (*endptr != '\0'))
+    fprintf (stderr, "Invalid numeric time entry for 'login': '%s'\n",
+            argv[3]);
+
+  int id = add_entry (db_dest,
+                     type,
+                     user,
+                     login_t,
+                     tty,
+                     host,
+                     service,
+                     &error);
+  if (id >=0)
+    {
+      if ( argv[4] )
+       {
+          int64_t logout_t = strtoul(argv[4], &endptr, 10);
+         if ((errno == ERANGE && logout_t == INT64_MAX)
+             || (endptr == argv[1]) || (*endptr != '\0'))
+         {
+           fprintf (stderr, "Invalid numeric time entry for 'logout': '%s'\n", 
argv[4]);
+           return -1;
+         }
+          if (update_logout (db_dest, id, logout_t, &error) == -1)
+         {
+            fprintf (stderr, "Cannot update DB value: '%s'\n", error);
+           return -1;
+         }
+       }
+    }
+  else
+    {
+       fprintf (stderr, "Cannot insert DB value: '%s'\n", error);
+       return -1;
+    }
+
+   return 0;
+}
+
+/* Reads all entries from database and calls the callback function for
+   each entry.
+   Returns 0 on success, -1 on failure. */
+int
+wtmpdb_logrotate  (const char *db_path,
+                  const int days,
+                  char **error)
+{
+  sqlite3 *db_src;
+  sqlite3 *db_dest;
+  char *err_msg = 0;
+  struct timespec ts_now;
+  clock_gettime (CLOCK_REALTIME, &ts_now);
+  time_t rawtime = time(0); // System time: number of seconds since 00:00, Jan 
1 1970 UTC
+  time(&rawtime);
+  struct tm *tm = localtime (&rawtime);
+  uint64_t login_t = (ts_now.tv_sec - days * 86400) * USEC_PER_SEC;
+  char date[10];
+  strftime (date, 10, "%Y%m%d", tm);
+
+  char *dest_path = NULL;
+  char *dest_file = strdup(db_path);
+  strip_extension(dest_file);
+  if (asprintf (&dest_path, "%s/%s_%s.db", dirname(dest_file), 
basename(dest_file), date) < 0)
+    {
+      *error = strdup ("Out of memory");
+      return -1;
+    }
+  if ((db_dest = open_database_rw (dest_path, error)) == NULL)
+    {
+      free(dest_path);
+      free(dest_file);
+      return -1;
+    }
+
+  if ((db_src = open_database_rw (db_path?db_path:_PATH_WTMPDB, error)) == 
NULL)
+    {
+      free(dest_path);
+      free(dest_file);
+      sqlite3_close (db_dest);
+      return -1;
+    }
+
+  char *sql = NULL;
+  if (asprintf (&sql, "SELECT * FROM wtmp where Login <= %lld",
+               (long long unsigned)login_t) < 0) /* conversation for 
i586/x86_64 build needed */
+    {
+      *error = strdup ("Out of memory");
+      sqlite3_close (db_src);
+      sqlite3_close (db_dest);
+      free(dest_path);
+      free(dest_file);
+      return -1;
+    }
+
+  if (sqlite3_exec (db_src, sql, logrotate_callback, (void*)db_dest, &err_msg) 
!= SQLITE_OK)
+    {
+      if (error)
+        if (asprintf (error, "SQL error: %s", err_msg) < 0)
+          *error = strdup ("Out of memory");
+
+      sqlite3_free (err_msg);
+      sqlite3_close (db_src);
+      sqlite3_close (db_dest);
+      free(sql);
+      free(dest_path);
+      free(dest_file);
+      return -1;
+    }
+
+  free(sql);
+  if (asprintf (&sql, "DELETE FROM wtmp where Login <= %lld",
+               (long long unsigned)login_t) < 0) /* conversation for 
i586/x86_64 build needed */
+    {
+      *error = strdup ("Out of memory");
+      sqlite3_close (db_src);
+      sqlite3_close (db_dest);
+      free(dest_path);
+      free(dest_file);
+      return -1;
+    }
+
+  if (sqlite3_exec (db_src, sql, NULL, NULL, &err_msg) != SQLITE_OK)
+    {
+      if (error)
+        if (asprintf (error, "SQL error: %s", err_msg) < 0)
+          *error = strdup ("Out of memory");
+
+      sqlite3_free (err_msg);
+      sqlite3_close (db_src);
+      sqlite3_close (db_dest);
+      free(sql);
+      free(dest_path);
+      free(dest_file);
+      return -1;
+    }
+
+  free(sql);
+  sqlite3_close (db_src);
+  sqlite3_close (db_dest);
+  free(dest_path);
+  free(dest_file);
+
+  return 0;
+}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/man/wtmpdb.8.xml 
new/wtmpdb-0.6.0/man/wtmpdb.8.xml
--- old/wtmpdb-0.5.0/man/wtmpdb.8.xml   2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/man/wtmpdb.8.xml   2023-06-12 16:15:30.000000000 +0200
@@ -197,6 +197,40 @@
        </listitem>
       </varlistentry>
       <varlistentry>
+        <term><command>rotate</command>
+       <optional><replaceable>option</replaceable>…</optional></term>
+        <listitem>
+          <para>
+           <command>wtmpdb rotate</command> exports old log entries
+           to the <filename>/var/lib/wtmpdb/wtmp_yyyymmmdd.db</filename>
+           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>
+           </term>
+           <listitem>
+             <para>
+               Entries will be exported which are older than
+                <replaceable>DAYS</replaceable> days. Default is 60 days.
+             </para>
+           </listitem>
+         </varlistentry>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
        <term>global options</term>
        <title>global options</title>
        <varlistentry>
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/meson.build new/wtmpdb-0.6.0/meson.build
--- old/wtmpdb-0.5.0/meson.build        2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/meson.build        2023-06-12 16:15:30.000000000 +0200
@@ -11,7 +11,7 @@
                  'b_pie=true',
                  'warning_level=3',],
   license : ['BSD-2-Clause',],
-  version : '0.5.0',
+  version : '0.6.0',
 )
 
 conf = configuration_data()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/src/wtmpdb.c 
new/wtmpdb-0.6.0/src/wtmpdb.c
--- old/wtmpdb-0.5.0/src/wtmpdb.c       2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/src/wtmpdb.c       2023-06-12 16:15:30.000000000 +0200
@@ -49,6 +49,8 @@
 #define TIMEFMT_SHORT 2
 #define TIMEFMT_HHMM  3
 
+#define LOGROTATE_DAYS 60
+
 static uint64_t wtmp_start = UINT64_MAX;
 static int after_reboot = 0;
 
@@ -306,7 +308,7 @@
   FILE *output = (retval != EXIT_SUCCESS) ? stderr : stdout;
 
   fprintf (output, "Usage: wtmpdb [command] [options]\n");
-  fputs ("Commands: last, boot, shutdown\n\n", output);
+  fputs ("Commands: last, boot, rotate, shutdown\n\n", output);
   fputs ("Options for last:\n", output);
   fputs ("  -a, --lasthost      Display hostnames as last entry\n", output);
   fputs ("  -f, --file FILE     Use FILE as wtmpdb database\n", output);
@@ -319,12 +321,20 @@
   fputs ("  -t, --until TIME    Display who was logged in until TIME\n", 
output);
   fputs ("TIME must be in the format \"YYYY-MM-DD HH:MM:SS\"\n", output);
   fputs ("\n", output);
+
   fputs ("Options for boot (writes boot entry to wtmpdb):\n", output);
   fputs ("  -f, --file FILE     Use FILE as wtmpdb database\n", output);
   fputs ("\n", output);
+
+  fputs ("Options for rotate (exports old entries to wtmpdb_<datetime>)):\n", 
output);
+  fputs ("  -f, --file FILE     Use FILE as wtmpdb database\n", output);
+  fputs ("  -d, --days INTEGER  Export all entries which are older than the 
given days\n", output);
+  fputs ("\n", output);
+
   fputs ("Options for shutdown (writes shutdown time to wtmpdb):\n", output);
   fputs ("  -f, --file FILE     Use FILE as wtmpdb database\n", output);
   fputs ("\n", output);
+
   fputs ("Generic options:\n", output);
   fputs ("  -h, --help          Display this help message and exit\n", output);
   fputs ("  -v, --version       Print version number and exit\n", output);
@@ -333,6 +343,62 @@
 }
 
 static int
+main_logrotate (int argc, char **argv)
+{
+  struct option const longopts[] = {
+    {"file", required_argument, NULL, 'f'},
+    {"days", no_argument, NULL, 'd'},
+    {NULL, 0, NULL, '\0'}
+  };
+  char *error = NULL;
+  int days = LOGROTATE_DAYS;
+
+  int c;
+
+  while ((c = getopt_long (argc, argv, "f:d:", longopts, NULL)) != -1)
+    {
+      switch (c)
+        {
+        case 'f':
+          wtmpdb_path = optarg;
+          break;
+       case 'd':
+         days = atoi (optarg);
+         break;
+        default:
+          usage (EXIT_FAILURE);
+          break;
+        }
+    }
+
+  if (argc > optind)
+    {
+      fprintf (stderr, "Unexpected argument: %s\n", argv[optind]);
+      usage (EXIT_FAILURE);
+    }
+
+  if (wtmpdb_logrotate (wtmpdb_path, days, &error) != 0)
+    {
+      if (error)
+        {
+          fprintf (stderr, "%s\n", error);
+          free (error);
+        }
+      else
+        fprintf (stderr, "Couldn't read all wtmp entries\n");
+
+      exit (EXIT_FAILURE);
+    }
+
+  char wtmptime[32];
+  format_time (TIMEFMT_CTIME, wtmptime, sizeof (wtmptime),
+              wtmp_start/USEC_PER_SEC);
+  printf ("\n%s begins %s\n", wtmpdb_path, wtmptime);
+
+  return EXIT_SUCCESS;
+}
+
+static int
 main_last (int argc, char **argv)
 {
   struct option const longopts[] = {
@@ -344,7 +410,7 @@
     {"nohostname", no_argument, NULL, 'R'},
     {"since", required_argument, NULL, 's'},
     {"service", no_argument, NULL, 'S'},
-    {"until", required_argument, NULL, 't'},
+    {"until", required_argument, NULL, 'u'},
     {NULL, 0, NULL, '\0'}
   };
   char *error = NULL;
@@ -481,7 +547,7 @@
     {
       switch (c)
         {
-        case 'd':
+        case 'f':
           wtmpdb_path = optarg;
           break;
         default:
@@ -540,7 +606,7 @@
     {
       switch (c)
         {
-        case 'd':
+        case 'f':
           wtmpdb_path = optarg;
           break;
         default:
@@ -613,6 +679,8 @@
     return main_boot (--argc, ++argv);
   else if (strcmp (argv[1], "shutdown") == 0)
     return main_shutdown (--argc, ++argv);
+  else if (strcmp (argv[1], "rotate") == 0)
+    return main_logrotate (--argc, ++argv);
 
   while ((c = getopt_long (argc, argv, "hv", longopts, NULL)) != -1)
     {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/tests/tst-login-logout.c 
new/wtmpdb-0.6.0/tests/tst-login-logout.c
--- old/wtmpdb-0.5.0/tests/tst-login-logout.c   2023-04-26 11:10:14.000000000 
+0200
+++ new/wtmpdb-0.6.0/tests/tst-login-logout.c   2023-06-12 16:15:30.000000000 
+0200
@@ -48,6 +48,7 @@
   int64_t logout_t = -1;
 
   clock_gettime (CLOCK_REALTIME, &ts);
+  ts.tv_sec -= 259200; /* three days behind */
   login_t = wtmpdb_timespec2usec (ts);
 
   if ((id = wtmpdb_login (db_path, USER_PROCESS, user,
@@ -81,12 +82,81 @@
   return 0;
 }
 
+static int counter = 0;
+
+static int
+count_entry (void *unused __attribute__((__unused__)),
+            int argc, char **argv, char **azColName)
+{
+  (void)argc;
+  (void)argv;
+  (void)azColName;
+  counter++;
+  return 0;
+}
+
+static int
+test_logrotate (const char *db_path)
+{
+  char *error = NULL;
+
+  counter = 0;
+  if (wtmpdb_read_all (db_path, count_entry, &error) != 0)
+    {
+      if (error)
+        {
+          fprintf (stderr, "%s\n", error);
+          free (error);
+        }
+      else
+       fprintf (stderr, "wtmpdb_read_all failed\n");
+      return 1;
+    }
+  if (counter != 5)
+    {
+      fprintf (stderr, "wtmpdb_read_all returned %d expected 5\n", counter);
+      return 1;
+    }
+
+  if (wtmpdb_logrotate (db_path, 1, &error) != 0)
+    {
+      if (error)
+        {
+          fprintf (stderr, "%s\n", error);
+          free (error);
+        }
+      else
+       fprintf (stderr, "wtmpdb_logrotate failed\n");
+      return 1;
+    }
+
+  counter = 0;
+  if (wtmpdb_read_all (db_path, count_entry, &error) != 0)
+    {
+      if (error)
+        {
+          fprintf (stderr, "%s\n", error);
+          free (error);
+        }
+      else
+       fprintf (stderr, "wtmpdb_read_all failed\n");
+      return 1;
+    }
+  if (counter != 0)
+    {
+      fprintf (stderr, "wtmpdb_read_all returned %d expected 0\n", counter);
+      return 1;
+    }
+
+  return 0;
+}
+
 int
 main(void)
 {
   const char *db_path = "tst-login-logout.db";
 
-  /* make sure there is no old stuff flying around */
+  /* make sure there is no old stuff flying around. The backup file is not so 
important. */
   remove (db_path);
 
   if (test_args (db_path, "user1", "test-tty", "localhost", NULL) != 0)
@@ -100,5 +170,24 @@
   if (test_args (db_path, "user5", NULL, "localhost", NULL) != 0)
     return 1;
 
+  if (test_logrotate (db_path) != 0)
+    return 1;
+
+  /* cleanup */
+  time_t rawtime = time(0); /* System time: number of seconds since 00:00, Jan 
1 1970 UTC */
+  time(&rawtime);
+  struct tm *tm = localtime (&rawtime);
+  char date[10];
+  strftime (date, 10, "%Y%m%d", tm);
+  char *backup_path = NULL;
+  if (asprintf (&backup_path, "tst-login-logout_%s.db", date) < 0)
+    {
+      fprintf (stderr, "Out of memory");
+      return 1;
+    }
+  remove (backup_path);
+  free (backup_path);
+  remove (db_path);
+
   return 0;
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/units/meson.build 
new/wtmpdb-0.6.0/units/meson.build
--- old/wtmpdb-0.5.0/units/meson.build  2023-04-26 11:10:14.000000000 +0200
+++ new/wtmpdb-0.6.0/units/meson.build  2023-06-12 16:15:30.000000000 +0200
@@ -1 +1,3 @@
 install_data('wtmpdb-update-boot.service', install_dir : systemunitdir)
+install_data('wtmpdb-rotate.service', install_dir : systemunitdir)
+install_data('wtmpdb-rotate.timer', install_dir : systemunitdir)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/units/wtmpdb-rotate.service 
new/wtmpdb-0.6.0/units/wtmpdb-rotate.service
--- old/wtmpdb-0.5.0/units/wtmpdb-rotate.service        1970-01-01 
01:00:00.000000000 +0100
+++ new/wtmpdb-0.6.0/units/wtmpdb-rotate.service        2023-06-12 
16:15:30.000000000 +0200
@@ -0,0 +1,11 @@
+[Unit]
+Description=Rotate wtmpdb
+Documentation=man:wtmpdb(8)
+RequiresMountsFor=/var/lib/wtmpdb
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/wtmpdb rotate
+Nice=19
+IOSchedulingClass=best-effort
+IOSchedulingPriority=7
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/wtmpdb-0.5.0/units/wtmpdb-rotate.timer 
new/wtmpdb-0.6.0/units/wtmpdb-rotate.timer
--- old/wtmpdb-0.5.0/units/wtmpdb-rotate.timer  1970-01-01 01:00:00.000000000 
+0100
+++ new/wtmpdb-0.6.0/units/wtmpdb-rotate.timer  2023-06-12 16:15:30.000000000 
+0200
@@ -0,0 +1,11 @@
+[Unit]
+Description=Monthly rotation of wtmpdb
+Documentation=man:wtmpdb(8)
+
+[Timer]
+OnCalendar=monthly
+RandomizedDelaySec=900
+Persistent=true
+
+[Install]
+WantedBy=timers.target

Reply via email to