| 1 |
/* |
| 2 |
Copyright (C) 1997-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
#if defined HAVE_UPDWTMPX && !defined HAVE_LOGWTMP |
| 22 |
# include <utmpx.h> /* updwtmp() */ |
| 23 |
#endif |
| 24 |
|
| 25 |
#define KEEP_OPEN |
| 26 |
#include "logwtmp.c" |
| 27 |
|
| 28 |
/* Solaris does not provide logwtmp(3c). |
| 29 |
* It is needed in addition to logwtmp_keep_open(). |
| 30 |
*/ |
| 31 |
#if defined HAVE_UPDWTMPX && !defined HAVE_LOGWTMP |
| 32 |
void |
| 33 |
logwtmp (char *line, char *name, char *host) |
| 34 |
{ |
| 35 |
struct utmpx ut; |
| 36 |
struct timeval tv; |
| 37 |
|
| 38 |
memset (&ut, 0, sizeof (ut)); |
| 39 |
# ifdef HAVE_STRUCT_UTMPX_UT_TYPE |
| 40 |
if (name && *name) |
| 41 |
ut.ut_type = USER_PROCESS; |
| 42 |
else |
| 43 |
ut.ut_type = DEAD_PROCESS; |
| 44 |
# endif/* UT_TYPE */ |
| 45 |
|
| 46 |
strncpy (ut.ut_line, line, sizeof ut.ut_line); |
| 47 |
# ifdef HAVE_STRUCT_UTMPX_UT_USER |
| 48 |
strncpy (ut.ut_user, name, sizeof ut.ut_user); |
| 49 |
# elif defined HAVE_STRUCT_UTMPX_UT_NAME |
| 50 |
strncpy (ut.ut_name, name, sizeof ut.ut_name); |
| 51 |
# endif |
| 52 |
# ifdef HAVE_STRUCT_UTMPX_UT_HOST |
| 53 |
strncpy (ut.ut_host, host, sizeof ut.ut_host); |
| 54 |
# ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN |
| 55 |
if (strlen (host) < sizeof (ut.ut_host)) |
| 56 |
ut.ut_syslen = strlen (host) + 1; |
| 57 |
else |
| 58 |
{ |
| 59 |
ut.ut_host[sizeof (ut.ut_host) - 1] = '\0'; |
| 60 |
ut.ut_syslen = sizeof (ut.ut_host); |
| 61 |
} |
| 62 |
# endif |
| 63 |
/* UT_SYSLEN */ |
| 64 |
# endif |
| 65 |
# ifdef HAVE_STRUCT_UTMPX_UT_PID |
| 66 |
ut.ut_pid = getpid (); |
| 67 |
# endif |
| 68 |
|
| 69 |
gettimeofday (&tv, NULL); |
| 70 |
ut.ut_tv.tv_sec = tv.tv_sec; |
| 71 |
ut.ut_tv.tv_usec = tv.tv_usec; |
| 72 |
|
| 73 |
updwtmpx (PATH_WTMPX, &ut); |
| 74 |
} |
| 75 |
#endif /* HAVE_UPDWTMPX && !HAVE_LOGWTMP */ |