diff -u --recursive --new-file afd-1.3.6.old/src/amg/amgdefs.h afd-1.3.6/src/amg/amgdefs.h --- afd-1.3.6.old/src/amg/amgdefs.h 2007-11-25 09:28:38.000000000 +0100 +++ afd-1.3.6/src/amg/amgdefs.h 2008-10-04 18:15:03.000000000 +0200 @@ -245,11 +245,10 @@ #define STD_OPTIONS_PTR_POS 9 #define RECIPIENT_PTR_POS 10 #define DIR_CONFIG_ID_PTR_POS 11 -#ifdef WITH_MULTI_DIR_DEFINITION -# define OFFSET_TO_SAME_DIR_PTR_POS 12 +#define MAX_DATA_PTRS 12 struct p_array { - long ptr[13]; /* Pointer offdet to the following */ + long ptr[MAX_DATA_PTRS]; /* Pointer offdet to the following */ /* information: */ /* 0 - priority char x */ /* 1 - directory char x[]\0 */ @@ -263,27 +262,7 @@ /* 9 - std. options char x[][]\0 */ /* 10 - recipient char x[]\0 */ /* 11 - DIR_CONFIG ID char x[]\0 */ - /* 12 - offset to same dir char x[]\0 */ }; -#else -struct p_array - { - long ptr[12]; /* Pointer offdet to the following */ - /* information: */ - /* 0 - priority char x */ - /* 1 - directory char x[]\0 */ - /* 2 - alias name char x[]\0 */ - /* 3 - no. of files char x[]\0 */ - /* 4 - file char x[]\0 */ - /* 5 - no. loc. options char x[]\0 */ - /* 6 - loc. options char x[][]\0 */ - /* 7 - local options flag char x[]\0 */ - /* 8 - no. std. options char x[]\0 */ - /* 9 - std. options char x[][]\0 */ - /* 10 - recipient char x[]\0 */ - /* 11 - DIR_CONFIG ID char x[]\0 */ - }; -#endif /* Structure that holds one directory entry of the AMG database. */ struct dest_group diff -u --recursive --new-file afd-1.3.6.old/src/amg/create_db.c afd-1.3.6/src/amg/create_db.c --- afd-1.3.6.old/src/amg/create_db.c 2007-11-13 21:21:11.000000000 +0100 +++ afd-1.3.6/src/amg/create_db.c 2008-10-04 18:34:44.000000000 +0200 @@ -144,9 +144,6 @@ #endif not_in_same_file_system = 0, one_job_only_dir = 0, -#ifdef WITH_MULTI_DIR_DEFINITION - original_i = -1, -#endif show_one_job_no_link, size, dir_counter = 0, @@ -466,17 +463,6 @@ exec_flag_dir = 0; for (i = 0; i < no_of_jobs; i++) { -#ifdef WITH_MULTI_DIR_DEFINITION - if (*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == 1) - { - continue; - } - else if ((original_i != -1) && - (*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == '\0')) - { - *(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) = 1; - } -#endif exec_flag = 0; /* Store DIR_CONFIG ID. */ @@ -499,13 +485,7 @@ * is necessary so we can specify overlapping wild cards in * different file sections for one directory section. */ -#ifdef WITH_MULTI_DIR_DEFINITION - if ((i > 0) && - (((original_i == -1) && (db[i].dir != db[i - 1].dir)) || - ((original_i != -1) && (strcmp(db[i].dir, db[original_i].dir) != 0)))) -#else if ((i > 0) && (db[i].dir != db[i - 1].dir)) -#endif { if ((de[dir_counter].flag & DELETE_ALL_FILES) || ((de[dir_counter].flag & IN_SAME_FILESYSTEM) && @@ -1156,47 +1136,8 @@ fjd[no_fork_jobs].system_time = 0; no_fork_jobs++; } -#ifdef WITH_MULTI_DIR_DEFINITION - if ((*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) != '\0') && - (*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) != 1)) - { - int tmp_original_i = original_i; - - original_i = i; - i = atoi(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) - 1; - if (tmp_original_i != -1) - { - *(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) = 1; - } - } - else - { - if ((original_i != -1) && - (((i + 1) >= no_of_jobs) || - (db[original_i].dir != db[i + 1].dir))) - { - i = original_i; - original_i = -1; - } - } -#endif } /* for (i = 0; i < no_of_jobs; i++) */ -#ifdef WITH_MULTI_DIR_DEFINITION - /* - * NOTE: We need to reset our jump back marks (1), otherwise when - * this function is called again (changing alias order with edit_hc) - * will fall over those jump marks! - */ - for (i = 0; i < no_of_jobs; i++) - { - if (*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == 1) - { - *(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) = '\0'; - } - } -#endif - if ((de[dir_counter].flag & DELETE_ALL_FILES) || ((de[dir_counter].flag & IN_SAME_FILESYSTEM) && (exec_flag_dir == 0))) { @@ -1235,8 +1176,8 @@ if (db[i].job_id == db[j].job_id) { system_log(WARN_SIGN, __FILE__, __LINE__, - "Duplicate job entries for job %x with directory %s and recipient %s!", - db[i].job_id, db[i].dir, db[i].recipient); + "Duplicate job entries for job %x with directory %s and recipient %s [%d]!", + db[i].job_id, db[i].dir, db[i].recipient, i); break; } } diff -u --recursive --new-file afd-1.3.6.old/src/amg/eval_dir_config.c afd-1.3.6/src/amg/eval_dir_config.c --- afd-1.3.6.old/src/amg/eval_dir_config.c 2007-11-29 12:55:55.000000000 +0100 +++ afd-1.3.6/src/amg/eval_dir_config.c 2008-10-04 18:32:55.000000000 +0200 @@ -176,14 +176,10 @@ #endif count_new_lines(char *, char *); static void copy_to_file(void), -#ifdef WITH_MULTI_DIR_DEFINITION - copy_job(int, int, int, struct dir_group *), - insert_dir(struct dir_group *, int), -#else copy_job(int, int, struct dir_group *), insert_dir(struct dir_group *), -#endif insert_hostname(struct dir_group *), + sort_jobs(void), store_full_path(char *, char *); static char *posi_identifier(char *, char *, size_t); @@ -1935,12 +1931,10 @@ /* Check if this directory was not already specified. */ for (j = 0; j < no_of_local_dirs; j++) { - if (CHECK_STRCMP(dir->location, dd[j].dir_name) == 0) + if (strcmp(dir->location, dd[j].dir_name) == 0) { -#ifdef WITH_MULTI_DIR_DEFINITION if (dcl[dcd].dc_id == dd[j].dir_config_id) { -#endif system_log(WARN_SIGN, __FILE__, __LINE__, "Ignoring duplicate directory entry %s in %s.", dir->location, dcl[dcd].dir_config_file); @@ -1949,21 +1943,17 @@ (*warn_counter)++; } duplicate = YES; -#ifdef WITH_MULTI_DIR_DEFINITION } else { duplicate = NEITHER; } -#endif break; } } -#ifdef WITH_MULTI_DIR_DEFINITION if (duplicate != YES) { -#endif if (duplicate == NO) { if ((no_of_local_dirs % 10) == 0) @@ -2127,34 +2117,26 @@ } } #endif - - /* Insert directory into temporary memory. */ -#ifdef WITH_MULTI_DIR_DEFINITION - insert_dir(dir, NO); -#else - insert_dir(dir); -#endif } -#ifdef WITH_MULTI_DIR_DEFINITION else { (void)strcpy(dir->alias, dd[j].dir_alias); dir->dir_config_id = dcl[dcd].dc_id; +#ifdef WHEN_WE_KNOW if (dir->type == REMOTE_DIR) { /* add_file_mask(dd[j].dir_alias, dir); */ } - - /* Insert directory into temporary memory. */ - insert_dir(dir, YES); - } #endif + } + + /* Insert directory into temporary memory. */ + insert_dir(dir); /* Insert hostnames into temporary memory. */ insert_hostname(dir); -#ifdef WITH_MULTI_DIR_DEFINITION } /* if (duplicate == NO) */ -#endif + for (j = 0; j < dir->fgc; j++) { int m; @@ -2224,6 +2206,14 @@ } else { + /* Before we copy the data to a file lets sort */ + /* the directories so that same directories are */ + /* in one group and not scattered over the hole */ + /* list. Remember we might have multiple */ + /* DIR_CONFIG's where the user specifies the */ + /* same directory in each DIR_CONFIG. */ + sort_jobs(); + /* Now copy data and pointers in their relevant */ /* shared memory areas. */ copy_to_file(); @@ -2492,64 +2482,8 @@ /*++++++++++++++++++++++++++++ insert_dir() ++++++++++++++++++++++++++++*/ static void -#ifdef WITH_MULTI_DIR_DEFINITION -insert_dir(struct dir_group *dir, int dup_entry) -#else insert_dir(struct dir_group *dir) -#endif { -#ifdef WITH_MULTI_DIR_DEFINITION - int i, - j, - prev_job_no = -1; - - if (dup_entry == YES) - { - char *p_offset; - struct p_array *p_ptr; - - p_ptr = pp; - p_offset = p_t; - for (i = 0; i < job_no; i++) - { - if (strcmp(p_ptr[i].ptr[DIRECTORY_PTR_POS] + p_offset, dir->location) == 0) - { - i++; - while ((strcmp(p_ptr[i].ptr[DIRECTORY_PTR_POS] + p_offset, dir->location) == 0) && - (i < job_no)) - { - i++; - } - i--; - - /* - * If the value is already set, it means the directory - * appears more then two times. - */ - if (*(p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == '\0') - { - (void)sprintf((p_ptr[i].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset), "%d", job_no); - prev_job_no = i; - break; - } - } - } - if (prev_job_no == -1) - { - system_log(DEBUG_SIGN, __FILE__, __LINE__, - "Hmmm, failed to locate duplicate directory `%s'.", - dir->location); - } - } - - for (i = 0; i < dir->fgc; i++) - { - for (j = 0; j < dir->file[i].dgc; j++) - { - copy_job(i, j, prev_job_no, dir); - } /* next destination group */ - } /* next file group */ -#else int i, j; @@ -2560,7 +2494,6 @@ copy_job(i, j, dir); } /* next destination group */ } /* next file group */ -#endif return; } @@ -2582,12 +2515,7 @@ /* new pointer array for each new recipient. */ /*----------------------------------------------------------------------*/ static void -copy_job(int file_no, - int dest_no, -#ifdef WITH_MULTI_DIR_DEFINITION - int prev_job_no, -#endif - struct dir_group *dir) +copy_job(int file_no, int dest_no, struct dir_group *dir) { int i, j, k, offset, @@ -2740,33 +2668,21 @@ ptr++; /* Insert directory. */ -#ifdef WITH_MULTI_DIR_DEFINITION - if (prev_job_no == -1) + if ((file_no == 0) && (dest_no == 0)) { -#endif - if ((file_no == 0) && (dest_no == 0)) - { - offset = sprintf(ptr, "%s", dir->location); - p_ptr[job_no].ptr[DIRECTORY_PTR_POS] = ptr - p_offset; - ptr += offset + 1; + offset = sprintf(ptr, "%s", dir->location); + p_ptr[job_no].ptr[DIRECTORY_PTR_POS] = ptr - p_offset; + ptr += offset + 1; - offset = sprintf(ptr, "%s", dir->alias); - p_ptr[job_no].ptr[ALIAS_NAME_PTR_POS] = ptr - p_offset; - ptr += offset + 1; - } - else - { - p_ptr[job_no].ptr[DIRECTORY_PTR_POS] = p_ptr[job_no - 1].ptr[DIRECTORY_PTR_POS]; /* Directory */ - p_ptr[job_no].ptr[ALIAS_NAME_PTR_POS] = p_ptr[job_no - 1].ptr[ALIAS_NAME_PTR_POS]; /* Alias */ - } -#ifdef WITH_MULTI_DIR_DEFINITION + offset = sprintf(ptr, "%s", dir->alias); + p_ptr[job_no].ptr[ALIAS_NAME_PTR_POS] = ptr - p_offset; + ptr += offset + 1; } else { - p_ptr[job_no].ptr[DIRECTORY_PTR_POS] = p_ptr[prev_job_no].ptr[DIRECTORY_PTR_POS]; /* Directory */ - p_ptr[job_no].ptr[ALIAS_NAME_PTR_POS] = p_ptr[prev_job_no].ptr[ALIAS_NAME_PTR_POS]; /* Alias */ + p_ptr[job_no].ptr[DIRECTORY_PTR_POS] = p_ptr[job_no - 1].ptr[DIRECTORY_PTR_POS]; /* Directory */ + p_ptr[job_no].ptr[ALIAS_NAME_PTR_POS] = p_ptr[job_no - 1].ptr[ALIAS_NAME_PTR_POS]; /* Alias */ } -#endif /* Insert file masks. */ p_ptr[job_no].ptr[NO_OF_FILES_PTR_POS] = ptr - p_offset; @@ -2921,14 +2837,6 @@ offset = sprintf(ptr, "%x", dir->dir_config_id); ptr += offset + 1; -#ifdef WITH_MULTI_DIR_DEFINITION - /* Offset to same directory. */ - p_ptr[job_no].ptr[OFFSET_TO_SAME_DIR_PTR_POS] = ptr - p_offset; - *ptr = '\0'; - ptr += MAX_INT_LENGTH + 1; -#endif - ptr++; - /* Increase job number. */ job_no++; @@ -2978,6 +2886,145 @@ } +/*+++++++++++++++++++++++++++++++ sort_jobs() +++++++++++++++++++++++++++*/ +static void +sort_jobs(void) +{ + int i, j, k, m; + size_t move_size_1, + move_size_2; + char *buffer, + *ptr; + struct p_array *p_ptr; + + p_ptr = pp; + for (i = 0; i < (job_no - 1); i++) + { + while (p_ptr[i].ptr[DIRECTORY_PTR_POS] == p_ptr[i + 1].ptr[DIRECTORY_PTR_POS]) + { + i++; + } + for (j = (i + 1); j < job_no; j++) + { + if (strcmp(p_t + p_ptr[i].ptr[DIRECTORY_PTR_POS], + p_t + p_ptr[j].ptr[DIRECTORY_PTR_POS]) == 0) + { + int start_j = j; + + while (p_ptr[j].ptr[DIRECTORY_PTR_POS] == p_ptr[j + 1].ptr[DIRECTORY_PTR_POS]) + { + j++; + } + + /* First copy the real data into its correct place. */ + if (p_ptr[j].ptr[DIR_CONFIG_ID_PTR_POS] > p_ptr[j].ptr[RECIPIENT_PTR_POS]) + { + ptr = p_t + p_ptr[j].ptr[DIR_CONFIG_ID_PTR_POS]; + } + else + { + ptr = p_t + p_ptr[j].ptr[RECIPIENT_PTR_POS]; + } + while (*ptr != '\0') + { + ptr++; + } + move_size_1 = ptr + 1 - (p_t + p_ptr[start_j].ptr[PRIORITY_PTR_POS]); + if ((buffer = malloc(move_size_1)) == NULL) + { + system_log(FATAL_SIGN, __FILE__, __LINE__, + "Failed to malloc() %d bytes : %s", + move_size_1, strerror(errno)); + exit(INCORRECT); + } + (void)memcpy(buffer, (p_t + p_ptr[start_j].ptr[PRIORITY_PTR_POS]), + move_size_1); + + if (p_ptr[i].ptr[DIR_CONFIG_ID_PTR_POS] > p_ptr[i].ptr[RECIPIENT_PTR_POS]) + { + ptr = p_t + p_ptr[i].ptr[DIR_CONFIG_ID_PTR_POS]; + } + else + { + ptr = p_t + p_ptr[i].ptr[RECIPIENT_PTR_POS]; + } + while (*ptr != '\0') + { + ptr++; + } + move_size_2 = p_t + p_ptr[start_j].ptr[PRIORITY_PTR_POS] - (ptr + 1); + (void)memmove((p_t + p_ptr[i + 1].ptr[PRIORITY_PTR_POS] + move_size_1), + (p_t + p_ptr[i + 1].ptr[PRIORITY_PTR_POS]), + move_size_2); + (void)memcpy((p_t + p_ptr[i + 1].ptr[PRIORITY_PTR_POS]), + buffer, move_size_1); + + /* Correct all pointer positions. */ + for (k = 0; k < (j + 1 - start_j); k++) + { + for (m = 0; m < MAX_DATA_PTRS; m++) + { + p_ptr[start_j + k].ptr[m] -= move_size_2; + } + } + for (k = (i + 1); k < start_j; k++) + { + for (m = 0; m < MAX_DATA_PTRS; m++) + { + p_ptr[k].ptr[m] += move_size_1; + } + } + + /* Now copy the pointer array. */ + m = (j + 1 - start_j) * sizeof(struct p_array); + if (move_size_1 < m) + { + if ((buffer = realloc(buffer, m)) == NULL) + { + system_log(FATAL_SIGN, __FILE__, __LINE__, + "Failed to realloc() %d bytes : %s", + m, strerror(errno)); + exit(INCORRECT); + } + } + move_size_1 = m; + (void)memcpy(buffer, &p_ptr[start_j], move_size_1); + move_size_2 = (start_j - (i + 1)) * sizeof(struct p_array); + (void)memmove(&p_ptr[i + 1 + (j + 1 - start_j)], &p_ptr[i + 1], + move_size_2); + (void)memcpy(&p_ptr[i + 1], buffer, move_size_1); + + /* Let all same directories point to the directory position, */ + /* in case we do have more same directories. We do waste some */ + /* memory here but it is not worth the trouble resetting all */ + /* pointers if we free the memory. */ + for (m = 0; m < (j + 1 - start_j); m++) + { + p_ptr[i + 1 + m].ptr[DIRECTORY_PTR_POS] = p_ptr[i].ptr[DIRECTORY_PTR_POS]; /* Directory. */ + p_ptr[i + 1 + m].ptr[ALIAS_NAME_PTR_POS] = p_ptr[i].ptr[ALIAS_NAME_PTR_POS]; /* Alias. */ + } + + /* Free memory for buffer. */ + free(buffer); + + /* No need to check those directories we just have moved. */ + i += (j - start_j + 1); + } + else + { + while ((j < job_no) && + (p_ptr[j].ptr[DIRECTORY_PTR_POS] == p_ptr[j + 1].ptr[DIRECTORY_PTR_POS])) + { + j++; + } + } + } + } + + return; +} + + /*+++++++++++++++++++++++++++++ copy_to_file() ++++++++++++++++++++++++++*/ /* -------------- */ /* Description: Creates a file and copies the number of */ diff -u --recursive --new-file afd-1.3.6.old/src/amg/show_amg_data.c afd-1.3.6/src/amg/show_amg_data.c --- afd-1.3.6.old/src/amg/show_amg_data.c 2007-02-25 19:01:28.000000000 +0100 +++ afd-1.3.6/src/amg/show_amg_data.c 2008-10-04 18:33:17.000000000 +0200 @@ -191,20 +191,6 @@ (void)fprintf(output, "DIR_CONFIG ID : %s\n", p_ptr[j].ptr[DIR_CONFIG_ID_PTR_POS] + p_offset); (void)fprintf(output, "Directory : %s\n", p_ptr[j].ptr[DIRECTORY_PTR_POS] + p_offset); (void)fprintf(output, "Alias name : %s\n", p_ptr[j].ptr[ALIAS_NAME_PTR_POS] + p_offset); -#ifdef WITH_MULTI_DIR_DEFINITION - if (*(p_ptr[j].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == '\0') - { - (void)fprintf(output, "Offset to same dir : Not set (0)\n"); - } - else if (*(p_ptr[j].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset) == 1) - { - (void)fprintf(output, "Offset to same dir : Jump back (1)\n"); - } - else - { - (void)fprintf(output, "Offset to same dir : %s\n", p_ptr[j].ptr[OFFSET_TO_SAME_DIR_PTR_POS] + p_offset); - } -#endif (void)fprintf(output, "Priority : %c\n", *(p_ptr[j].ptr[PRIORITY_PTR_POS] + p_offset)); /* Show files to be send */