From 0b9727cd538eda9135656e74a5295a8e7829b67e Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Mon, 20 Nov 2017 22:10:16 +0300 Subject: [PATCH] update to version 1.2.1. \"Silent mode\" implemented. --- loperIRCLogBot.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/loperIRCLogBot.c b/loperIRCLogBot.c index b8bc4f8..1c60659 100644 --- a/loperIRCLogBot.c +++ b/loperIRCLogBot.c @@ -16,6 +16,8 @@ // only to get PATH_MAX #include +#include + //define period before sending PING to server (5 min - 300). #define TIME_TO_PING 300 @@ -124,7 +126,7 @@ configuration load_config(int run, char * nick_or_path) { } - for (i=0;i<15;i++){ + for (i=0;i<15;i++){ // add Switch-case if ( strstr(sta[i][0], "server") != NULL ) checksum |= 1<<0; else if ( strstr(sta[i][0], "channel") != NULL ) @@ -630,16 +632,16 @@ int main(int argc, char *argv[]) { } // in future define deamon mode here else if( (strcmp("-s", argv[1]) == 0) || (strcmp("--silent", argv[1]) == 0)) { - if ( (freopen ("output.txt", "ab", stdout)) == NULL ){ // todo - add validation for errno - printf("Unable to redirect stdout to file\n"); + if ( (freopen ("output.txt", "a", stdout)) == NULL ){ // todo - add validation for errno? return 1; } - if ( (freopen ("output.txt", "ab", stderr)) == NULL ){ // todo - add validation for errno - printf("Unable to redirect stderr to file\n"); - return 1; - } - freopen("/dev/null", "rb", stdin); + setlinebuf(stdout); // line buffer + if ( (freopen ("output.txt", "a", stderr)) == NULL ){ // todo - add validation for errno? + return 1; + } + setvbuf(stderr, NULL, _IONBF, 0); // no buffering for srderr + freopen("/dev/null", "rb", stdin); } // end else if( (strcmp("-n", argv[1]) == 0) || (strcmp("--nomessage", argv[1]) == 0)) {