]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_dsi.c
Fix all remaining warnings from gcc -Wall that can be fixed
[netatalk.git] / etc / afpd / afp_dsi.c
index 8fdd42505501eb35fbc63d5b305cecf5c5f2577a..ac6d8fbce618337b8f06cdb09eb99bb580a8f2e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_dsi.c,v 1.40 2009-10-14 02:24:05 didg Exp $
+ * $Id: afp_dsi.c,v 1.45 2009-10-22 13:40:11 franklahm Exp $
  *
  * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -46,6 +46,7 @@
 #define CHILD_DIE         (1 << 0)
 #define CHILD_RUNNING     (1 << 1)
 #define CHILD_SLEEPING    (1 << 2)
+#define CHILD_DATA        (1 << 3)
 
 static struct {
     AFPObj *obj;
@@ -163,7 +164,9 @@ static void afp_dsi_reload(int sig _U_)
 #ifdef SERVERTEXT
 static void afp_dsi_getmesg (int sig _U_)
 {
-    readmessage(child.obj);
+    DSI *dsi = (DSI *) child.obj->handle;
+
+    dsi->msg_request = 1;
     dsi_attention(child.obj->handle, AFPATTN_MESG | AFPATTN_TIME(5));
 }
 #endif /* SERVERTEXT */
@@ -171,12 +174,26 @@ static void afp_dsi_getmesg (int sig _U_)
 static void alarm_handler(int sig _U_)
 {
     int err;
+    DSI *dsi = (DSI *) child.obj->handle;
+
+    /* we have to restart the timer because some libraries 
+     * may use alarm() */
+    setitimer(ITIMER_REAL, &dsi->timer, NULL);
+
+    /* we got some traffic from the client since the previous timer 
+     * tick. */
+    if ((child.flags & CHILD_DATA)) {
+        child.flags &= ~CHILD_DATA;
+        return;
+    }
 
     /* if we're in the midst of processing something,
        don't die. */
     if ((child.flags & CHILD_SLEEPING) && child.tickle++ < child.obj->options.sleep) {
         return;
-    } else if ((child.flags & CHILD_RUNNING) || (child.tickle++ < child.obj->options.timeout)) {
+    } 
+        
+    if ((child.flags & CHILD_RUNNING) || (child.tickle++ < child.obj->options.timeout)) {
         if (!(err = pollvoltime(child.obj)))
             err = dsi_tickle(child.obj->handle);
         if (err <= 0) 
@@ -188,23 +205,20 @@ static void alarm_handler(int sig _U_)
     }
 }
 
-
-#ifdef DEBUG1
-/*  ---------------------------------
- *  old signal handler for SIGUSR1 - set the debug flag and 
- *  redirect stdout to <tmpdir>/afpd-debug-<pid>.
- */
-void afp_set_debug (int sig)
+/* ----------------- 
+   if dsi->in_write is set attention, tickle (and close?) msg
+   aren't sent. We don't care about tickle 
+*/
+static void pending_request(DSI *dsi)
 {
-    char       fname[MAXPATHLEN];
+    /* send pending attention */
 
-    snprintf(fname, MAXPATHLEN-1, "%safpd-debug-%d", P_tmpdir, getpid());
-    freopen(fname, "w", stdout);
-    child.obj->options.flags |= OPTION_DEBUG;
-
-    return;
+    /* read msg if any, it could be done in afp_getsrvrmesg */
+    if (dsi->msg_request) {
+        dsi->msg_request = 0;
+        readmessage(child.obj);
+    }
 }
-#endif
 
 /* -------------------------------------------
  afp over dsi. this never returns. 
@@ -304,10 +318,6 @@ void afp_over_dsi(AFPObj *obj)
     }
 #endif /* DEBUGGING */
 
-#ifdef DEBUG1
-    fault_setup((void (*)(void *))afp_dsi_die);
-#endif
-
     /* get stuck here until the end */
     while ((cmd = dsi_receive(dsi))) {
         child.tickle = 0;
@@ -322,20 +332,15 @@ void afp_over_dsi(AFPObj *obj)
             /* timer is not every 30 seconds anymore, so we don't get killed on the client side. */
             if ((child.flags & CHILD_DIE))
                 dsi_tickle(dsi);
+            pending_request(dsi);
             continue;
-        } else if (!(child.flags & CHILD_DIE)) { /* reset tickle timer */
-#ifndef DEBUGGING
-            setitimer(ITIMER_REAL, &dsi->timer, NULL);
-#endif
-        }
+        } 
+
+        child.flags |= CHILD_DATA;
         switch(cmd) {
         case DSIFUNC_CLOSE:
             afp_dsi_close(obj);
             LOG(log_info, logtype_afpd, "done");
-#ifdef DEBUG1
-            if (obj->options.flags & OPTION_DEBUG )
-                printf("done\n");
-#endif                
             return;
             break;
 
@@ -350,12 +355,6 @@ void afp_over_dsi(AFPObj *obj)
 #endif /* AFS */
 
             function = (u_char) dsi->commands[0];
-#ifdef DEBUG1
-            if (obj->options.flags & OPTION_DEBUG ) {
-                printf("command: %d (%s)\n", function, AfpNum2name(function));
-                bprint((char *) dsi->commands, dsi->cmdlen);
-            }
-#endif            
 
             /* send off an afp command. in a couple cases, we take advantage
              * of the fact that we're a stream-based protocol. */
@@ -367,8 +366,8 @@ void afp_over_dsi(AFPObj *obj)
                 LOG(log_debug, logtype_afpd, "=> Start AFP command: %s", afpcmpstr);
 
                 err = (*afp_switch[function])(obj,
-                                              dsi->commands, dsi->cmdlen,
-                                              dsi->data, &dsi->datalen);
+                                              (char *)&dsi->commands, dsi->cmdlen,
+                                              (char *)&dsi->data, &dsi->datalen);
 
                 LOG(log_debug, logtype_afpd, "=> Finished AFP command: %s", afpcmpstr);
 #ifdef FORCE_UIDGID
@@ -389,12 +388,6 @@ void afp_over_dsi(AFPObj *obj)
                 break;
             }
 
-#ifdef DEBUG1
-            if (obj->options.flags & OPTION_DEBUG ) {
-                printf( "reply: %d, %d\n", err, dsi->clientID);
-                bprint((char *) dsi->data, dsi->datalen);
-            }
-#endif
             if (!dsi_cmdreply(dsi, err)) {
                 LOG(log_error, logtype_afpd, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) );
                 afp_dsi_die(EXITERR_CLNT);
@@ -403,17 +396,12 @@ void afp_over_dsi(AFPObj *obj)
 
         case DSIFUNC_WRITE: /* FPWrite and FPAddIcon */
             function = (u_char) dsi->commands[0];
-#ifdef DEBUG1
-            if ( obj->options.flags & OPTION_DEBUG ) {
-                printf("(write) command: %d, %d\n", function, dsi->cmdlen);
-                bprint((char *) dsi->commands, dsi->cmdlen);
-            }
-#endif
             if ( afp_switch[ function ] != NULL ) {
                 dsi->datalen = DSI_DATASIZ;
                 child.flags |= CHILD_RUNNING;
-                err = (*afp_switch[function])(obj, dsi->commands, dsi->cmdlen,
-                                              dsi->data, &dsi->datalen);
+                err = (*afp_switch[function])(obj,
+                                              (char *)&dsi->commands, dsi->cmdlen,
+                                              (char *)&dsi->data, &dsi->datalen);
                 child.flags &= ~CHILD_RUNNING;
 #ifdef FORCE_UIDGID
                /* bring everything back to old euid, egid */
@@ -426,12 +414,6 @@ void afp_over_dsi(AFPObj *obj)
                 err = AFPERR_NOOP;
             }
 
-#ifdef DEBUG1
-            if (obj->options.flags & OPTION_DEBUG ) {
-                printf( "(write) reply code: %d, %d\n", err, dsi->clientID);
-                bprint((char *) dsi->data, dsi->datalen);
-            }
-#endif
             if (!dsi_wrtreply(dsi, err)) {
                 LOG(log_error, logtype_afpd, "dsi_wrtreply: %s", strerror(errno) );
                 afp_dsi_die(EXITERR_CLNT);
@@ -439,7 +421,6 @@ void afp_over_dsi(AFPObj *obj)
             break;
 
         case DSIFUNC_ATTN: /* attention replies */
-            continue;
             break;
 
             /* error. this usually implies a mismatch of some kind
@@ -451,15 +432,7 @@ void afp_over_dsi(AFPObj *obj)
             dsi_writeflush(dsi);
             break;
         }
-#ifdef DEBUG1
-        if ( obj->options.flags & OPTION_DEBUG ) {
-#ifdef notdef
-            pdesc( stdout );
-#endif /* notdef */
-            of_pforkdesc( stdout );
-            fflush( stdout );
-        }
-#endif
+        pending_request(dsi);
     }
 
     /* error */