mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 16:24:39 +02:00
Cleaned up win32_log.c
This commit is contained in:
parent
6608961bb0
commit
6c049683d7
@ -1,3 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Microsoft Corp.
|
||||||
|
* All rights reserved
|
||||||
|
*
|
||||||
|
* Implementation of sys log for windows:
|
||||||
|
* openlog(), closelog, syslog
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
@ -8,12 +37,16 @@
|
|||||||
#define MSGBUFSIZ 1024
|
#define MSGBUFSIZ 1024
|
||||||
static int logfd = -1;
|
static int logfd = -1;
|
||||||
|
|
||||||
void openlog(char *ident, unsigned int option, int facility) {
|
void
|
||||||
if ((logfd == -1) && (ident != NULL)) {
|
openlog(char *ident, unsigned int option, int facility) {
|
||||||
|
if (logfd != -1 || ident == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
wchar_t path[MAX_PATH], log_file[MAX_PATH + 12];
|
wchar_t path[MAX_PATH], log_file[MAX_PATH + 12];
|
||||||
if (GetModuleFileNameW(NULL, path, MAX_PATH) == 0)
|
if (GetModuleFileNameW(NULL, path, MAX_PATH) == 0)
|
||||||
return;
|
return;
|
||||||
path[MAX_PATH - 1] = '\0';
|
path[MAX_PATH - 1] = '\0';
|
||||||
|
|
||||||
/* split path root and module */
|
/* split path root and module */
|
||||||
{
|
{
|
||||||
wchar_t* tail = path + wcslen(path), *p;
|
wchar_t* tail = path + wcslen(path), *p;
|
||||||
@ -28,16 +61,17 @@ void openlog(char *ident, unsigned int option, int facility) {
|
|||||||
p += wcslen(tail + 1) - 3;
|
p += wcslen(tail + 1) - 3;
|
||||||
memcpy(p, L"log\0", 8);
|
memcpy(p, L"log\0", 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
logfd = _wopen(log_file, O_WRONLY | O_CREAT | O_APPEND,
|
logfd = _wopen(log_file, O_WRONLY | O_CREAT | O_APPEND,
|
||||||
S_IREAD | S_IWRITE);
|
S_IREAD | S_IWRITE);
|
||||||
if (logfd != -1)
|
if (logfd != -1)
|
||||||
SetHandleInformation((HANDLE)_get_osfhandle(logfd),
|
SetHandleInformation((HANDLE)_get_osfhandle(logfd),
|
||||||
HANDLE_FLAG_INHERIT, 0);
|
HANDLE_FLAG_INHERIT, 0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void closelog(void) {
|
void
|
||||||
//NOOP
|
closelog(void) {
|
||||||
|
/*NOOP*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user