diff --git a/yasnd.c b/yasnd.c index cb40775..2a0261d 100644 --- a/yasnd.c +++ b/yasnd.c @@ -53,15 +53,18 @@ void* allocate_memory(int bytes) */ void lpt_init() { - if (ioperm (lpt_port, 3, 1)) + if (lpt_enable) { - log_event("Error: Unlocking the circuit fails due to LPT port access error"); - // disable LPT port usage - lpt_enable=false; - return; + 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); } - // Unlock circuit - outb (0, lpt_port); } /* @@ -71,15 +74,18 @@ void lpt_init() */ void lpt_lock() { - if (ioperm (lpt_port, 3, 1)) + if (lpt_enable) { - log_event("Error: Locking the circuit fails due to LPT port access error"); - // disable LPT port usage - lpt_enable=false; - return; + 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); } - // Lock circuit - outb (1, lpt_port); } // Function, that checks that defined host entry is valid @@ -164,8 +170,7 @@ void init() if (sms_enable) gammu_init(); // initialize LPT control circuit - if (lpt_enable) - lpt_init(); + lpt_init(); } void check_host(int num,host_decl* host) @@ -198,23 +203,26 @@ void check_host(int num,host_decl* host) */ void reset_pin(int pin_num) { - if (pin_num==0) - return; // there is no LPT control for target host - if (pin_num<0 || pin_num>8) + if (lpt_enable) { - log_event("Error: incorrent LPT pin number"); - return; + if (pin_num==0) + return; // there is no LPT control for target host + if (pin_num<0 || pin_num>8) + { + log_event("Error: incorrent LPT pin number"); + return; + } + int pins = 1<<(pin_num); + 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); } - int pins = 1<<(pin_num); - 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); } int loop_function() @@ -319,8 +327,7 @@ void signal_handler(int signum) { log_event("SIGTERM captured, daemon stopping"); // block LPT control circuit - if (lpt_enable) - lpt_lock(); + lpt_lock(); // close log decriptor closelog(); // free resources