summaryrefslogtreecommitdiff
path: root/server/miav_server.cc
diff options
context:
space:
mode:
authordeva <deva>2006-07-25 16:35:32 +0000
committerdeva <deva>2006-07-25 16:35:32 +0000
commitbad686c6eba0d6afc39b8fcdd78f5069ec4d2cb8 (patch)
tree5af7bb7561ec08460503f6487341838898a78d38 /server/miav_server.cc
parentdffe8d4a8ce470d315639331bdc1f45f25244618 (diff)
Moved the ETC and PIXMAPS symbols to config.h.
Moved the ETC and PIXMAPS symbols to config.h. Moved the ETC and PIXMAPS symbols to config.h.
Diffstat (limited to 'server/miav_server.cc')
-rw-r--r--server/miav_server.cc66
1 files changed, 45 insertions, 21 deletions
diff --git a/server/miav_server.cc b/server/miav_server.cc
index b1dfcac..28c45b6 100644
--- a/server/miav_server.cc
+++ b/server/miav_server.cc
@@ -24,7 +24,8 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
+// For ETC
+#include "config.h"
#include "miav_server.h"
#include "miav_config.h"
@@ -36,6 +37,7 @@
#include "server.h"
#include "socket.h"
+#include "network.h"
#include <signal.h>
#include <errno.h>
@@ -56,24 +58,27 @@
static const char usage_str[] =
"Usage: %s [options]\n"
"Options:\n"
-" -c file Read configfile from 'file'\n"
-" -i Run in interactive mode (non-background mode)\n"
-" -h This message\n"
+" -c file Read configfile from 'file'\n"
+" -f Run in foreground mode (non-background mode)\n"
+" -u user Run as 'user' (overrides the configfile)\n"
+" -g group Run as 'group' (overrides the configfile)\n"
+" -h This message\n"
;
-static char *config_file = ETC"/miav.conf";
-/**
- * This function starts the MIaV server.
- */
int main(int argc, char *argv[])
{
+ char *config_file = ETC"/miav.conf";
+
int optc;
int lose = 0;
- bool interactive = false;
+ bool foreground = false;
+
+ char *user_opt = NULL;
+ char *group_opt = NULL;
// Parse the commandline
- while((optc = getopt(argc, argv, "c:ih")) != EOF) {
+ while((optc = getopt(argc, argv, "c:fhu:g:")) != EOF) {
switch(optc) {
case 'c':
config_file = strdup(optarg);
@@ -82,8 +87,22 @@ int main(int argc, char *argv[])
return 1;
}
break;
- case 'i':
- interactive = true;
+ case 'u':
+ user_opt = strdup(optarg);
+ if(!user_opt) {
+ fprintf(stderr, "Fatal: out of memory\n");
+ return 1;
+ }
+ break;
+ case 'g':
+ group_opt = strdup(optarg);
+ if(!group_opt) {
+ fprintf(stderr, "Fatal: out of memory\n");
+ return 1;
+ }
+ break;
+ case 'f':
+ foreground = true;
break;
case 'h':
fprintf(stdout, usage_str, argv[0]);
@@ -107,39 +126,44 @@ int main(int argc, char *argv[])
InfoConsole info;
MIaV::initInfo(&info);
- string *user = cfg.readString("server_user");
- string *group = cfg.readString("server_group");
-
+ string user;
+ if(user_opt) user = string(user_opt);
+ else user = *cfg.readString("server_user");
+
+ string group;
+ if(group_opt) group = string(group_opt);
+ else group = *cfg.readString("server_group");
+
// Fetch user id
int uid = -1;
struct passwd *p = getpwent();
while(p) {
- if(strcmp(p->pw_name, user->c_str()) == 0) uid = p->pw_uid;
+ if(strcmp(p->pw_name, user.c_str()) == 0) uid = p->pw_uid;
p = getpwent();
}
if(uid == -1) {
- fprintf(stderr, "Could not find user \"%s\" in /etc/passwd file.\n", user->c_str());
+ fprintf(stderr, "Could not find user \"%s\" in /etc/passwd file.\n", user.c_str());
}
// Fetch group id
int gid = -1;
struct group *g = getgrent();
while(g) {
- if(strcmp(g->gr_name, group->c_str()) == 0) gid = g->gr_gid;
+ if(strcmp(g->gr_name, group.c_str()) == 0) gid = g->gr_gid;
g = getgrent();
}
if(gid == -1) {
- fprintf(stderr, "Could not find group \"%s\" in /etc/group file.\n", group->c_str());
+ fprintf(stderr, "Could not find group \"%s\" in /etc/group file.\n", group.c_str());
}
- if(!interactive) {
+ if(!foreground) {
fprintf(stderr, "Entering daemon mode\n");
daemon(0,0);
signal (SIGTERM, SIG_IGN);
signal (SIGINT, SIG_IGN);
signal (SIGHUP, SIG_IGN);
} else {
- fprintf(stderr, "Running interactive\n");
+ fprintf(stderr, "Running in foreground mode.\n");
}
int port = MIaV::config->readInt("server_port");