From fe808525acbc71410e22bbb6b5cfa5266b2dd30f Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 25 Mar 2014 14:31:07 -0500 Subject: fixed a bug in libirc where pong was sending ping. dunno. I don't remember what else I did. --- segfault.c | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'segfault.c') diff --git a/segfault.c b/segfault.c index 0b38a20..9fb6df5 100644 --- a/segfault.c +++ b/segfault.c @@ -58,7 +58,6 @@ timer_t timer; int lines_sent; unsigned long oldtime; - struct tail { FILE *fp; char *file; @@ -82,9 +81,12 @@ void c_untail(int fd,char *from, char *file); void mywrite(int fd,char *b) { + int r; if(!b) return; if(fd<0) return; - write(fd,b,strlen(b)); + r=write(fd,b,strlen(b)); + if(r == -1) exit(1); + if(r != strlen(b)) exit(2); lines_sent++; } @@ -173,6 +175,13 @@ char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) { return output; } +void eofd(int fd) { + char b; + if(lseek(fd,0,SEEK_END) == -1) { + while(read(fd,&b,1) > 0);//this is used on named pipes usually. + } +} + void eofp(FILE *fp) { if(fseek(fp,0,SEEK_END) == -1) { while(fgetc(fp) != -1);//this is used on named pipes usually. @@ -283,7 +292,9 @@ void file_tail(int fd,char *from,char *file,char *args,char opt) { privmsg(fd,from,tmp); } else { fcntl(fileno(tailf[i].fp),F_SETFL,O_NONBLOCK); - if(!(opt & TAILO_BEGIN)) fseek(tailf[i].fp,0,SEEK_END); + if(!(opt & TAILO_BEGIN)) { + eofp(tailf[i].fp); + } tailf[i].to=malloc(strlen(from)+1); if(!tailf[i].to) { mywrite(fd,"QUIT :malloc error 3!!!\r\n"); @@ -568,7 +579,9 @@ void c_leetuntail(int fd,char *from,char *line) { if(tailf[i].fp && !strcmp(tailf[i].file,file)) { //c_untail(fd,tailf[i].to,file); eofp(tailf[i].fp); - fclose(tailf[i].fp); + if(fclose(tailf[i].fp) == -1) { + privmsg(fd,from,"well, shit. fclose failed somehow."); + } tailf[i].fp=0; free(tailf[i].to); free(tailf[i].file); @@ -583,7 +596,9 @@ void c_leetuntail(int fd,char *from,char *line) { } else { frmN=atoi(frm); if(frmN < MAXTAILS && tailf[frmN].fp) { - fclose(tailf[frmN].fp); + if(fclose(tailf[frmN].fp) == -1) { + privmsg(fd,from,"well shit. fclose failed. #2"); + } tailf[frmN].fp=0; free(tailf[frmN].to); free(tailf[frmN].file); @@ -613,7 +628,9 @@ void c_untail(int fd,char *from, char *file) { for(i=0;i