login.c 500 B

12345678910111213141516171819202122232425
  1. #include <errno.h>
  2. #include <limits.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6. #include <utmp.h>
  7. /* Write the given entry into utmp and wtmp. */
  8. void login (const struct utmp *entry)
  9. {
  10. struct utmp copy = *entry;
  11. utmpname(_PATH_UTMP);
  12. setutent();
  13. #if _HAVE_UT_TYPE - 0
  14. copy.ut_type = USER_PROCESS;
  15. #endif
  16. #if _HAVE_UT_PID - 0
  17. copy.ut_pid = getpid();
  18. #endif
  19. strncpy (copy.ut_line, entry->ut_line, UT_LINESIZE);
  20. pututline(entry);
  21. endutent();
  22. }