Commit 1d716d35 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(cached_create_text): Check that writing the text

	do disk succeeds, and return KOM_TEMPFAIL if it doesn't.
parent 7e36afb1
/*
* $Id: simple-cache.c,v 0.48 1994/10/22 13:23:17 ceder Exp $
* $Id: simple-cache.c,v 0.49 1994/12/31 12:03:15 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -33,20 +33,18 @@
* New save algorithm by ceder.
*/
static char *rcsid = "$Id: simple-cache.c,v 0.48 1994/10/22 13:23:17 ceder Exp $";
static char *rcsid = "$Id: simple-cache.c,v 0.49 1994/12/31 12:03:15 ceder Exp $";
#include "rcs.h"
USE(rcsid);
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef SEEK_END
# include <fcntl.h>
#endif
#ifndef SEEK_END
# include <unistd.h>
#endif
#ifndef SEEK_END
# define SEEK_SET 0
# define SEEK_END 2
#endif
......@@ -925,6 +923,7 @@ cached_create_text(const String message)
{
Text_no tno;
Cache_node *node;
long file_pos;
tno = next_text_num++;
......@@ -938,6 +937,45 @@ cached_create_text(const String message)
return 0;
}
if (fseek(text_file, 0, SEEK_END) != 0)
{
log("ERROR: cannot seek to end of text_file: %s\n", strerror(errno));
clearerr(text_file);
return 0;
}
file_pos = ftell(text_file);
if (fwrite(message.string, 1, message.len, text_file) != message.len)
{
if (errno != ENOSPC)
log("WARNING: cached_create_text: Couldn't write text %d: %s\n",
tno, strerror(errno));
kom_errno = KOM_TEMPFAIL;
clearerr(text_file);
return 0;
}
if (fflush(text_file) != 0)
{
if (errno != ENOSPC)
log("WARNING: cached_create_text: Couldn't fflush text %d: %s\n",
tno, strerror(errno));
kom_errno = KOM_TEMPFAIL;
clearerr(text_file);
return 0;
}
if (fsync(fileno(text_file)) != 0)
{
if (errno != ENOSPC)
log("WARNING: cached_create_text: Couldn't fsync text %d: %s\n",
tno, strerror(errno));
kom_errno = KOM_TEMPFAIL;
clearerr(text_file);
return 0;
}
create_cache_node(text_mcb, tno);
node = get_text_node (tno);
......@@ -952,19 +990,11 @@ cached_create_text(const String message)
((Text_stat *)node->ptr)->no_of_marks = 0;
((Text_stat *)node->ptr)->no_of_lines = 0;
((Text_stat *)node->ptr)->no_of_chars = 0;
fseek(text_file, 0, SEEK_END);
((Text_stat *)node->ptr)->file_pos = ftell(text_file);
((Text_stat *)node->ptr)->file_pos = file_pos;
text_set_mru( tno );
if ( fwrite(message.string, sizeof(char), message.len, text_file)
!= message.len ) {
log("WARNING: cached_create_text: Couldn't write the text %d\n",
tno);
}
fflush(text_file);
LOGACC(lt_create_text, tno);
TRACE2("cached_create_text -> %lu\n", tno);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment