Пример #1
0
/*
 * test sending a break
 */
int
test3(void)
{
	int masterfd, slavefd;
	char *slavename;

	masterfd = open(MASTERCLONE, O_RDWR);
	if (masterfd < 0) {
		tst_resm(TBROK,"%s",MASTERCLONE);
		tst_exit();
	}

	slavename = ptsname(masterfd);
	if (slavename == NULL) {
		tst_resm(TBROK|TERRNO, "ptsname() call failed");
		tst_exit();
	}

	if (grantpt(masterfd) != 0) {
		tst_resm(TBROK|TERRNO, "grantpt() call failed");
		tst_exit();
	}

	if (unlockpt(masterfd) != 0) {
		tst_resm(TBROK,"unlockpt() call failed");
		tst_exit();
	}

	if ((slavefd = open(slavename, O_RDWR)) < 0) {
		tst_resm(TBROK,"Could not open %s",slavename);
		tst_exit();
	}

	if (tcsendbreak(masterfd, 10) != 0) {
		tst_resm(TFAIL,"tcsendbreak");
		tst_exit();
	}

	if (tcsendbreak(slavefd, 10) != 0) {
		tst_resm(TFAIL,"tcsendbreak");
		tst_exit();
	}

	if (close(slavefd) != 0) {
		tst_resm(TBROK,"close slave");
		tst_exit();
	}

	if (close(masterfd) != 0) {
		tst_resm(TBROK,"close master");
		tst_exit();
	}
	tst_resm(TPASS,"test3");

	/** NOT REACHED **/
	return 0;
}
Пример #2
0
s48_ref_t sch_tcsendbreak(s48_call_t call, s48_ref_t sch_fd, s48_ref_t sch_duration) {
    if (tcsendbreak (s48_extract_long_2(call, sch_fd),
                     s48_extract_long_2(call, sch_duration)) == -1)
        s48_os_error_2(call, "sch_tcsendbreak", errno, 2, sch_fd, sch_duration);

    return s48_unspecific_2(call);
}
Пример #3
0
int ndiSerialBreak(int serial_port)
{
  tcflush(serial_port,TCIOFLUSH);     /* clear input/output buffers */
  tcsendbreak(serial_port,0);         /* send the break */

  return 0;
}
Пример #4
0
int serialPort::portMode(setType setting, char *set)
{
    switch (setting)
    {
        case CONFIG:
            strcpy(config, set);
            break;
        case EOSMODE:
            eosMode = *set;
            break;
        case CLEAR:
#ifdef __WIN32__
			SetCommBreak( handle );
			Sleep ( 300 ); // sleep 300 ms
			ClearCommBreak( handle );
			Sleep ( 50 ); // sleep 50 ms
#endif
#ifdef __linux__
			printf("serialPort::portMode break 300\n");
			tcsendbreak( handle, 300); // should send 300 ms break
			usleep(100000); // a bit of a guard after
			tcdrain( handle );
#endif
            break;
        case TIMEOUT:
            timeout = strtoul(set, NULL, 10) * 1000L;
            break;
        case PACING:
            pace = strtoul(set, NULL, 10) * 1000L;
            break;
    }

    return 0;
}
Пример #5
0
static void
sol_serial_send_break(ipmi_sol_t *sol)
{
    soldata_t *sd = sol->soldata;

    tcsendbreak(sd->fd, 0);
}
Пример #6
0
void sendbreak(void)
{
	if(serial_port_fd == -1)
		return;
	else
		tcsendbreak(serial_port_fd, 0);
}
Пример #7
0
static int
hardwire_send_break (struct serial *scb)
{
#ifdef HAVE_TERMIOS
  return tcsendbreak (scb->fd, 0);
#endif

#ifdef HAVE_TERMIO
  return ioctl (scb->fd, TCSBRK, 0);
#endif

#ifdef HAVE_SGTTY
  {
    int status;
    struct timeval timeout;

    status = ioctl (scb->fd, TIOCSBRK, 0);

    /* Can't use usleep; it doesn't exist in BSD 4.2.  */
    /* Note that if this select() is interrupted by a signal it will not wait
       the full length of time.  I think that is OK.  */
    timeout.tv_sec = 0;
    timeout.tv_usec = 250000;
    select (0, 0, 0, 0, &timeout);
    status = ioctl (scb->fd, TIOCCBRK, 0);
    return status;
  }
#endif
}
Пример #8
0
unit
posix_tty_tcsendbreak(cerr er, int fd, int duration)
{
	if(tcsendbreak(fd, duration) == -1)
		send_errno(er,errno);
	return empty_record;
}
void EIO_Break(uv_work_t* req) {
  BreakBaton* data = static_cast<BreakBaton*>(req->data);

  data->result = tcsendbreak(data->fd, 1000);
  if (data->result == -1) {
    snprintf(data->errorString, sizeof(data->errorString), "Error %s calling ioctl( ..., tcsendbreak)", strerror(errno));
  }
}
Пример #10
0
/***
Send a stream of zero valued bits.
@function tcsendbreak
@see tcsendbreak(3)
@int fd terminal descriptor
@int duration if non-zero, stream for some implementation defined time
@return 0 if successful, otherwise nil
@return error message if failed
*/
static int
Ptcsendbreak(lua_State *L)
{
	int fd = checkint(L, 1);
	int duration = checkint(L, 2);
	checknargs(L, 2);
	return pushresult(L, tcsendbreak(fd, duration), NULL);
}
Пример #11
0
int
xf86SerialSendBreak(int fd, int duration)
{
    int r;

    SYSCALL(r = tcsendbreak(fd, duration));
    return r;

}
Пример #12
0
void SerialPort::sendBreak()
{
#ifdef __WIN32__
    SetCommBreak(handle);
    ClearCommBreak(handle);
#endif
#if defined(__gnu_linux__) || (defined(__APPLE__) && defined(__MACH__))
    tcsendbreak(handle, 0);
#endif
}
Пример #13
0
/*
 * Send serial special codes.
 */
static void serial_special(void *handle, Telnet_Special code)
{
    Serial serial = (Serial) handle;

    if (serial->fd >= 0 && code == TS_BRK) {
	tcsendbreak(serial->fd, 0);
	logevent(serial->frontend, "Sending serial break at user request");
    }

    return;
}
Пример #14
0
/*
 * Class:     com_pi4j_jni_Serial
 * Method:    sendBreak
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_com_pi4j_jni_Serial_sendBreak
  (JNIEnv *env, jclass obj, jint fd, jint duration)
{
	// transmit break
	if(tcsendbreak(fd, duration) != 0){
        int err_number = errno;
        char err_message[100];
        sprintf(err_message, "Failed to transmit BREAK signal to serial port. (Error #%d)", err_number);
        throwIOException(env, err_message);
	}
}
Пример #15
0
int gpio_serial_send_break (gpio_device *dev, int duration) {

        /* Duration is in seconds */

#if HAVE_TERMIOS_H
        tcsendbreak(dev->device_fd, duration / 3);
        tcdrain(dev->device_fd);
#else
        /* ioctl */
#endif
        return 0;
}
Пример #16
0
static bool _srmio_ios_send_break( srmio_io_t h, srmio_error_t *err )
{
	assert( h );
	assert( SELF(h)->fd >= 0 );

	if( 0 != tcsendbreak( SELF(h)->fd, 0 ) ){
		srmio_error_errno( err, "ios break" );
		return false;
	}

	return true;
}
Пример #17
0
void _DtTermPrimPtySendBreak(int pty, int msec)
{
#if	defined(USE_TIOCBREAK)
    (void) ioctl(pty, TIOCBREAK, 0);
#elif	defined(USE_TCSBRK)
    (void) ioctl(pty, TCSBRK, 0);
#elif	defined(USE_TCSENDBREAK)
    (void) tcsendbreak(pty, 0);
#else	/* none specified... */
    There is no RS232 break code specified for this architecture.  See
    TermPrimOSDepI.h for a list of #defines...
#endif	/* rs232 break definition... */
}
Пример #18
0
int send_to_modem(unsigned char *buffer, unsigned int bytes)
{
	unsigned char outbuf[256];
	unsigned int i;
	int res;
	int msr;
	char errorbuf[256];

	if (debug)
		printf("Sending to modem %d bytes\n", bytes);

	outbuf[0] = 0x55;
	outbuf[1] = bytes;
	outbuf[2] = 0x00;

	for (i = 0; i < bytes; i++) {
		outbuf[3 + i] = buffer[i];
	}

	msr = TIOCM_RTS;

	ioctl(modem_fd, TIOCMBIS, &msr);

	msr = 0;

	while (!(msr & TIOCM_CTS)) {

		if ((ioctl(modem_fd, TIOCMGET, &msr)) == -1) {
			sprintf(errorbuf, "ioctl(TIOCMGET) failed, (%s)",
				strerror(errno));
			printf("%s\n", errorbuf);
			//return errno;
		}
		if (debug)
			msr_display(msr);

		// We cant do it if its 4146 it must be 4126
	}

	tcsendbreak(modem_fd, 0);

	if (debug)
		display("send", outbuf, i + 3);

	res = write(modem_fd, outbuf, i + 3);

	if (debug)
		printf("send_to_modem about to return %d\n", res);

	return res;
}
Пример #19
0
/* process function for help_state=0 */
static void help_send_escape(int fd, char c) { 
  struct  termios pts;  /* termios settings on port */

  in_escape = 0;
  help_state = 0;
  
  switch (c) {
  case 'x':
    /* restore termios settings and exit */
    write(STDOUT_FILENO, "\n", 1);
    cleanup_termios(0);
    break;
  case 'q': /* quit help */
    break;
  case 'l': /* log on/off */    
    if (flog == 0) { /* open log file */
      open_logFile(log_file);
    }
    else { /* close log file */
      close_logFile();
    }
    break;
  case 's': /* script active/inactive */
    script_init(scr_name);
    script = (script)? 0: 1;
    break;
  case 'b': /* send break */
    /* send a break */
    tcsendbreak(fd, 0);
    break;
  case 't': /* set terminal */
    help_state = 1;
    help_terminal();
    in_escape = 1;
    break;
  case '~': /* display it again */
    help_escape();
    break;
  default:
    /* pass the character through */
    /* "C-\ C-\" sends "C-\" */
    write(fd, &c, 1);
    break;
  }

  if (in_escape == 0)
    help_done();

  return;
}
static PyObject *
termios_tcsendbreak(PyObject *self, PyObject *args)
{
    int fd, duration;

    if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
                          fdconv, &fd, &duration))
        return NULL;
    if (tcsendbreak(fd, duration) == -1)
        return PyErr_SetFromErrno(TermiosError);

    Py_INCREF(Py_None);
    return Py_None;
}
Пример #21
0
/* the serial control callin function: */
static int
_tme_posix_serial_ctrl(struct tme_serial_connection *conn_serial, unsigned int control)
{
  struct tme_posix_serial *serial;
  int modem_state;
  int rc;

  /* recover our data structure: */
  serial = conn_serial->tme_serial_connection.tme_connection_element->tme_element_private;

  /* lock our mutex: */
  tme_mutex_lock(&serial->tme_posix_serial_mutex);

  /* get the current output device modem state: */
  rc = ioctl(serial->tme_posix_serial_fd_out, TIOCMGET, &modem_state);

  /* update the modem state: */
  if (control & TME_SERIAL_CTRL_DTR) {
    modem_state |= TIOCM_DTR;
  }
  else {
    modem_state &= TIOCM_DTR;
  }
  if (control & TME_SERIAL_CTRL_RTS) {
    modem_state |= TIOCM_RTS;
  }
  else {
    modem_state &= TIOCM_RTS;
  }

  /* set the new modem state: */
  rc = ioctl(serial->tme_posix_serial_fd_out, TIOCMSET, &modem_state);

  /* send a break: */
  if (control & TME_SERIAL_CTRL_BREAK) {
    tcsendbreak(serial->tme_posix_serial_fd_out, 0);
  }

  /* remember these controls.  if the OK_READ is set, call out a read: */
  serial->tme_posix_serial_ctrl_callin = control;
  if (control & TME_SERIAL_CTRL_OK_READ) {
    _tme_posix_serial_callout(serial);
  }

  /* unlock our mutex: */
  tme_mutex_unlock(&serial->tme_posix_serial_mutex);

  /* done: */
  return (TME_OK);
}
/**
 *The ability to send a Break signal (~.5sec of tying the TX pin low) in Linux
 */
void CMOOSLinuxSerialPort::Break()
{

    if (m_nPortFD < 0)
    {
        MOOSTrace("Cannot Break because port is not open\n");
        return;
    }

    //according to http://www.mkssoftware.com/docs/man3/tcsendbreak.3.asp
    //a default value of 0 should work fine, sends a break for 250-500ms,
#ifndef _WIN32
    tcsendbreak(m_nPortFD, 0);
#endif
}
Пример #23
0
void serialuartbreak (int v)
{
    if (ser_fd < 0 || !currprefs.use_serial) {
        return;
    }
    
#ifdef POSIX_SERIAL
    if(v) {
        /* in posix serial calls we can't fulfill this function interface 
        completely: as we are not able to toggle the break mode with "v".
        We simply trigger a default break here if v is enabled... */
        if(tcsendbreak(ser_fd, 0) < 0) {
            write_log("serial: TCSENDBREAK failed\n");
        }
    }
#endif
}
Пример #24
0
void
sendbrk(int fd)
{
#ifdef USE_TERMIOS
	tcsendbreak(fd,0);
#endif
#ifdef USE_TERMIO
	ioctl(fd, TCSBRK, 0);
#endif
#ifdef USE_SGTTY
#ifdef TIOCSBRK
	sleep(1);
	ioctl(fd, TIOCSBRK, 0);
	sleep(1);
	ioctl(fd, TIOCCBRK, 0);
#endif
#endif
}
Пример #25
0
sendbrk()
{
#ifdef V7
#ifdef TIOCSBRK
#define CANBREAK
	sleep(1);
	ioctl(Tty, TIOCSBRK, 0);
	sleep(1);
	ioctl(Tty, TIOCCBRK, 0);
#endif
#endif
#ifdef USG
#define CANBREAK
#ifdef POSIX
	tcsendbreak(Tty, 200);
#else
	ioctl(Tty, TCSBRK, 0);
#endif
#endif
}
Пример #26
0
mraa_result_t
mraa_uart_sendbreak(mraa_uart_context dev, int duration)
{
    if (!dev) {
        syslog(LOG_ERR, "uart: sendbreak: context is NULL");
        return MRAA_ERROR_INVALID_HANDLE;
    }

    if (IS_FUNC_DEFINED(dev, uart_sendbreak_replace)) {
        return dev->advance_func->uart_sendbreak_replace(dev, duration);
    }

#if !defined(PERIPHERALMAN)
    if (tcsendbreak(dev->fd, duration) == -1) {
        return MRAA_ERROR_INVALID_PARAMETER;
    }
#endif

    return MRAA_SUCCESS;
}
Пример #27
0
static int
gp_port_serial_send_break (GPPort *dev, int duration)
{
	/* The device needs to be opened for that operation */
	if (!dev->pl->fd)
		CHECK (gp_port_serial_open (dev));

	/* Make sure we are operating at the specified speed */
	CHECK (gp_port_serial_check_speed (dev));

        /* Duration is in milliseconds */
#ifdef HAVE_TERMIOS_H
        tcsendbreak (dev->pl->fd, duration / 310);
        tcdrain (dev->pl->fd);
#else
# ifdef __GCC__
#  warning SEND BREAK NOT IMPLEMENTED FOR NON TERMIOS SYSTEMS!
# endif
#endif

        return GP_OK;
}
Пример #28
0
Val   _lib7_P_TTY_tcsendbreak   (Task* task,  Val arg)   {
    //=======================
    //
    // Mythryl type:   (Int, Int) -> Void
    //
    // Send break condition on tty line.
    //
    // This fn gets bound as   tcsendbreak   in:
    //
    //     src/lib/std/src/posix-1003.1b/posix-tty.pkg

									    ENTER_MYTHRYL_CALLABLE_C_FN("_lib7_P_TTY_tcsendbreak");

    int fd       =  GET_TUPLE_SLOT_AS_INT( arg, 0 );
    int duration =  GET_TUPLE_SLOT_AS_INT( arg, 1 );

    RELEASE_MYTHRYL_HEAP( task->pthread, "_lib7_P_TTY_tcsendbreak", NULL );
	//
	int status = tcsendbreak( fd, duration );
	//
    RECOVER_MYTHRYL_HEAP( task->pthread, "_lib7_P_TTY_tcsendbreak" );

    RETURN_VOID_EXCEPT_RAISE_SYSERR_ON_NEGATIVE_STATUS__MAY_HEAPCLEAN(task, status, NULL);
}
Пример #29
0
int
main(int argc, char **argv)
{
    int             ups_fd, stat_fd, ch;
    int             flags;
    int             pstatus, poldstat = 1;
    int             bstatus, boldstat = 1;
    int             count = 0;
    int             bcount = 0;
    int             tries = 0;
    int             ikill = 0;
    int             ioctlbit;
    char           *self = argv[0];
    char            killchar = ' ';
    struct upsdef  *pups;

    while ((ch = getopt(argc, argv, "kc:d:r:s:t:")) != -1)
	switch (ch) {
	  case 'k':
	    ikill = 1;
	    break;
	  case 'c':
	    config_file = optarg;
	    break;
	  case 'd':
	    upsport = optarg;
	    break;
	  case 'r':
	    rcpowerfail = optarg;
	    break;
	  case 's':
	    upsstat = optarg;
	    break;
	  case 't':
	    upstype = optarg;
	    break;
	  case '?':
	  default:
	    usage(self);
	}
    argc -= optind;
    argv += optind;
    if (argc > 0)
	usage(self);

    parse_config(config_file);

    if (upsport == NULL || upstype == NULL || upsstat == NULL) {
	usage(self);
    }
    for (pups = ups; pups; pups = pups->next) {
	if (strcmp(pups->tag, upstype) == 0)
	    break;
    }
    if (!pups) {
	fprintf(stderr, "Error: %s: UPS <%s> unknown\n", self, argv[2]);
	exit(1);
    }
    /* Start syslog. */
    openlog(self, LOG_CONS | LOG_PERROR, LOG_DAEMON);

    if ((ups_fd = open(upsport, O_RDWR | O_NDELAY)) < 0) {
	syslog(LOG_ERR, "%s: %s", upsport, strerror(errno));
	closelog();
	exit(1);
    }
    /* Kill the inverter and close out if inverter kill was selected */
    if (ikill) {
	if (pups->killtime) {

	    /* Explicitly clear both DTR and RTS as soon as possible  */
	    ioctlbit = TIOCM_RTS;
	    ioctl(ups_fd, TIOCMBIC, &ioctlbit);
	    ioctlbit = TIOCM_DTR;
	    ioctl(ups_fd, TIOCMBIC, &ioctlbit);

	    /* clear killpower, apply cablepower to enable monitoring */
	    setlevel(ups_fd, pups->kill.line, !pups->kill.inverted);
	    setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted);

	    if (pups->kill.line == TIOCM_ST) {
		/* Send BREAK (TX high) to kill the UPS inverter. */
		tcsendbreak(ups_fd, 1000 * pups->killtime);
	    } else {
		/* Force high to send the UPS the inverter kill signal. */
		setlevel(ups_fd, pups->kill.line, pups->kill.inverted);
		sleep(pups->killtime);
	    }
	    ioctl(ups_fd, TIOCMGET, &flags);

	    /*
	     * Feb/05/2001 Added support for Tripplite Omnismart 450PNP, this
	     * UPS shutdowns inverter when data is sent over the Tx line
	     * (jhcaiced)
	     */
	    if (pups->flags & UPS_TXD_KILL_INVERTER) {
		sleep(2);
		write(ups_fd, &killchar, 1);
	    }
	    close(ups_fd);

	    /************************************************************/
	    /* We never should have gotten here.                        */
	    /* The inverter kill has failed for one reason or another.  */
	    /* If still in powerfail mode, exit with an error.          */
	    /* If power is ok (power has returned) let rc.0 finish the  */
	    /* reboot.                                                  */
	    /************************************************************/
	    if (getlevel(&pups->powerok, flags) == 0) {
		fprintf(stderr, "%s: UPS inverter kill failed.\n", self);
		exit(1);
	    }			/* if (getlevel(&pups->powerok,flags) == 0) */
	    /* Otherwise, exit normaly, power has returned. */
	    exit(0);
	} else {
	    fprintf(stderr, "Error: %s: UPS <%s> has no support for killing the inverter.\n",
		    self, pups->tag);
	    exit(1);
	}			/* if (pups->kill) */
    }				/* if (ikill) */
    /****************************************/
    /* If no kill signal, monitor the line. */
    /****************************************/
    /* Explicitly clear both DTR and RTS as soon as possible  */
    ioctl(ups_fd, TIOCMBIC, TIOCM_RTS);
    ioctl(ups_fd, TIOCMBIC, TIOCM_DTR);

    /* clear killpower, apply cablepower to enable monitoring */
    setlevel(ups_fd, pups->kill.line, !pups->kill.inverted);
    setlevel(ups_fd, pups->cablepower.line, !pups->cablepower.inverted);

    /* Daemonize. */
#ifdef DEBUG
    closelog();
    setsid();
#else
    switch (fork()) {
      case 0:			/* Child */
	closelog();
	setsid();
	break;
      case -1:			/* Error */
	syslog(LOG_ERR, "can't fork.");
	closelog();
	exit(1);
      default:			/* Parent */
	closelog();
	exit(0);
    }
#endif				/* switch(fork()) */

    /* Restart syslog. */
    openlog(self, LOG_CONS, LOG_DAEMON);

    /* Create an info file for powerfail scripts. */
    unlink(upsstat);
    if ((stat_fd = open(upsstat, O_CREAT | O_WRONLY, 0644)) >= 0) {
	write(stat_fd, "OK\n", 3);
	close(stat_fd);
    }
    /* Give the UPS a chance to reach a stable state. */
    sleep(2);

    /* Now sample the line. */
    while (1) {
	/* Get the status. */
	ioctl(ups_fd, TIOCMGET, &flags);

	/* Calculate present status. */
	pstatus = getlevel(&pups->powerok, flags);
	bstatus = getlevel(&pups->battok, flags);

	if (pups->cableok.line) {
	    /* Check the connection. */
	    tries = 0;
	    while (getlevel(&pups->cableok, flags) == 0) {
		/* Keep on trying, and warn every two minutes. */
		if ((tries % 60) == 0)
		    syslog(LOG_ALERT, "UPS connection error");
		sleep(2);
		tries++;
		ioctl(ups_fd, TIOCMGET, &flags);
	    }			/* while(getlevel(&pups->cableok,flags) */
	    if (tries > 0)
		syslog(LOG_ALERT, "UPS connection OK");
	} else {
	    /*
	     * Do pseudo-cable check, bad power on startup == possible bad
	     * cable
	     */
	    if (tries < 1) {
		tries++;

		/* Do startup failure check */
		if (!pstatus) {
		    /*
		     * Power is out: assume bad cable, but semi-scram to be
		     * safe
		     */
		    syslog(LOG_ALERT, "No power on startup; UPS connection error?");

		    /*
		     * Set status registers to prevent further processing
		     * until
		     */
		    /* the status of the cable is changed.                      */
		    poldstat = pstatus;
		    boldstat = bstatus;

		    powerfail(PFM_CABLE);
		}		/* if (!pstatus) */
	    }			/* if (tries < 1) */
	}			/* if (pups->cableok.line) */

	/* If anything has changed, process the change */
	if (pstatus != poldstat || bstatus != boldstat) {
	    count++;
	    if (count < 4) {
		/* Wait a little to ride out short brown-outs */
		sleep(1);
		continue;
	    }			/* if (count < 4) */
	    if (pstatus != poldstat) {
		if (pstatus) {
		    /* Power is OK */
		    syslog(LOG_ALERT, "Line power restored");
		    powerfail(PFM_OK);
		} else {
		    /* Power has FAILED */
		    if (bstatus) {
			/* Battery OK, normal shutdown */
			syslog(LOG_ALERT, "Line power has failed");
			powerfail(PFM_FAIL);
		    } else {
			/* Low Battery, SCRAM! */
			syslog(LOG_ALERT, "UPS battery power is low!");
			powerfail(PFM_SCRAM);
		    }		/* if (bstatus) */
		}		/* if (pstatus) */
	    }			/* if (pstatus != poldstat) */
	    if (bstatus != boldstat) {
		if (!bstatus && !pstatus) {
		    /* Power is out and Battery is now low, SCRAM! */
		    syslog(LOG_ALERT, "UPS battery power is low!");
		    powerfail(PFM_SCRAM);
		} else {
		    /* Battery status has changed */
		    if (bstatus) {
			/* Battery power is back */
			syslog(LOG_ALERT, "UPS battery power is now OK");
		    }		/* if (!bstatus) */
		}		/* if (!bstatus && !pstatus) */
	    }			/* if (bstatus != boldstat) */
	}			/* if (pstatus != poldstat || bstatus !=
				 * boldstat) */

	if (!bstatus && pstatus) {
	    /* Line power is OK and UPS signals battery is low */
	    /* Log a message to the syslog every 10 minutes */
	    if ((bcount % 300) == 0)
		syslog(LOG_ALERT, "UPS battery power is low!");
	    bcount++;
	} else {
	    /* Reset count */
	    bcount = 0;
	}			/* if (!bstatus && pstatus) */

	/* Reset count, remember status and sleep 2 seconds. */
	count = 0;
	poldstat = pstatus;
	boldstat = bstatus;
	sleep(2);
    }				/* while(1) */
    /* Never happens */
    return (0);
}
Пример #30
0
static void sendbrk(void)
{
	tcsendbreak(iofd, 1);
}