Created
February 26, 2018 06:42
-
-
Save recih/454f9ca4fc959df7678145f3a6630a34 to your computer and use it in GitHub Desktop.
rinetd patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 40fcb6d6794bb21ea16353c13a265454b5b43603 Mon Sep 17 00:00:00 2001 | |
From: pw_prg_fengbo <[email protected]> | |
Date: Mon, 26 Feb 2018 14:36:13 +0800 | |
Subject: [PATCH] add -f option | |
--- | |
rinetd.8 | 3 +++ | |
rinetd.c | 16 ++++++++++++---- | |
2 files changed, 15 insertions(+), 4 deletions(-) | |
diff --git a/rinetd.8 b/rinetd.8 | |
index 3b3f329..4b10591 100644 | |
--- a/rinetd.8 | |
+++ b/rinetd.8 | |
@@ -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. | |
diff --git a/rinetd.c b/rinetd.c | |
index 78027d3..74d24ca 100755 | |
--- a/rinetd.c | |
+++ b/rinetd.c | |
@@ -211,10 +211,12 @@ typedef struct _rinetd_options RinetdOptions; | |
struct _rinetd_options | |
{ | |
char *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; | |
@@ -1490,10 +1493,15 @@ int readArgs (int argc, | |
} | |
strcpy(options->conf_file, optarg); | |
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"); | |
-- | |
2.13.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment