Esempio n. 1
0
/* This function must be called with the LOCK held */
static void __set_unlocked(void)
{
	if (static_fd < 0) {
		static_fd = open_not_cancel_2(current_file, O_RDWR | O_CLOEXEC);
		if (static_fd < 0) {
			static_fd = open_not_cancel_2(current_file, O_RDONLY | O_CLOEXEC);
			if (static_fd < 0) {
				return; /* static_fd remains < 0 */
			}
		}
#ifndef __ASSUME_O_CLOEXEC
		/* Make sure the file will be closed on exec()  */
		fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC);
#endif
		return;
	}
	lseek(static_fd, 0, SEEK_SET);
}
Esempio n. 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;
}