diff --git a/common/wincompat.c b/common/wincompat.c index 9045ba4624..7671c13b96 100644 --- a/common/wincompat.c +++ b/common/wincompat.c @@ -1,6 +1,10 @@ /* - Copyright (C) 1999 Russell Kroll + Copyright (C) + 1999 Russell Kroll + 2010 - 2013 Frederic Bohe + 2010 Arnaud Quette + 2022 - 2026 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,8 +49,8 @@ char wincompat_password[SMALLBUF]; uid_t getuid(void) { - DWORD size = sizeof(wincompat_user_name); - if( !GetUserName(wincompat_user_name,&size) ) { + DWORD size = sizeof(wincompat_user_name); + if (!GetUserName(wincompat_user_name, &size)) { return NULL; } @@ -60,21 +64,21 @@ struct passwd *getpwuid(uid_t uid) return &wincompat_passwd; } -char *getpass( const char *prompt) +char *getpass(const char *prompt) { - HANDLE hStdin; - DWORD mode; + HANDLE hStdin; + DWORD mode; hStdin = GetStdHandle(STD_INPUT_HANDLE); - if(hStdin == INVALID_HANDLE_VALUE) { + if (hStdin == INVALID_HANDLE_VALUE) { return NULL; } printf("%s",prompt); - GetConsoleMode( hStdin, &mode ); + GetConsoleMode(hStdin, &mode); mode &= ~ENABLE_ECHO_INPUT; - SetConsoleMode( hStdin , mode); + SetConsoleMode(hStdin, mode); if (fgets(wincompat_password, sizeof(wincompat_password), stdin) == NULL) { upsdebug_with_errno(LOG_INFO, "%s", __func__); @@ -84,12 +88,12 @@ char *getpass( const char *prompt) /* deal with that pesky newline */ if (strlen(wincompat_password) > 1) { wincompat_password[strlen(wincompat_password) - 1] = '\0'; - }; + } hStdin = GetStdHandle(STD_INPUT_HANDLE); - GetConsoleMode( hStdin, &mode ); + GetConsoleMode(hStdin, &mode ); mode |= ENABLE_ECHO_INPUT; - SetConsoleMode( hStdin , mode); + SetConsoleMode(hStdin, mode); return wincompat_password; } @@ -100,10 +104,10 @@ char *getpass( const char *prompt) /* int __cdecl usleep(unsigned int useconds) */ int __cdecl usleep(useconds_t useconds) { - if(useconds == 0) + if (useconds == 0) return 0; - if(useconds >= 1000000) + if (useconds >= 1000000) return EINVAL; Sleep((useconds + 999) / 1000); @@ -114,7 +118,7 @@ int __cdecl usleep(useconds_t useconds) char * strtok_r(char *str, const char *delim, char **saveptr) { - char *token_start, *token_end; + char *token_start, *token_end; /* Subsequent call ? */ token_start = str ? str : *saveptr; @@ -141,25 +145,28 @@ char * strtok_r(char *str, const char *delim, char **saveptr) int sktconnect(int fh, struct sockaddr * name, int len) { - int ret = connect(fh,name,len); + int ret = connect(fh, name, len); errno = WSAGetLastError(); return ret; } + int sktread(int fh, char *buf, int size) { - int ret = recv(fh,buf,size,0); + int ret = recv(fh, buf, size, 0); errno = WSAGetLastError(); return ret; } + int sktwrite(int fh, char *buf, int size) { - int ret = send(fh,buf,size,0); + int ret = send(fh, buf, size, 0); errno = WSAGetLastError(); return ret; } + int sktclose(int fh) { - int ret = closesocket((SOCKET)fh); + int ret = closesocket((SOCKET)fh); errno = WSAGetLastError(); return ret; } @@ -181,7 +188,7 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t cnt) switch (af) { case AF_INET: { - struct sockaddr_in srcaddr; + struct sockaddr_in srcaddr; memset(&srcaddr, 0, sizeof(struct sockaddr_in)); memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr)); srcaddr.sin_family = af; @@ -195,7 +202,7 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t cnt) case AF_INET6: /* NOTE: Since WinXP SP1, with IPv6 installed on the system */ { - struct sockaddr_in6 srcaddr; + struct sockaddr_in6 srcaddr; memset(&srcaddr, 0, sizeof(struct sockaddr_in6)); memcpy(&(srcaddr.sin6_addr), src, sizeof(srcaddr.sin6_addr)); srcaddr.sin6_family = af; @@ -230,11 +237,11 @@ const char* inet_ntop(int af, const void* src, char* dst, size_t cnt) static int inet_pton4(const char *src, void *dst) { - uint8_t tmp[NS_INADDRSZ], *tp; /* for struct in_addr *dst */ + uint8_t tmp[NS_INADDRSZ], *tp; /* for struct in_addr *dst */ - int saw_digit = 0; - int octets = 0; - int ch; + int saw_digit = 0; + int octets = 0; + int ch; *(tp = tmp) = 0; @@ -242,7 +249,7 @@ static int inet_pton4(const char *src, void *dst) { if (ch >= '0' && ch <= '9') { - uint32_t n = *tp * 10 + (ch - '0'); + uint32_t n = *tp * 10 + (ch - '0'); if (saw_digit && *tp == 0) return 0; @@ -278,17 +285,16 @@ static int inet_pton4(const char *src, void *dst) static int inet_pton6(const char *src, void *dst) { - static const char xdigits[] = "0123456789abcdef"; - uint8_t tmp[NS_IN6ADDRSZ]; /* for struct in6_addr *dst */ + static const char xdigits[] = "0123456789abcdef"; + uint8_t tmp[NS_IN6ADDRSZ]; /* for struct in6_addr *dst */ - uint8_t *tp = (uint8_t*) memset(tmp, '\0', NS_IN6ADDRSZ); - uint8_t *endp = tp + NS_IN6ADDRSZ; - uint8_t *colonp = NULL; + uint8_t *tp = (uint8_t*) memset(tmp, '\0', NS_IN6ADDRSZ); + uint8_t *endp = tp + NS_IN6ADDRSZ; + uint8_t *colonp = NULL; - const char *curtok = NULL; - int saw_xdigit = 0; - uint32_t val = 0; - int ch; + const char *curtok = NULL; + int saw_xdigit = 0, ch; + uint32_t val = 0; /* Leading :: requires some special handling. */ if (*src == ':') @@ -301,7 +307,7 @@ static int inet_pton6(const char *src, void *dst) while ((ch = tolower(*src++)) != '\0') { - const char *pch = strchr(xdigits, ch); + const char *pch = strchr(xdigits, ch); if (pch != NULL) { val <<= 4; @@ -355,8 +361,8 @@ static int inet_pton6(const char *src, void *dst) * Since some memmove()'s erroneously fail to handle * overlapping regions, we'll do the shift by hand. */ - const int n = tp - colonp; - int i; + const int n = tp - colonp; + int i; if (tp == endp) return 0; @@ -393,17 +399,17 @@ int inet_pton(int af, const char *src, void *dst) /* "system" call seems to handle path with blank name incorrectly */ int win_system(const char * command) { - BOOL res; - STARTUPINFO si; - PROCESS_INFORMATION pi; + BOOL res; + STARTUPINFO si; + PROCESS_INFORMATION pi; - memset(&si,0,sizeof(si)); + memset(&si, 0, sizeof(si)); si.cb = sizeof(si); - memset(&pi,0,sizeof(pi)); + memset(&pi, 0, sizeof(pi)); - res = CreateProcess(NULL,(char *)command,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); + res = CreateProcess(NULL, (char *)command, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); - if( res != 0 ) { + if (res != 0) { return 0; } @@ -416,16 +422,16 @@ distinguish the command from its parameter. This avoid complicated explanation in the documentation */ char * filter_path(const char * source) { - char * res; - unsigned int i,j; + char *res; + unsigned int i, j; - if( source == NULL ) { + if (source == NULL) { return NULL; } - res = xmalloc(strlen(source)+1); - for(i=0,j=0;i<=strlen(source);i++) { - if(source[i] != '"') { + res = xmalloc(strlen(source) + 1); + for (i=0, j=0; i <= strlen(source); i++) { + if (source[i] != '"') { res[j] = source[i]; j++; } @@ -434,26 +440,28 @@ char * filter_path(const char * source) return res; } - /* syslog sends a message through a pipe to the wininit service. Which is in charge of adding an event in the Windows event logger. The message is made of 4 bytes containing the priority followed by an array of chars containing the message to display (no terminal 0 required here) */ void syslog(int priority, const char *fmt, ...) { - char pipe_name[] = "\\\\.\\pipe\\"EVENTLOG_PIPE_NAME; - char buf1[LARGEBUF+sizeof(DWORD)]; - char buf2[LARGEBUF]; - va_list ap; - HANDLE pipe; - DWORD bytesWritten = 0; - - if( EventLogName == NULL ) { + /* At least while this is not configurable, can be static to speed up; + * see https://github.com/networkupstools/nut/issues/3375 + */ + static char pipe_full_name[] = "\\\\.\\pipe\\"EVENTLOG_PIPE_NAME; + char buf1[LARGEBUF + sizeof(DWORD)]; + char buf2[LARGEBUF]; + va_list ap; + HANDLE pipe; + DWORD bytesWritten = 0; + + if (EventLogName == NULL) { return; } /* Format message */ - va_start(ap,fmt); + va_start(ap, fmt); vsnprintf(buf1, sizeof(buf1), fmt, ap); va_end(ap); @@ -462,25 +470,24 @@ void syslog(int priority, const char *fmt, ...) /* Create the frame */ /* first 4 bytes are priority */ - memcpy(buf1,&priority,sizeof(DWORD)); + memcpy(buf1, &priority, sizeof(DWORD)); /* then comes the message */ - memcpy(buf1+sizeof(DWORD),buf2,sizeof(buf2)); + memcpy(buf1 + sizeof(DWORD), buf2, sizeof(buf2)); pipe = CreateFile( - pipe_name, /* pipe name */ - GENERIC_WRITE, - 0, /* no sharing */ - NULL, /* default security attributes FIXME */ - OPEN_EXISTING, /* opens existing pipe */ - FILE_FLAG_OVERLAPPED, /* enable async IO */ - NULL); /* no template file */ - + pipe_full_name, /* pipe name */ + GENERIC_WRITE, + 0, /* no sharing */ + NULL, /* default security attributes FIXME */ + OPEN_EXISTING, /* opens existing pipe */ + FILE_FLAG_OVERLAPPED, /* enable async IO */ + NULL); /* no template file */ if (pipe == INVALID_HANDLE_VALUE) { return; } - WriteFile (pipe,buf1,strlen(buf2)+sizeof(DWORD),&bytesWritten,NULL); + WriteFile(pipe, buf1, strlen(buf2) + sizeof(DWORD), &bytesWritten, NULL); /* testing result is useless. If we have an error and try to report it, * this will probably lead to a call to this function and an infinite @@ -491,14 +498,16 @@ void syslog(int priority, const char *fmt, ...) /* Signal emulation via NamedPipe */ static HANDLE pipe_connection_handle; +static const char *named_pipe_name=NULL; + +/* Note these are shared (upsd, upsmon, nut.exe...) for other named pipe uses as well */ OVERLAPPED pipe_connection_overlapped; pipe_conn_t *pipe_connhead = NULL; -static const char *named_pipe_name=NULL; void pipe_create(const char * pipe_name) { - BOOL ret; - char pipe_full_name[NUT_PATH_MAX + 1]; + BOOL ret; + char pipe_full_name[NUT_PATH_MAX + 1]; /* save pipe name for further use in pipe_connect */ if (pipe_name == NULL) { @@ -513,22 +522,22 @@ void pipe_create(const char * pipe_name) snprintf(pipe_full_name, sizeof(pipe_full_name), "\\\\.\\pipe\\%s", named_pipe_name); - if( pipe_connection_overlapped.hEvent != 0 ) { + if (pipe_connection_overlapped.hEvent != 0) { CloseHandle(pipe_connection_overlapped.hEvent); } - memset(&pipe_connection_overlapped,0,sizeof(pipe_connection_overlapped)); + memset(&pipe_connection_overlapped, 0, sizeof(pipe_connection_overlapped)); pipe_connection_handle = CreateNamedPipe( - pipe_full_name, - PIPE_ACCESS_INBOUND | /* to server only */ - FILE_FLAG_OVERLAPPED, /* async IO */ - PIPE_TYPE_MESSAGE | - PIPE_READMODE_MESSAGE | - PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, /* max. instances */ - LARGEBUF, /* output buffer size */ - LARGEBUF, /* input buffer size */ - 0, /* client time-out */ - NULL); /* FIXME: default security attribute */ + pipe_full_name, + PIPE_ACCESS_INBOUND /* to server only */ + | FILE_FLAG_OVERLAPPED, /* async IO */ + PIPE_TYPE_MESSAGE + | PIPE_READMODE_MESSAGE + | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, /* max. instances */ + LARGEBUF, /* output buffer size */ + LARGEBUF, /* input buffer size */ + 0, /* client time-out */ + NULL); /* FIXME: default security attribute */ if (pipe_connection_handle == INVALID_HANDLE_VALUE) { upslogx(LOG_ERR, "Error creating named pipe"); @@ -537,28 +546,30 @@ void pipe_create(const char * pipe_name) } /* Prepare an async wait on a connection on the pipe */ - pipe_connection_overlapped.hEvent = CreateEvent(NULL, /*Security*/ - FALSE, /* auto-reset*/ - FALSE, /* inital state = non signaled*/ - NULL /* no name*/); - if(pipe_connection_overlapped.hEvent == NULL ) { + pipe_connection_overlapped.hEvent = CreateEvent( + NULL, /* Security */ + FALSE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); + if (pipe_connection_overlapped.hEvent == NULL) { upslogx(LOG_ERR, "Error creating event"); fatal_with_errno(EXIT_FAILURE, "Can't create event"); } /* Wait for a connection */ - ret = ConnectNamedPipe(pipe_connection_handle,&pipe_connection_overlapped); - if(ret == 0 && GetLastError() != ERROR_IO_PENDING ) { - upslogx(LOG_ERR,"ConnectNamedPipe error"); + ret = ConnectNamedPipe(pipe_connection_handle, &pipe_connection_overlapped); + if (ret == 0 && GetLastError() != ERROR_IO_PENDING) { + upslogx(LOG_ERR, "ConnectNamedPipe error"); } } void pipe_connect() { /* We have detected a connection on the opened pipe. So we start by saving its handle and create a new pipe for future connections */ - pipe_conn_t *conn; + pipe_conn_t *conn; - conn = xcalloc(1,sizeof(*conn)); + conn = xcalloc(1, sizeof(*conn)); conn->handle = pipe_connection_handle; /* restart a new listening pipe */ @@ -566,19 +577,22 @@ void pipe_connect() /* A new pipe waiting for new client connection has been created. We could manage the current connection now */ /* Start a read operation on the newly connected pipe so we could wait on the event associated to this IO */ - memset(&conn->overlapped,0,sizeof(conn->overlapped)); - memset(conn->buf,0,sizeof(conn->buf)); - conn->overlapped.hEvent = CreateEvent(NULL, /*Security*/ - FALSE, /* auto-reset*/ - FALSE, /* inital state = non signaled*/ - NULL /* no name*/); - if(conn->overlapped.hEvent == NULL ) { - upslogx(LOG_ERR,"Can't create event for reading event log"); + memset(&conn->overlapped, 0, sizeof(conn->overlapped)); + memset(conn->buf, 0, sizeof(conn->buf)); + conn->overlapped.hEvent = CreateEvent( + NULL, /* Security */ + FALSE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); + if (conn->overlapped.hEvent == NULL) { + /* FIXME: Is this (still) about event log only? */ + upslogx(LOG_ERR, "Can't create event for reading event log"); return; } - ReadFile (conn->handle, conn->buf, - sizeof(conn->buf)-1, /* -1 to be sure to have a trailling 0 */ + ReadFile(conn->handle, conn->buf, + sizeof(conn->buf) - 1, /* -1 to be sure to have a trailling 0 */ NULL, &(conn->overlapped)); if (pipe_connhead) { @@ -591,12 +605,13 @@ void pipe_connect() void pipe_disconnect(pipe_conn_t *conn) { - if( conn->overlapped.hEvent != INVALID_HANDLE_VALUE) { + if (conn->overlapped.hEvent != INVALID_HANDLE_VALUE) { CloseHandle(conn->overlapped.hEvent); conn->overlapped.hEvent = INVALID_HANDLE_VALUE; } - if( conn->handle != INVALID_HANDLE_VALUE) { - if ( DisconnectNamedPipe(conn->handle) == 0 ) { + + if (conn->handle != INVALID_HANDLE_VALUE) { + if (DisconnectNamedPipe(conn->handle) == 0) { upslogx(LOG_ERR, "DisconnectNamedPipe error : %d", (int)GetLastError()); @@ -604,6 +619,7 @@ void pipe_disconnect(pipe_conn_t *conn) CloseHandle(conn->handle); conn->handle = INVALID_HANDLE_VALUE; } + if (conn->prev) { conn->prev->next = conn->next; } else { @@ -621,45 +637,45 @@ void pipe_disconnect(pipe_conn_t *conn) int pipe_ready(pipe_conn_t *conn) { - DWORD bytesRead; - BOOL res; + DWORD bytesRead; + BOOL res; res = GetOverlappedResult(conn->handle, &conn->overlapped, &bytesRead, FALSE); - if( res == 0 ) { + if (res == 0) { upslogx(LOG_ERR, "Pipe read error"); pipe_disconnect(conn); return 0; } + return 1; } /* return 1 on error, 0 if OK */ int send_to_named_pipe(const char * pipe_name, const char * data) { - HANDLE pipe; - BOOL result = FALSE; - DWORD bytesWritten = 0; - char buf[SMALLBUF]; + HANDLE pipe; + BOOL result = FALSE; + DWORD bytesWritten = 0; + char pipe_full_name[NUT_PATH_MAX + 1]; - snprintf(buf, sizeof(buf), "\\\\.\\pipe\\%s", pipe_name); + snprintf(pipe_full_name, sizeof(pipe_full_name), "\\\\.\\pipe\\%s", pipe_name); pipe = CreateFile( - buf, - GENERIC_WRITE, - 0, /* no sharing */ - NULL, /* default security attributes FIXME */ - OPEN_EXISTING, /* opens existing pipe */ - FILE_FLAG_OVERLAPPED, /* enable async IO */ - NULL); /* no template file */ - + pipe_full_name, + GENERIC_WRITE, + 0, /* no sharing */ + NULL, /* default security attributes FIXME */ + OPEN_EXISTING, /* opens existing pipe */ + FILE_FLAG_OVERLAPPED, /* enable async IO */ + NULL); /* no template file */ if (pipe == INVALID_HANDLE_VALUE) { return 1; } - result = WriteFile (pipe,data,strlen(data)+1,&bytesWritten,NULL); + result = WriteFile(pipe, data, strlen(data) + 1, &bytesWritten, NULL); - if (result == 0 || bytesWritten != strlen(data)+1 ) { + if (result == 0 || bytesWritten != strlen(data) + 1) { CloseHandle(pipe); return 1; } @@ -668,31 +684,31 @@ int send_to_named_pipe(const char * pipe_name, const char * data) return 0; } -int w32_setcomm ( serial_handler_t * h, int * flags ) +int w32_setcomm(serial_handler_t *h, int *flags) { int ret = 0; - if( *flags & TIOCM_DTR ) { - if( !EscapeCommFunction(h->handle,SETDTR) ) { + if (*flags & TIOCM_DTR) { + if (!EscapeCommFunction(h->handle,SETDTR)) { errno = EIO; ret = -1; } } else { - if( !EscapeCommFunction(h->handle,CLRDTR) ) { + if (!EscapeCommFunction(h->handle,CLRDTR)) { errno = EIO; ret = -1; } } - if( *flags & TIOCM_RTS ) { - if( !EscapeCommFunction(h->handle,SETRTS) ) { + if (*flags & TIOCM_RTS) { + if (!EscapeCommFunction(h->handle,SETRTS)) { errno = EIO; ret = -1; } } else { - if( !EscapeCommFunction(h->handle,CLRRTS) ) { + if (!EscapeCommFunction(h->handle,CLRRTS)) { errno = EIO; ret = -1; } @@ -701,10 +717,10 @@ int w32_setcomm ( serial_handler_t * h, int * flags ) return ret; } -int w32_getcomm ( serial_handler_t * h, int * flags ) +int w32_getcomm(serial_handler_t *h, int *flags) { - BOOL ret_val; - DWORD f; + BOOL ret_val; + DWORD f; ret_val = GetCommModemStatus(h->handle, &f); if (ret_val == 0) { @@ -720,19 +736,24 @@ int w32_getcomm ( serial_handler_t * h, int * flags ) /* Serial port wrapper inspired by : http://serial-programming-in-win32-os.blogspot.com/2008/07/convert-linux-code-to-windows-serial.html */ -void overlapped_setup (serial_handler_t * sh) +void overlapped_setup(serial_handler_t *sh) { - memset (&sh->io_status, 0, sizeof (sh->io_status)); - sh->io_status.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); + memset(&sh->io_status, 0, sizeof(sh->io_status)); + sh->io_status.hEvent = CreateEvent( + NULL, /* Security */ + TRUE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); sh->overlapped_armed = 0; } -int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeout) +int w32_serial_read(serial_handler_t *sh, void *ptr, size_t ulen, DWORD timeout) { - int tot; - DWORD num; - HANDLE w4; - DWORD minchars = sh->vmin_ ? sh->vmin_ : ulen; + int tot; + DWORD num; + HANDLE w4; + DWORD minchars = sh->vmin_ ? sh->vmin_ : ulen; errno = 0; @@ -742,14 +763,14 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou "w32_serial_read : ulen %" PRIuSIZE ", vmin_ %d, vtime_ %d, hEvent %p", ulen, sh->vmin_, sh->vtime_, sh->io_status.hEvent); if (!sh->overlapped_armed) { - SetCommMask (sh->handle, EV_RXCHAR); - ResetEvent (sh->io_status.hEvent); + SetCommMask(sh->handle, EV_RXCHAR); + ResetEvent(sh->io_status.hEvent); } for (num = 0, tot = 0; ulen; ulen -= num, ptr = (char *)ptr + num) { - DWORD ev; - COMSTAT st; - DWORD inq = 1; + DWORD ev; + COMSTAT st; + DWORD inq = 1; num = 0; @@ -765,7 +786,7 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou inq = ulen; } - if (!ClearCommError (sh->handle, &ev, &st)) { + if (!ClearCommError(sh->handle, &ev, &st)) { goto err; } else if (ev) { @@ -780,30 +801,30 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou if ((size_t)tot >= minchars) { break; } - else if (WaitCommEvent (sh->handle, &ev, &sh->io_status)) { + else if (WaitCommEvent(sh->handle, &ev, &sh->io_status)) { /* WaitCommEvent succeeded */ if (!ev) { continue; } } - else if (GetLastError () != ERROR_IO_PENDING) { + else if (GetLastError() != ERROR_IO_PENDING) { goto err; } else { sh->overlapped_armed = 1; - switch (WaitForSingleObject (w4, timeout)) { + switch (WaitForSingleObject(w4, timeout)) { case WAIT_OBJECT_0: - if (!GetOverlappedResult (sh->handle, &sh->io_status, &num, FALSE)) { + if (!GetOverlappedResult(sh->handle, &sh->io_status, &num, FALSE)) { goto err; } upsdebugx(4, "w32_serial_read : characters are available on input buffer"); break; case WAIT_TIMEOUT: - if(!tot) { + if (!tot) { CancelIo(sh->handle); sh->overlapped_armed = 0; - ResetEvent (sh->io_status.hEvent); + ResetEvent(sh->io_status.hEvent); upsdebugx(4, "w32_serial_read : timeout %d ms elapsed", (int)timeout); @@ -818,20 +839,20 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou } sh->overlapped_armed = 0; - ResetEvent (sh->io_status.hEvent); + ResetEvent(sh->io_status.hEvent); if (inq > ulen) { inq = ulen; } upsdebugx(4, "w32_serial_read : Reading %d characters", (int)inq); - if (ReadFile (sh->handle, ptr, min (inq, ulen), &num, &sh->io_status)) { + if (ReadFile(sh->handle, ptr, min(inq, ulen), &num, &sh->io_status)) { /* Got something */; } - else if (GetLastError () != ERROR_IO_PENDING) { + else if (GetLastError() != ERROR_IO_PENDING) { goto err; } - else if (!GetOverlappedResult (sh->handle, &sh->io_status, &num, TRUE)) { + else if (!GetOverlappedResult(sh->handle, &sh->io_status, &num, TRUE)) { goto err; } @@ -845,11 +866,11 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou continue; err: - PurgeComm (sh->handle, PURGE_RXABORT); + PurgeComm(sh->handle, PURGE_RXABORT); upsdebugx(4, "w32_serial_read : err %d", (int)GetLastError()); - if (GetLastError () == ERROR_OPERATION_ABORTED) { + if (GetLastError() == ERROR_OPERATION_ABORTED) { num = 0; } else @@ -865,22 +886,27 @@ int w32_serial_read (serial_handler_t * sh, void *ptr, size_t ulen, DWORD timeou /* Cover function to WriteFile to provide Posix interface and semantics (as much as possible). */ -int w32_serial_write (serial_handler_t * sh, const void *ptr, size_t len) +int w32_serial_write(serial_handler_t *sh, const void *ptr, size_t len) { DWORD bytes_written; OVERLAPPED write_status; errno = 0; - memset (&write_status, 0, sizeof (write_status)); - write_status.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); + memset(&write_status, 0, sizeof(write_status)); + write_status.hEvent = CreateEvent( + NULL, /* Security */ + TRUE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); for (;;) { - if (WriteFile (sh->handle, ptr, len, &bytes_written, &write_status)) + if (WriteFile(sh->handle, ptr, len, &bytes_written, &write_status)) break; - switch (GetLastError ()) + switch (GetLastError()) { case ERROR_OPERATION_ABORTED: continue; @@ -890,7 +916,7 @@ int w32_serial_write (serial_handler_t * sh, const void *ptr, size_t len) goto err; } - if (!GetOverlappedResult (sh->handle, &write_status, &bytes_written, TRUE)) + if (!GetOverlappedResult(sh->handle, &write_status, &bytes_written, TRUE)) goto err; break; @@ -906,47 +932,46 @@ int w32_serial_write (serial_handler_t * sh, const void *ptr, size_t len) return -1; } -serial_handler_t * w32_serial_open (const char *name, int flags) +serial_handler_t * w32_serial_open(const char *name, int flags) { + COMMTIMEOUTS to; + DCB state; + serial_handler_t *sh; /* flags are currently ignored, it's here just to have the same * interface as POSIX open */ NUT_UNUSED_VARIABLE(flags); - COMMTIMEOUTS to; errno = 0; upslogx(LOG_INFO, "w32_serial_open (%s)", name); - serial_handler_t * sh; - sh = xmalloc(sizeof(serial_handler_t)); - memset(sh,0,sizeof(serial_handler_t)); + memset(sh, 0, sizeof(serial_handler_t)); sh->handle = CreateFile(name, - GENERIC_READ|GENERIC_WRITE, + GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0); - if(sh->handle == INVALID_HANDLE_VALUE) { + if (sh->handle == INVALID_HANDLE_VALUE) { upslogx(LOG_ERR, "could not open %s", name); errno = EPERM; return NULL; } - SetCommMask (sh->handle, EV_RXCHAR); + SetCommMask(sh->handle, EV_RXCHAR); - overlapped_setup (sh); + overlapped_setup(sh); - memset (&to, 0, sizeof (to)); - SetCommTimeouts (sh->handle, &to); + memset(&to, 0, sizeof(to)); + SetCommTimeouts(sh->handle, &to); /* Reset serial port to known state of 9600-8-1-no flow control * on open for better behavior under Win 95. */ - DCB state; - GetCommState (sh->handle, &state); - upslogx (LOG_INFO, "setting initial state on %s", name); + GetCommState(sh->handle, &state); + upslogx(LOG_INFO, "setting initial state on %s", name); state.BaudRate = CBR_9600; state.ByteSize = 8; state.StopBits = ONESTOPBIT; @@ -968,27 +993,27 @@ serial_handler_t * w32_serial_open (const char *name, int flags) state.fDsrSensitivity = FALSE; /* don't assert DSR */ state.fAbortOnError = TRUE; - if (!SetCommState (sh->handle, &state)) { - upslogx (LOG_ERR, + if (!SetCommState(sh->handle, &state)) { + upslogx(LOG_ERR, "couldn't set initial state for %s", name); } - SetCommMask (sh->handle, EV_RXCHAR); + SetCommMask(sh->handle, EV_RXCHAR); - upslogx (LOG_INFO, + upslogx(LOG_INFO, "%p = w32_serial_open (%s)", sh->handle, name); return sh; } -int w32_serial_close (serial_handler_t * sh) +int w32_serial_close(serial_handler_t *sh) { - if( sh->io_status.hEvent != INVALID_HANDLE_VALUE ) { - CloseHandle (sh->io_status.hEvent); + if (sh->io_status.hEvent != INVALID_HANDLE_VALUE) { + CloseHandle(sh->io_status.hEvent); } - if( sh->handle != INVALID_HANDLE_VALUE ) { - CloseHandle (sh->handle); + if (sh->handle != INVALID_HANDLE_VALUE) { + CloseHandle(sh->handle); } free(sh); @@ -1000,24 +1025,24 @@ int w32_serial_close (serial_handler_t * sh) /* tcsendbreak: POSIX 7.2.2.1 */ /* Break for 250-500 milliseconds if duration == 0 */ /* Otherwise, units for duration are undefined */ -int tcsendbreak (serial_handler_t * sh, int duration) +int tcsendbreak(serial_handler_t *sh, int duration) { - unsigned int sleeptime = 300000; + unsigned int sleeptime = 300000; errno = 0; if (duration > 0) sleeptime *= duration; - if (SetCommBreak (sh->handle) == 0) { + if (SetCommBreak(sh->handle) == 0) { errno = EIO; return -1; } /* FIXME: need to send zero bits during duration */ - usleep (sleeptime); + usleep(sleeptime); - if (ClearCommBreak (sh->handle) == 0) { + if (ClearCommBreak(sh->handle) == 0) { errno = EIO; return -1; } @@ -1028,11 +1053,11 @@ int tcsendbreak (serial_handler_t * sh, int duration) } /* tcdrain: POSIX 7.2.2.1 */ -int tcdrain (serial_handler_t * sh) +int tcdrain(serial_handler_t *sh) { errno = 0; - if (FlushFileBuffers (sh->handle) == 0) { + if (FlushFileBuffers(sh->handle) == 0) { errno = EIO; return -1; } @@ -1041,11 +1066,11 @@ int tcdrain (serial_handler_t * sh) } /* tcflow: POSIX 7.2.2.1 */ -int tcflow (serial_handler_t * sh, int action) +int tcflow(serial_handler_t *sh, int action) { - DWORD win32action = 0; - DCB dcb; - char xchar; + DWORD win32action = 0; + DCB dcb; + char xchar; errno = 0; @@ -1056,27 +1081,33 @@ int tcflow (serial_handler_t * sh, int action) case TCOOFF: win32action = SETXOFF; break; + case TCOON: win32action = SETXON; break; + case TCION: case TCIOFF: - if (GetCommState (sh->handle, &dcb) == 0) + if (GetCommState(sh->handle, &dcb) == 0) return -1; + if (action == TCION) xchar = (dcb.XonChar ? dcb.XonChar : 0x11); else xchar = (dcb.XoffChar ? dcb.XoffChar : 0x13); - if (TransmitCommChar (sh->handle, xchar) == 0) + + if (TransmitCommChar(sh->handle, xchar) == 0) return -1; + return 0; break; + default: return -1; break; } - if (EscapeCommFunction (sh->handle, win32action) == 0) { + if (EscapeCommFunction(sh->handle, win32action) == 0) { errno = EIO; return -1; } @@ -1085,34 +1116,36 @@ int tcflow (serial_handler_t * sh, int action) } /* tcflush: POSIX 7.2.2.1 */ -int tcflush (serial_handler_t * sh, int queue) +int tcflush(serial_handler_t *sh, int queue) { - int max; + int max; errno = 0; if (queue == TCOFLUSH || queue == TCIOFLUSH) - PurgeComm (sh->handle, PURGE_TXABORT | PURGE_TXCLEAR); + PurgeComm(sh->handle, PURGE_TXABORT | PURGE_TXCLEAR); if ((queue == TCIFLUSH) | (queue == TCIOFLUSH)) + { /* Input flushing by polling until nothing turns up * (we stop after 1000 chars anyway) */ for (max = 1000; max > 0; max--) { - DWORD ev; - COMSTAT st; - if (!PurgeComm (sh->handle, PURGE_RXABORT | PURGE_RXCLEAR)) + DWORD ev; + COMSTAT st; + if (!PurgeComm(sh->handle, PURGE_RXABORT | PURGE_RXCLEAR)) break; - Sleep (100); - if (!ClearCommError (sh->handle, &ev, &st) || !st.cbInQue) + Sleep(100); + if (!ClearCommError(sh->handle, &ev, &st) || !st.cbInQue) break; } + } return 0; } /* tcsetattr: POSIX 7.2.1.1 */ -int tcsetattr (serial_handler_t * sh, int action, const struct termios *t) +int tcsetattr(serial_handler_t *sh, int action, const struct termios *t) { /* Possible actions: TCSANOW: immediately change attributes. @@ -1120,24 +1153,25 @@ TCSADRAIN: flush output, then change attributes. TCSAFLUSH: flush output and discard input, then change attributes. */ - BOOL dropDTR = FALSE; - COMMTIMEOUTS to; - DCB ostate, state; - unsigned int ovtime = sh->vtime_, ovmin = sh->vmin_; + BOOL dropDTR = FALSE; + COMMTIMEOUTS to; + DCB ostate, state; + unsigned int ovtime = sh->vtime_, ovmin = sh->vmin_; + int res; errno = 0; upslogx(LOG_DEBUG, "action %d", action); if ((action == TCSADRAIN) || (action == TCSAFLUSH)) { - FlushFileBuffers (sh->handle); + FlushFileBuffers(sh->handle); upslogx(LOG_DEBUG, "flushed file buffers"); } if (action == TCSAFLUSH) - PurgeComm (sh->handle, (PURGE_RXABORT | PURGE_RXCLEAR)); + PurgeComm(sh->handle, (PURGE_RXABORT | PURGE_RXCLEAR)); /* get default/last comm state */ - if (!GetCommState (sh->handle, &ostate)) { + if (!GetCommState(sh->handle, &ostate)) { errno = EIO; return -1; } @@ -1290,12 +1324,12 @@ TCSAFLUSH: flush output and discard input, then change attributes. /* RTS/CTS flow control */ if (t->c_cflag & CRTSCTS) - { /* enable */ + { /* enable */ state.fOutxCtsFlow = TRUE; state.fRtsControl = RTS_CONTROL_HANDSHAKE; } else - { /* disable */ + { /* disable */ state.fRtsControl = RTS_CONTROL_ENABLE; state.fOutxCtsFlow = FALSE; } @@ -1325,14 +1359,14 @@ TCSAFLUSH: flush output and discard input, then change attributes. state.fAbortOnError = TRUE; /* -------------- Set state and exit ------------------ */ - if (memcmp (&ostate, &state, sizeof (state)) != 0) - SetCommState (sh->handle, &state); + if (memcmp(&ostate, &state, sizeof(state)) != 0) + SetCommState(sh->handle, &state); sh->r_binary = ((t->c_iflag & IGNCR) ? 0 : 1); sh->w_binary = ((t->c_oflag & ONLCR) ? 0 : 1); if (dropDTR == TRUE) - EscapeCommFunction (sh->handle, CLRDTR); + EscapeCommFunction(sh->handle, CLRDTR); else { /* FIXME: Sometimes when CLRDTR is set, setting @@ -1341,7 +1375,7 @@ TCSAFLUSH: flush output and discard input, then change attributes. * change some parameters while DTR is still down. */ - EscapeCommFunction (sh->handle, SETDTR); + EscapeCommFunction(sh->handle, SETDTR); } /* @@ -1395,7 +1429,7 @@ TCSAFLUSH: flush output and discard input, then change attributes. return 0; } - memset (&to, 0, sizeof (to)); + memset(&to, 0, sizeof(to)); if ((sh->vmin_ > 0) && (sh->vtime_ == 0)) { @@ -1432,7 +1466,7 @@ TCSAFLUSH: flush output and discard input, then change attributes. (int)to.ReadIntervalTimeout, (int)to.ReadTotalTimeoutMultiplier); - int res = SetCommTimeouts(sh->handle, &to); + res = SetCommTimeouts(sh->handle, &to); if (!res) { upslogx(LOG_ERR, "SetCommTimeout failed"); @@ -1444,20 +1478,20 @@ TCSAFLUSH: flush output and discard input, then change attributes. } /* tcgetattr: POSIX 7.2.1.1 */ -int tcgetattr (serial_handler_t * sh, struct termios *t) +int tcgetattr(serial_handler_t *sh, struct termios *t) { DCB state; errno = 0; /* Get current Win32 comm state */ - if (GetCommState (sh->handle, &state) == 0) { + if (GetCommState(sh->handle, &state) == 0) { errno = EIO; return -1; } /* for safety */ - memset (t, 0, sizeof (*t)); + memset(t, 0, sizeof(*t)); /* -------------- Baud rate ------------------ */ @@ -1593,14 +1627,14 @@ int tcgetattr (serial_handler_t * sh, struct termios *t) /* FIXME: need to handle IGNCR */ #if 0 - if (!sh->r_binary ()) + if (!sh->r_binary()) t->c_iflag |= IGNCR; #endif if (!sh->w_binary) t->c_oflag |= ONLCR; - upslogx (LOG_DEBUG, + upslogx(LOG_DEBUG, "vmin_ %d, vtime_ %d", sh->vmin_, sh->vtime_); if (sh->vmin_ == MAXDWORD) @@ -1618,14 +1652,16 @@ int tcgetattr (serial_handler_t * sh, struct termios *t) } /* FIXME no difference between ispeed and ospeed */ -void cfsetispeed(struct termios * t, speed_t speed) +void cfsetispeed(struct termios *t, speed_t speed) { t->c_ispeed = t->c_ospeed = speed; } -void cfsetospeed(struct termios * t, speed_t speed) + +void cfsetospeed(struct termios *t, speed_t speed) { t->c_ispeed = t->c_ospeed = speed; } + speed_t cfgetispeed(const struct termios *t) { return t->c_ispeed; @@ -1639,6 +1675,6 @@ speed_t cfgetospeed(const struct termios *t) #else /* !WIN32 */ /* Just avoid: ISO C forbids an empty translation unit [-Werror=pedantic] */ -int main (int argc, char ** argv); +int main(int argc, char ** argv); #endif /* !WIN32 */ diff --git a/drivers/dstate.c b/drivers/dstate.c index f8ea29356d..93edf86fcb 100644 --- a/drivers/dstate.c +++ b/drivers/dstate.c @@ -195,17 +195,17 @@ static TYPE_FD sock_open(const char *fn) #else /* WIN32 */ fd = CreateNamedPipe( - fn, /* pipe name */ - PIPE_ACCESS_DUPLEX | /* read/write access */ - FILE_FLAG_OVERLAPPED, /* async IO */ - PIPE_TYPE_BYTE | - PIPE_READMODE_BYTE | - PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, /* max. instances */ - ST_SOCK_BUF_LEN, /* output buffer size */ - ST_SOCK_BUF_LEN, /* input buffer size */ - 0, /* client time-out */ - NULL); /* FIXME: default security attribute */ + fn, /* pipe name */ + PIPE_ACCESS_DUPLEX /* read/write access */ + | FILE_FLAG_OVERLAPPED, /* async IO */ + PIPE_TYPE_BYTE + | PIPE_READMODE_BYTE + | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, /* max. instances */ + ST_SOCK_BUF_LEN, /* output buffer size */ + ST_SOCK_BUF_LEN, /* input buffer size */ + 0, /* client time-out */ + NULL); /* FIXME: default security attribute */ if (INVALID_FD(fd)) { fatal_with_errno(EXIT_FAILURE, @@ -214,10 +214,12 @@ static TYPE_FD sock_open(const char *fn) /* Prepare an async wait on a connection on the pipe */ memset(&connect_overlapped, 0, sizeof(connect_overlapped)); - connect_overlapped.hEvent = CreateEvent(NULL, /*Security*/ - FALSE, /* auto-reset*/ - FALSE, /* inital state = non signaled*/ - NULL /* no name*/); + connect_overlapped.hEvent = CreateEvent( + NULL, /* Security */ + FALSE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); if (connect_overlapped.hEvent == NULL) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } @@ -322,13 +324,13 @@ static void send_to_all(const char *fmt, ...) DWORD bytesWritten = 0; BOOL result = FALSE; - result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); - if( result == 0 ) { + result = WriteFile(conn->fd, buf, buflen, &bytesWritten, NULL); + if (result == 0) { upsdebugx(2, "%s: write failed on handle %p, disconnecting", __func__, conn->fd); sock_disconnect(conn); continue; } - else { + else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ @@ -421,11 +423,11 @@ static int send_to_one(conn_t *conn, const char *fmt, ...) #ifndef WIN32 ret = write(conn->fd, buf, buflen); #else /* WIN32 */ - result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); - if( result == 0 ) { + result = WriteFile(conn->fd, buf, buflen, &bytesWritten, NULL); + if (result == 0) { ret = 0; } - else { + else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ @@ -447,11 +449,11 @@ static int send_to_one(conn_t *conn, const char *fmt, ...) #ifndef WIN32 ret = write(conn->fd, buf, buflen); #else /* WIN32 */ - result = WriteFile (conn->fd, buf, buflen, &bytesWritten, NULL); - if( result == 0 ) { + result = WriteFile(conn->fd, buf, buflen, &bytesWritten, NULL); + if (result == 0) { ret = 0; } - else { + else { ret = (ssize_t)bytesWritten; } #endif /* WIN32 */ @@ -564,17 +566,17 @@ static void sock_connect(TYPE_FD sock) /* sockfd is the handle of the connection pending pipe */ sockfd = CreateNamedPipe( - pipename, /* pipe name */ - PIPE_ACCESS_DUPLEX | /* read/write access */ - FILE_FLAG_OVERLAPPED, /* async IO */ - PIPE_TYPE_BYTE | - PIPE_READMODE_BYTE | - PIPE_WAIT, - PIPE_UNLIMITED_INSTANCES, /* max. instances */ - ST_SOCK_BUF_LEN, /* output buffer size */ - ST_SOCK_BUF_LEN, /* input buffer size */ - 0, /* client time-out */ - NULL); /* FIXME: default security attribute */ + pipename, /* pipe name */ + PIPE_ACCESS_DUPLEX /* read/write access */ + | FILE_FLAG_OVERLAPPED, /* async IO */ + PIPE_TYPE_BYTE + | PIPE_READMODE_BYTE + | PIPE_WAIT, + PIPE_UNLIMITED_INSTANCES, /* max. instances */ + ST_SOCK_BUF_LEN, /* output buffer size */ + ST_SOCK_BUF_LEN, /* input buffer size */ + 0, /* client time-out */ + NULL); /* FIXME: default security attribute */ if (INVALID_FD(sockfd)) { fatal_with_errno(EXIT_FAILURE, @@ -583,31 +585,35 @@ static void sock_connect(TYPE_FD sock) /* Prepare a new async wait for a connection on the pipe */ CloseHandle(connect_overlapped.hEvent); - memset(&connect_overlapped,0,sizeof(connect_overlapped)); - connect_overlapped.hEvent = CreateEvent(NULL, /*Security*/ - FALSE, /* auto-reset*/ - FALSE, /* inital state = non signaled*/ - NULL /* no name*/); - if(connect_overlapped.hEvent == NULL ) { + memset(&connect_overlapped, 0, sizeof(connect_overlapped)); + connect_overlapped.hEvent = CreateEvent( + NULL, /* Security */ + FALSE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); + if (connect_overlapped.hEvent == NULL) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } /* Wait for a connection */ - ConnectNamedPipe(sockfd,&connect_overlapped); + ConnectNamedPipe(sockfd, &connect_overlapped); /* A new pipe waiting for new client connection has been created. We could manage the current connection now */ /* Start a read operation on the newly connected pipe so we could wait on the event associated to this IO */ - memset(&conn->read_overlapped,0,sizeof(conn->read_overlapped)); - memset(conn->buf,0,sizeof(conn->buf)); - conn->read_overlapped.hEvent = CreateEvent(NULL, /*Security*/ - FALSE, /* auto-reset*/ - FALSE, /* inital state = non signaled*/ - NULL /* no name*/); - if(conn->read_overlapped.hEvent == NULL ) { + memset(&conn->read_overlapped, 0, sizeof(conn->read_overlapped)); + memset(conn->buf, 0, sizeof(conn->buf)); + conn->read_overlapped.hEvent = CreateEvent( + NULL, /* Security */ + FALSE, /* auto-reset */ + FALSE, /* initial state = non signaled */ + NULL /* no name */ + ); + if (conn->read_overlapped.hEvent == NULL) { fatal_with_errno(EXIT_FAILURE, "Can't create event"); } - ReadFile (conn->fd, conn->buf, + ReadFile(conn->fd, conn->buf, sizeof(conn->buf) - 1, /* -1 to be sure to have a trailling 0 */ NULL, &(conn->read_overlapped)); #endif /* WIN32 */ @@ -1039,8 +1045,8 @@ static void sock_read(conn_t *conn) DWORD bytesRead; BOOL res; res = GetOverlappedResult(conn->fd, &conn->read_overlapped, &bytesRead, FALSE); - if( res == 0 ) { - upslogx(LOG_INFO, "Read error : %d",(int)GetLastError()); + if (res == 0) { + upslogx(LOG_INFO, "Read error : %d", (int)GetLastError()); sock_disconnect(conn); return; } @@ -1087,8 +1093,14 @@ static void sock_read(conn_t *conn) #ifdef WIN32 /* Restart async read */ - memset(conn->buf,0,sizeof(conn->buf)); - ReadFile(conn->fd,conn->buf,sizeof(conn->buf)-1,NULL,&(conn->read_overlapped)); /* -1 to be sure to have a trailling 0 */ + memset(conn->buf, 0, sizeof(conn->buf)); + ReadFile( + conn->fd, + conn->buf, + sizeof(conn->buf) - 1, /* -1 to be sure to have a trailing 0 */ + NULL, + &(conn->read_overlapped) + ); #endif /* WIN32 */ } @@ -1318,7 +1330,7 @@ int dstate_poll_fds(struct timeval timeout, TYPE_FD arg_extrafd) /* Retrieve the signaled connection */ for (conn = connhead; conn != NULL; conn = conn->next) { - if( conn->read_overlapped.hEvent == rfds[ret-WAIT_OBJECT_0]) { + if (conn->read_overlapped.hEvent == rfds[ret-WAIT_OBJECT_0]) { break; } } @@ -2049,7 +2061,9 @@ void alarm_set(const char *buf) } } upslogx(LOG_ERR, "%s: error setting alarm_buf to: %s%s", - __func__, alarm_tmp, ( (buflen < sizeof(alarm_tmp)) ? "" : "..." ) ); + __func__, alarm_tmp, + ( (buflen < sizeof(alarm_tmp)) ? "" : "..." ) + ); } else if ((size_t)ret > sizeof(alarm_buf)) { char alarm_tmp[LARGEBUF]; int ibuflen; @@ -2085,7 +2099,8 @@ void alarm_set(const char *buf) upslogx(LOG_WARNING, "%s: result was truncated while setting or appending " "alarm_buf (limited to %" PRIuSIZE " bytes), with message: %s%s", __func__, sizeof(alarm_buf), alarm_tmp, - ( (buflen < sizeof(alarm_tmp)) ? "" : "..." )); + ( (buflen < sizeof(alarm_tmp)) ? "" : "..." ) + ); } } #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_BESIDEFUNC) && (!defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP_INSIDEFUNC) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS_BESIDEFUNC) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE_BESIDEFUNC) ) diff --git a/include/wincompat.h b/include/wincompat.h index d42815d28e..dfee5a24c1 100644 --- a/include/wincompat.h +++ b/include/wincompat.h @@ -2,7 +2,11 @@ #define NUT_WINCOMPAT_H 1 /* - Copyright (C) 2001 Andrew Delpha (delpha@computer.org) + Copyright (C) + 2001 Andrew Delpha (delpha@computer.org) + 2010 - 2013 Frederic Bohe + 2012 Arnaud Quette + 2022 - 2026 Jim Klimov This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by