clamonacc - rename/cleanup filenames, variables, and some logging to be more unified and explicit

pull/111/head
Mickey Sola 6 years ago committed by Micah Snyder
parent 2b4b18045c
commit 78b1b1b4c6
  1. 36
      clamonacc/Makefile.am
  2. 20
      clamonacc/clamonacc.c
  3. 6
      clamonacc/client/client.c
  4. 0
      clamonacc/client/client.h
  5. 2
      clamonacc/client/communication.c
  6. 0
      clamonacc/client/communication.h
  7. 6
      clamonacc/client/protocol.c
  8. 0
      clamonacc/client/protocol.h
  9. 16
      clamonacc/fanotif/fanotif.c
  10. 0
      clamonacc/fanotif/fanotif.h
  11. 6
      clamonacc/inotif/hash.c
  12. 0
      clamonacc/inotif/hash.h
  13. 12
      clamonacc/inotif/inotif.c
  14. 0
      clamonacc/inotif/inotif.h
  15. 10
      clamonacc/misc/utils.c
  16. 0
      clamonacc/misc/utils.h
  17. 54
      clamonacc/scan/queue.c
  18. 4
      clamonacc/scan/queue.h
  19. 34
      clamonacc/scan/thread.c
  20. 0
      clamonacc/scan/thread.h

@ -35,25 +35,25 @@ clamonacc_SOURCES = \
$(top_srcdir)/shared/actions.c \
$(top_srcdir)/shared/actions.h \
clamonacc.c \
./client/onaccess_client.c \
./client/onaccess_client.h \
./client/onaccess_proto.c \
./client/onaccess_proto.h \
./client/onaccess_com.c \
./client/onaccess_com.h \
./inotif/onaccess_ddd.c \
./inotif/onaccess_ddd.h \
./fanotif/onaccess_fan.c \
./fanotif/onaccess_fan.h \
./inotif/onaccess_hash.c \
./inotif/onaccess_hash.h \
./misc/onaccess_others.c \
./misc/onaccess_others.h \
./client/client.c \
./client/client.h \
./client/protocol.c \
./client/protocol.h \
./client/communication.c \
./client/communication.h \
./inotif/inotif.c \
./inotif/inotif.h \
./fanotif/fanotif.c \
./fanotif/fanotif.h \
./inotif/hash.c \
./inotif/hash.h \
./misc/utils.c \
./misc/utils.h \
./misc/priv_fts.h \
./scan/onaccess_scth.c \
./scan/onaccess_scth.h \
./scan/onaccess_scque.c \
./scan/onaccess_scque.h \
./scan/thread.c \
./scan/thread.h \
./scan/queue.c \
./scan/queue.h \
./c-thread-pool/thpool.c \
./c-thread-pool/thpool.h

@ -48,14 +48,14 @@
#include "../shared/actions.h"
#include "./clamonacc.h"
#include "./client/onaccess_client.h"
#include "./fanotif/onaccess_fan.h"
#include "./inotif/onaccess_ddd.h"
#include "./scan/onaccess_scque.h"
#include "./client/client.h"
#include "./fanotif/fanotif.h"
#include "./inotif/inotif.h"
#include "./scan/queue.h"
pthread_t ddd_pid = 0;
pthread_t scque_pid = 0;
pthread_t scan_queue_pid = 0;
static void onas_handle_signals();
static int startup_checks(struct onas_context *ctx);
@ -76,11 +76,11 @@ static void onas_clamonacc_exit(int sig)
}
logg("*Clamonacc: attempting to stop event consumer thread ...\n");
if (scque_pid > 0) {
pthread_cancel(scque_pid);
pthread_join(scque_pid, NULL);
if (scan_queue_pid > 0) {
pthread_cancel(scan_queue_pid);
pthread_join(scan_queue_pid, NULL);
}
scque_pid = 0;
scan_queue_pid = 0;
logg("*Clamonacc: attempting to stop ddd thread ... \n");
if (ddd_pid > 0) {
@ -159,7 +159,7 @@ int main(int argc, char **argv)
ctx->maxthreads = optget(ctx->clamdopts, "OnAccessMaxThreads")->numarg;
/* Setup our event queue */
switch(onas_scanque_start(&ctx)) {
switch(onas_scan_queue_start(&ctx)) {
case CL_SUCCESS:
break;
case CL_BREAK:

@ -61,9 +61,9 @@
#include "../../libclamav/str.h"
#include "../../libclamav/others.h"
#include "./onaccess_com.h"
#include "./onaccess_client.h"
#include "./onaccess_proto.h"
#include "./communication.h"
#include "./client.h"
#include "./protocol.h"
#include "../clamonacc.h"

@ -40,7 +40,7 @@
#include "../../shared/output.h"
#include "./onaccess_com.h"
#include "./communication.h"
static int onas_socket_wait(curl_socket_t sockfd, int32_t b_recv, uint64_t timeout_ms);

@ -58,9 +58,9 @@
#include "../../shared/output.h"
#include "../../shared/misc.h"
#include "./onaccess_com.h"
#include "./onaccess_proto.h"
#include "./onaccess_client.h"
#include "./communication.h"
#include "./protocol.h"
#include "./client.h"
static const char *scancmd[] = { "CONTSCAN", "MULTISCAN", "INSTREAM", "FILDES", "ALLMATCHSCAN" };

@ -42,20 +42,20 @@
#include "../../shared/optparser.h"
#include "../../shared/output.h"
#include "../misc/onaccess_others.h"
#include "../misc/utils.h"
#include "../../clamd/server.h"
#include "./onaccess_fan.h"
#include "../inotif/onaccess_hash.h"
#include "../inotif/onaccess_ddd.h"
#include "./fanotif.h"
#include "../inotif/hash.h"
#include "../inotif/inotif.h"
#include "../client/onaccess_client.h"
#include "../client/client.h"
#include "../scan/onaccess_scth.h"
#include "../scan/onaccess_scque.h"
#include "../scan/thread.h"
#include "../scan/queue.h"
extern pthread_t ddd_pid;
extern pthread_t scque_pid;
extern pthread_t scan_queue_pid;
static int onas_fan_fd;
cl_error_t onas_setup_fanotif(struct onas_context **ctx) {

@ -38,9 +38,9 @@
#include <sys/fanotify.h>
#endif
#include "../fanotif/onaccess_fan.h"
#include "./onaccess_hash.h"
#include "./onaccess_ddd.h"
#include "../fanotif/fanotif.h"
#include "./hash.h"
#include "./inotif.h"
#include "../../libclamav/clamav.h"
#include "../../libclamav/scanners.h"

@ -40,12 +40,12 @@
#include <sys/inotify.h>
#endif
#include "../fanotif/onaccess_fan.h"
#include "./onaccess_hash.h"
#include "./onaccess_ddd.h"
#include "../scan/onaccess_scth.h"
#include "../scan/onaccess_scque.h"
#include "../misc/onaccess_others.h"
#include "../fanotif/fanotif.h"
#include "./hash.h"
#include "./inotif.h"
#include "../scan/thread.h"
#include "../scan/queue.h"
#include "../misc/utils.h"
#include "../../libclamav/clamav.h"
#include "../../libclamav/scanners.h"

@ -34,15 +34,15 @@
#include "../../shared/optparser.h"
#include "../../shared/output.h"
#include "./onaccess_others.h"
#include "./utils.h"
#include "../../clamd/scanner.h"
#include "../clamonacc.h"
#include "../client/onaccess_client.h"
#include "../scan/onaccess_scque.h"
#include "../client/client.h"
#include "../scan/queue.h"
#if defined(FANOTIFY)
extern pthread_cond_t onas_scque_empty_cond;
extern pthread_cond_t onas_scan_queue_empty_cond;
int onas_fan_checkowner(int pid, const struct optstruct *opts)
{
@ -106,7 +106,7 @@ int onas_fan_checkowner(int pid, const struct optstruct *opts)
continue;
} else {
logg("*ClamMisc: fds have been exhausted ... attempting to force the consumer thread to catch up ... (excluding for safety)\n");
pthread_cond_signal(&onas_scque_empty_cond);
pthread_cond_signal(&onas_scan_queue_empty_cond);
sleep(3);
return CHK_FOUND;
}

@ -32,7 +32,7 @@
#include <pthread.h>
#include <string.h>
#include "../misc/onaccess_others.h"
#include "../misc/utils.h"
#include "../../libclamav/clamav.h"
@ -41,19 +41,19 @@
#include "../c-thread-pool/thpool.h"
#include "./onaccess_scth.h"
#include "./onaccess_scque.h"
#include "./thread.h"
#include "./queue.h"
static void onas_scanque_exit(void * arg);
static void onas_scan_queue_exit(void * arg);
static int onas_consume_event(threadpool thpool);
static cl_error_t onas_new_event_queue_node(struct onas_event_queue_node **node);
static void onas_destroy_event_queue_node(struct onas_event_queue_node *node);
static pthread_mutex_t onas_queue_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t onas_scque_loop = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t onas_scque_empty_cond = PTHREAD_COND_INITIALIZER;
extern pthread_t scque_pid;
static pthread_mutex_t onas_scan_queue_loop = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t onas_scan_queue_empty_cond = PTHREAD_COND_INITIALIZER;
extern pthread_t scan_queue_pid;
static threadpool g_thpool;
@ -140,7 +140,7 @@ static void onas_destroy_event_queue() {
}
void *onas_scanque_th(void *arg) {
void *onas_scan_queue_th(void *arg) {
/* not a ton of use for context right now, but perhaps in the future we can pass in more options */
struct onas_context *ctx = (struct onas_context *) arg;
@ -165,23 +165,23 @@ void *onas_scanque_th(void *arg) {
sigdelset(&sigset, SIGBUS);
#endif
logg("*ClamQueue: initializing event queue consumer ... (%d) threads in thread pool\n", ctx->maxthreads);
logg("*ClamScanQueue: initializing event queue consumer ... (%d) threads in thread pool\n", ctx->maxthreads);
onas_init_event_queue();
threadpool thpool = thpool_init(ctx->maxthreads);
g_thpool = thpool;
/* loop w/ onas_consume_event until we die */
pthread_cleanup_push(onas_scanque_exit, NULL);
logg("*ClamQueue: waiting to consume events ...\n");
pthread_cleanup_push(onas_scan_queue_exit, NULL);
logg("*ClamScanQueue: waiting to consume events ...\n");
do {
pthread_mutex_lock(&onas_scque_loop);
pthread_cond_wait(&onas_scque_empty_cond, &onas_scque_loop);
pthread_mutex_lock(&onas_scan_queue_loop);
pthread_cond_wait(&onas_scan_queue_empty_cond, &onas_scan_queue_loop);
/* run 'till we're empty */
do {
pthread_testcancel();
ret = onas_consume_event(thpool);
} while (1 != ret);
pthread_mutex_unlock(&onas_scque_loop);
pthread_mutex_unlock(&onas_scan_queue_loop);
} while(1);
@ -209,7 +209,7 @@ static int onas_consume_event(threadpool thpool) {
}
#ifdef ONAS_DEBUG
logg("*ClamonQueue: consuming event!\n");
logg("*ClamScanQueue: consuming event!\n");
#endif
thpool_add_work(thpool, (void *) onas_scan_worker, (void *) popped_node->data);
@ -232,7 +232,7 @@ cl_error_t onas_queue_event(struct onas_scan_event *event_data) {
struct onas_event_queue_node *node = NULL;
#ifdef ONAS_DEBUG
logg("*ClamonQueue: queueing event!\n");
logg("*ClamScanQueue: queueing event!\n");
#endif
if (CL_EMEM == onas_new_event_queue_node(&node)) {
@ -251,39 +251,39 @@ cl_error_t onas_queue_event(struct onas_scan_event *event_data) {
g_onas_event_queue.size++;
pthread_mutex_unlock(&onas_queue_lock);
pthread_cond_signal(&onas_scque_empty_cond);
pthread_cond_signal(&onas_scan_queue_empty_cond);
return CL_SUCCESS;
}
cl_error_t onas_scanque_start(struct onas_context **ctx) {
cl_error_t onas_scan_queue_start(struct onas_context **ctx) {
pthread_attr_t scque_attr;
pthread_attr_t scan_queue_attr;
int32_t thread_started = 1;
if (!ctx || !*ctx) {
logg("*ClamQueue: unable to start clamonacc. (bad context)\n");
logg("*ClamScanQueue: unable to start clamonacc. (bad context)\n");
return CL_EARG;
}
if(pthread_attr_init(&scque_attr)) {
if(pthread_attr_init(&scan_queue_attr)) {
return CL_BREAK;
}
pthread_attr_setdetachstate(&scque_attr, PTHREAD_CREATE_JOINABLE);
thread_started = pthread_create(&scque_pid, &scque_attr, onas_scanque_th, *ctx);
pthread_attr_setdetachstate(&scan_queue_attr, PTHREAD_CREATE_JOINABLE);
thread_started = pthread_create(&scan_queue_pid, &scan_queue_attr, onas_scan_queue_th, *ctx);
if (0 != thread_started) {
/* Failed to create thread */
logg("*ClamQueue: Unable to start event consumer queue thread ... \n");
logg("*ClamScanQueue: Unable to start event consumer queue thread ... \n");
return CL_ECREAT;
}
return CL_SUCCESS;
}
static void onas_scanque_exit(void *arg) {
static void onas_scan_queue_exit(void *arg) {
logg("*ClamScanque: onas_scanque_exit()\n");
logg("*ClamScanQueue: onas_scan_queue_exit()\n");
pthread_mutex_lock(&onas_queue_lock);
onas_destroy_event_queue();
@ -294,6 +294,6 @@ static void onas_scanque_exit(void *arg) {
g_thpool = NULL;
pthread_mutex_unlock(&onas_queue_lock);
logg("ClamScanque: stopped\n");
logg("ClamScanQueue: stopped\n");
}

@ -35,9 +35,9 @@ struct onas_event_queue_node {
struct onas_scan_event *data;
};
void *onas_scanque_th(void *arg);
void *onas_scan_queue_th(void *arg);
cl_error_t onas_queue_event(struct onas_scan_event *event_data);
cl_error_t onas_scanque_start(struct onas_context **ctx);
cl_error_t onas_scan_queue_start(struct onas_context **ctx);
#endif

@ -40,24 +40,24 @@
#include "../../libclamav/others.h"
#include "../misc/priv_fts.h"
#include "../misc/onaccess_others.h"
#include "../client/onaccess_client.h"
#include "./onaccess_scth.h"
#include "../misc/utils.h"
#include "../client/client.h"
#include "./thread.h"
static pthread_mutex_t onas_scan_lock = PTHREAD_MUTEX_INITIALIZER;
static int onas_scan(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code);
static cl_error_t onas_scan_safe(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code);
static cl_error_t onas_scth_scanfile(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code);
static cl_error_t onas_scth_handle_dir(struct onas_scan_event *event_data, const char *pathname);
static cl_error_t onas_scth_handle_file(struct onas_scan_event *event_data, const char *pathname);
static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code);
static cl_error_t onas_scan_thread_handle_dir(struct onas_scan_event *event_data, const char *pathname);
static cl_error_t onas_scan_thread_handle_file(struct onas_scan_event *event_data, const char *pathname);
static void onas_scth_exit(int sig);
static void onas_scan_thread_exit(int sig);
static void onas_scth_exit(int sig)
static void onas_scan_thread_exit(int sig)
{
logg("*ScanOnAccess: onas_scth_exit(), signal %d\n", sig);
logg("*ScanOnAccess: onas_scan_thread_exit(), signal %d\n", sig);
pthread_exit(NULL);
}
@ -136,7 +136,7 @@ static cl_error_t onas_scan_safe(struct onas_scan_event *event_data, const char
return ret;
}
static cl_error_t onas_scth_scanfile(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code) {
static cl_error_t onas_scan_thread_scanfile(struct onas_scan_event *event_data, const char *fname, STATBUF sb, int *infected, int *err, cl_error_t *ret_code) {
#if defined(FANOTIFY)
@ -215,7 +215,7 @@ static cl_error_t onas_scth_scanfile(struct onas_scan_event *event_data, const c
return ret;
}
static cl_error_t onas_scth_handle_dir(struct onas_scan_event *event_data, const char *pathname) {
static cl_error_t onas_scan_thread_handle_dir(struct onas_scan_event *event_data, const char *pathname) {
FTS *ftsp = NULL;
int32_t ftspopts = FTS_NOCHDIR | FTS_PHYSICAL | FTS_XDEV;
FTSENT *curr = NULL;
@ -249,7 +249,7 @@ static cl_error_t onas_scth_handle_dir(struct onas_scan_event *event_data, const
}
}
ret = onas_scth_scanfile(event_data, curr->fts_path, sb, &infected, &err, &ret_code);
ret = onas_scan_thread_scanfile(event_data, curr->fts_path, sb, &infected, &err, &ret_code);
}
}
@ -261,7 +261,7 @@ out:
return ret;
}
static cl_error_t onas_scth_handle_file(struct onas_scan_event *event_data, const char *pathname) {
static cl_error_t onas_scan_thread_handle_file(struct onas_scan_event *event_data, const char *pathname) {
STATBUF sb;
int32_t infected = 0;
@ -284,7 +284,7 @@ static cl_error_t onas_scth_handle_file(struct onas_scan_event *event_data, cons
}
}
ret = onas_scth_scanfile(event_data, pathname, sb, &infected, &err, &ret_code);
ret = onas_scan_thread_scanfile(event_data, pathname, sb, &infected, &err, &ret_code);
#ifdef ONAS_DEBUG
/* very noisy, debug only */
@ -329,16 +329,16 @@ void *onas_scan_worker(void *arg) {
if (b_dir) {
logg("*ClamWorker: performing (extra) scanning on directory '%s'\n", event_data->pathname);
onas_scth_handle_dir(event_data, event_data->pathname);
onas_scan_thread_handle_dir(event_data, event_data->pathname);
} else if (b_file) {
logg("*ClamWorker: performing (extra) scanning on file '%s'\n", event_data->pathname);
onas_scth_handle_file(event_data, event_data->pathname);
onas_scan_thread_handle_file(event_data, event_data->pathname);
}
} else if (b_fanotify) {
logg("*ClamWorker: performing scanning on file '%s'\n", event_data->pathname);
onas_scth_handle_file(event_data, event_data->pathname);
onas_scan_thread_handle_file(event_data, event_data->pathname);
} else {
/* something went very wrong, so check if we have an open fd,
* try to close it to resolve any potential lingering permissions event,
Loading…
Cancel
Save