Skip to content

Commit

Permalink
Switch from compile-time debug to run-time debug where applicable, Is…
Browse files Browse the repository at this point in the history
…sue #536

 - Remove the --enable-debug1 option
 - Refactor the afpd non-forking debug mode, and flip the afpd.conf option from -nodebug to -debug
 - Replace DEBUG macros with debug9 level logs
 - in papd and atalkd, use the runtime debug mode instead of compile time macro
  • Loading branch information
rdmark committed Dec 24, 2023
1 parent 8d0664a commit d0bca7e
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 170 deletions.
18 changes: 0 additions & 18 deletions configure.ac
Expand Up @@ -199,24 +199,6 @@ AC_ARG_ENABLE(ddp,
]
)

AC_MSG_CHECKING([whether to enable debug code])
AC_ARG_ENABLE(debug1,
[ --enable-debug1 enable debug code],[
if test "$enableval" != "no"; then
if test "$enableval" = "yes"; then
AC_DEFINE(DEBUG1, 1, [Define if debugging information should be included])
else
AC_DEFINE_UNQUOTED(DEBUG1, $enableval, [Define if debugging information should be included])
fi
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
],[
AC_MSG_RESULT([no])
]
)

AC_MSG_CHECKING([whether to enable verbose debug code])
AC_ARG_ENABLE(debug,
[ --enable-debug enable verbose debug code],[
Expand Down
4 changes: 2 additions & 2 deletions doc/manual/man/man5/afpd.conf.5.xml
Expand Up @@ -736,10 +736,10 @@
</varlistentry>

<varlistentry>
<term>-nodebug</term>
<term>-debug</term>

<listitem>
<para>Disables debugging.</para>
<para>Prevents afpd from forking, for debugging purposes.</para>
</listitem>
</varlistentry>

Expand Down
6 changes: 2 additions & 4 deletions doc/manual/man/man8/afpd.8.xml
Expand Up @@ -5,7 +5,7 @@

<manvolnum>8</manvolnum>

<refmiscinfo class="date">01 Mar 2023</refmiscinfo>
<refmiscinfo class="date">24 Dec 2023</refmiscinfo>

<refmiscinfo class="source">:NETATALK_VERSION:</refmiscinfo>
</refmeta>
Expand Down Expand Up @@ -89,9 +89,7 @@
<term>-d</term>

<listitem>
<para>Specifies that the daemon should not fork. If netatalk has
been configured with <emphasis>--enable-debug1</emphasis>, a trace
of all AFP commands will be written to stdout.</para>
<para>Prevents the daemon from forking, for debugging purposes.</para>
</listitem>
</varlistentry>

Expand Down
5 changes: 2 additions & 3 deletions doc/manual/man/man8/papd.8.xml
Expand Up @@ -5,7 +5,7 @@

<manvolnum>8</manvolnum>

<refmiscinfo class="date">01 Mar 2023</refmiscinfo>
<refmiscinfo class="date">24 Dec 2023</refmiscinfo>

<refmiscinfo class="source">:NETATALK_VERSION:</refmiscinfo>
</refmeta>
Expand Down Expand Up @@ -210,8 +210,7 @@
<term>-d</term>

<listitem>
<para>Do not fork or disassociate from the terminal. Write some
debugging information to stderr.</para>
<para>Do not fork or disassociate from the terminal.</para>
</listitem>
</varlistentry>

Expand Down
46 changes: 13 additions & 33 deletions etc/afpd/afp_asp.c
Expand Up @@ -212,9 +212,7 @@ void afp_over_asp(AFPObj *obj)
ASP asp;
struct sigaction action;
int func, reply = 0;
#ifdef DEBUG1
int ccnt = 0;
#endif

AFPobj = obj;
obj->exit = afp_asp_die;
Expand Down Expand Up @@ -306,22 +304,13 @@ void afp_over_asp(AFPObj *obj)
afp_asp_close(obj);
LOG(log_info, logtype_afpd, "done" );

#ifdef DEBUG1
if ( obj->options.flags & OPTION_DEBUG ) {
printf( "done\n" );
}
#endif
return;
break;

case ASPFUNC_CMD :
func = (u_char) asp->commands[0];
#ifdef DEBUG1
if ( obj->options.flags & OPTION_DEBUG ) {
printf("command: %d (%s)\n", func, AfpNum2name(func));
bprint( asp->commands, asp->cmdlen );
}
#endif
LOG(log_debug9, logtype_afpd, "command: %d (%s)\n", func, AfpNum2name(func));

if ( afp_switch[ func ] != NULL ) {
/*
* The function called from afp_switch is expected to
Expand All @@ -338,12 +327,9 @@ void afp_over_asp(AFPObj *obj)
asp->datalen = 0;
reply = AFPERR_NOOP;
}
#ifdef DEBUG1
if ( obj->options.flags & OPTION_DEBUG ) {
printf( "reply: %d, %d\n", reply, ccnt++ );
bprint( asp->data, asp->datalen );
}
#endif

LOG(log_debug9, logtype_afpd, "reply: %d, %d\n", reply, ccnt++ );

if ( asp_cmdreply( asp, reply ) < 0 ) {
LOG(log_error, logtype_afpd, "asp_cmdreply: %s", strerror(errno) );
afp_asp_die(EXITERR_CLNT);
Expand All @@ -352,12 +338,9 @@ void afp_over_asp(AFPObj *obj)

case ASPFUNC_WRITE :
func = (u_char) asp->commands[0];
#ifdef DEBUG1
if ( obj->options.flags & OPTION_DEBUG ) {
printf( "(write) command: %d\n", func );
bprint( asp->commands, asp->cmdlen );
}
#endif

LOG(log_debug9, logtype_afpd, "(write) command: %d\n", func );

if ( afp_switch[ func ] != NULL ) {
asp->datalen = ASP_DATASIZ;
reply = (*afp_switch[ func ])(obj,
Expand All @@ -368,12 +351,9 @@ void afp_over_asp(AFPObj *obj)
asp->datalen = 0;
reply = AFPERR_NOOP;
}
#ifdef DEBUG1
if ( obj->options.flags & OPTION_DEBUG ) {
printf( "(write) reply code: %d, %d\n", reply, ccnt++ );
bprint( asp->data, asp->datalen );
}
#endif

LOG(log_debug9, logtype_afpd, "(write) reply code: %d, %d\n", reply, ccnt++ );

if ( asp_wrtreply( asp, reply ) < 0 ) {
LOG(log_error, logtype_afpd, "asp_wrtreply: %s", strerror(errno) );
afp_asp_die(EXITERR_CLNT);
Expand All @@ -387,12 +367,12 @@ void afp_over_asp(AFPObj *obj)
LOG(log_info, logtype_afpd, "main: asp_getrequest: %d", reply );
break;
}
#ifdef DEBUG1

if ( obj->options.flags & OPTION_DEBUG ) {
of_pforkdesc( stdout );
fflush( stdout );
}
#endif

}
}

Expand Down
4 changes: 2 additions & 2 deletions etc/afpd/afp_options.c
Expand Up @@ -216,8 +216,8 @@ int afp_options_parseline(char *buf, struct afp_options *options)
options->server = opt;

/* parse toggles */
if (strstr(buf, " -nodebug"))
options->flags &= ~OPTION_DEBUG;
if (strstr(buf, " -debug"))
options->flags |= OPTION_DEBUG;
#ifdef USE_SRVLOC
if (strstr(buf, " -slp"))
options->flags &= ~OPTION_NOSLP;
Expand Down
14 changes: 3 additions & 11 deletions etc/afpd/desktop.c
Expand Up @@ -38,7 +38,6 @@
#include "desktop.h"
#include "mangle.h"


int afp_opendt(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbuflen)
{
struct vol *vol;
Expand Down Expand Up @@ -225,12 +224,7 @@ int afp_addicon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t
if ((asp_wrtcont(obj->handle, rbuf, &buflen) < 0) || buflen != bsize)
return( AFPERR_PARAM );

#ifdef DEBUG1
if (obj->options.flags & OPTION_DEBUG) {
printf("(write) len: %d\n", (unsigned long) buflen);
bprint(rbuf, buflen);
}
#endif
LOG(log_debug9, logtype_afpd, "(write) len: %d\n", buflen);

/*
* We're at the end of the file, add the headers, etc. */
Expand Down Expand Up @@ -577,9 +571,8 @@ char *mtoupath(const struct vol *vol, char *mpath, cnid_t did, int utf8)
return NULL;
}

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "mtoupath: '%s':'%s'", mpath, upath);
#endif /* DEBUG */

return( upath );
}

Expand Down Expand Up @@ -613,9 +606,8 @@ char *utompath(const struct vol *vol, char *upath, cnid_t id, int utf8)

m = mangle(vol, mpath, outlen, upath, id, flags);

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "utompath: '%s':'%s':'%2.2X'", upath, m, ntohl(id));
#endif /* DEBUG */

return(m);

utompath_error:
Expand Down
9 changes: 1 addition & 8 deletions etc/afpd/file.c
Expand Up @@ -857,9 +857,7 @@ int setfilparams(struct vol *vol,
ssize_t len;
char symbuf[MAXPATHLEN+1];

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "begin setfilparams:");
#endif /* DEBUG */

adp = of_ad(vol, path, &ad);
upath = path->u_name;
Expand Down Expand Up @@ -1090,9 +1088,8 @@ int setfilparams(struct vol *vol,
setdirparams(vol, &Cur_Path, bitmap, (char *)&newdate);
}

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "end setfilparams:");
#endif /* DEBUG */

return err;
}

Expand Down Expand Up @@ -1375,9 +1372,7 @@ static int copy_all(const int dfd, const void *buf,
{
ssize_t cc;

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "begin copy_all:");
#endif /* DEBUG */

while (buflen > 0) {
if ((cc = write(dfd, buf, buflen)) < 0) {
Expand All @@ -1391,9 +1386,7 @@ static int copy_all(const int dfd, const void *buf,
buflen -= cc;
}

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "end copy_all:");
#endif /* DEBUG */

return 0;
}
Expand Down
11 changes: 2 additions & 9 deletions etc/afpd/fork.c
Expand Up @@ -36,12 +36,6 @@
#include "desktop.h"
#include "volume.h"

#ifdef DEBUG1
#define Debug(a) ((a)->options.flags & OPTION_DEBUG)
#else
#define Debug(a) (0)
#endif

static int getforkparams(struct ofork *ofork, u_int16_t bitmap, char *buf, size_t *buflen)
{
struct path path;
Expand Down Expand Up @@ -942,7 +936,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si
/* due to the nature of afp packets, we have to exit if we get
an error. we can't do this with translation on. */
#ifdef WITH_SENDFILE
if (!(xlate || Debug(obj) )) {
if (!(xlate || obj->options.flags & OPTION_DEBUG)) {
int fd;

fd = ad_readfile_init(ofork->of_ad, eid, &offset, 0);
Expand Down Expand Up @@ -1265,12 +1259,11 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s
return( AFPERR_PARAM );
}

#ifdef DEBUG1
if (obj->options.flags & OPTION_DEBUG) {
printf("(write) len: %ld\n", (unsigned long) *rbuflen);
bprint(rbuf, *rbuflen);
}
#endif

if ((cc = write_file(ofork, eid, offset, rbuf, *rbuflen,
xlate)) < 0) {
*rbuflen = 0;
Expand Down
11 changes: 4 additions & 7 deletions etc/afpd/messages.c
Expand Up @@ -22,7 +22,6 @@

#include "misc.h"


#define MAXMESGSIZE 199

/* this is only used by afpd children, so it's okay. */
Expand Down Expand Up @@ -57,9 +56,7 @@ void readmessage(AFPObj *obj)

sprintf(filename, "%s/message.%d", SERVERTEXT, getpid());

#ifdef DEBUG
LOG(log_debug9, logtype_afpd, "Reading file %s ", filename);
#endif

message=fopen(filename, "r");
if (message==NULL) {
Expand Down Expand Up @@ -100,13 +97,13 @@ void readmessage(AFPObj *obj)
if (rc < 0) {
LOG(log_error, logtype_afpd, "Error deleting %s: %s", filename, strerror(rc));
}
#ifdef DEBUG

else {
LOG(log_debug9, logtype_afpd, "Deleted %s", filename);
LOG(log_debug9, logtype_afpd, "Deleted %s", filename);
}

LOG(log_debug9, logtype_afpd, "Set server message to \"%s\"", servermesg);
#endif
LOG(log_debug9, logtype_afpd, "Set server message to \"%s\"", servermesg);

}
free(filename);
#endif /* SERVERTEXT */
Expand Down
2 changes: 0 additions & 2 deletions etc/afpd/ofork.c
Expand Up @@ -60,7 +60,6 @@ static void of_unhash(struct ofork *of)
}
}

#ifdef DEBUG1
void of_pforkdesc( FILE *f)
{
int ofrefnum;
Expand All @@ -74,7 +73,6 @@ void of_pforkdesc( FILE *f)
}
}
}
#endif

int of_flush(const struct vol *vol)
{
Expand Down

0 comments on commit d0bca7e

Please sign in to comment.