summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Kleine-Budde <mkl@pengutronix.de>2008-06-27 13:27:44 +0000
committerMarc Kleine-Budde <mkl@pengutronix.de>2008-06-27 13:27:44 +0000
commit5092c5da23b74d6b3fd1923e0f1255f02fb89961 (patch)
tree0aefa32fa9e138c7c290ccc11a667b0f5569793b
parent4aacbf94c001a4c080c3f17ec2203b2014acd47d (diff)
downloadurshd-5092c5da23b74d6b3fd1923e0f1255f02fb89961.tar.gz
urshd-5092c5da23b74d6b3fd1923e0f1255f02fb89961.tar.xz
* src/urshd.c:
add daemonisation
-rw-r--r--src/urshd.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/urshd.c b/src/urshd.c
index 7e71dac..7fb5840 100644
--- a/src/urshd.c
+++ b/src/urshd.c
@@ -83,7 +83,7 @@ static char rcsid[] =
#define PROG "urshd"
-#define OPTIONS "hnp:P:"
+#define OPTIONS "hnp:P:D"
#define USAGE \
"Usage: " PROG " [options]\n" \
@@ -95,7 +95,8 @@ static char rcsid[] =
" -p <num>\n" \
" --priority=<num> Set " PROG " priority to <num>\n\n" \
" -P <num>\n" \
-" --command-priority=<num> Set command priority to <num>\n\n"
+" --command-priority=<num> Set command priority to <num>\n\n" \
+" -D don't daemonize\n\n"
#define STDERR 1
#define SYSLOG 2
@@ -112,6 +113,7 @@ static int keepalive = 1;
static int sent_null;
static int priority;
static int cmd_priority;
+static int opt_daemon = 1;
static char username[20] = "USER=";
static char homedir[64] = "HOME=";
@@ -528,11 +530,14 @@ mainloop(char *port)
} else {
sp = getservbyname("shell", "tcp");
if (!sp) {
- fatal("tcp/shell: unknown service");
+ fatal("tcp/shell: unknown service (/etc/services or \"shell\" entry missing?)");
}
sn.sin_port = sp->s_port;
}
+ if (opt_daemon)
+ daemon(0, 0);
+
s = socket(AF_INET, SOCK_STREAM, 0);
if (s < 0) {
fatal("socket: %s", strerror(errno));
@@ -602,6 +607,11 @@ main(int argc, char *argv[])
case 'h':
usage(STDERR, NULL);
+ break;
+
+ case 'D':
+ opt_daemon = 0;
+ break;
default:
if (optopt == 0) {