[Spread-cvs] cvs commit: spread/daemon log.c
jonathan at spread.org
jonathan at spread.org
Sun Feb 3 14:19:55 EST 2002
jonathan 02/02/03 14:19:55
Modified: daemon log.c
Log:
Improved error handling for file operations in log.c.
Revision Changes Path
1.2 +21 -11 spread/daemon/log.c
Index: log.c
===================================================================
RCS file: /storage/cvsroot/spread/daemon/log.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- log.c 21 Aug 2001 14:28:21 -0000 1.1
+++ log.c 3 Feb 2002 19:19:53 -0000 1.2
@@ -34,6 +34,9 @@
#include <stdio.h>
#include "arch.h"
+#include <errno.h>
+#include <string.h>
+
#include "log.h"
#include "configuration.h"
#include "membership.h"
@@ -52,19 +55,23 @@
void Log_init()
{
- int32 start_file_pos;
+ long start_file_pos;
Is_inited = 1;
My = Conf_my();
fd = fopen( My.name, "a" );
+ if( fd == NULL )
+ Alarm( EXIT, "Log_init: error (%s) could not open file %s\n",strerror(errno), My.name );
start_file_pos = ftell(fd);
+ if (start_file_pos == -1)
+ Alarm( EXIT, "Log_init: failed to find end of file %s\n", My.name );
fclose(fd);
fd = fopen( My.name, "r+" );
- fseek( fd, start_file_pos, 0 );
if( fd == NULL )
- Alarm( EXIT, "Log_init: could not open file %s\n",My.name );
+ Alarm( EXIT, "Log_init: error (%s) could not open file %s\n",strerror(errno), My.name );
+ fseek( fd, start_file_pos, SEEK_SET );
alive_time.sec = 10;
alive_time.usec = 0;
@@ -76,22 +83,25 @@
static void Log_alive(int dummy, void *dummy_p)
{
- int ret;
- int32 file_pos;
+ long file_pos;
if( !Is_inited ) return;
#if ( SPREAD_PROTOCOL == 3 )
- ret = fprintf( fd, "A %13ld %11d\n",E_get_time().sec, Highest_seq );
+ fprintf( fd, "A %13ld %11d\n",E_get_time().sec, Highest_seq );
#else
- ret = fprintf( fd, "A %13ld \n",E_get_time().sec );
+ fprintf( fd, "A %13ld \n",E_get_time().sec );
#endif
- ret = fseek( fd, -28, 1 );
-
+ if( fseek( fd, -28, SEEK_CUR ) )
+ Alarm( EXIT, "Log_alive: error (%s) in fseek -28 on %s\n", strerror(errno), My.name);
file_pos = ftell(fd);
- ret = fseek( fd, 28, 1 );
+ if( fseek( fd, 28, SEEK_CUR ) )
+ Alarm( EXIT, "Log_alive: error (%s) in fseek 28 on %s\n", strerror(errno), My.name);
fclose(fd);
fd = fopen( My.name, "r+" );
- fseek( fd, file_pos, 0 );
+ if( fd == NULL )
+ Alarm( EXIT, "Log_alive: error (%s) could not open file %s\n",strerror(errno), My.name );
+ if( fseek( fd, file_pos, SEEK_SET ) )
+ Alarm( EXIT, "Log_alive: error (%s) in fseek file_pos (%ld) on %s\n", strerror(errno), file_pos, My.name);
E_queue( Log_alive, 0, NULL, alive_time );
}
More information about the Spread-cvs
mailing list