Skip to content

Commit

Permalink
drivers/clone.c, drivers/clone-outlet.c: reconcile shared code style
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Sep 7, 2024
1 parent 47a0de0 commit 93d0b00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
21 changes: 10 additions & 11 deletions drivers/clone-outlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <sys/un.h>
#endif

#define DRIVER_NAME "clone outlet UPS Driver"
#define DRIVER_VERSION "0.04"
#define DRIVER_NAME "Clone outlet UPS driver"
#define DRIVER_VERSION "0.05"

/* driver description structure */
upsdrv_info_t upsdrv_info = {
Expand Down Expand Up @@ -69,12 +69,12 @@ static int dumpdone = 0;
static PCONF_CTX_t sock_ctx;
static time_t last_heard = 0, last_ping = 0;

#ifdef WIN32
static char read_buf[SMALLBUF];
static OVERLAPPED read_overlapped;
#else
#ifndef WIN32
/* TODO: Why not built in WIN32? */
static time_t last_connfail = 0;
#else
static char read_buf[SMALLBUF];
static OVERLAPPED read_overlapped;
#endif

static int parse_args(size_t numargs, char **arg)
Expand Down Expand Up @@ -154,11 +154,11 @@ static int parse_args(size_t numargs, char **arg)
static TYPE_FD sstate_connect(void)
{
TYPE_FD fd;
const char *dumpcmd = "DUMPALL\n";

#ifndef WIN32
ssize_t ret;
int len;
const char *dumpcmd = "DUMPALL\n";
struct sockaddr_un sa;

memset(&sa, '\0', sizeof(sa));
Expand Down Expand Up @@ -234,7 +234,6 @@ static TYPE_FD sstate_connect(void)
/* continued below... */
#else /* WIN32 */
char pipename[SMALLBUF];
const char *dumpcmd = "DUMPALL\n";
BOOL result = FALSE;

snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s/%s", dflt_statepath(), device_path);
Expand Down Expand Up @@ -324,12 +323,12 @@ static int sstate_sendline(const char *buf)
DWORD bytesWritten = 0;
BOOL result = FALSE;

result = WriteFile (upsfd,buf,strlen(buf),&bytesWritten,NULL);
result = WriteFile (upsfd, buf, strlen(buf), &bytesWritten, NULL);

if( result == 0 ) {
if (result == 0) {
ret = 0;
}
else {
else {
ret = (int)bytesWritten;
}
#endif
Expand Down
51 changes: 26 additions & 25 deletions drivers/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ static long offdelay = 120, ondelay = 30;
static PCONF_CTX_t sock_ctx;
static time_t last_poll = 0, last_heard = 0,
last_ping = 0;

#ifndef WIN32
static time_t last_connfail = 0;
/* TODO: Why not built in WIN32? */
static time_t last_connfail = 0;
#else
static char read_buf[SMALLBUF];
static OVERLAPPED read_overlapped;
static char read_buf[SMALLBUF];
static OVERLAPPED read_overlapped;
#endif

static int instcmd(const char *cmdname, const char *extra);
Expand Down Expand Up @@ -168,11 +170,11 @@ static int parse_args(size_t numargs, char **arg)
static TYPE_FD sstate_connect(void)
{
TYPE_FD fd;
const char *dumpcmd = "DUMPALL\n";

#ifndef WIN32
ssize_t ret;
int len;
const char *dumpcmd = "DUMPALL\n";
struct sockaddr_un sa;

memset(&sa, '\0', sizeof(sa));
Expand Down Expand Up @@ -248,7 +250,6 @@ static TYPE_FD sstate_connect(void)
/* continued below... */
#else /* WIN32 */
char pipename[SMALLBUF];
const char *dumpcmd = "DUMPALL\n";
BOOL result = FALSE;

snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\%s/%s", dflt_statepath(), device_path);
Expand Down Expand Up @@ -338,7 +339,7 @@ static int sstate_sendline(const char *buf)
DWORD bytesWritten = 0;
BOOL result = FALSE;

result = WriteFile (upsfd,buf,strlen(buf),&bytesWritten,NULL);
result = WriteFile (upsfd, buf, strlen(buf), &bytesWritten, NULL);

if (result == 0) {
ret = 0;
Expand Down Expand Up @@ -373,13 +374,13 @@ static int sstate_readline(void)
if (ret < 0) {
switch(errno)
{
case EINTR:
case EAGAIN:
return 0;
case EINTR:
case EAGAIN:
return 0;

default:
upslog_with_errno(LOG_WARNING, "Read from UPS [%s] failed", device_path);
return -1;
default:
upslog_with_errno(LOG_WARNING, "Read from UPS [%s] failed", device_path);
return -1;
}
}
#else
Expand All @@ -398,19 +399,19 @@ static int sstate_readline(void)

switch (pconf_char(&sock_ctx, buf[i]))
{
case 1:
if (parse_args(sock_ctx.numargs, sock_ctx.arglist)) {
time(&last_heard);
}
continue;

case 0:
continue; /* haven't gotten a line yet */

default:
/* parse error */
upslogx(LOG_NOTICE, "Parse error on sock: %s", sock_ctx.errmsg);
return -1;
case 1:
if (parse_args(sock_ctx.numargs, sock_ctx.arglist)) {
time(&last_heard);
}
continue;

case 0:
continue; /* haven't gotten a line yet */

default:
/* parse error */
upslogx(LOG_NOTICE, "Parse error on sock: %s", sock_ctx.errmsg);
return -1;
}
}

Expand Down

0 comments on commit 93d0b00

Please sign in to comment.