Exemplo n.º 1
0
static void
binary_protocol_check_file_overflow (void)
{
	if (file_size_limit <= 0 || current_file_size < file_size_limit)
		return;

	close_binary_protocol_file ();

	if (current_file_index > 0) {
		char *filename = filename_for_index (current_file_index - 1);
		unlink (filename);
		free_filename (filename);
	}

	++current_file_index;
	current_file_size = 0;

	binary_protocol_open_file ();
}
Exemplo n.º 2
0
static void
binary_protocol_open_file (void)
{
	char *filename;

	if (file_size_limit > 0)
		filename = filename_for_index (current_file_index);
	else
		filename = filename_or_prefix;

	do {
		binary_protocol_file = open (filename, O_CREAT|O_WRONLY|O_TRUNC, 0644);
		if (binary_protocol_file == -1 && errno != EINTR)
			break; /* Failed */
	} while (binary_protocol_file == -1);

	if (file_size_limit > 0)
		free_filename (filename);
}
Exemplo n.º 3
0
static void
binary_protocol_open_file (gboolean assert_on_failure)
{
	char *filename;
#ifdef F_SETLK
	struct flock lock;
	lock.l_type = F_WRLCK;
	lock.l_whence = SEEK_SET;
	lock.l_start = 0;
	lock.l_len = 0;
#endif

	if (file_size_limit > 0)
		filename = filename_for_index (current_file_index);
	else
		filename = filename_or_prefix;

	do {
		binary_protocol_file = open (filename, O_CREAT | O_WRONLY, 0644);
		if (binary_protocol_file == -1) {
			if (errno != EINTR)
				break; /* Failed */
#ifdef F_SETLK
		} else if (fcntl (binary_protocol_file, F_SETLK, &lock) == -1) {
			/* The lock for the file is already taken. Fail */
			close (binary_protocol_file);
			binary_protocol_file = -1;
			break;
#endif
		} else {
			/* We have acquired the lock. Truncate the file */
			ftruncate (binary_protocol_file, 0);
		}
	} while (binary_protocol_file == -1);

	if (binary_protocol_file == -1 && assert_on_failure)
		g_error ("sgen binary protocol: failed to open file");

	if (file_size_limit > 0)
		free_filename (filename);
}