+ DSI *dsi = (DSI *)AFPobj->handle;
+
+ dsi->msg_request = 1;
+ if (dsi_attention(AFPobj->handle, AFPATTN_MESG | AFPATTN_TIME(5)) < 0)
+ dsi->msg_request = 2;
+}
+
+static void alarm_handler(int sig _U_)
+{
+ int err;
+ DSI *dsi = (DSI *)AFPobj->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 ((dsi->flags & DSI_DATA)) {
+ dsi->flags &= ~DSI_DATA;
+ return;
+ }
+
+ dsi->tickle++;
+ LOG(log_maxdebug, logtype_afpd, "alarm: tickles: %u, flags: %s|%s|%s|%s|%s|%s|%s|%s|%s",
+ dsi->tickle,
+ (dsi->flags & DSI_DATA) ? "DSI_DATA" : "-",
+ (dsi->flags & DSI_RUNNING) ? "DSI_RUNNING" : "-",
+ (dsi->flags & DSI_SLEEPING) ? "DSI_SLEEPING" : "-",
+ (dsi->flags & DSI_EXTSLEEP) ? "DSI_EXTSLEEP" : "-",
+ (dsi->flags & DSI_DISCONNECTED) ? "DSI_DISCONNECTED" : "-",
+ (dsi->flags & DSI_DIE) ? "DSI_DIE" : "-",
+ (dsi->flags & DSI_NOREPLY) ? "DSI_NOREPLY" : "-",
+ (dsi->flags & DSI_RECONSOCKET) ? "DSI_RECONSOCKET" : "-",
+ (dsi->flags & DSI_RECONINPROG) ? "DSI_RECONINPROG" : "-");
+
+ if (dsi->flags & DSI_SLEEPING) {
+ if (dsi->tickle > AFPobj->options.sleep) {
+ LOG(log_note, logtype_afpd, "afp_alarm: sleep time ended");
+ afp_dsi_die(EXITERR_CLNT);
+ }
+ return;
+ }
+
+ if (dsi->flags & DSI_DISCONNECTED) {
+ if (geteuid() == 0) {
+ LOG(log_note, logtype_afpd, "afp_alarm: unauthenticated user, connection problem");
+ afp_dsi_die(EXITERR_CLNT);
+ }
+ if (dsi->tickle > AFPobj->options.disconnected) {
+ LOG(log_error, logtype_afpd, "afp_alarm: reconnect timer expired, goodbye");
+ afp_dsi_die(EXITERR_CLNT);
+ }
+ return;
+ }
+
+ /* if we're in the midst of processing something, don't die. */
+ if ( !(dsi->flags & DSI_RUNNING) && (dsi->tickle >= AFPobj->options.timeout)) {
+ LOG(log_error, logtype_afpd, "afp_alarm: child timed out, entering disconnected state");
+ if (dsi_disconnect(dsi) != 0)
+ afp_dsi_die(EXITERR_CLNT);
+ return;
+ }
+
+ if ((err = pollvoltime(AFPobj)) == 0)
+ LOG(log_debug, logtype_afpd, "afp_alarm: sending DSI tickle");
+ err = dsi_tickle(AFPobj->handle);
+ if (err <= 0) {
+ if (geteuid() == 0) {
+ LOG(log_note, logtype_afpd, "afp_alarm: unauthenticated user, connection problem");
+ afp_dsi_die(EXITERR_CLNT);
+ }
+ LOG(log_error, logtype_afpd, "afp_alarm: connection problem, entering disconnected state");
+ if (dsi_disconnect(dsi) != 0)
+ afp_dsi_die(EXITERR_CLNT);