Imported Upstream version 2.6.4

This commit is contained in:
Arnaud Quette 2012-06-01 15:55:19 +02:00
parent fad6ced6f6
commit fefe62b2bd
257 changed files with 6020 additions and 1394 deletions

View file

@ -45,6 +45,81 @@ upsdrv_info_t upsdrv_info = {
static int ups_status = 0;
/*
* Aix compatible names
*/
#if defined(VWERSE) && !defined(VWERASE)
#define VWERASE VWERSE
#endif /* VWERSE && !VWERASE */
#if defined(VDISCRD) && !defined(VDISCARD)
#define VDISCARD VDISCRD
#endif /* VDISCRD && !VDISCARD */
#ifndef CTRL
#define CONTROL(x) (x&037)
#else
#define CONTROL CTRL
#endif
/*
* Allow use of system default characters if defined and reasonable.
* These are based on the BSD ttydefaults.h
*/
#ifndef CDISCARD
#define CDISCARD CONTROL('O')
#endif
#ifndef CDSUSP
#define CDSUSP CONTROL('Y')
#endif
#ifndef CEOF
#define CEOF CONTROL('D')
#endif
#ifndef CEOL
#define CEOL 0xff /* was 0 */
#endif
#ifndef CERASE
#define CERASE 0177
#endif
#ifndef CINTR
#define CINTR CONTROL('C')
#endif
#ifndef CKILL
#define CKILL CONTROL('U') /* was '@' */
#endif
#ifndef CLNEXT
#define CLNEXT CONTROL('V')
#endif
#ifndef CMIN
#define CMIN CEOF
#endif
#ifndef CQUIT
#define CQUIT CONTROL('\\')
#endif
#ifndef CRPRNT
#define CRPRNT CONTROL('R')
#endif
#ifndef CREPRINT
#define CREPRINT CRPRNT
#endif
#ifndef CSTART
#define CSTART CONTROL('Q')
#endif
#ifndef CSTOP
#define CSTOP CONTROL('S')
#endif
#ifndef CSUSP
#define CSUSP CONTROL('Z')
#endif
#ifndef CTIME
#define CTIME CEOL
#endif
#ifndef CWERASE
#define CWERASE CONTROL('W')
#endif
/* some forwards */
static int sdcmd_S(const void *);
@ -188,7 +263,10 @@ static void apc_ser_set(void)
tio.c_cflag |= (CS8 | CLOCAL | CREAD);
tio.c_lflag |= ICANON;
tio.c_lflag &= ~ISIG;
#ifdef NOKERNINFO
tio.c_lflag |= NOKERNINFO;
#endif
tio.c_lflag &= ~(ISIG | IEXTEN);
tio.c_iflag |= (IGNCR | IGNPAR);
tio.c_iflag &= ~(IXON | IXOFF);
@ -220,11 +298,92 @@ static void apc_ser_set(void)
if (tcsetattr(upsfd, TCSANOW, &tio))
fatal_with_errno(EXIT_FAILURE, "tcsetattr(%s)", device_path);
/* clear status flags so that they don't affect our binary compare */
#ifdef PENDIN
tio.c_lflag &= ~PENDIN;
#endif
#ifdef FLUSHO
tio.c_lflag &= ~FLUSHO;
#endif
memset(&tio_chk, 0, sizeof(tio_chk));
if (tcgetattr(upsfd, &tio_chk))
fatal_with_errno(EXIT_FAILURE, "tcgetattr(%s)", device_path);
if (memcmp(&tio_chk, &tio, sizeof(tio)))
fatalx(EXIT_FAILURE, "unable to set the required attributes (%s)", device_path);
/* clear status flags so that they don't affect our binary compare */
#ifdef PENDIN
tio_chk.c_lflag &= ~PENDIN;
#endif
#ifdef FLUSHO
tio_chk.c_lflag &= ~FLUSHO;
#endif
if (memcmp(&tio_chk, &tio, sizeof(tio))) {
struct cchar {
const char *name;
int sub;
u_char def;
};
const struct cchar cchars1[] = {
#ifdef VDISCARD
{ "discard", VDISCARD, CDISCARD },
#endif
#ifdef VDSUSP
{ "dsusp", VDSUSP, CDSUSP },
#endif
{ "eof", VEOF, CEOF },
{ "eol", VEOL, CEOL },
{ "eol2", VEOL2, CEOL },
{ "erase", VERASE, CERASE },
#ifdef VINTR
{ "intr", VINTR, CINTR },
#endif
{ "kill", VKILL, CKILL },
{ "lnext", VLNEXT, CLNEXT },
{ "min", VMIN, CMIN },
{ "quit", VQUIT, CQUIT },
#ifdef VREPRINT
{ "reprint", VREPRINT, CREPRINT },
#endif
{ "start", VSTART, CSTART },
#ifdef VSTATUS
{ "status", VSTATUS, CSTATUS },
#endif
{ "stop", VSTOP, CSTOP },
{ "susp", VSUSP, CSUSP },
{ "time", VTIME, CTIME },
{ "werase", VWERASE, CWERASE },
{ .name = NULL },
};
const struct cchar *cp;
struct termios *tp;
upslogx(LOG_NOTICE, "%s: device reports different attributes than what were set", device_path);
/*
* According to the manual the most common problem is
* mis-matched combinations of input and output baud rates. If
* the combination is not supported then neither are changed.
* This should not be a problem here since we set them both to
* the same extremely common rate of 2400.
*/
tp = &tio;
upsdebugx(1, "tcsetattr(): gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
(unsigned int) tp->c_cflag, (unsigned int) tp->c_iflag,
(unsigned int) tp->c_lflag, (unsigned int) tp->c_oflag);
for (cp = cchars1; cp->name; ++cp)
upsdebugx(1, "\t%s=%x:", cp->name, tp->c_cc[cp->sub]);
upsdebugx(1, "\tispeed=%d:ospeed=%d", (int) cfgetispeed(tp), (int) cfgetospeed(tp));
tp = &tio_chk;
upsdebugx(1, "tcgetattr(): gfmt1:cflag=%x:iflag=%x:lflag=%x:oflag=%x:",
(unsigned int) tp->c_cflag, (unsigned int) tp->c_iflag,
(unsigned int) tp->c_lflag, (unsigned int) tp->c_oflag);
for (cp = cchars1; cp->name; ++cp)
upsdebugx(1, "\t%s=%x:", cp->name, tp->c_cc[cp->sub]);
upsdebugx(1, "\tispeed=%d:ospeed=%d", (int) cfgetispeed(tp), (int) cfgetospeed(tp));
}
cable = getval("cable");
if (cable && !strcasecmp(cable, ALT_CABLE_1)) {
@ -464,7 +623,8 @@ static int apc_write_long(const char *code)
return -1;
}
return ser_send_pace(upsfd, 50000, "%s", code + 1);
ret = ser_send_pace(upsfd, 50000, "%s", code + 1);
return ret < 0 ? ret : ret + 1;
}
static int apc_write_rep(unsigned char code)
@ -1747,9 +1907,9 @@ static int setvar_string(apc_vartab_t *vt, const char *val)
*ptr++ = '\015'; /* pad with CRs */
*ptr = 0;
ret = apc_write_long(ptr);
ret = apc_write_long(temp);
if ((size_t)ret != strlen(ptr)) {
if (ret != APC_STRLEN + 1) {
upslog_with_errno(LOG_ERR, "setvar_string: apc_write_long failed");
return STAT_SET_FAILED;
}