Add a -f flag to run in the foreground.

This patch is imported from the rinetd Debian package.
This commit is contained in:
Sam Hocevar 2016-01-10 21:31:08 +01:00
parent 13f2f7f854
commit 39e4d7a0e8
3 changed files with 18 additions and 4 deletions

View File

@ -189,6 +189,9 @@ logcommon
The -c command line option is used to specify an alternate
configuration file.
<p>
The -f command line option is used to run rinetd in the
foreground, without forking to the background.
<p>
The -h command line option produces a short help message.
<p>
The -v command line option displays the version number.

View File

@ -150,6 +150,9 @@ logcommon
The -c command line option is used to specify an alternate
configuration file.
.Pp
The -f command line option is used to run rinetd in the
foreground, without forking to the background.
.Pp
The -h command line option produces a short help message.
.Pp
The -v command line option displays the version number.

View File

@ -211,10 +211,12 @@ typedef struct _rinetd_options RinetdOptions;
struct _rinetd_options
{
char const *conf_file;
int foreground;
};
RinetdOptions options = {
"/etc/rinetd.conf"
"/etc/rinetd.conf",
0,
};
int readArgs (int argc,
@ -236,8 +238,8 @@ int main(int argc, char *argv[])
readArgs(argc, argv, &options);
#ifndef WIN32
#ifndef DEBUG
if (!fork()) {
if (!fork()) {
if (options.foreground || !fork()) {
if (options.foreground || !fork()) {
#endif /* DEBUG */
signal(SIGPIPE, plumber);
signal(SIGHUP, hup);
@ -1471,11 +1473,12 @@ int readArgs (int argc,
int option_index = 0;
static struct option long_options[] = {
{"conf-file", 1, 0, 'c'},
{"foreground", 0, 0, 'f'},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'v'},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "c:shv",
c = getopt_long (argc, argv, "c:fshv",
long_options, &option_index);
if (c == -1) {
break;
@ -1489,10 +1492,15 @@ int readArgs (int argc,
exit(1);
}
break;
case 'f':
options->foreground=1;
break;
case 'h':
printf("Usage: rinetd [OPTION]\n"
" -c, --conf-file FILE read configuration "
"from FILE\n"
" -f, --foreground do not run in the "
"background\n"
" -h, --help display this help\n"
" -v, --version display version "
"number\n\n");