You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/11/05 20:22:50 UTC
[commons-daemon] branch master updated (48ab942 -> 604ac13)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git.
from 48ab942 Slightly better local variable name.
new ed39a02 Slightly better local variable name.
new 604ac13 Refactor common call sites into a utility method.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/native/windows/include/log.h | 6 +++++
src/native/windows/src/log.c | 47 ++++++++++++++++++++++------------------
2 files changed, 32 insertions(+), 21 deletions(-)
[commons-daemon] 02/02: Refactor common call sites into a utility
method.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
commit 604ac139fa90ad83d6e14f2bac513784fe505f60
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 5 16:22:48 2021 -0400
Refactor common call sites into a utility method.
---
src/native/windows/include/log.h | 6 ++++++
src/native/windows/src/log.c | 37 +++++++++++++++++++++----------------
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/native/windows/include/log.h b/src/native/windows/include/log.h
index 05fac9f..9188e1e 100644
--- a/src/native/windows/include/log.h
+++ b/src/native/windows/include/log.h
@@ -112,6 +112,12 @@ apxDisplayError(
...
);
+DWORD
+apxGetMessage(
+ DWORD dwMessageId,
+ LPSTR lpBuffer,
+ DWORD nSize);
+
__APXEND_DECLS
#endif /* _LOG_H_INCLUDED_ */
diff --git a/src/native/windows/src/log.c b/src/native/windows/src/log.c
index 821541f..e1ef8fb 100644
--- a/src/native/windows/src/log.c
+++ b/src/native/windows/src/log.c
@@ -285,6 +285,25 @@ void apxLogLevelSetW(HANDLE hFile,
}
}
+DWORD
+apxGetMessage(
+ DWORD dwMessageId,
+ LPSTR lpBuffer,
+ DWORD nSize)
+{
+ if (nSize == 0 || lpBuffer == 0) {
+ return 0;
+ }
+ return FormatMessageA(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwMessageId,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ lpBuffer,
+ nSize,
+ NULL);
+}
+
int
apxLogWrite(
HANDLE hFile,
@@ -339,14 +358,7 @@ apxLogWrite(
}
}
else
- FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwMessageId,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- szBp,
- 1000,
- NULL);
+ apxGetMessage(dwMessageId, szBp, 1000);
}
else {
va_start(args, szFormat);
@@ -458,14 +470,7 @@ apxDisplayError(
f = "";
sysbuf[0] = '\0';
if (dwMessageId != ERROR_SUCCESS) {
- len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwMessageId,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- sysbuf,
- SIZ_DESLEN,
- NULL);
+ len = apxGetMessage(dwMessageId, sysbuf, SIZ_DESLEN);
sysbuf[len] = '\0';
if (len > 0) {
if (sysbuf[len - 1] == '\n')
[commons-daemon] 01/02: Slightly better local variable name.
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
commit ed39a0201d436bf6134827d8a661cfe3ff194053
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 5 15:52:26 2021 -0400
Slightly better local variable name.
---
src/native/windows/src/log.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/native/windows/src/log.c b/src/native/windows/src/log.c
index ce1a356..821541f 100644
--- a/src/native/windows/src/log.c
+++ b/src/native/windows/src/log.c
@@ -302,11 +302,11 @@ apxLogWrite(
LPCSTR f = szFile;
CHAR sb[SIZ_PATHLEN];
DWORD wr;
- DWORD err;
+ DWORD dwMessageId;
BOOL dolock = TRUE;
apx_logfile_st *lf = (apx_logfile_st *)hFile;
- err = GetLastError(); /* save the last Error code */
+ dwMessageId = GetLastError(); /* save the last Error code */
if (IS_INVALID_HANDLE(lf))
lf = _st_sys_loghandle;
if (IS_INVALID_HANDLE(lf)) {
@@ -331,7 +331,7 @@ apxLogWrite(
f = NULL;
szBp = buffer;
if (!szFormat) {
- if (err == 0) {
+ if (dwMessageId == 0) {
lstrcpyA(szBp, "Unknown error code");
if (dwLevel == APXLOG_LEVEL_ERROR) {
szBp += 18;
@@ -342,7 +342,7 @@ apxLogWrite(
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- err,
+ dwMessageId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
szBp,
1000,
@@ -407,8 +407,8 @@ apxLogWrite(
}
APX_LOGLEAVE();
/* Restore the last Error code */
- SetLastError(err);
- if (szFormat && err != 0 && dwLevel == APXLOG_LEVEL_ERROR) {
+ SetLastError(dwMessageId);
+ if (szFormat && dwMessageId != 0 && dwLevel == APXLOG_LEVEL_ERROR) {
/* Print the System error description
*/
apxLogWrite(hFile, dwLevel, bTimeStamp, szFile, dwLine, NULL);