From 23f887d0168697eae11d1674804581ca12e3809c Mon Sep 17 00:00:00 2001 From: jmarcus Date: Fri, 3 May 2002 22:51:32 +0000 Subject: [PATCH] * Allow afpd debugging to be enabled at runtime by sending the afpd process a SIGUSR1. stdout will be redirected to a temp file. * Allow SLP to be disabled per afpd process by adding a new -noslp flag to afpd.conf * Update documentation accordingly. Submitted by: Glenn Trewitt --- NEWS | 7 +++ config/afpd.conf.tmpl | 2 + etc/afpd/afp_config.c | 105 +++++++++++++++++++++----------------- etc/afpd/afp_dsi.c | 29 ++++++++++- etc/afpd/afp_options.c | 6 ++- etc/afpd/globals.h | 3 +- man/man5/afpd.conf.5.tmpl | 8 ++- man/man8/afpd.8.tmpl | 51 ++++++++++++++++++ 8 files changed, 161 insertions(+), 50 deletions(-) diff --git a/NEWS b/NEWS index d7e08b7d..dc6be34c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +Changes from 1.5.3 +================== + +* NEW: Add the ability to enable debugging at runtime by sending afpd a + SIGUSR1. +* NEW: Add a -noslp option to disable SLP per afpd instance. + Changes from 1.5.2 ================== diff --git a/config/afpd.conf.tmpl b/config/afpd.conf.tmpl index 7c131381..7a2b19ae 100644 --- a/config/afpd.conf.tmpl +++ b/config/afpd.conf.tmpl @@ -49,6 +49,8 @@ # if you don't want the proxy server to act as # a ddp server as well, set -uamlist to an # empty string. +# -noslp Don't register this server with the Service +# Location Protocol. # # # Authentication Methods: diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index e5f1f633..6842f54b 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -1,5 +1,5 @@ /* - * $Id: afp_config.c,v 1.19 2002-04-02 02:41:40 sibaz Exp $ + * $Id: afp_config.c,v 1.20 2002-05-03 22:51:33 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * All Rights Reserved. See COPYRIGHT. @@ -107,6 +107,11 @@ static void dsi_cleanup(const AFPConfig *config) SLPError err; SLPError callbackerr; SLPHandle hslp; + + /* Do nothing if we didn't register. */ + if (srvloc_url[0] == '\0') + return; + err = SLPOpen("en", SLP_FALSE, &hslp); if (err != SLP_OK) { LOG(log_error, logtype_afpd, "dsi_cleanup: Error opening SRVLOC handle"); @@ -309,54 +314,62 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options, } #ifdef USE_SRVLOC - err = SLPOpen("en", SLP_FALSE, &hslp); - if (err != SLP_OK) { - LOG(log_error, logtype_afpd, "DSIConfigInit: Error opening SRVLOC handle"); - goto srvloc_reg_err; - } - - /* XXX We don't want to tack on the port number if we don't have to. Why? - * Well, this seems to break MacOS < 10. If the user _really_ wants to - * use a non-default port, they can, but be aware, this server might not - * show up int the Network Browser. */ - afpovertcp = getservbyname("afpovertcp", "tcp"); + srvloc_url[0] = '\0'; /* Mark that we haven't registered. */ + if (!(options->flags & OPTION_NOSLP)) { + err = SLPOpen("en", SLP_FALSE, &hslp); + if (err != SLP_OK) { + LOG(log_error, logtype_afpd, "DSIConfigInit: Error opening SRVLOC handle"); + goto srvloc_reg_err; + } + + /* XXX We don't want to tack on the port number if we don't have to. + * Why? + * Well, this seems to break MacOS < 10. If the user _really_ wants to + * use a non-default port, they can, but be aware, this server might + * not show up int the Network Browser. + */ + afpovertcp = getservbyname("afpovertcp", "tcp"); srvloc_hostname = (options->server ? options->server : options->hostname); - if (afpovertcp != NULL) { - afp_port = afpovertcp->s_port; - } - if (strlen(srvloc_hostname) > (sizeof(srvloc_url) - strlen(inet_ntoa(dsi->server.sin_addr)) - 21)) { - LOG(log_error, logtype_afpd, "DSIConfigInit: Hostname is too long for SRVLOC"); - goto srvloc_reg_err; - } - if (dsi->server.sin_port == afp_port) { - sprintf(srvloc_url, "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), srvloc_hostname); - } - else { - sprintf(srvloc_url, "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), srvloc_hostname); - } - - err = SLPReg(hslp, - srvloc_url, - SLP_LIFETIME_MAXIMUM, - "", - "", - SLP_TRUE, - SRVLOC_callback, - &callbackerr); - if (err != SLP_OK) { - LOG(log_error, logtype_afpd, "DSIConfigInit: Error registering %s with SRVLOC", srvloc_url); - goto srvloc_reg_err; - } - - if (callbackerr != SLP_OK) { - LOG(log_error, logtype_afpd, "DSIConfigInit: Error in callback trying to register %s with SRVLOC", srvloc_url); - goto srvloc_reg_err; - } - - LOG(log_info, logtype_afpd, "Sucessfully registered %s with SRVLOC", srvloc_url); + if (afpovertcp != NULL) { + afp_port = afpovertcp->s_port; + } + if (strlen(srvloc_hostname) > (sizeof(srvloc_url) - strlen(inet_ntoa(dsi->server.sin_addr)) - 21)) { + LOG(log_error, logtype_afpd, "DSIConfigInit: Hostname is too long for SRVLOC"); + srvloc_url[0] = '\0'; + goto srvloc_reg_err; + } + if (dsi->server.sin_port == afp_port) { + sprintf(srvloc_url, "afp://%s/?NAME=%s", inet_ntoa(dsi->server.sin_addr), srvloc_hostname); + } + else { + sprintf(srvloc_url, "afp://%s:%d/?NAME=%s", inet_ntoa(dsi->server.sin_addr), ntohs(dsi->server.sin_port), srvloc_hostname); + } + + err = SLPReg(hslp, + srvloc_url, + SLP_LIFETIME_MAXIMUM, + "", + "", + SLP_TRUE, + SRVLOC_callback, + &callbackerr); + if (err != SLP_OK) { + LOG(log_error, logtype_afpd, "DSIConfigInit: Error registering %s with SRVLOC", srvloc_url); + srvloc_url[0] = '\0'; + goto srvloc_reg_err; + } + + if (callbackerr != SLP_OK) { + LOG(log_error, logtype_afpd, "DSIConfigInit: Error in callback trying to register %s with SRVLOC", srvloc_url); + srvloc_url[0] = '\0'; + goto srvloc_reg_err; + } + + LOG(log_info, logtype_afpd, "Sucessfully registered %s with SRVLOC", srvloc_url); srvloc_reg_err: - SLPClose(hslp); + SLPClose(hslp); + } #endif /* USE_SRVLOC */ diff --git a/etc/afpd/afp_dsi.c b/etc/afpd/afp_dsi.c index 5c6ef680..97f3d312 100644 --- a/etc/afpd/afp_dsi.c +++ b/etc/afpd/afp_dsi.c @@ -1,5 +1,5 @@ /* - * $Id: afp_dsi.c,v 1.20 2002-03-24 01:23:40 sibaz Exp $ + * $Id: afp_dsi.c,v 1.21 2002-05-03 22:51:33 jmarcus Exp $ * * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -134,6 +134,23 @@ static void alarm_handler() } } + +/* + * Signal handler for SIGUSR1 - set the debug flag and + * redirect stdout to /afpd-debug-. + */ +void afp_set_debug (int sig) +{ + char fname[MAXPATHLEN]; + + snprintf(fname, MAXPATHLEN-1, "%safpd-debug-%d", P_tmpdir, getpid()); + freopen(fname, "w", stdout); + child.obj->options.flags |= OPTION_DEBUG; + + return; +} + + /* afp over dsi. this never returns. */ void afp_over_dsi(AFPObj *obj) { @@ -183,6 +200,16 @@ void afp_over_dsi(AFPObj *obj) } #endif /* SERVERTEXT */ + /* SIGUSR1 - set "debug" flag on this process. */ + action.sa_handler = afp_set_debug; + sigemptyset( &action.sa_mask ); + sigaddset(&action.sa_mask, SIGUSR1); + action.sa_flags = SA_RESTART; + if ( sigaction( SIGUSR1, &action, 0) < 0 ) { + LOG(log_error, logtype_afpd, "afp_over_dsi: sigaction: %s", strerror(errno) ); + afp_dsi_die(1); + } + /* tickle handler */ action.sa_handler = alarm_handler; sigemptyset(&action.sa_mask); diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index 36e7c35f..0bc77f35 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -1,5 +1,5 @@ /* - * $Id: afp_options.c,v 1.23 2002-04-02 02:45:28 sibaz Exp $ + * $Id: afp_options.c,v 1.24 2002-05-03 22:51:34 jmarcus Exp $ * * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) * Copyright (c) 1990,1993 Regents of The University of Michigan. @@ -169,6 +169,10 @@ int afp_options_parseline(char *buf, struct afp_options *options) /* parse toggles */ if (strstr(buf, " -nodebug")) options->flags &= ~OPTION_DEBUG; +#ifdef USE_SRVLOC + if (strstr(buf, " -noslp")) + options->flags |= OPTION_NOSLP; +#endif /* USE_SRVLOC */ if (strstr(buf, " -nouservolfirst")) options->flags &= ~OPTION_USERVOLFIRST; diff --git a/etc/afpd/globals.h b/etc/afpd/globals.h index 3afcff9d..173930df 100644 --- a/etc/afpd/globals.h +++ b/etc/afpd/globals.h @@ -1,5 +1,5 @@ /* - * $Id: globals.h,v 1.11 2002-03-16 20:38:09 jmarcus Exp $ + * $Id: globals.h,v 1.12 2002-05-03 22:51:34 jmarcus Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -36,6 +36,7 @@ #define OPTION_NOUSERVOL (1 << 2) #define OPTION_PROXY (1 << 3) #define OPTION_CUSTOMICON (1 << 4) +#define OPTION_NOSLP (1 << 5) /* a couple of these options could get stuck in unions to save * space. */ diff --git a/man/man5/afpd.conf.5.tmpl b/man/man5/afpd.conf.5.tmpl index 18a2aa89..ce20135a 100644 --- a/man/man5/afpd.conf.5.tmpl +++ b/man/man5/afpd.conf.5.tmpl @@ -1,4 +1,4 @@ -.\" $Id: afpd.conf.5.tmpl,v 1.2 2001-06-26 23:58:32 srittau Exp $ +.\" $Id: afpd.conf.5.tmpl,v 1.3 2002-05-03 22:51:34 jmarcus Exp $ .TH afpd.conf 5 "28 September 2000" "netatalk 1.5" .UC 4 .SH NAME @@ -164,6 +164,12 @@ This specifoes the DSI server quantum. The minimum value is 1 MB. The maximum value is 0xFFFFFFFFF. If you specify a value that is out of range, the default value will be set (which is the minimum). +.TP +.B -noslp +Do not register this server using the Service Location Protocol (if SLP +support was compiled in). This is useful if you are running multiple +servers and want one to be hidden, perhaps because it is advertised elsewhere. + .TP .I Miscellaneous Options diff --git a/man/man8/afpd.8.tmpl b/man/man8/afpd.8.tmpl index be235032..8fb097df 100644 --- a/man/man8/afpd.8.tmpl +++ b/man/man8/afpd.8.tmpl @@ -246,6 +246,51 @@ parses the files with either end of line character. .LP Unix filenames that are longer than 31 characters are inaccessible from the Macintosh. + +.SH SIGNALS +Signals that are sent to the main +.B afpd +process are propagated to the children, so all will be affected. +.TP 13 +.B SIGHUP +The +.B afpd +process will send the message "The server is going down for maintenance." +to the client and shut itself down in 5 minutes. New connections are not +allowed. If this is sent to a child +.BR afpd , +the other children are not affected. However, the main process will still +exit, disabling all new connections. +.TP 13 +.B SIGUSR1 +If the +.B --with-message-dir +configure option was used, the +.B afpd +process will set the +.B debug +option and redirect the messages to +.RI /var/tmp/afpd-debug- pid . +This should only be sent to a child +.BR afpd . +.B Warning: +If the +.B --with-message-dir +option was not used, this will kill the +.B afpd +process. + +.TP 13 +.B SIGUSR2 +The +.B afpd +process will look in the +.I msg +directory for a file named +.RI message. pid . +For each one found, a the contents will be sent as a message to the +associated AFP client. The file is removed after the message is sent. + .SH FILES .TP 20 .B :ETCDIR:/AppleVolumes.default @@ -256,6 +301,12 @@ list of volumes to offer all users .TP 20 .B ~/AppleVolumes user's list of volumes to mount +.TP 20 +.BI :ETCDIR:/msg/message. pid +contains messages to be sent to users. +.TP 20 +.BI /var/tmp/afpd-debug- pid +contains debug output, if triggered. .SH BUGS A few calls from the AFP specification are not implemented, because the Macintosh does not use them. -- 2.39.2