]> sourceware.org Git - glibc.git/blobdiff - login/tst-utmp.c
[BZ #6634]
[glibc.git] / login / tst-utmp.c
index 9ff8b5ddaa139aa4293f148b56daedefa54acca8..12a2088558b21da096dbfaebc1fe3adbac94901b 100644 (file)
@@ -1,21 +1,22 @@
 /* Tests for UTMP functions.
-   Copyright (C) 1998 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2001-2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
    Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1998.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+   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.
 
    The GNU C Library 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
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
 
 #include <errno.h>
 #include <error.h>
@@ -39,6 +40,8 @@
 #endif
 
 
+#if _HAVE_UT_TYPE || defined UTMPX
+
 /* Prototype for our test function.  */
 static int do_test (int argc, char *argv[]);
 
@@ -71,22 +74,26 @@ do_prepare (int argc, char *argv[])
     error (EXIT_FAILURE, errno, "cannot open test file `%s'", name);
 }
 
-
 struct utmp entry[] =
 {
-  { ut_type: BOOT_TIME, ut_pid: 1, ut_tv: { tv_sec: 1000 } },
-  { ut_type: RUN_LVL, ut_pid: 1, ut_tv: { tv_sec: 2000 } },
-  { ut_type: INIT_PROCESS, ut_pid: 5, ut_id: "si", ut_tv: { tv_sec: 3000 } },
-  { ut_type: LOGIN_PROCESS, ut_pid: 23, ut_line: "tty1", ut_id: "1",
-    ut_user: "LOGIN", ut_session: 23, ut_tv: { tv_sec: 4000 } },
-  { ut_type: USER_PROCESS, ut_pid: 24, ut_line: "tty2", ut_id: "2",
-    ut_user: "albert", ut_session: 24, ut_tv: { tv_sec: 8000 } },
-  { ut_type: USER_PROCESS, ut_pid: 196, ut_line: "ttyp0", ut_id: "p0",
-    ut_user: "niels", ut_session: 196, ut_tv: { tv_sec: 10000 } },
-  { ut_type: DEAD_PROCESS, ut_line: "ttyp1", ut_id: "p1",
-    ut_tv: { tv_sec: 16000 } },
-  { ut_type: EMPTY },
-  { ut_type: EMPTY }
+#if _HAVE_UT_TV || defined UTMPX
+#define UT(a)  .ut_tv = { .tv_sec = (a)}
+#else
+#define UT(a)  .ut_time = (a)
+#endif
+
+  { .ut_type = BOOT_TIME, .ut_pid = 1, UT(1000) },
+  { .ut_type = RUN_LVL, .ut_pid = 1, UT(2000) },
+  { .ut_type = INIT_PROCESS, .ut_pid = 5, .ut_id = "si", UT(3000) },
+  { .ut_type = LOGIN_PROCESS, .ut_pid = 23, .ut_line = "tty1", .ut_id = "1",
+    .ut_user = "LOGIN", UT(4000) },
+  { .ut_type = USER_PROCESS, .ut_pid = 24, .ut_line = "tty2", .ut_id = "2",
+    .ut_user = "albert", UT(8000) },
+  { .ut_type = USER_PROCESS, .ut_pid = 196, .ut_line = "ttyp0", .ut_id = "p0",
+    .ut_user = "niels", UT(10000) },
+  { .ut_type = DEAD_PROCESS, .ut_line = "ttyp1", .ut_id = "p1", UT(16000) },
+  { .ut_type = EMPTY },
+  { .ut_type = EMPTY }
 };
 int num_entries = sizeof entry / sizeof (struct utmp);
 
@@ -160,9 +167,12 @@ simulate_login (const char *line, const char *user)
          if (entry[n].ut_pid == DEAD_PROCESS)
            entry[n].ut_pid = (entry_pid += 27);
          entry[n].ut_type = USER_PROCESS;
-         strcpy (entry[n].ut_user, user);
+         strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
+#if _HAVE_UT_TV - 0 || defined UTMPX
          entry[n].ut_tv.tv_sec = (entry_time += 1000);
-
+#else
+          entry[n].ut_time = (entry_time += 1000);
+#endif
          setutent ();
 
          if (pututline (&entry[n]) == NULL)
@@ -191,9 +201,12 @@ simulate_logout (const char *line)
       if (strcmp (line, entry[n].ut_line) == 0)
        {
          entry[n].ut_type = DEAD_PROCESS;
-         entry[n].ut_user[0] = '\0';
-         entry[n].ut_tv.tv_sec = (entry_time += 1000);
-
+         strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
+#if _HAVE_UT_TV - 0 || defined UTMPX
+          entry[n].ut_tv.tv_sec = (entry_time += 1000);
+#else
+          entry[n].ut_time = (entry_time += 1000);
+#endif
          setutent ();
 
          if (pututline (&entry[n]) == NULL)
@@ -378,3 +391,14 @@ do_test (int argc, char *argv[])
 
   return result;
 }
+
+#else
+
+/* No field 'ut_type' in struct utmp.  */
+int
+main ()
+{
+  return 0;
+}
+
+#endif
This page took 0.02756 seconds and 5 git commands to generate.