Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
d9369130
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d9369130
编写于
11月 12, 2015
作者:
E
Enrico Giordani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Code cleanup] Fixed tabs.
上级
606bc94f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
123 deletion
+123
-123
src/Win32_Interop/Win32_CommandLine.cpp
src/Win32_Interop/Win32_CommandLine.cpp
+3
-3
src/Win32_Interop/Win32_EventLog.cpp
src/Win32_Interop/Win32_EventLog.cpp
+107
-107
src/Win32_Interop/Win32_EventLog.h
src/Win32_Interop/Win32_EventLog.h
+13
-13
未找到文件。
src/Win32_Interop/Win32_CommandLine.cpp
浏览文件 @
d9369130
...
...
@@ -290,9 +290,9 @@ public:
{
"current-epoch"
,
&
fp1
},
// sentinel current-epoch <epoch>
{
"leader-epoch"
,
&
fp2
},
// sentinel leader-epoch [name] [epoch]
{
"known-slave"
,
&
fp3
},
// sentinel known-slave <name> <ip> <port>
{
"known-sentinel"
,
&
fp4
},
// sentinel known-sentinel <name> <ip> <port> [runid]
{
"announce-ip"
,
&
fp1
},
// sentinel announce-ip <ip>
{
"announce-port"
,
&
fp1
}
// sentinel announce-port <port>
{
"known-sentinel"
,
&
fp4
},
// sentinel known-sentinel <name> <ip> <port> [runid]
{
"announce-ip"
,
&
fp1
},
// sentinel announce-ip <ip>
{
"announce-port"
,
&
fp1
}
// sentinel announce-port <port>
};
}
...
...
src/Win32_Interop/Win32_EventLog.cpp
浏览文件 @
d9369130
...
...
@@ -33,128 +33,128 @@ using namespace std;
#include "EventLog.h"
void
RedisEventLog
::
UninstallEventLogSource
()
{
SmartRegistryHandle
appKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogApplicitonPath
.
c_str
(),
appKey
))
{
SmartRegistryHandle
eventLogNameKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
appKey
,
eventLogName
.
c_str
(),
eventLogNameKey
))
{
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
appKey
,
eventLogName
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
}
}
SmartRegistryHandle
appKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogApplicitonPath
.
c_str
(),
appKey
))
{
SmartRegistryHandle
eventLogNameKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
appKey
,
eventLogName
.
c_str
(),
eventLogNameKey
))
{
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
appKey
,
eventLogName
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
}
}
SmartRegistryHandle
eventLogKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogPath
.
c_str
(),
eventLogKey
))
{
SmartRegistryHandle
eventServiceKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
eventServiceKey
))
{
SmartRegistryHandle
eventServiceSubKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
eventServiceKey
,
cRedisServer
.
c_str
(),
eventServiceSubKey
))
{
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
eventServiceKey
,
cRedisServer
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
eventLogKey
,
cRedis
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
}
}
}
SmartRegistryHandle
eventLogKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogPath
.
c_str
(),
eventLogKey
))
{
SmartRegistryHandle
eventServiceKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
eventServiceKey
))
{
SmartRegistryHandle
eventServiceSubKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
eventServiceKey
,
cRedisServer
.
c_str
(),
eventServiceSubKey
))
{
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
eventServiceKey
,
cRedisServer
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
if
(
ERROR_SUCCESS
!=
RegDeleteKeyA
(
eventLogKey
,
cRedis
.
c_str
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegDeleteKeyA failed"
);
}
}
}
}
}
// sets up the registry keys required for the EventViewer message filter
void
RedisEventLog
::
InstallEventLogSource
(
string
appPath
)
{
SmartRegistryHandle
eventLogKey
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogPath
.
c_str
(),
eventLogKey
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegOpenKey failed"
);
}
SmartRegistryHandle
redis1
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
redis1
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
redis1
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
SmartRegistryHandle
redisserver
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
redis1
,
cRedisServer
.
c_str
(),
redisserver
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
redis1
,
cRedisServer
.
c_str
(),
redisserver
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
DWORD
value
=
0
;
DWORD
type
=
REG_DWORD
;
DWORD
size
=
sizeof
(
DWORD
);
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
type
=
REG_SZ
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
SmartRegistryHandle
eventLogKey
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogPath
.
c_str
(),
eventLogKey
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegOpenKey failed"
);
}
SmartRegistryHandle
redis1
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
redis1
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
eventLogKey
,
cRedis
.
c_str
(),
redis1
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
SmartRegistryHandle
redisserver
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
redis1
,
cRedisServer
.
c_str
(),
redisserver
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
redis1
,
cRedisServer
.
c_str
(),
redisserver
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
DWORD
value
=
0
;
DWORD
type
=
REG_DWORD
;
DWORD
size
=
sizeof
(
DWORD
);
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
type
=
REG_SZ
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
SmartRegistryHandle
application
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cApplication
.
c_str
()
,
application
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
SmartRegistryHandle
redis2
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
application
,
cRedis
.
c_str
(),
redis2
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
application
,
cRedis
.
c_str
(),
redis2
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
type
=
REG_DWORD
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
SmartRegistryHandle
application
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cApplication
.
c_str
()
,
application
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
SmartRegistryHandle
redis2
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
application
,
cRedis
.
c_str
(),
redis2
))
{
if
(
ERROR_SUCCESS
!=
RegCreateKeyA
(
application
,
cRedis
.
c_str
(),
redis2
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
}
type
=
REG_DWORD
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
}
void
RedisEventLog
::
LogMessageToEventLog
(
LPCSTR
msg
,
const
WORD
type
)
{
DWORD
eventID
;
switch
(
type
)
{
case
EVENTLOG_ERROR_TYPE
:
eventID
=
MSG_ERROR_1
;
break
;
case
EVENTLOG_WARNING_TYPE
:
eventID
=
MSG_WARNING_1
;
break
;
case
EVENTLOG_INFORMATION_TYPE
:
eventID
=
MSG_INFO_1
;
break
;
default:
std
::
cerr
<<
"Unrecognized type: "
<<
type
<<
"
\n
"
;
eventID
=
MSG_INFO_1
;
break
;
}
DWORD
eventID
;
switch
(
type
)
{
case
EVENTLOG_ERROR_TYPE
:
eventID
=
MSG_ERROR_1
;
break
;
case
EVENTLOG_WARNING_TYPE
:
eventID
=
MSG_WARNING_1
;
break
;
case
EVENTLOG_INFORMATION_TYPE
:
eventID
=
MSG_INFO_1
;
break
;
default:
std
::
cerr
<<
"Unrecognized type: "
<<
type
<<
"
\n
"
;
eventID
=
MSG_INFO_1
;
break
;
}
HANDLE
hEventLog
=
RegisterEventSourceA
(
0
,
this
->
eventLogName
.
c_str
());
HANDLE
hEventLog
=
RegisterEventSourceA
(
0
,
this
->
eventLogName
.
c_str
());
if
(
0
==
hEventLog
)
{
std
::
cerr
<<
"Failed open source '"
<<
this
->
eventLogName
<<
"': "
<<
GetLastError
()
<<
endl
;
}
else
{
if
(
FALSE
==
ReportEventA
(
hEventLog
,
type
,
0
,
eventID
,
0
,
1
,
0
,
&
msg
,
0
))
{
std
::
cerr
<<
"Failed to write message: "
<<
GetLastError
()
<<
endl
;
}
if
(
0
==
hEventLog
)
{
std
::
cerr
<<
"Failed open source '"
<<
this
->
eventLogName
<<
"': "
<<
GetLastError
()
<<
endl
;
}
else
{
if
(
FALSE
==
ReportEventA
(
hEventLog
,
type
,
0
,
eventID
,
0
,
1
,
0
,
&
msg
,
0
))
{
std
::
cerr
<<
"Failed to write message: "
<<
GetLastError
()
<<
endl
;
}
DeregisterEventSource
(
hEventLog
);
}
DeregisterEventSource
(
hEventLog
);
}
}
extern
"C"
void
WriteEventLog
(
const
char
*
sysLogInstance
,
const
char
*
msg
)
{
try
{
stringstream
ss
;
try
{
stringstream
ss
;
ss
<<
"syslog-ident = "
<<
sysLogInstance
<<
endl
;
ss
<<
msg
;
RedisEventLog
().
LogMessageToEventLog
(
ss
.
str
().
c_str
(),
EVENTLOG_INFORMATION_TYPE
);
}
catch
(...)
{
}
RedisEventLog
().
LogMessageToEventLog
(
ss
.
str
().
c_str
(),
EVENTLOG_INFORMATION_TYPE
);
}
catch
(...)
{
}
}
src/Win32_Interop/Win32_EventLog.h
浏览文件 @
d9369130
...
...
@@ -28,29 +28,29 @@ using namespace std;
typedef
class
RedisEventLog
{
public:
~
RedisEventLog
()
{}
~
RedisEventLog
()
{}
void
InstallEventLogSource
(
string
appPath
);
void
UninstallEventLogSource
();
void
InstallEventLogSource
(
string
appPath
);
void
UninstallEventLogSource
();
void
LogMessageToEventLog
(
LPCSTR
msg
,
const
WORD
type
);
void
LogMessageToEventLog
(
LPCSTR
msg
,
const
WORD
type
);
private:
const
string
eventLogName
=
"redis"
;
const
string
cEventLogPath
=
"SYSTEM
\\
CurrentControlSet
\\
Services
\\
EventLog
\\
"
;
const
string
cEventLogApplicitonPath
=
cEventLogPath
+
"Application
\\
"
;
const
string
cRedis
=
"redis"
;
const
string
cEventMessageFile
=
"EventMessageFile"
;
const
string
cRedisServer
=
"redis-server"
;
const
string
cTypesSupported
=
"TypesSupported"
;
const
string
cApplication
=
"Application"
;
const
string
eventLogName
=
"redis"
;
const
string
cEventLogPath
=
"SYSTEM
\\
CurrentControlSet
\\
Services
\\
EventLog
\\
"
;
const
string
cEventLogApplicitonPath
=
cEventLogPath
+
"Application
\\
"
;
const
string
cRedis
=
"redis"
;
const
string
cEventMessageFile
=
"EventMessageFile"
;
const
string
cRedisServer
=
"redis-server"
;
const
string
cTypesSupported
=
"TypesSupported"
;
const
string
cApplication
=
"Application"
;
}
RedisEventLog
;
extern
"C"
{
#endif
void
WriteEventLog
(
const
char
*
sysLogInstance
,
const
char
*
msg
);
void
WriteEventLog
(
const
char
*
sysLogInstance
,
const
char
*
msg
);
#ifdef __cplusplus
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录