[11507] Fixed problem with too later config read in recent added posix daemon support.

Restore read config _after_ option parsing in any cases.
This commit is contained in:
VladimirMangos 2011-05-18 19:27:13 +04:00
parent 945466934d
commit 6ed4dfe827
3 changed files with 79 additions and 77 deletions

View file

@ -87,14 +87,7 @@ extern int main(int argc, char **argv)
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v');
#ifndef WIN32 // need call before options for posix daemon
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#endif
char serviceDaemonMode = '\0';
int option;
while ((option = cmd_opts()) != EOF)
@ -108,24 +101,20 @@ extern int main(int argc, char **argv)
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
return 0;
case 's':
{
#ifdef WIN32
{
const char *mode = cmd_opts.opt_arg();
if (!strcmp(mode, "install"))
{
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
}
if (!strcmp(mode, "run"))
serviceDaemonMode = 'r';
#ifdef WIN32
else if (!strcmp(mode, "install"))
serviceDaemonMode = 'i';
else if (!strcmp(mode, "uninstall"))
{
if (WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
}
else if (!strcmp(mode, "run"))
WinServiceRun();
serviceDaemonMode = 'u';
#else
else if (!strcmp(mode, "stop"))
serviceDaemonMode = 's';
#endif
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
@ -134,22 +123,7 @@ extern int main(int argc, char **argv)
return 1;
}
break;
#else
const char *mode = cmd_opts.opt_arg();
if (!strcmp(mode, "run"))
startDaemon(120);
else if (!strcmp(mode, "stop"))
stopDaemon();
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#endif
}
break;
case ':':
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
usage(argv[0]);
@ -163,13 +137,40 @@ extern int main(int argc, char **argv)
}
}
#ifdef WIN32 // need call after options for windows service
#ifndef WIN32 // posix daemon commands need apply before config read
switch (serviceDaemonMode)
{
case 'r':
startDaemon();
break;
case 's':
stopDaemon();
break
}
#endif
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#ifdef WIN32 // windows service command need execute after config read
switch (serviceDaemonMode)
{
case 'i':
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
case 'u':
if (WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
case 'r':
WinServiceRun();
break;
}
#endif
sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );

View file

@ -96,17 +96,9 @@ extern int main(int argc, char **argv)
ACE_Get_Opt cmd_opts(argc, argv, options);
cmd_opts.long_option("version", 'v');
#ifndef WIN32 // need call before options for posix daemon
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#endif
char serviceDaemonMode = '\0';
int option;
while ((option = cmd_opts()) != EOF)
{
switch (option)
@ -120,36 +112,19 @@ extern int main(int argc, char **argv)
case 's':
{
#ifdef WIN32
const char *mode = cmd_opts.opt_arg();
if (!strcmp(mode, "install"))
{
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
}
else if (!strcmp(mode, "uninstall"))
{
if (WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
}
else if (!strcmp(mode, "run"))
WinServiceRun();
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
usage(argv[0]);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#else
const char *mode = cmd_opts.opt_arg();
if (!strcmp(mode, "run"))
startDaemon();
serviceDaemonMode = 'r';
#ifdef WIN32
else if (!strcmp(mode, "install"))
serviceDaemonMode = 'i';
else if (!strcmp(mode, "uninstall"))
serviceDaemonMode = 'u';
#else
else if (!strcmp(mode, "stop"))
stopDaemon();
serviceDaemonMode = 's';
#endif
else
{
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
@ -157,7 +132,6 @@ extern int main(int argc, char **argv)
Log::WaitBeforeContinueIfNeed();
return 1;
}
#endif
break;
}
case ':':
@ -173,13 +147,40 @@ extern int main(int argc, char **argv)
}
}
#ifdef WIN32 // need call after options for windows service
#ifndef WIN32 // posix daemon commands need apply before config read
switch (serviceDaemonMode)
{
case 'r':
startDaemon();
break;
case 's':
stopDaemon();
break
}
#endif
if (!sConfig.SetSource(cfg_file))
{
sLog.outError("Could not find configuration file %s.", cfg_file);
Log::WaitBeforeContinueIfNeed();
return 1;
}
#ifdef WIN32 // windows service command need execute after config read
switch (serviceDaemonMode)
{
case 'i':
if (WinServiceInstall())
sLog.outString("Installing service");
return 1;
case 'u':
if (WinServiceUninstall())
sLog.outString("Uninstalling service");
return 1;
case 'r':
WinServiceRun();
break;
}
#endif
sLog.Initialize();

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11506"
#define REVISION_NR "11507"
#endif // __REVISION_NR_H__