]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Added some log rotation support and other tweaks.
authorsplidge <redacted>
Wed, 12 Mar 2008 16:41:51 +0000 (16:41 +0000)
committersplidge <redacted>
Wed, 12 Mar 2008 16:41:51 +0000 (16:41 +0000)
Used the new SIGUSR1 hook to trigger a reopen of the chanserv log file.
Changed the name of the active logfile to "chanservlog" for better logrotate compatibility
Fixed grep to actually work and tested it with the rotating logfiles
Updated userflags & whois to use the new "printflagsornone" when displaying user flags
Fixed incorrect error message in giveowner

chanserv/chancmds/giveowner.c
chanserv/chanservgrep.c
chanserv/chanservlog.c
chanserv/chanservstdcmds.c
chanserv/chanservuser.c
chanserv/usercmds/userflags.c
chanserv/usercmds/whois.c

index 8c866a19f0b2e6bf76ccc5850dcdaf159133cc35..2a19cc7a16bd09bd9720850376314be513dbb78b 100644 (file)
@@ -48,7 +48,7 @@ int csc_dogiveowner(void *source, int cargc, char **cargv) {
 
   /* You need to either be +n or have the relevant override... */
   if (!(cip=cs_checkaccess(sender, cargv[0], CA_OWNERPRIV,
-                          NULL, "chanlev", QPRIV_CHANGECHANLEV, 0)))
+                          NULL, "giveowner", QPRIV_CHANGECHANLEV, 0)))
     return CMD_ERROR;
   
   rcp=cip->exts[chanservext];
index 20f0f507773d8288a21bb718ac6d9dc085b72ec0..4a8dba9de2294a029a2b1fbdcbd30cba8b0d666c 100644 (file)
 #include <stdio.h>
 #include <unistd.h>
 
-#define CSG_BUFSIZE    512
+#define CSG_BUFSIZE    1024
 
 pcre           *csg_curpat;        /* Compiled pattern from pcre */
 int             csg_curfile;       /* Which logfile is being searched */
 unsigned long   csg_curnum;        /* What numeric is doing a search */
 int             csg_matches;       /* How many lines have been returned so far */
 int             csg_maxmatches=0;  /* How many matches are allowed */
+int            csg_bytesread;
 
 char            csg_readbuf[CSG_BUFSIZE];  /* Buffer */
 int             csg_bytesleft;     /* How much valid data there is in the buffer */
@@ -58,7 +59,7 @@ int csg_dogrep(void *source, int cargc, char **cargv) {
     return CMD_ERROR;
   }
 
-  if ((fd=open("chanservlog.0",O_RDONLY))<0) {
+  if ((fd=open("chanservlog",O_RDONLY))<0) {
     chanservsendmessage(sender, "Unable to open logfile.");
     free(csg_curpat);    
     return CMD_ERROR;
@@ -70,6 +71,7 @@ int csg_dogrep(void *source, int cargc, char **cargv) {
   csg_curnum=sender->numeric;
   csg_curfile=0;
   csg_bytesleft=0;
+  csg_bytesread=0;
 
   registerhandler(fd, POLLIN, csg_handleevents);
   chanservsendmessage(sender, "Started grep for %s...",cargv[0]);
@@ -96,6 +98,7 @@ retry:
   res=read(fd, csg_readbuf+csg_bytesleft, CSG_BUFSIZE-csg_bytesleft);
   
   if (res<=0) {
+/*    chanservsendmessage(np, "Closing file: res=%d, errno=%d(%s), bytes read=%d",res,errno,sys_errlist[errno],csg_bytesread); */
     /* End of file (or error) */
     deregisterhandler(fd, 1);
     sprintf(filename,"chanservlog.%d",++csg_curfile);
@@ -111,6 +114,8 @@ retry:
     return;
   }
 
+  csg_bytesread+=res;
+
   linestart=chp=csg_readbuf;
   csg_bytesleft+=res;
   
index 64b12e79e5aee9648e32633d51d83b2d148ad6f7..62c4e3dcc7945fe414ed92b00f3a2e0802776fe5 100644 (file)
@@ -5,16 +5,30 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include "chanserv.h"
+#include "../core/hooks.h"
+#include "../core/error.h"
 
 int logfd;
 
+/* When we get a sigusr1, reopen the logfile */
+void cs_usr1handler(int hooknum, void *arg) {
+  Error("chanserv",ERR_INFO,"Reopening logfile.");
+
+  if (logfd>=0)
+    close(logfd);
+
+  logfd=open("chanservlog",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+}
+
 void cs_initlog() {
-  logfd=open("chanservlog.0",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+  logfd=open("chanservlog",O_WRONLY|O_CREAT|O_APPEND,S_IRUSR|S_IWUSR);
+  registerhook(HOOK_CORE_SIGUSR1, cs_usr1handler);
 }
 
 void cs_closelog() {
   if (logfd>=0)
     close(logfd);
+  deregisterhook(HOOK_CORE_SIGUSR1, cs_usr1handler);
 }
 
 void cs_log(nick *np, char *event, ... ) {
index 58fdcd99fec2c64fdd274c8a261a3b4546b9b0c3..556427a593e49455f02788234abd3a3e28994b9c 100644 (file)
@@ -82,6 +82,8 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
   chanservstdmessage(sender, QM_COMMANDLIST);
 
   for (i=0;i<n;i++) {
+    char cmdbuf[50];
+    
     if (cargc>0 && !match2strings(cargv[0],cmdlist[i]->command->content))
       continue;
 
@@ -114,6 +116,18 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
     
     summary=(cmdsummary *)cmdlist[i]->ext;
     
+    if (cmdlist[i]->level & QCMD_DEV) {
+      sprintf(cmdbuf,"%s (+d)",cmdlist[i]->command->content);
+    } else if(cmdlist[i]->level & QCMD_ADMIN) {
+      sprintf(cmdbuf,"%s (+a)",cmdlist[i]->command->content);
+    } else if(cmdlist[i]->level & QCMD_OPER) {
+      sprintf(cmdbuf,"%s (+o)",cmdlist[i]->command->content);
+    } else if(cmdlist[i]->level & QCMD_HELPER) {
+      sprintf(cmdbuf,"%s (+h)",cmdlist[i]->command->content);
+    } else {
+      strcpy(cmdbuf, cmdlist[i]->command->content);
+    }
+    
     if (summary->bylang[lang]) {
       message=summary->bylang[lang]->content;
     } else if (summary->bylang[0]) {
@@ -122,7 +136,7 @@ int cs_doshowcommands(void *source, int cargc, char **cargv) {
       message=summary->def->content;
     }
     
-    chanservsendmessage(sender, "%-20s %s",cmdlist[i]->command->content, message);
+    chanservsendmessage(sender, "%-20s %s",cmdbuf, message);
   }
 
   chanservstdmessage(sender, QM_ENDOFLIST);
index 03e63b18c75d81b170c154ce34dd42dabbd5357a..1ae1dd4ce443d39a04fde8cf12081c7738f6d945 100644 (file)
@@ -275,8 +275,14 @@ void chanservjoinchan(channel *cp) {
    * up later.  For modes we use the forced modes, plus the default channel
    * modes (unless any of those are explicitly denied) */
     
-  /* By default, we set the forcemodes and the default modes, but never denymodes */
-  themodes = (CHANMODE_DEFAULT | rcp->forcemodes) & ~rcp->denymodes;
+  /* By default, we set the forcemodes and the default modes, but never denymodes..
+   * OK, actually we should only set the default modes if our timestamp is older.*/
+  if (cp->timestamp > rcp->ltimestamp)
+    themodes |= CHANMODE_DEFAULT;
+  else
+    themodes=0;
+    
+  themodes = (themodes | rcp->forcemodes) & ~rcp->denymodes;
   
   /* Now, if someone has just created a channel and we are going to set +i
    * or +k on it, this will kick them off.  This could be construed as a
index d3970c7a2dc6939db8d1cc0a4b49eb23add0d8de..0fae7f538bd6c6f5b65580ca4867bade347ad889 100644 (file)
@@ -96,7 +96,7 @@ int csu_douserflags(void *source, int cargc, char **cargv) {
   else
     flagmask=QUFLAG_INFO | QUFLAG_NOTICE | QUFLAG_OPER | QUFLAG_HELPER | QUFLAG_DEV | QUFLAG_ADMIN;
   
-  chanservstdmessage(sender, QM_CURUSERFLAGS, target->username, printflags(target->flags & flagmask, ruflags));
+  chanservstdmessage(sender, QM_CURUSERFLAGS, target->username, printflagsornone(target->flags & flagmask, ruflags));
 
   return CMD_OK;
 }
index 5e733872728d246affde50bdd5bf867dfb38051d..15380853a5641cee04279bb2954c7101922c6bb9 100644 (file)
@@ -80,7 +80,7 @@ int csu_dowhois(void *source, int cargc, char **cargv) {
               QUFLAG_ADMIN | QUFLAG_INFO | QUFLAG_NOTICE);
 
   if (flagmask & target->flags)
-    chanservstdmessage(sender, QM_WHOIS_FLAGS, printflags(flagmask & target->flags, ruflags));
+    chanservstdmessage(sender, QM_WHOIS_FLAGS, printflagsornone(flagmask & target->flags, ruflags));
 
   if (!(anp=findauthname(target->ID)) || !anp->nicks) {
     chanservstdmessage(sender, QM_WHOIS_USERS, "(none)");