move lpt and logging functions into library
This commit is contained in:
@ -3,7 +3,7 @@ include_HEADERS = $(top_srcdir)/yasnd.h
|
||||
yasnd_LDADD = ${libconfuse_LIBS}
|
||||
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
|
||||
sbin_PROGRAMS = yasnd
|
||||
yasnd_SOURCES = yasnd.c yasnd-ipc.c yasnd-log.c yasnd-lpt.c
|
||||
yasnd_SOURCES = yasnd.c yasnd-ipc.c
|
||||
yasnd_CPPFLAGS = -I$(top_srcdir)
|
||||
|
||||
distclean-local:
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include <syslog.h>
|
||||
|
||||
int debug_flag=0; // debug verbosity flag
|
||||
|
||||
void log_init()
|
||||
{
|
||||
return openlog("yasnd", LOG_PID|LOG_CONS, LOG_USER);
|
||||
}
|
||||
|
||||
void log_close()
|
||||
{
|
||||
return closelog();
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that called to output various debug messages to syslog
|
||||
*/
|
||||
void log_debug(const char *message,int verbosity)
|
||||
{
|
||||
if (debug_flag>=verbosity)
|
||||
syslog(LOG_INFO,"%s",message);
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that called to output information message to syslog
|
||||
*/
|
||||
void log_event(const char *message)
|
||||
{
|
||||
syslog(LOG_INFO,"%s",message);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef YASND_LOG_H
|
||||
#define YASND_LOG_H
|
||||
|
||||
// Debug verbosity
|
||||
#define DEBUG_BASE 1
|
||||
#define DEBUG_ALL 2
|
||||
|
||||
// External variables
|
||||
extern int debug_flag;
|
||||
|
||||
// External functions
|
||||
extern void log_init();
|
||||
extern void log_close();
|
||||
extern void log_debug(const char *message,int verbosity);
|
||||
extern void log_event(const char *message);
|
||||
|
||||
#endif
|
@ -1,76 +0,0 @@
|
||||
#include <sys/io.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
bool lpt_enable=false; // control usage of LPT port to reset target devices
|
||||
int lpt_port=0x378; // LPT port in hex(0x378 is usually LPT1)
|
||||
|
||||
/*
|
||||
Function, that turn off all LPT port pins.
|
||||
This is needed to unlock LPT control circuit, when
|
||||
management computer is just booted
|
||||
*/
|
||||
void lpt_init()
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Unlocking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Unlock circuit
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on first LPT port pin and turn off others.
|
||||
This is needed to lock LPT control circuit, when
|
||||
management computer is rebooted
|
||||
*/
|
||||
void lpt_lock_cond(bool ignore_options)
|
||||
{
|
||||
if (lpt_enable || ignore_options)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Locking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Lock circuit
|
||||
outb (1, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on only one LPT port pin, defined by it argument, wait a second,
|
||||
and turn off all pins. That is enough to reset specified host.
|
||||
*/
|
||||
void reset_pin(int pin_num)
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (pin_num==0)
|
||||
return; // there is no LPT control for target host
|
||||
if (pin_num<2 || pin_num>8)
|
||||
{
|
||||
log_event("Error: incorrent LPT pin number");
|
||||
return;
|
||||
}
|
||||
int pins = 1<<(pin_num-1);
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: LPT port access error");
|
||||
return;
|
||||
}
|
||||
// Reset host
|
||||
outb (pins, lpt_port);
|
||||
sleep(1);
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
#ifndef YASND_LPT_H
|
||||
#define YASND_LPT_H
|
||||
|
||||
// External variables
|
||||
extern bool lpt_enable; // control usage of LPT port to reset target devices
|
||||
extern int lpt_port; // LPT port in hex(0x378 is usually LPT1)
|
||||
|
||||
// External functions
|
||||
extern void lpt_init();
|
||||
extern void lpt_lock_cond(bool ignore_options);
|
||||
extern void lpt_lock();
|
||||
extern void reset_pin(int pin_num);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user