Dovecot

user stats

*** dovecot-1.0.beta3/src/pop3/client.c.orig    2006-03-20 22:30:53.000000000 +0100
--- dovecot-1.0.beta3/src/pop3/client.c 2006-03-20 22:32:19.000000000 +0100
***************
*** 208,215 ****

  void client_destroy(struct client *client, const char *reason)
  {
!       if (reason != NULL)
                i_info("%s %s", reason, client_stats(client));

        if (client->cmd != NULL) {
                /* deinitialize command */
--- 208,219 ----

  void client_destroy(struct client *client, const char *reason)
  {
+       static void jplogme(const char *);
+
+       jplogme(client_stats(client));
!       if (reason != NULL) {
                i_info("%s %s", reason, client_stats(client));
+       }

        if (client->cmd != NULL) {
                /* deinitialize command */
***************
*** 447,449 ****
--- 451,496 ----

        timeout_remove(&to_idle);
  }
+
+ #include <stdio.h>
+ #include <fcntl.h>
+ #include <unistd.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include <sys/file.h>
+
+ #define LOGDIR "/var/spool/dovestats"
+
+ void jplogme(const char *line)
+ {
+       char path[1024], buf[5120], *user;
+       int fd;
+       long count;
+
+       if ((user = getenv("USER")) == NULL)
+               user = "dovecot.null.user";
+
+       sprintf(path, "%s/%s", LOGDIR, user);
+
+       if ((fd = open(path, O_RDWR)) == -1) {
+               if ((fd = creat(path, 0644)) == -1)
+                       return;
+               fchmod(fd, 0644);
+       }
+
+       flock(fd, LOCK_EX);
+       if (read(fd, buf, sizeof(buf)) < 2)
+               count = 0L;
+       else {
+               count = atol(buf);
+       }
+
+       lseek(fd, 0L, SEEK_SET);        // rewind
+       sprintf(buf, "%ld\n%s\n", ++count, line);
+
+       if (write(fd, buf, strlen(buf)) == strlen(buf)) {
+               if (ftruncate(fd, lseek(fd, 0L, SEEK_CUR)) == -1)
+                       perror("truncate");
+       }
+       close(fd);
+ }

 
imap/dovecot.txt · Last modified: 2006-09-22 13:44
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki