Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions popa3d.8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ popa3d \- Post Office Protocol (POP3) server
.SH SYNOPSIS
.B popa3d
.RB [ -D ]
.RB [ -F ]
.RB [ -V ]
.SH DESCRIPTION
.B popa3d
Expand Down Expand Up @@ -44,6 +45,13 @@ In this mode
also does quite a few checks to significantly reduce the impact of
connection flood attacks.
.TP
.B -F
Foreground server mode.
Like
.B -D
but staying in the foreground rather than becoming a daemon.
This supports improved service integration with init systems.
.TP
.B -V
Print version information and exit.
.SH COMMANDS
Expand Down
29 changes: 17 additions & 12 deletions standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ static void check_access(int sock)
#endif

#if POP_OPTIONS
int do_standalone(void)
int do_standalone(int foreground)
{
#else
int main(void)
#endif
{
int foreground = 0;
#endif
int true = 1;
int sock, new;
struct sockaddr_in addr;
Expand Down Expand Up @@ -137,20 +139,23 @@ int main(void)
return log_error("listen");

chdir("/");
setsid();

switch (fork()) {
case -1:
return log_error("fork");
if (!foreground) {
setsid();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can reasonably minimize the code differences vs. LKRG logger.c here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get why the first (unconditional) of the two setsid() calls was there in both tools. So it's possible I was wrong to make them conditional on not being in foreground mode.


case 0:
break;
switch (fork()) {
case -1:
return log_error("fork");

default:
return 0;
}
case 0:
break;

setsid();
default:
return 0;
}

setsid();
}

#if defined(_SC_CLK_TCK) || !defined(CLK_TCK)
min_delay = MIN_DELAY * sysconf(_SC_CLK_TCK);
Expand Down
12 changes: 8 additions & 4 deletions startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern char popa3d_version[];
extern char popa3d_date[];

/* standalone.c */
extern int do_standalone(void);
extern int do_standalone(int foreground);

/* pop_root.c */
extern int do_pop_startup(void);
Expand All @@ -30,7 +30,7 @@ static char *progname;

static void usage(void)
{
fprintf(stderr, "Usage: %s [-D] [-V]\n", progname);
fprintf(stderr, "Usage: %s [-D] [-F] [-V]\n", progname);
exit(1);
}

Expand All @@ -44,14 +44,18 @@ int main(int argc, char **argv)
{
int c;
int standalone = 0;
int foreground = 0;

#ifndef HAVE_PROGNAME
if (!(progname = argv[0]))
progname = POP_SERVER;
#endif

while ((c = getopt(argc, argv, "DV")) != -1) {
while ((c = getopt(argc, argv, "DFV")) != -1) {
switch (c) {
case 'F':
foreground++;
/* fallthrough */
case 'D':
standalone++;
break;
Expand All @@ -68,7 +72,7 @@ int main(int argc, char **argv)
usage();

if (standalone)
return do_standalone();
return do_standalone(foreground);

if (do_pop_startup()) return 1;
return do_pop_session();
Expand Down