Source File modules/mi/mirror.c

    1    | /***************************************
    2    |   $Revision: 1.1 $
    3    |
    4    |   Mirror module (mi).
    5    |
    6    |   Status: NOT REVUED, NOT TESTED
    7    |
    8    |   ******************/ /******************
    9    |   Filename            : access_control.c
    10   |   Author              : ottrey@ripe.net
    11   |   OSs Tested          : Solaris
    12   |   ******************/ /******************
    13   |   Copyright (c) 1999                              RIPE NCC
    14   |
    15   |   All Rights Reserved
    16   |
    17   |   Permission to use, copy, modify, and distribute this software and its
    18   |   documentation for any purpose and without fee is hereby granted,
    19   |   provided that the above copyright notice appear in all copies and that
    20   |   both that copyright notice and this permission notice appear in
    21   |   supporting documentation, and that the name of the author not be
    22   |   used in advertising or publicity pertaining to distribution of the
    23   |   software without specific, written prior permission.
    24   |
    25   |   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
    26   |   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
    27   |   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
    28   |   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
    29   |   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    30   |   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    31   |   ***************************************/
    32   | #include <stdio.h>
    33   | #include <sys/timeb.h>
    34   | #include <glib.h>
    35   | #include "thread.h"
    36   |
    37   | /*+ String sizes +*/
    38   | #define STR_S   63
    39   | #define STR_M   255
    40   | #define STR_L   1023
    41   | #define STR_XL  4095
    42   | #define STR_XXL 16383
    43   |
    44   | #define SLEEP_TIME 10
    45   |
    46   | static producer_run(void) {
    47   |   FILE *f1, *f2;
    48   |   GString *current_serial;
    49   |   int serial_curr=0;
    50   |   int serial_prev=0;
    51   |   int i, j;
    52   |   char line[STR_XL];
    53   |
    54   |   printf("Producer thread started.\n");
    55   |
    56   |   current_serial = g_string_sized_new(STR_L);
    57   |
    58   |   for (i=0; i< 300; i++) {
    59   |     sleep(SLEEP_TIME);
    60   |
    61   |     serial_prev = serial_curr;
    62   |
    63   |     f1 = fopen("/ncc/db2/serials/current/RIPE.CURRENTSERIAL", "r");
    64   |     fscanf(f1, "%d", &serial_curr);
    65   |     fclose(f1);
    66   |
    67   |     if (serial_prev != 0) {
    68   |       for (j=serial_prev; j < serial_curr; j++) {
    69   |         printf("[%d][%d]\n", i, j);
    70   |         g_string_sprintf(current_serial, "/ncc/db2/serials/current/RIPE.%d", j);
    71   |         f2 = fopen((char *)current_serial->str, "r");
    72   |         while (fgets(line, STR_XL, f2) != NULL) {
    73   |           printf("%s", line);
    74   |         }
    75   |         fclose(f2);
    76   |       }
    77   |     }
    78   |   }
    79   |
    80   |   g_string_free(current_serial, TRUE);
    81   |
    82   |   pthread_exit((void *)0);
    83   | } /* producer_run() */
    84   |
    85   | /* MI_init() */
    86   | /*++++++++++++++++++++++++++++++++++++++
    87   |   Initialize the mirroring.
    88   |
    89   |   More:
    90   |   +html+ <PRE>
    91   |   Authors:
    92   |         ottrey
    93   |
    94   |   +html+ </PRE><DL COMPACT>
    95   |   +html+ <DT>Online References:
    96   |   +html+ <DD><UL>
    97   |   +html+ </UL></DL>
    98   |
    99   |   ++++++++++++++++++++++++++++++++++++++*/
    100  | void MI_init() {
    101  |   pthread_t tid;
    102  |   pthread_attr_t attr;
    103  |
    104  |   printf("Initialising mirroring.\n");
    105  |
    106  |   pthread_attr_init(&attr);     /* initialize attr with default attributes */
    107  |   pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
    108  |   pthread_create(&tid, &attr, (void *(*)(void *))producer_run, NULL);
    109  | } /* MI_init() */
    110  |
    111  | int main(void) {
    112  |   MI_init();
    113  |   sleep(1000);
    114  |   return 0;
    115  | }