From: Ray Lee <ray-lk@madrabbit.org>
To: root@chaos.analogic.com, Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: Large files
Date: 10 Jun 2003 15:38:12 -0700 [thread overview]
Message-ID: <1055284691.1177.4.camel@orca.madrabbit.org> (raw)
[-- 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;
}
next reply other threads:[~2003-06-10 22:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-10 22:38 Ray Lee [this message]
-- 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1055284691.1177.4.camel@orca.madrabbit.org \
--to=ray-lk@madrabbit.org \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®