From 4eeef5bb5b64cff590cc9dde973c78e87dfcc4f6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 12 Dec 2009 00:47:10 +0000 Subject: [PATCH] Allow remote connections from the command-line interface --- src/init.c | 5 ++--- src/init.h | 4 +++- src/main.c | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/init.c b/src/init.c index 5994ee8..5d54b2a 100644 --- a/src/init.c +++ b/src/init.c @@ -15,7 +15,6 @@ -#include #include #ifdef DEBUG # include @@ -39,7 +38,7 @@ struct _Init /* public */ /* functions */ /* init_new */ -Init * init_new(char const * profile) +Init * init_new(AppServerOptions options, char const * profile) { Init * init; @@ -53,7 +52,7 @@ Init * init_new(char const * profile) ? session_new("Init", profile, init->event) : NULL; /* FIXME ASO_LOCAL or ASO_REMOTE comes from the configuration file */ init->appserver = (init->event != NULL) - ? appserver_new_event("Init", ASO_REMOTE, init->event) : NULL; + ? appserver_new_event("Init", options, init->event) : NULL; /* FIXME handle signals (Event class?) */ /* error handling */ if(init->event == NULL || init->appserver == NULL) diff --git a/src/init.h b/src/init.h index f4e4d96..13cf21c 100644 --- a/src/init.h +++ b/src/init.h @@ -18,6 +18,8 @@ #ifndef INIT_INIT_H # define INIT_INIT_H +# include + /* Init */ /* types */ @@ -25,7 +27,7 @@ typedef struct _Init Init; /* functions */ -Init * init_new(char const * profile); +Init * init_new(AppServerOptions options, char const * profile); void init_delete(Init * init); /* AppInterface */ diff --git a/src/main.c b/src/main.c index fc11a02..e8f97d3 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,6 @@ -#include #include #include #include "init.h" @@ -27,14 +26,14 @@ /* private */ -static int _init(char const * profile); +static int _init(AppServerOptions options, char const * profile); static int _usage(void); /* functions */ /* private */ /* init */ -static int _init(char const * profile) +static int _init(AppServerOptions options, char const * profile) { int ret = 0; Init * init; @@ -42,7 +41,7 @@ static int _init(char const * profile) #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, profile); #endif - if((init = init_new(profile)) == NULL) + if((init = init_new(options, profile)) == NULL) return error_print(PACKAGE); for(;;) { @@ -59,8 +58,10 @@ static int _init(char const * profile) /* usage */ static int _usage(void) { - fputs("Usage: " PACKAGE " -s [-P profile]\n" + fputs("Usage: " PACKAGE " [-L|-R] -s [-P profile]\n" +" -L Only bind to the local machine\n" " -P Profile to load\n" +" -R Allow remote connections\n" " -s Force the single-user profile\n", stderr); return 1; } @@ -71,22 +72,29 @@ int main(int argc, char * argv[]) { int ret; int o; + AppServerOptions options = ASO_LOCAL; char const * profile = NULL; char * shell[] = { "/bin/sh", NULL }; - while((o = getopt(argc, argv, "P:s")) != -1) + while((o = getopt(argc, argv, "LRP:s")) != -1) switch(o) { + case 'L': + options = ASO_LOCAL; + break; case 'P': profile = optarg; break; + case 'R': + options = ASO_REMOTE; + break; case 's': profile = "single-user"; break; default: return _usage(); } - if((ret = _init(profile) != 0) && getpid() == 1) + if((ret = _init(options, profile) != 0) && getpid() == 1) { fputs(PACKAGE ": Spawning a shell\n", stderr); execve(shell[0], shell, NULL);