]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_dsi.c
Merge branch-2-1
[netatalk.git] / etc / afpd / afp_dsi.c
index 7edb2e98740e650438f0132ba2e05c140940a6de..963a291244bcf8b55d0d5a5fb6064c815ae2d6c2 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: afp_dsi.c,v 1.52 2010-03-08 19:49:59 franklahm Exp $
- *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -37,6 +35,7 @@
 #include "switch.h"
 #include "auth.h"
 #include "fork.h"
+#include "dircache.h"
 
 #ifdef FORCE_UIDGID
 #warning UIDGID
@@ -73,16 +72,21 @@ static void afp_dsi_close(AFPObj *obj)
      * as uid 0, that's the wrong user for volume's prexec_close scripts if any,
      * restore our login user
      */
-    if (seteuid( obj->uid ) < 0) {
-        LOG(log_error, logtype_afpd, "can't seteuid back %s", strerror(errno));
-        exit(EXITERR_SYS);
+    if (geteuid() != obj->uid) {
+        if (seteuid( obj->uid ) < 0) {
+            LOG(log_error, logtype_afpd, "can't seteuid(%u) back %s: uid: %u, euid: %u", 
+                obj->uid, strerror(errno), getuid(), geteuid());
+            exit(EXITERR_SYS);
+        }
     }
+
     close_all_vol();
     if (obj->logout)
         (*obj->logout)();
 
-    LOG(log_info, logtype_afpd, "%.2fKB read, %.2fKB written",
+    LOG(log_info, logtype_afpd, "AFP statistics: %.2f KB read, %.2f KB written",
         dsi->read_count/1024.0, dsi->write_count/1024.0);
+    log_dircache_stat();
 
     dsi_close(dsi);
 }
@@ -171,8 +175,7 @@ static void afp_dsi_timedown(int sig _U_)
 
 /* ---------------------------------
  * SIGHUP reload configuration file
- * FIXME here or we wait ?
-*/
+ */
 volatile int reload_request = 0;
 
 static void afp_dsi_reload(int sig _U_)
@@ -372,6 +375,9 @@ void afp_over_dsi(AFPObj *obj)
     }
 #endif /* DEBUGGING */
 
+    if (dircache_init(obj->options.dircachesize) != 0)
+        afp_dsi_die(EXITERR_SYS);
+
     /* get stuck here until the end */
     while ((cmd = dsi_receive(dsi))) {
         child.tickle = 0;
@@ -381,23 +387,27 @@ void afp_over_dsi(AFPObj *obj)
         if (reload_request) {
             reload_request = 0;
             load_volumes(child.obj);
+            dircache_dump();
+            log_dircache_stat();
         }
 
+        /* The first SIGINT enables debugging, the next restores the config */
         if (debug_request) {
-            char logstr[50];
+            static int debugging = 0;
             debug_request = 0;
 
-            /* The first SIGINT enables debugging, the second one kills us */
-            action.sa_handler = afp_dsi_die;
-            sigfillset( &action.sa_mask );
-            action.sa_flags = SA_RESTART;
-            if ( sigaction( SIGINT, &action, NULL ) < 0 ) {
-                LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
-                afp_dsi_die(EXITERR_SYS);
+            if (debugging) {
+                if (obj->options.logconfig)
+                    setuplog(obj->options.logconfig);
+                else
+                    setuplog("default log_note");
+                debugging = 0;
+            } else {
+                char logstr[50];
+                debugging = 1;
+                sprintf(logstr, "default log_maxdebug /tmp/afpd.%u.XXXXXX", getpid());
+                setuplog(logstr);
             }
-
-            sprintf(logstr, "default log_maxdebug /tmp/afpd.%u.XXXXXX", getpid());
-            setuplog(logstr);
         }
 
         if (cmd == DSIFUNC_TICKLE) {
@@ -442,6 +452,9 @@ void afp_over_dsi(AFPObj *obj)
 
                 LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
                     AfpNum2name(function), AfpErr2name(err));
+
+                dir_free_invalid_q();
+
 #ifdef FORCE_UIDGID
                /* bring everything back to old euid, egid */
                 if (obj->force_uid)
@@ -471,9 +484,16 @@ void afp_over_dsi(AFPObj *obj)
             if ( afp_switch[ function ] != NULL ) {
                 dsi->datalen = DSI_DATASIZ;
                 child.flags |= CHILD_RUNNING;
+
+                LOG(log_debug, logtype_afpd, "<== Start AFP command: %s", AfpNum2name(function));
+
                 err = (*afp_switch[function])(obj,
                                               (char *)&dsi->commands, dsi->cmdlen,
                                               (char *)&dsi->data, &dsi->datalen);
+
+                LOG(log_debug, logtype_afpd, "==> Finished AFP command: %s -> %s",
+                    AfpNum2name(function), AfpErr2name(err));
+
                 child.flags &= ~CHILD_RUNNING;
 #ifdef FORCE_UIDGID
                /* bring everything back to old euid, egid */