diff -u -r ./configuration.c ../../spamdyke-4.0.5-beta1/spamdyke/configuration.c --- ./configuration.c 2008-10-01 21:18:10.000000000 -0500 +++ ../../spamdyke-4.0.5-beta1/spamdyke/configuration.c 2008-10-01 22:08:57.000000000 -0500 @@ -38,6 +38,8 @@ #include "configuration.h" extern int opterr; +extern int exiting; //FIXME +extern char exit_path[MAX_BUF + 1]; //FIXME void init_option_set(struct filter_settings *current_settings, struct option_set *target_options) { @@ -117,8 +119,12 @@ ((*current_string_array) != base_string_array)) { for (i = 0; (*current_string_array)[i] != NULL; i++) + { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing array index %d, ptr = " FORMAT_UINT64_T ": %s", i, (uint64_t)(*current_string_array)[i], ctime(&exit_time)); fclose(exit_file); } } //FIXME free((*current_string_array)[i]); + } + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing string array, ptr = " FORMAT_UINT64_T ": %s", (uint64_t)(*current_string_array), ctime(&exit_time)); fclose(exit_file); } } //FIXME free(*current_string_array); } @@ -151,11 +157,14 @@ { if (current_settings->current_options->rejection == ¤t_settings->current_options->rejection_buf) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying rejection_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)¤t_settings->base_options.rejection_buf, (uint64_t)¤t_settings->current_options->rejection_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(¤t_settings->base_options.rejection_buf, ¤t_settings->current_options->rejection_buf, sizeof(struct rejection_data)); current_settings->base_options.rejection = ¤t_settings->base_options.rejection_buf; + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying reject_message_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)current_settings->base_options.reject_message_buf, (uint64_t)current_settings->current_options->reject_message_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(current_settings->base_options.reject_message_buf, current_settings->current_options->reject_message_buf, MAX_BUF); current_settings->base_options.reject_message_buf[MAX_BUF] = '\0'; + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying short_reject_message_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)current_settings->base_options.short_reject_message_buf, (uint64_t)current_settings->current_options->short_reject_message_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(current_settings->base_options.short_reject_message_buf, current_settings->current_options->short_reject_message_buf, MAX_BUF); current_settings->base_options.short_reject_message_buf[MAX_BUF] = '\0'; @@ -172,11 +181,14 @@ { if (current_settings->current_options->transient_rejection == ¤t_settings->current_options->transient_rejection_buf) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying transient_rejection_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)¤t_settings->base_options.transient_rejection_buf, (uint64_t)¤t_settings->current_options->transient_rejection_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(¤t_settings->base_options.transient_rejection_buf, ¤t_settings->current_options->transient_rejection_buf, sizeof(struct rejection_data)); current_settings->base_options.transient_rejection = ¤t_settings->base_options.transient_rejection_buf; + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying transient_reject_message_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)current_settings->base_options.transient_reject_message_buf, (uint64_t)current_settings->current_options->transient_reject_message_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(current_settings->base_options.transient_reject_message_buf, current_settings->current_options->transient_reject_message_buf, MAX_BUF); current_settings->base_options.transient_reject_message_buf[MAX_BUF] = '\0'; + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "copying transient_short_reject_message_buf, dest = " FORMAT_UINT64_T ", src = " FORMAT_UINT64_T ": %s", (uint64_t)current_settings->base_options.transient_short_reject_message_buf, (uint64_t)current_settings->current_options->transient_short_reject_message_buf, ctime(&exit_time)); fclose(exit_file); } } //FIXME memcpy(current_settings->base_options.transient_short_reject_message_buf, current_settings->current_options->transient_short_reject_message_buf, MAX_BUF); current_settings->base_options.transient_short_reject_message_buf[MAX_BUF] = '\0'; @@ -208,6 +220,7 @@ ((*(ptr.string_ptr)) != NULL) && (*(ptr.string_ptr) != *(*(current_settings->option_list[i].getter.get_string))(¤t_settings->base_options))) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing current string value for %s, ptr = " FORMAT_UINT64_T ": %s", current_settings->option_list[i].getopt_option.name, (uint64_t)(*(ptr.string_ptr)), ctime(&exit_time)); fclose(exit_file); } } //FIXME free(*(ptr.string_ptr)); *(ptr.string_ptr) = NULL; } @@ -221,11 +234,15 @@ case CONFIG_TYPE_OPTION_ARRAY: if ((current_settings->option_list[i].getter.get_string_array != NULL) && ((ptr.string_array_ptr = (*(current_settings->option_list[i].getter.get_string_array))(current_settings->current_options)) != NULL)) + { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing current string array for %s, ptr = " FORMAT_UINT64_T ": %s", current_settings->option_list[i].getopt_option.name, (uint64_t)(*(ptr.string_array_ptr)), ctime(&exit_time)); fclose(exit_file); } } //FIXME free_string_array(ptr.string_array_ptr, *(*(current_settings->option_list[i].getter.get_string_array))(¤t_settings->base_options)); + } break; } + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing current_options, ptr = " FORMAT_UINT64_T ": %s", (uint64_t)current_settings->current_options, ctime(&exit_time)); fclose(exit_file); } } //FIXME free(current_settings->current_options); } @@ -2752,6 +2769,7 @@ return_value = (*main_function)(&tmp_settings, argc, argv); else return_value = 111; + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "do_spamdyke() returned %d: %s", return_value, ctime(&exit_time)); fclose(exit_file); } } //FIXME free_current_options(&tmp_settings); @@ -2773,6 +2791,7 @@ ((ptr.string_ptr = (*(option_list[i].getter.get_string))(&tmp_settings.base_options)) != NULL) && ((*(ptr.string_ptr)) != NULL)) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing string option %s, ptr = " FORMAT_UINT64_T ": %s", option_list[i].getopt_option.name, (uint64_t)(*(ptr.string_ptr)), ctime(&exit_time)); fclose(exit_file); } } //FIXME free(*(ptr.string_ptr)); *(ptr.string_ptr) = NULL; } @@ -2789,7 +2808,11 @@ ((*(ptr.string_array_ptr)) != NULL)) { for (j = 0; (*(ptr.string_array_ptr))[j] != NULL; j++) + { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing string array value %d of option %s, ptr = " FORMAT_UINT64_T ": %s", j, option_list[i].getopt_option.name, (uint64_t)(*(ptr.string_ptr)), ctime(&exit_time)); fclose(exit_file); } } //FIXME free((*(ptr.string_array_ptr))[j]); + } + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing string array option %s, ptr = " FORMAT_UINT64_T ": %s", option_list[i].getopt_option.name, (uint64_t)(*(ptr.string_ptr)), ctime(&exit_time)); fclose(exit_file); } } //FIXME free(*(ptr.string_array_ptr)); *(ptr.string_array_ptr) = NULL; } @@ -2799,18 +2822,22 @@ if (tmp_settings.option_lookup != NULL) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing option_lookup, ptr = " FORMAT_UINT64_T ": %s", (uint64_t)tmp_settings.option_lookup, ctime(&exit_time)); fclose(exit_file); } } //FIXME free(tmp_settings.option_lookup); tmp_settings.option_lookup = NULL; } if (tmp_settings.long_options != NULL) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing long_options, ptr = " FORMAT_UINT64_T ": %s", (uint64_t)tmp_settings.long_options, ctime(&exit_time)); fclose(exit_file); } } //FIXME free(tmp_settings.long_options); tmp_settings.long_options = NULL; } + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "going to free_environment(): %s", ctime(&exit_time)); fclose(exit_file); } } //FIXME free_environment(tmp_settings.original_environment, &tmp_settings.current_environment, NULL); + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "prepare_settings() returning %d: %s", return_value, ctime(&exit_time)); fclose(exit_file); } } //FIXME return(return_value); } diff -u -r ./environment.c ../../spamdyke-4.0.5-beta1/spamdyke/environment.c --- ./environment.c 2008-10-01 21:18:10.000000000 -0500 +++ ../../spamdyke-4.0.5-beta1/spamdyke/environment.c 2008-10-01 22:10:00.000000000 -0500 @@ -22,6 +22,9 @@ #include "log.h" #include "environment.h" +extern int exiting; //FIXME +extern char exit_path[MAX_BUF + 1]; //FIXME + /* * Return value: * SUCCESS: pointer to value of target_variable within the environment arary (not copied) @@ -78,9 +81,13 @@ } if (!found_match) + { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing environment entry %d, ptr = " FORMAT_UINT64_T ": %s", i, (uint64_t)((*target_envp)[i]), ctime(&exit_time)); fclose(exit_file); } } //FIXME free((*target_envp)[i]); + } } + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "freeing environment, ptr = " FORMAT_UINT64_T ": %s", (uint64_t)(*target_envp), ctime(&exit_time)); fclose(exit_file); } } //FIXME free(*target_envp); *target_envp = NULL; } diff -u -r ./log.c ../../spamdyke-4.0.5-beta1/spamdyke/log.c --- ./log.c 2008-10-01 21:18:10.000000000 -0500 +++ ../../spamdyke-4.0.5-beta1/spamdyke/log.c 2008-10-01 21:43:20.000000000 -0500 @@ -48,6 +48,9 @@ #include "tls.h" #include "log.h" +extern int exiting; //FIXME +extern char exit_path[MAX_BUF + 1]; //FIXME + /* * Expects: * action == @@ -192,6 +195,7 @@ tmp_tm = localtime(&tmp_time); snprintf(log_filename, MAX_BUF, "%s" DIR_DELIMITER_STR "%d%.2d%.2d_%.2d%.2d%.2d_" FORMAT_PID_T "_%ld", current_settings->current_options->log_dir, tmp_tm->tm_year + 1900, tmp_tm->tm_mon + 1, tmp_tm->tm_mday, tmp_tm->tm_hour, tmp_tm->tm_min, tmp_tm->tm_sec, getpid(), random()); + memcpy(exit_path, log_filename, MAX_BUF); exit_path[MAX_BUF] = '\0'; //FIXME if ((log_file = fopen(log_filename, "w")) != NULL) { @@ -528,6 +532,7 @@ } else if (syslog_initialized) { + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "Closing syslogd: %s", ctime(&exit_time)); fclose(exit_file); } } //FIXME closelog(); syslog_initialized = 0; } diff -u -r ./spamdyke.c ../../spamdyke-4.0.5-beta1/spamdyke/spamdyke.c --- ./spamdyke.c 2008-10-01 21:18:10.000000000 -0500 +++ ../../spamdyke-4.0.5-beta1/spamdyke/spamdyke.c 2008-10-01 21:43:45.000000000 -0500 @@ -61,6 +61,9 @@ #include "config_test.h" #include "filter.h" +int exiting; //FIXME +char exit_path[MAX_BUF + 1]; //FIXME + /* * Expects: * strlen_haystack == strlen(haystack) @@ -2465,7 +2468,9 @@ nihdns_initialize(current_settings, 1); output_writeln(NULL, 0, -1, NULL, 0); + exiting = 1; //FIXME SPAMDYKE_LOG_NONE(current_settings, NULL); + if (exiting && (exit_path[0] != '\0')) { FILE *exit_file = NULL; time_t exit_time; if ((exit_file = fopen(exit_path, "a+")) != NULL) { exit_time = time(NULL); fprintf(exit_file, "Leaving do_spamdyke(): %s", ctime(&exit_time)); fclose(exit_file); } } //FIXME return(0); } @@ -2475,5 +2480,7 @@ srandom(time(NULL) * getpid()); signal(SIGPIPE, SIG_IGN); + exiting = 0; //FIXME + exit_path[0] = '\0'; //FIXME return(prepare_settings(argc, argv, envp, &do_spamdyke)); }