*
* Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
* Copyright (c) 1990,1993 Regents of The University of Michigan.
*
* Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
* Copyright (c) 1990,1993 Regents of The University of Michigan.
#define CHILD_DIE (1 << 0)
#define CHILD_RUNNING (1 << 1)
#define CHILD_SLEEPING (1 << 2)
#define CHILD_DIE (1 << 0)
#define CHILD_RUNNING (1 << 1)
#define CHILD_SLEEPING (1 << 2)
- /* UAM had syslog control; afpd needs to reassert itself */
- set_processname("afpd");
- syslog_setup(log_debug, logtype_default, logoption_ndelay | logoption_pid, logfacility_daemon);
LOG(log_info, logtype_afpd, "%.2fKB read, %.2fKB written",
dsi->read_count/1024.0, dsi->write_count/1024.0);
dsi_close(dsi);
}
LOG(log_info, logtype_afpd, "%.2fKB read, %.2fKB written",
dsi->read_count/1024.0, dsi->write_count/1024.0);
dsi_close(dsi);
}
dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN);
afp_dsi_close(child.obj);
if (sig) /* if no signal, assume dieing because logins are disabled &
dsi_attention(child.obj->handle, AFPATTN_SHUTDOWN);
afp_dsi_close(child.obj);
if (sig) /* if no signal, assume dieing because logins are disabled &
LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
memset(&sv, 0, sizeof(sv));
sv.sa_handler = afp_dsi_die;
sigemptyset( &sv.sa_mask );
sigaddset(&sv.sa_mask, SIGHUP);
sigaddset(&sv.sa_mask, SIGTERM);
sv.sa_flags = SA_RESTART;
memset(&sv, 0, sizeof(sv));
sv.sa_handler = afp_dsi_die;
sigemptyset( &sv.sa_mask );
sigaddset(&sv.sa_mask, SIGHUP);
sigaddset(&sv.sa_mask, SIGTERM);
sv.sa_flags = SA_RESTART;
LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGHUP: %s", strerror(errno) );
+/* ---------------------------------
+ * SIGHUP reload configuration file
+ * FIXME here or we wait ?
+*/
+volatile int reload_request = 0;
+
+static void afp_dsi_reload(int sig _U_)
+{
+ reload_request = 1;
+}
+
+/* ---------------------- */
+ 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;
/* 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 { /* didn't receive a tickle. close connection */
LOG(log_error, logtype_afpd, "afp_alarm: child timed out");
} else { /* didn't receive a tickle. close connection */
LOG(log_error, logtype_afpd, "afp_alarm: child timed out");
-
-/*
- * 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)
- snprintf(fname, MAXPATHLEN-1, "%s/afpd-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);
+ }
obj->exit = afp_dsi_die;
obj->reply = (int (*)()) dsi_cmdreply;
obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention;
obj->exit = afp_dsi_die;
obj->reply = (int (*)()) dsi_cmdreply;
obj->attention = (int (*)(void *, AFPUserBytes)) dsi_attention;
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGTERM);
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGTERM);
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
action.sa_handler = afp_dsi_die;
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGHUP);
action.sa_handler = afp_dsi_die;
sigemptyset( &action.sa_mask );
sigaddset(&action.sa_mask, SIGALRM);
sigaddset(&action.sa_mask, SIGHUP);
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
}
#ifdef SERVERTEXT
/* Added for server message support */
action.sa_handler = afp_dsi_getmesg;
sigemptyset( &action.sa_mask );
}
#ifdef SERVERTEXT
/* Added for server message support */
action.sa_handler = afp_dsi_getmesg;
sigemptyset( &action.sa_mask );
- sigaddset(&action.sa_mask, SIGUSR2);
+ sigaddset(&action.sa_mask, SIGALRM);
+ sigaddset(&action.sa_mask, SIGTERM);
+ sigaddset(&action.sa_mask, SIGUSR1);
+ sigaddset(&action.sa_mask, SIGHUP);
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
- sigaddset(&action.sa_mask, SIGUSR1);
+ sigaddset(&action.sa_mask, SIGALRM);
+ sigaddset(&action.sa_mask, SIGHUP);
+ sigaddset(&action.sa_mask, SIGTERM);
+#ifdef SERVERTEXT
+ sigaddset(&action.sa_mask, SIGUSR2);
+#endif
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) );
/* tickle handler */
action.sa_handler = alarm_handler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGHUP);
sigaddset(&action.sa_mask, SIGTERM);
/* tickle handler */
action.sa_handler = alarm_handler;
sigemptyset(&action.sa_mask);
sigaddset(&action.sa_mask, SIGHUP);
sigaddset(&action.sa_mask, SIGTERM);
action.sa_flags = SA_RESTART;
if ((sigaction(SIGALRM, &action, NULL) < 0) ||
(setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) {
action.sa_flags = SA_RESTART;
if ((sigaction(SIGALRM, &action, NULL) < 0) ||
(setitimer(ITIMER_REAL, &dsi->timer, NULL) < 0)) {
/* get stuck here until the end */
while ((cmd = dsi_receive(dsi))) {
child.tickle = 0;
child.flags &= ~CHILD_SLEEPING;
dsi_sleep(dsi, 0); /* wake up */
/* get stuck here until the end */
while ((cmd = dsi_receive(dsi))) {
child.tickle = 0;
child.flags &= ~CHILD_SLEEPING;
dsi_sleep(dsi, 0); /* wake up */
- if (obj->options.flags & OPTION_DEBUG ) {
- printf("command: %d (%s)\n", function, AfpNum2name(function));
- bprint((char *) dsi->commands, dsi->cmdlen);
- }
/* send off an afp command. in a couple cases, we take advantage
* of the fact that we're a stream-based protocol. */
/* send off an afp command. in a couple cases, we take advantage
* of the fact that we're a stream-based protocol. */
- 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);
restore_uidgid ( &obj->uidgid );
#endif /* FORCE_UIDGID */
child.flags &= ~CHILD_RUNNING;
restore_uidgid ( &obj->uidgid );
#endif /* FORCE_UIDGID */
child.flags &= ~CHILD_RUNNING;
- if (obj->options.flags & OPTION_DEBUG ) {
- printf( "reply: %d, %d\n", err, dsi->clientID);
- bprint((char *) dsi->data, dsi->datalen);
- }
-
if (!dsi_cmdreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) );
if (!dsi_cmdreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_cmdreply(%d): %s", dsi->socket, strerror(errno) );
- if ( obj->options.flags & OPTION_DEBUG ) {
- printf("(write) command: %d, %d\n", function, dsi->cmdlen);
- bprint((char *) dsi->commands, dsi->cmdlen);
- }
-
if ( afp_switch[ function ] != NULL ) {
dsi->datalen = DSI_DATASIZ;
child.flags |= CHILD_RUNNING;
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 */
child.flags &= ~CHILD_RUNNING;
#ifdef FORCE_UIDGID
/* bring everything back to old euid, egid */
- if (obj->options.flags & OPTION_DEBUG ) {
- printf( "(write) reply code: %d, %d\n", err, dsi->clientID);
- bprint((char *) dsi->data, dsi->datalen);
- }
-
if (!dsi_wrtreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_wrtreply: %s", strerror(errno) );
if (!dsi_wrtreply(dsi, err)) {
LOG(log_error, logtype_afpd, "dsi_wrtreply: %s", strerror(errno) );