Singleton类在重新启动时失败

问题描述:






我正在写一个Windows服务。当我的机器运行时,当我启动

服务时,代码运行正常但是当机器重新启动时,它无法自动启动。代码

当它到达试图访问单个类的
的代码时会爆炸。这是代码。


void ClientLogging :: initClientErrorLog(InstallationInfo安装)

{


// next线路重启失败

string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


Logging :: Instance()。Initialize(" IseeCltLog");


Logging :: LogLevel severity =

Logging :: Instance()。 toSeverity(szLogLevel);


m_pFileLogAppender = new FileLogAppender(severity,logFile); //这个

行在重启时失败

if(false == Logging :: Instance()。addAppender(m_pFileLogAppender))

{

}


}


奇怪的是ClientLogging也是一个单例,第一个

被调用,这个工作正常。

这个叫做:


ClientLogging :: Instance()。initClientErrorLog (insta ll);


但是在这里出现了问题,就行了如上所示

以上


string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


代码刚终止。

我能做些什么来防止这种情况,任何编译指示。

这可能是因为我初始化静态变量。

我们将非常感谢您的帮助。

Enda


Hi,

I am writing a windows service. The code runs fine when I start the
service when my machine is running but
it fails to start automatically when the machine reboots. The code
bombs out when it reaches code that tries to access
a singleton class. This is the code.

void ClientLogging::initClientErrorLog(InstallationInfo install)
{

// next line fails on a reboot
string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

Logging::Instance().Initialize("IseeCltLog");

Logging::LogLevel severity =
Logging::Instance().toSeverity(szLogLevel);

m_pFileLogAppender = new FileLogAppender(severity, logFile); //this
line fails on reboot
if(false == Logging::Instance().addAppender(m_pFileLogAppender ))
{

}

}

The strange thing is ClientLogging is also a singleton, the first one
that is called, and this works fine.
This is called using:

ClientLogging::Instance().initClientErrorLog(insta ll);

But it is inside this that the problems arise, on the line as seen
above

string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

The code just terminates.
Is there anything I can do to prevent this, any pragma.
Could this be because I initialize static variables.
Your help would be greatly appreciated.
Enda


柯** **************@yahoo.co.uk 写道:

ke****************@yahoo.co.uk wrote:




我正在写一个Windows服务。当我的机器运行时,当我启动

服务时,代码运行正常但是当机器重新启动时,它无法自动启动。代码

当它到达试图访问单个类的
的代码时会爆炸。这是代码。


void ClientLogging :: initClientErrorLog(InstallationInfo安装)

{


// next线路重启失败

string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


Logging :: Instance()。Initialize(" IseeCltLog");


Logging :: LogLevel severity =

Logging :: Instance()。 toSeverity(szLogLevel);


m_pFileLogAppender = new FileLogAppender(severity,logFile); //这个

行在重启时失败

if(false == Logging :: Instance()。addAppender(m_pFileLogAppender))

{

}


}


奇怪的是ClientLogging也是一个单例,第一个

被调用,这个工作正常。

这个叫做:


ClientLogging :: Instance()。initClientErrorLog (insta ll);


但是在这里出现了问题,就行了如上所示

以上


string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


代码刚终止。


我能做些什么来防止这种情况,任何编译指示。

这可能是因为我初始化静态变量。


非常感谢您的帮助。


Enda
Hi,

I am writing a windows service. The code runs fine when I start the
service when my machine is running but
it fails to start automatically when the machine reboots. The code
bombs out when it reaches code that tries to access
a singleton class. This is the code.

void ClientLogging::initClientErrorLog(InstallationInfo install)
{

// next line fails on a reboot
string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

Logging::Instance().Initialize("IseeCltLog");

Logging::LogLevel severity =
Logging::Instance().toSeverity(szLogLevel);

m_pFileLogAppender = new FileLogAppender(severity, logFile); //this
line fails on reboot
if(false == Logging::Instance().addAppender(m_pFileLogAppender ))
{

}

}

The strange thing is ClientLogging is also a singleton, the first one
that is called, and this works fine.
This is called using:

ClientLogging::Instance().initClientErrorLog(insta ll);

But it is inside this that the problems arise, on the line as seen
above

string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

The code just terminates.
Is there anything I can do to prevent this, any pragma.
Could this be because I initialize static variables.
Your help would be greatly appreciated.
Enda



您的第二个标记失败涉及文件访问。我猜你的

第一次标记失败还涉及文件访问(也许读一个配置

文件?)


我只能想到一件事 - 一个安全问题:用户你的服务

正在启动,因为重新启动后的用户不同于你的时候

手动启动它,前者对

所需文件没有访问权限?


但我可能错了......


我觉得单身的东西是红鲱鱼。


Doug

Your second flagged failure involves file access. I''m guessing your
first flagged failure also involves file access (maybe reading a config
file?)

I can only think of one thing - a security issue: the user your service
is starting as after a reboot is not the same user as you are when you
start it manually, and the former doesn''t have access rights to the
required files?

But I''m probably wrong...

I think the singleton thing is a red herring.

Doug




< ke **************** @ yahoo.co.ukwrote in message

news:11 **** *****************@b68g2000cwa.googlegro ups.com ...

<ke****************@yahoo.co.ukwrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...

>




我正在写一个Windows服务。当我的机器运行时,当我启动

服务时,代码运行正常但是当机器重新启动时,它无法自动启动。代码

当它到达试图访问单个类的
的代码时会爆炸。这是代码。


void ClientLogging :: initClientErrorLog(InstallationInfo安装)

{


// next线路重启失败

string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


Logging :: Instance()。Initialize(" IseeCltLog");


Logging :: LogLevel severity =

Logging :: Instance()。 toSeverity(szLogLevel);


m_pFileLogAppender = new FileLogAppender(severity,logFile); //这个

行在重启时失败

if(false == Logging :: Instance()。addAppender(m_pFileLogAppender))

{

}


}


奇怪的是ClientLogging也是一个单例,第一个

被调用,这个工作正常。

这个叫做:


ClientLogging :: Instance()。initClientErrorLog (insta ll);


但是在这里出现了问题,就行了如上所示

以上


string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


代码刚终止。


我能做些什么来防止这种情况,任何编译指示。

这可能是因为我初始化静态变量。
>
Hi,

I am writing a windows service. The code runs fine when I start the
service when my machine is running but
it fails to start automatically when the machine reboots. The code
bombs out when it reaches code that tries to access
a singleton class. This is the code.

void ClientLogging::initClientErrorLog(InstallationInfo install)
{

// next line fails on a reboot
string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

Logging::Instance().Initialize("IseeCltLog");

Logging::LogLevel severity =
Logging::Instance().toSeverity(szLogLevel);

m_pFileLogAppender = new FileLogAppender(severity, logFile); //this
line fails on reboot
if(false == Logging::Instance().addAppender(m_pFileLogAppender ))
{

}

}

The strange thing is ClientLogging is also a singleton, the first one
that is called, and this works fine.
This is called using:

ClientLogging::Instance().initClientErrorLog(insta ll);

But it is inside this that the problems arise, on the line as seen
above

string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

The code just terminates.
Is there anything I can do to prevent this, any pragma.
Could this be because I initialize static variables.



我们无法从您显示的小代码中看出来。我怀疑

问题与你如何使用或配置服务有关(例如,

权限,如Doug建议的那样)。它也可能与静态变量初始化的顺序有关,但是你没有显示那些变量或者它们是如何初始化的那样。


我建议你在windows新闻组中询问任何与windows相关的问题

问题。


但是如果你认为这真的是一个C ++ _language_问题,你可以尝试暂时更改代码,以便你的函数不做任何事情

特定于Windows,看看如果你仍然得到相同的行为。然后发布

代码(涉及静态变量以及它们如何初始化)

这里我们可以帮助看看它是否是与语言相关的问题。


-Howard

We can''t tell from the little code you''ve shown. I''d suspect that the
problem has to do with how you''re using or configuring the service (e.g.,
permissions, as Doug suggests). It could also have to do with the order of
initialization of static variables, but you haven''t shown those variables or
how they''re initialized.

I''d suggest you ask in a windows newsgroup with any windows-related
questions.

But if you think this is really a C++ _language_ question, you could try to
temporarily change the code so that your functions don''t do anything
specific to Windows, and see if you still get the same behavior. Then post
the code (with the static variables involved and how they''re initialized)
here and we can help see if it''s a language-related issue.

-Howard


它也可能是服务依赖项。你的服务可能依赖于(比如说)RPC服务,但是如果你没有安装它,那么它将首先出现
并失败。当然,当您稍后手动启动时,其他相关服务已经运行了。

-

Phil Wilson [MVP Windows Installer]

----

< ke **************** @ yahoo.co.ukwrote留言

news:11 ********************* @ b68g2000cwa.googlegro ups.com ...
It could also be a service dependency thing. Your service could be dependent
on (say) the RPC service, but if you haven''t installed it that way it will
come up first and fail. Of course those other dependent services are
already running when you start yours manually later.
--
Phil Wilson [MVP Windows Installer]
----
<ke****************@yahoo.co.ukwrote in message
news:11*********************@b68g2000cwa.googlegro ups.com...

>




我正在写一个Windows服务。当我的机器运行时,当我启动

服务时,代码运行正常但是当机器重新启动时,它无法自动启动。代码

当它到达试图访问单个类的
的代码时会爆炸。这是代码。


void ClientLogging :: initClientErrorLog(InstallationInfo安装)

{


// next线路重启失败

string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


Logging :: Instance()。Initialize(" IseeCltLog");


Logging :: LogLevel severity =

Logging :: Instance()。 toSeverity(szLogLevel);


m_pFileLogAppender = new FileLogAppender(severity,logFile); //这个

行在重启时失败

if(false == Logging :: Instance()。addAppender(m_pFileLogAppender))

{

}


}


奇怪的是ClientLogging也是一个单例,第一个

被调用,这个工作正常。

这个叫做:


ClientLogging :: Instance()。initClientErrorLog (insta ll);


但是在这里出现了问题,就行了如上所示

以上


string szLogLevel =

ConfigManager :: Instance()。getConfigMgrValue(" LOG_L EVEL");


代码刚终止。


我能做些什么来防止这种情况,任何编译指示。

这可能是因为我初始化静态变量。


非常感谢您的帮助。


Enda
>
Hi,

I am writing a windows service. The code runs fine when I start the
service when my machine is running but
it fails to start automatically when the machine reboots. The code
bombs out when it reaches code that tries to access
a singleton class. This is the code.

void ClientLogging::initClientErrorLog(InstallationInfo install)
{

// next line fails on a reboot
string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

Logging::Instance().Initialize("IseeCltLog");

Logging::LogLevel severity =
Logging::Instance().toSeverity(szLogLevel);

m_pFileLogAppender = new FileLogAppender(severity, logFile); //this
line fails on reboot
if(false == Logging::Instance().addAppender(m_pFileLogAppender ))
{

}

}

The strange thing is ClientLogging is also a singleton, the first one
that is called, and this works fine.
This is called using:

ClientLogging::Instance().initClientErrorLog(insta ll);

But it is inside this that the problems arise, on the line as seen
above

string szLogLevel =
ConfigManager::Instance().getConfigMgrValue("LOG_L EVEL");

The code just terminates.
Is there anything I can do to prevent this, any pragma.
Could this be because I initialize static variables.
Your help would be greatly appreciated.
Enda