mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: Large files
@ 2003-06-10 22:38 Ray Lee
  0 siblings, 0 replies; 10+ messages in thread
From: Ray Lee @ 2003-06-10 22:38 UTC (permalink / raw)
  To: root, Linux Kernel

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

> With 32 bit return values, ix86 Linux has a file-size limitation 
> which is currently about 0x7fffffff. Unfortunately, instead of 
> returning from a write() with a -1 and errno being set, so that 
> a program can do something about it, write() executes a signal(25) 
> which kills the task even if trapped

Works For Me(tm)

        ray:~/work/test/signals$ ls
        sig.c
        ray:~/work/test/signals$ tcc -run sig.c
        write errored
        seem to have gone overboard, switching to next log file...
        write errored
        seem to have gone overboard, switching to next log file...
        write errored
        seem to have gone overboard, switching to next log file...
        ray:~/work/test/signals$ ls -l
        total 4
        -rw-------    1 ray      ray      2147483647 Jun 10 15:35 log.0
        -rw-------    1 ray      ray      2147483647 Jun 10 15:35 log.1
        -rw-------    1 ray      ray      2147483647 Jun 10 15:35 log.2
        -rw-------    1 ray      ray           259 Jun 10 15:35 log.3
        -rw-r--r--    1 ray      ray          2119 Jun 10 15:33 sig.c
        ray:~/work/test/signals$
        
Test code attached. Please excuse the somewhat haphazard structure, it
was tossed together from code I'd written for other projects.

Ray


[-- Attachment #2: sig.c --]
[-- Type: text/x-c, Size: 2119 bytes --]

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>

#include <errno.h>
#include <signal.h>

typedef void sigfunc_t(int);

void signal_handler(int param) {
	static int fd;
	unsigned char sig;

	if (fd && param==0) {
		close(fd);
		return;
	}
	
	if (param < 1) {
		fd = -param;
		return;
	}

	if (fd) {
		sig=param;
		while (-1 == write(fd, &sig, 1) && EINTR == errno)
			;
	}
}

sigfunc_t *connect_signal(int signo, sigfunc_t *func) {
	struct sigaction act, oact;

	act.sa_handler = func;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	if (sigaction(signo, &act, &oact) < 0)
		return SIG_ERR;
	return oact.sa_handler;
}

int open_signal_file(void) {
	int fd[2];
	
	pipe(fd);
	signal_handler(-fd[1]);    // hand off the write side of the pipe

	connect_signal(SIGHUP, signal_handler);
	connect_signal(SIGINT, signal_handler);
	connect_signal(SIGXFSZ, signal_handler);

	return fd[0];  //return the read side of the pipe
}

void close_signal_file(int fd) {
	signal_handler(0);
	close(fd);
}

int main(void) {
	fd_set read_fds;
	char buf[256], fname[]="log.0";
	int sigfd, fd, i;
	unsigned long long bytes_left=3ull * (1ull<<31) + 256ull;

	sigfd = open_signal_file();

	if (!sigfd)
		return 1;
	
	while (bytes_left) {
		int len;
		fd = creat(fname, S_IRUSR | S_IWUSR);
		if (fd == -1)
			return 2;
		
		len = 0x7fffffff;
		if (len > bytes_left)
			len = bytes_left;
		ftruncate(fd, len);
		bytes_left -= len;
		
		if (!bytes_left)
			break;
		
		lseek(fd, 0, SEEK_END);
		i = write(fd, buf, 256);

		if (i>0)
			bytes_left -= i;
		if (i<0)
			puts("write errored");
		
		FD_SET(sigfd, &read_fds);
		select(sigfd + 1, &read_fds, NULL, NULL, NULL);
		
		if (FD_ISSET(sigfd, &read_fds)) {
			int sigs = read(sigfd, buf, 256);
			if (sigs > 0)
				for (i=0; i<sigs; i++)
					switch(buf[i]) {
						case SIGINT:
							return 0;
						case SIGXFSZ:
							puts("seem to have gone overboard, switching to next log file...");
							break;
						default:
							break;
					}
		}
		
		close(fd);
		fname[4]++;
	}

	close_signal_file(sigfd);
	return 0;
}

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Large files
@ 2003-06-10 13:57 Richard B. Johnson
  2003-06-10 14:16 ` ZCane, Ed (Test Purposes)
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Richard B. Johnson @ 2003-06-10 13:57 UTC (permalink / raw)
  To: Linux kernel


With 32 bit return values, ix86 Linux has a file-size limitation
which is currently about 0x7fffffff. Unfortunately, instead of
returning from a write() with a -1 and errno being set, so that
a program can do something about it, write() executes a signal(25)
which kills the task even if trapped. Is this one of those <expletive
deleted> POSIX requirements or is somebody going to fix it?

Cheers,
Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-06-10 22:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-10 22:38 Large files Ray Lee
  -- strict thread matches above, loose matches on Subject: below --
2003-06-10 13:57 Richard B. Johnson
2003-06-10 14:16 ` ZCane, Ed (Test Purposes)
2003-06-10 14:17 ` Matti Aarnio
2003-06-10 15:12   ` Richard B. Johnson
2003-06-10 17:25     ` Martin Mares
2003-06-10 18:14     ` Andreas Dilger
2003-06-10 22:12     ` Rob Landley
2003-06-10 20:14 ` David Schwartz
2003-06-10 20:31   ` Richard B. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®