Beispiel #1
0
static int
setutent_file (void)
{
  if (file_fd < 0)
    {
      const char *file_name;

      file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);

      file_writable = false;
      file_fd = __open_nocancel
	(file_name, O_RDONLY | O_LARGEFILE | O_CLOEXEC);
      if (file_fd == -1)
	return 0;
    }

  __lseek64 (file_fd, 0, SEEK_SET);
  file_offset = 0;

  /* Make sure the entry won't match.  */
#if _HAVE_UT_TYPE - 0
  last_entry.ut_type = -1;
#else
  last_entry.ut_line[0] = '\177';
# if _HAVE_UT_ID - 0
  last_entry.ut_id[0] = '\0';
# endif
#endif

  return 1;
}
Beispiel #2
0
static int
setutent_file (void)
{
  if (file_fd < 0)
    {
      const char *file_name;

      file_name = TRANSFORM_UTMP_FILE_NAME (__libc_utmp_file_name);

#ifdef O_CLOEXEC
# define O_flags O_LARGEFILE | O_CLOEXEC
#else
# define O_flags O_LARGEFILE
#endif
      file_writable = false;
      file_fd = open_not_cancel_2 (file_name, O_RDONLY | O_flags);
      if (file_fd == -1)
	return 0;

#ifndef __ASSUME_O_CLOEXEC
# ifdef O_CLOEXEC
      if (__have_o_cloexec <= 0)
# endif
	{
	  /* We have to make sure the file is `closed on exec'.  */
	  int result = fcntl_not_cancel (file_fd, F_GETFD, 0);
	  if (result >= 0)
	    {
# ifdef O_CLOEXEC
	      if (__have_o_cloexec == 0)
		__have_o_cloexec = (result & FD_CLOEXEC) ? 1 : -1;

	      if (__have_o_cloexec < 0)
# endif
		result = fcntl_not_cancel (file_fd, F_SETFD,
					   result | FD_CLOEXEC);
	    }

	  if (result == -1)
	    {
	      close_not_cancel_no_status (file_fd);
	      return 0;
	    }
	}
#endif
    }

  __lseek64 (file_fd, 0, SEEK_SET);
  file_offset = 0;

  /* Make sure the entry won't match.  */
#if _HAVE_UT_TYPE - 0
  last_entry.ut_type = -1;
#else
  last_entry.ut_line[0] = '\177';
# if _HAVE_UT_ID - 0
  last_entry.ut_id[0] = '\0';
# endif
#endif

  return 1;
}