. Added --accf instead of compile-time NO_ACCEPTFILTER.

. Fixed const issues in dlent_cmp().
. Fixed uninitialized from/to warning.
This commit is contained in:
Emil Mikulic 2003-11-29 07:36:01 +00:00
parent 36f027c8c8
commit b175db347d

View File

@ -32,7 +32,6 @@ static const char rcsid[] =
/* /*
* Note: Solaris users: link with -lxnet * Note: Solaris users: link with -lxnet
* Note: FreeBSD users: -DNO_ACCEPTFILTER to turn off acceptfilter
*/ */
#ifdef __linux #ifdef __linux
@ -257,7 +256,7 @@ static int sockin = -1; /* socket to accept connections from */
static char *wwwroot = NULL; /* a path name */ static char *wwwroot = NULL; /* a path name */
static char *logfile_name = NULL; /* NULL = no logging */ static char *logfile_name = NULL; /* NULL = no logging */
static FILE *logfile = NULL; static FILE *logfile = NULL;
static int want_chroot = 0; static int want_chroot = 0, want_accf = 0;
#define INVALID_UID ((uid_t) -1) #define INVALID_UID ((uid_t) -1)
#define INVALID_GID ((gid_t) -1) #define INVALID_GID ((gid_t) -1)
@ -461,15 +460,20 @@ static void nonblock_socket(const int sock)
*/ */
static void acceptfilter_socket(const int sock) static void acceptfilter_socket(const int sock)
{ {
#if defined(__FreeBSD__) && !defined(NO_ACCEPTFILTER) if (want_accf)
struct accept_filter_arg filt = {"httpready", ""}; {
if (setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER, #if defined(__FreeBSD__)
&filt, sizeof(filt)) == -1) struct accept_filter_arg filt = {"httpready", ""};
fprintf(stderr, "cannot enable acceptfilter: %s\n", if (setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER,
strerror(errno)); &filt, sizeof(filt)) == -1)
else fprintf(stderr, "cannot enable acceptfilter: %s\n",
printf("enabled acceptfilter\n"); strerror(errno));
else
printf("enabled acceptfilter\n");
#else
printf("this platform doesn't support acceptfilter\n");
#endif #endif
}
} }
@ -924,6 +928,11 @@ static void usage(void)
"\n" "\n"
"\t--uid uid, --gid gid\n" "\t--uid uid, --gid gid\n"
"\t\tDrops privileges to given uid:gid after initialization.\n" "\t\tDrops privileges to given uid:gid after initialization.\n"
#ifdef __FreeBSD__
"\n"
"\t--accf\n"
"\t\tUse acceptfilter.\n"
#endif
"\n", "\n",
bindport, index_name); bindport, index_name);
} }
@ -1037,6 +1046,10 @@ static void parse_commandline(const int argc, char *argv[])
if (g == NULL) errx(1, "no such gid: `%s'", argv[i]); if (g == NULL) errx(1, "no such gid: `%s'", argv[i]);
drop_gid = g->gr_gid; drop_gid = g->gr_gid;
} }
else if (strcmp(argv[i], "--accf") == 0)
{
want_accf = 1;
}
else else
errx(1, "unknown argument `%s'", argv[i]); errx(1, "unknown argument `%s'", argv[i]);
} }
@ -1545,8 +1558,8 @@ struct dlent
static int dlent_cmp(const void *a, const void *b) static int dlent_cmp(const void *a, const void *b)
{ {
return strcmp( (*(const struct dlent **)a)->name, return strcmp( (*((const struct dlent * const *)a))->name,
(*(const struct dlent **)b)->name ); (*((const struct dlent * const *)b))->name );
} }
static ssize_t make_sorted_dirlist(const char *path, struct dlent ***output) static ssize_t make_sorted_dirlist(const char *path, struct dlent ***output)
@ -1588,7 +1601,7 @@ static ssize_t make_sorted_dirlist(const char *path, struct dlent ***output)
entries++; entries++;
} }
(void)closedir(dir); /* FIXME: not checking return -1 */ (void)closedir(dir); /* can't error out if opendir() succeeded */
safefree(currname); safefree(currname);
qsort(list, entries, sizeof(struct dlent*), dlent_cmp); qsort(list, entries, sizeof(struct dlent*), dlent_cmp);
@ -1826,6 +1839,7 @@ static void process_get(struct connection *conn)
/* check for wrapping */ /* check for wrapping */
if (from < 0 || from > to) from = 0; if (from < 0 || from > to) from = 0;
} }
else errx(1, "internal error - from/to mismatch");
conn->reply_start = from; conn->reply_start = from;
conn->reply_length = to - from + 1; conn->reply_length = to - from + 1;