mirror of https://github.com/jrbrtsn/ban2fail
Consolidate ez_* categories to library
This commit is contained in:
parent
e0b8257ddf
commit
0ef57ad814
|
@ -3,7 +3,7 @@ libsDir := $(baseDir)/libs
|
|||
projectName := ban2fail
|
||||
versions := debug release
|
||||
cc_exe := ban2fail
|
||||
install_dir := /usr/local/bin
|
||||
#install_dir := /usr/local/bin
|
||||
|
||||
|
||||
########################################
|
||||
|
@ -15,10 +15,8 @@ src := \
|
|||
ban2fail.c \
|
||||
cfgmap.c \
|
||||
cntry.c \
|
||||
ez_dirent.c \
|
||||
ez_gzfile.c \
|
||||
ez_stdio.c \
|
||||
ez_stdlib.c \
|
||||
ez_libc.c \
|
||||
ez_libz.c \
|
||||
iptables.c \
|
||||
logType.c \
|
||||
logEntry.c \
|
||||
|
|
19
ban2fail.c
19
ban2fail.c
|
@ -31,10 +31,8 @@
|
|||
|
||||
#include "ban2fail.h"
|
||||
#include "cntry.h"
|
||||
#include "ez_dirent.h"
|
||||
#include "ez_gzfile.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_stdlib.h"
|
||||
#include "ez_libc.h"
|
||||
#include "ez_libz.h"
|
||||
#include "iptables.h"
|
||||
#include "logEntry.h"
|
||||
#include "logFile.h"
|
||||
|
@ -94,8 +92,8 @@ struct Global G= {
|
|||
|
||||
.version= {
|
||||
.major= 0,
|
||||
.minor= 11,
|
||||
.patch= 9
|
||||
.minor= 12,
|
||||
.patch= 0
|
||||
},
|
||||
|
||||
.bitTuples.flags= GlobalFlagBitTuples
|
||||
|
@ -185,7 +183,7 @@ main(int argc, char **argv)
|
|||
|
||||
int c, option_ndx= 0;
|
||||
|
||||
c= getopt_long(argc, argv, ":acst:v", long_options, &option_ndx);
|
||||
c= getopt_long(argc, argv, ":a::cst:v", long_options, &option_ndx);
|
||||
|
||||
if(-1 == c) break;
|
||||
|
||||
|
@ -202,6 +200,11 @@ main(int argc, char **argv)
|
|||
|
||||
case 'a':
|
||||
G.flags |= GLB_LIST_ADDR_FLG;
|
||||
if(optarg && *optarg == '+') {
|
||||
G.flags |= GLB_DNS_LOOKUP_FLG;
|
||||
} else {
|
||||
++errflg;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
|
@ -239,7 +242,7 @@ main(int argc, char **argv)
|
|||
"ban2fail v%d.%d.%d Usage:\n"
|
||||
"%s [options] [-t confFile]\n"
|
||||
" --help\tprint this usage message.\n"
|
||||
" -a\t\tList results by Address\n"
|
||||
" -a[+]\t\tList results by Address. '+' to perform DNS reverse lookups.\n"
|
||||
" -c\t\tlist results by Country\n"
|
||||
" -s\t\tlist Summary results only\n"
|
||||
" -t confFile\tTest confFile, do not apply iptables rules\n"
|
||||
|
|
|
@ -57,6 +57,7 @@ extern struct Global {
|
|||
GLB_DONT_IPTABLE_FLG =1<<3,
|
||||
GLB_LIST_SUMMARY_FLG =1<<4,
|
||||
GLB_PRINT_LOGFILE_NAMES_FLG =1<<5,
|
||||
GLB_DNS_LOOKUP_FLG =1<<6,
|
||||
GLB_LONG_LISTING_FLG = GLB_LIST_CNTRY_FLG|GLB_LIST_ADDR_FLG
|
||||
} flags;
|
||||
|
||||
|
|
60
ban2fail.sh
60
ban2fail.sh
|
@ -8,9 +8,12 @@
|
|||
# script is written - you will have a feedback loop!
|
||||
#
|
||||
|
||||
BAN2FAIL=/usr/local/bin/ban2fail
|
||||
BAN2FAIL_CFG=/etc/ban2fail/ban2fail.cfg
|
||||
INOTIFYWAIT=/usr/bin/inotifywait
|
||||
BAN2FAIL=/usr/local/bin/ban2fail
|
||||
|
||||
# For testing only
|
||||
#BAN2FAIL="/usr/local/bin/ban2fail -t $BAN2FAIL_CFG"
|
||||
|
||||
# Uncomment this if you wish to see output from the time command
|
||||
#TIME=time
|
||||
|
@ -24,72 +27,65 @@ MIN_PERIOD_DS=3
|
|||
|
||||
while true; do
|
||||
echo "Starting main loop"
|
||||
LOG_NAMES=$($BAN2FAIL --print-lfn | tr $'\n' ' ')
|
||||
LOG_NAMES="$LOG_NAMES $BAN2FAIL_CFG"
|
||||
MON_FNAMES=$($BAN2FAIL --print-lfn | tr $'\n' ' ')
|
||||
MON_FNAMES="$MON_FNAMES $BAN2FAIL_CFG"
|
||||
|
||||
# Always do initial check
|
||||
echo "Initial run for $BAN2FAIL"
|
||||
RAN_NS=$(date +%s%N)
|
||||
$TIME $BAN2FAIL
|
||||
|
||||
echo "Monitoring: $LOG_NAMES"
|
||||
echo "Monitoring: $MON_FNAMES"
|
||||
|
||||
while read; do
|
||||
while read FILE OPS; do
|
||||
|
||||
# if a file gets renamed, logrotate is doing it's thing.
|
||||
[[ "$REPLY" =~ MOVE_SELF ]] && break
|
||||
[[ "$REPLY" == $BAN2FAIL_CFG\ MODIFY ]] && break
|
||||
case "$OPS" in
|
||||
MOVE_SELF) break;;
|
||||
|
||||
[[ "$REPLY" =~ MODIFY ]] || continue
|
||||
MODIFY) [[ "$FILE" == $BAN2FAIL_CFG ]] && break;;
|
||||
|
||||
*) continue;;
|
||||
esac
|
||||
|
||||
# Uncomment this to see the inotifywait output which triggered this cycle
|
||||
#echo "REPLY= '$REPLY'"
|
||||
echo "FILE= '$FILE', OPS= '$OPS'"
|
||||
|
||||
NOW_NS=$(date +%s%N)
|
||||
(( SINCE_NS = NOW_NS - RAN_NS ))
|
||||
#echo "RAN_NS= $RAN_NS, NOW_NS= $NOW_NS, SINCE_NS= $SINCE_NS, MIN_PERIOD_NS= $MIN_PERIOD_NS"
|
||||
|
||||
if (( SINCE_NS < MIN_PERIOD_NS )); then
|
||||
|
||||
(( REMAINING_NS = MIN_PERIOD_NS - SINCE_NS ))
|
||||
|
||||
# break sleep time into seconds and nanosecond remainder components
|
||||
# 'sleep' command wants a string representation of floating point number of seconds,
|
||||
# so we need to break sleep time into seconds and nanosecond remainder components
|
||||
(( REMAINING_SEC = REMAINING_NS / 1000000000 ))
|
||||
(( REMAINING_NS_REM = REMAINING_NS % 1000000000 ))
|
||||
|
||||
#echo "REMAINING_NS= $REMAINING_NS, REMAINING_SEC= $REMAINING_SEC, REMAINING_NS_REM= $REMAINING_NS_REM"
|
||||
|
||||
if (( REMAINING_SEC || REMAINING_NS_REM > 1000000 )); then
|
||||
|
||||
# use printf command to format as floating point string
|
||||
remaining_sec_fp=$(printf '%d.%09d' $REMAINING_SEC $REMAINING_NS_REM)
|
||||
|
||||
#echo "sleeping for $remaining_sec_fp seconds"
|
||||
REMAINING_SEC_FP=$(printf '%d.%09d' $REMAINING_SEC $REMAINING_NS_REM)
|
||||
|
||||
# sleep for floating point period of seconds
|
||||
sleep $remaining_sec_fp
|
||||
sleep $REMAINING_SEC_FP
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# Consume queued input to avoid running ban2fail more than necessary
|
||||
while read -t 0; do read; done
|
||||
|
||||
echo "Running $BAN2FAIL"
|
||||
|
||||
# Check for offenses
|
||||
# If ban2fail failed, then pause to avoid monopolizing CPU
|
||||
# Here is where we check for offenses.
|
||||
# If ban2fail failes it is probably because logrotated
|
||||
# is managing the log files, so bail out...
|
||||
RAN_NS=$(date +%s%N)
|
||||
while ! $TIME $BAN2FAIL; do
|
||||
sleep .5
|
||||
RAN_NS=$(date +%s%N)
|
||||
done
|
||||
$TIME $BAN2FAIL || break
|
||||
|
||||
done < <(exec $INOTIFYWAIT -m $MON_FNAMES)
|
||||
|
||||
done < <(exec $INOTIFYWAIT -m $LOG_NAMES)
|
||||
|
||||
echo ' Exiting main loop'
|
||||
|
||||
echo 'Exiting main loop'
|
||||
# Pause to let things settle down
|
||||
sleep 1
|
||||
|
||||
done
|
||||
|
||||
|
||||
|
|
77
ez_dirent.c
77
ez_dirent.c
|
@ -1,77 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2019 by John D. Robertson *
|
||||
* john@rrci.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ez_dirent.h"
|
||||
|
||||
/***************************************************/
|
||||
DIR* _ez_opendir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
DIR *rtn= opendir (name);
|
||||
if (!rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "opendir(\"%s\") failed", name);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_closedir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
)
|
||||
{
|
||||
int rtn= closedir (dirp);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "closedir() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
struct dirent* _ez_readdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
)
|
||||
{
|
||||
|
||||
/* Pass on doctored format string and varargs to vfprintf() */
|
||||
errno= 0;
|
||||
struct dirent* rtn= readdir(dirp);
|
||||
|
||||
if (!rtn && errno) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "readdir() failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
70
ez_dirent.h
70
ez_dirent.h
|
@ -1,70 +0,0 @@
|
|||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2018 by John D. Robertson *
|
||||
* john@rrci.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
ez_dirent.h - description
|
||||
dirent calls with boilerplate error handling.
|
||||
|
||||
-------------------
|
||||
begin : Tue Nov 13 19:42:23 EST 2018
|
||||
email : john@rrci.com
|
||||
***************************************************************************/
|
||||
#ifndef EZ_DIRENT_H
|
||||
#define EZ_DIRENT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define ez_opendir(name) \
|
||||
_ez_opendir(__FILE__, __LINE__, __FUNCTION__, name)
|
||||
DIR* _ez_opendir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *name
|
||||
);
|
||||
|
||||
#define ez_closedir(dirp) \
|
||||
_ez_closedir(__FILE__, __LINE__, __FUNCTION__, dirp)
|
||||
int _ez_closedir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
);
|
||||
|
||||
#define ez_readdir(dirp) \
|
||||
_ez_readdir(__FILE__, __LINE__, __FUNCTION__, dirp)
|
||||
struct dirent* _ez_readdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -20,7 +20,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_libc.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_fputs (
|
||||
|
@ -236,3 +236,155 @@ int _ez_rename (
|
|||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
DIR* _ez_opendir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *name
|
||||
)
|
||||
{
|
||||
DIR *rtn= opendir (name);
|
||||
if (!rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "opendir(\"%s\") failed", name);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_closedir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
)
|
||||
{
|
||||
int rtn= closedir (dirp);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "closedir() failed");
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
struct dirent* _ez_readdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
)
|
||||
{
|
||||
|
||||
/* Pass on doctored format string and varargs to vfprintf() */
|
||||
errno= 0;
|
||||
struct dirent* rtn= readdir(dirp);
|
||||
|
||||
if (!rtn && errno) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "readdir() failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_close (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd
|
||||
)
|
||||
{
|
||||
int rtn= close (fd);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "close(%d) failed", fd);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ssize_t _ez_write (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
const void *buf,
|
||||
size_t count
|
||||
)
|
||||
{
|
||||
ssize_t rtn= write (fd, buf, count);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "write(fd= %d) failed", fd);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_stat (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
struct stat *statbuf
|
||||
)
|
||||
{
|
||||
int rtn= stat (pathname, statbuf);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "stat(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_mkdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
)
|
||||
{
|
||||
int rtn= mkdir (pathname, mode);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "mkdir(\"%s\", %04x) failed", pathname, (unsigned)mode);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_rmdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
)
|
||||
{
|
||||
int rtn= rmdir (pathname);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "rmdir(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_unlink (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
)
|
||||
{
|
||||
int rtn= unlink (pathname);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "unlink(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
|
@ -18,17 +18,22 @@
|
|||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
ez_stdio.h - description
|
||||
stdio calls with boilerplate error handling.
|
||||
ez_libc.h - description
|
||||
libc calls with boilerplate error handling.
|
||||
|
||||
-------------------
|
||||
begin : Tue Nov 13 19:42:23 EST 2018
|
||||
email : john@rrci.com
|
||||
***************************************************************************/
|
||||
#ifndef EZ_STDIO_H
|
||||
#define EZ_STDIO_H
|
||||
#ifndef EZ_LIBC_H
|
||||
#define EZ_LIBC_H
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -158,6 +163,107 @@ int _ez_rename (
|
|||
const char *oldpath,
|
||||
const char *newpath
|
||||
);
|
||||
|
||||
#define ez_opendir(name) \
|
||||
_ez_opendir(__FILE__, __LINE__, __FUNCTION__, name)
|
||||
DIR* _ez_opendir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *name
|
||||
);
|
||||
|
||||
#define ez_closedir(dirp) \
|
||||
_ez_closedir(__FILE__, __LINE__, __FUNCTION__, dirp)
|
||||
int _ez_closedir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
);
|
||||
|
||||
#define ez_readdir(dirp) \
|
||||
_ez_readdir(__FILE__, __LINE__, __FUNCTION__, dirp)
|
||||
struct dirent* _ez_readdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
DIR *dirp
|
||||
);
|
||||
|
||||
#define ez_close(fd) \
|
||||
_ez_close(__FILE__, __LINE__, __FUNCTION__, fd)
|
||||
int _ez_close (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd
|
||||
);
|
||||
|
||||
#if 0
|
||||
// FIXME: this needs to be implemented and tested
|
||||
#define ez_read(fd, buf, count) \
|
||||
_ez_read(__FILE__, __LINE__, __FUNCTION__, fd, buf, count)
|
||||
ssize_t _ez_read (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
void *buf,
|
||||
size_t count
|
||||
);
|
||||
#endif
|
||||
|
||||
#define ez_write(fd, buf, count) \
|
||||
_ez_write(__FILE__, __LINE__, __FUNCTION__, fd, buf, count)
|
||||
ssize_t _ez_write (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
const void *buf,
|
||||
size_t count
|
||||
);
|
||||
|
||||
#define ez_stat(pathname, statbuf) \
|
||||
_ez_stat(__FILE__, __LINE__, __FUNCTION__, pathname, statbuf)
|
||||
int _ez_stat (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
struct stat *statbuf
|
||||
);
|
||||
|
||||
// FIXME: xxxdir() function should be in ez_unistd.h
|
||||
#define ez_mkdir(pathname, mode) \
|
||||
_ez_mkdir(__FILE__, __LINE__, __FUNCTION__, pathname, mode)
|
||||
int _ez_mkdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
);
|
||||
|
||||
#define ez_rmdir(pathname) \
|
||||
_ez_rmdir(__FILE__, __LINE__, __FUNCTION__, pathname)
|
||||
int _ez_rmdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
);
|
||||
|
||||
#define ez_unlink(pathname) \
|
||||
_ez_unlink(__FILE__, __LINE__, __FUNCTION__, pathname)
|
||||
int _ez_unlink (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -18,7 +18,7 @@
|
|||
***************************************************************************/
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ez_gzfile.h"
|
||||
#include "ez_libz.h"
|
||||
#include "util.h"
|
||||
|
||||
/***************************************************/
|
122
ez_stdlib.c
122
ez_stdlib.c
|
@ -1,122 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2019 by John D. Robertson *
|
||||
* john@rrci.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include <unistd.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "ez_stdlib.h"
|
||||
|
||||
/***************************************************/
|
||||
int _ez_close (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd
|
||||
)
|
||||
{
|
||||
int rtn= close (fd);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "close(%d) failed", fd);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
ssize_t _ez_write (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
const void *buf,
|
||||
size_t count
|
||||
)
|
||||
{
|
||||
ssize_t rtn= write (fd, buf, count);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "write(fd= %d) failed", fd);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_stat (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
struct stat *statbuf
|
||||
)
|
||||
{
|
||||
int rtn= stat (pathname, statbuf);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "stat(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_mkdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
)
|
||||
{
|
||||
int rtn= mkdir (pathname, mode);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "mkdir(\"%s\", %04x) failed", pathname, (unsigned)mode);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_rmdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
)
|
||||
{
|
||||
int rtn= rmdir (pathname);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "rmdir(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
int _ez_unlink (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
)
|
||||
{
|
||||
int rtn= unlink (pathname);
|
||||
if (-1 == rtn) {
|
||||
_sys_eprintf((const char*(*)(int))strerror, fileName, lineNo, funcName, "unlink(\"%s\") failed", pathname);
|
||||
abort();
|
||||
}
|
||||
return rtn;
|
||||
}
|
117
ez_stdlib.h
117
ez_stdlib.h
|
@ -1,117 +0,0 @@
|
|||
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2018 by John D. Robertson *
|
||||
* john@rrci.com *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
ez_stdlib.h - description
|
||||
stdlib calls with boilerplate error handling.
|
||||
|
||||
-------------------
|
||||
begin : Tue Nov 13 19:42:23 EST 2018
|
||||
email : john@rrci.com
|
||||
***************************************************************************/
|
||||
#ifndef EZ_STDLIB_H
|
||||
#define EZ_STDLIB_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ez_close(fd) \
|
||||
_ez_close(__FILE__, __LINE__, __FUNCTION__, fd)
|
||||
int _ez_close (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd
|
||||
);
|
||||
|
||||
#if 0
|
||||
// FIXME: this needs to be implemented and tested
|
||||
#define ez_read(fd, buf, count) \
|
||||
_ez_read(__FILE__, __LINE__, __FUNCTION__, fd, buf, count)
|
||||
ssize_t _ez_read (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
void *buf,
|
||||
size_t count
|
||||
);
|
||||
#endif
|
||||
|
||||
#define ez_write(fd, buf, count) \
|
||||
_ez_write(__FILE__, __LINE__, __FUNCTION__, fd, buf, count)
|
||||
ssize_t _ez_write (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
int fd,
|
||||
const void *buf,
|
||||
size_t count
|
||||
);
|
||||
|
||||
#define ez_stat(pathname, statbuf) \
|
||||
_ez_stat(__FILE__, __LINE__, __FUNCTION__, pathname, statbuf)
|
||||
int _ez_stat (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
struct stat *statbuf
|
||||
);
|
||||
|
||||
// FIXME: xxxdir() function should be in ez_unistd.h
|
||||
#define ez_mkdir(pathname, mode) \
|
||||
_ez_mkdir(__FILE__, __LINE__, __FUNCTION__, pathname, mode)
|
||||
int _ez_mkdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname,
|
||||
mode_t mode
|
||||
);
|
||||
|
||||
#define ez_rmdir(pathname) \
|
||||
_ez_rmdir(__FILE__, __LINE__, __FUNCTION__, pathname)
|
||||
int _ez_rmdir (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
);
|
||||
|
||||
#define ez_unlink(pathname) \
|
||||
_ez_unlink(__FILE__, __LINE__, __FUNCTION__, pathname)
|
||||
int _ez_unlink (
|
||||
const char *fileName,
|
||||
int lineNo,
|
||||
const char *funcName,
|
||||
const char *pathname
|
||||
);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -23,7 +23,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include "ban2fail.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_libc.h"
|
||||
#include "iptables.h"
|
||||
#include "logEntry.h"
|
||||
#include "map.h"
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include "ban2fail.h"
|
||||
#include "cntry.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_libc.h"
|
||||
#include "map.h"
|
||||
#include "logEntry.h"
|
||||
#include "util.h"
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
#include "cntry.h"
|
||||
#include "logEntry.h"
|
||||
#include "logFile.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_gzfile.h"
|
||||
#include "ez_libc.h"
|
||||
#include "ez_libz.h"
|
||||
#include "util.h"
|
||||
|
||||
enum {
|
||||
|
|
|
@ -30,9 +30,7 @@
|
|||
#include "logEntry.h"
|
||||
#include "logFile.h"
|
||||
#include "logType.h"
|
||||
#include "ez_dirent.h"
|
||||
#include "ez_stdio.h"
|
||||
#include "ez_stdlib.h"
|
||||
#include "ez_libc.h"
|
||||
#include "str.h"
|
||||
#include "util.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue