Some help with write(2) and errno.

Bernie Kirby bernie at eric.ecr.mu.oz.au
Tue Mar 19 03:28:00 AEST 1991


I have some software that does a write(2) then if that fails sends a stop
signal to process so that the problem causing the write to fail can be
cleared up. The process is supposed to be then restarted with a 'kill
-CONT ...'.

The most usual cause for the write to fail (in this case) is that the file
sytem is full. However, once the process has been stopped and some more
space made available on the file system, and then restarted, the program
still believes that file system is full.  The write call appears to always
think that there is a problem.  Is there a way to tell the program that
the file system is no longer full? I cannot close and reopen the file.

I hope somebody can tell me what I'm missing.....

Bernie.

The code looks something like this:

#include <stdio.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
extern char	*sys_errlist[];

/*
 * Write out some bytes.....
 * Stop and send mail if we run out of space etc etc...
 */
int
my_write(fd, buf, nbytes)
	int	fd;
	char	*buf;
	int	nbytes;
{
	int	n;
	int	not_written = 1;
	long	pos = tell(fd);

	do {
		if ((n = write(fd, buf, nbytes)) < 0) {
			perror("write:");

			kill(getpid(), SIGSTOP);

			/*
			 * We live again....
			 */

			if (lseek(fd, pos, SEEK_SET) < 0) {
				perror("lseek:");
				exit(1);
			}
			not_written++;
		} else 
			not_written = 0;
	} while (not_written);

	return(n);
}



More information about the Comp.sys.sun mailing list