예제 #1
0
파일: change_name.c 프로젝트: hfs/afd
int
main(int argc, char *argv[])
{
   int  *counter,
        counter_fd;
   char new_name[MAX_PATH_LENGTH],
        work_dir[MAX_PATH_LENGTH];

   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(1);
   }
   p_work_dir = work_dir;
   if (argc != 4)
   {
      (void)fprintf(stderr,
                    "Usage: %s <original name> <filter> <rename to rule>\n",
                    argv[0]);
      exit(1);
   }
   if ((counter_fd = open_counter_file(COUNTER_FILE, &counter)) == -1)
   {
      printf("Failed to open counter file.\n");
      exit(1);
   }
   change_name(argv[1], argv[2], argv[3], new_name, MAX_PATH_LENGTH, &counter_fd, &counter, 0);
   printf("new name = %s\n", new_name);

   exit(0);
}
예제 #2
0
파일: get_counter.c 프로젝트: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int          counter,
                fd;
   char         counter_file[MAX_PATH_LENGTH],
                work_dir[MAX_PATH_LENGTH];
   struct flock wlock = {F_WRLCK, SEEK_SET, 0, 1},
                ulock = {F_UNLCK, SEEK_SET, 0, 1};

   /* Open file that holds the counter. */
   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   (void)strcpy(counter_file, work_dir);
   (void)strcat(counter_file, FIFO_DIR);
   (void)strcat(counter_file, AMG_COUNTER_FILE);
#ifdef GROUP_CAN_WRITE
   if ((fd = open(counter_file, O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) < 0)
#else
   if ((fd = open(counter_file, O_RDWR, S_IRUSR | S_IWUSR)) < 0)
#endif
   {
      (void)fprintf(stderr, "Could not open %s : %s (%s %d)\n",
                    counter_file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Try to lock file which holds counter. */
   if (fcntl(fd, F_SETLKW, &wlock) < 0)
   {
      (void)fprintf(stderr, "Could not set write lock. (%s %d)\n",
                    __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Read the value of counter. */
   if (read(fd, &counter, sizeof(int)) < 0)
   {
      (void)fprintf(stderr, "Could not read value of counter : %s (%s %d)\n",
                    strerror(errno),  __FILE__, __LINE__);
      exit(INCORRECT);
   }

   (void)fprintf(stdout, "AFD-counter = %d\n", counter);

   /* Unlock file which holds counter. */
   if (fcntl(fd, F_SETLKW, &ulock) < 0)
   {
      (void)fprintf(stderr, "Could not unset write lock : %s (%s %d)\n",
                    strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Close the counter file. */
   (void)close(fd);

   exit(SUCCESS);
}
예제 #3
0
파일: afd_status.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ afd_status() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int           i;
   char          work_dir[MAX_PATH_LENGTH];
   struct passwd *pwd;

   CHECK_FOR_VERSION(argc, argv);

   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   p_work_dir = work_dir;

   /* Attach to the AFD Status Area. */
   if (attach_afd_status(NULL, WAIT_AFD_STATUS_ATTACH) < 0)
   {
      (void)fprintf(stderr,
                    _("ERROR   : Failed to map to AFD status area. (%s %d)\n"),
                    __FILE__, __LINE__);
      exit(INCORRECT);
   }

   (void)fprintf(stdout, "Hostname             : %s\n", p_afd_status->hostname);
   (void)fprintf(stdout, "Working directory    : %s\n", p_afd_status->work_dir);
   if ((pwd = getpwuid(p_afd_status->user_id)) == NULL)
   {
#if SIZEOF_UID_T == 4
      (void)fprintf(stdout, "User ID              : %d\n", p_afd_status->user_id);
#else
      (void)fprintf(stdout, "User ID              : %lld\n", (pri_uid_t)p_afd_status->user_id);
#endif
   }
   else
   {
#if SIZEOF_UID_T == 4
      (void)fprintf(stdout, "User name + ID       : %s (%d)\n", pwd->pw_name, p_afd_status->user_id);
#else
      (void)fprintf(stdout, "User name + ID       : %s (%lld)\n", pwd->pw_name, (pri_uid_t)p_afd_status->user_id);
#endif
   }
   (void)fprintf(stdout, "AMG                  : %d\n", p_afd_status->amg);
   (void)fprintf(stdout, "AMG jobs status flag : %d\n", p_afd_status->amg_jobs);
   (void)fprintf(stdout, "FD                   : %d\n", p_afd_status->fd);
   (void)fprintf(stdout, "System log           : %d\n", p_afd_status->sys_log);
   (void)fprintf(stdout, "Event log            : %d\n", p_afd_status->event_log);
   (void)fprintf(stdout, "Transfer log         : %d\n", p_afd_status->trans_log);
   (void)fprintf(stdout, "Trans debug log      : %d\n", p_afd_status->trans_db_log);
   (void)fprintf(stdout, "Archive watch        : %d\n", p_afd_status->archive_watch);
   (void)fprintf(stdout, "afd_stat             : %d\n", p_afd_status->afd_stat);
   (void)fprintf(stdout, "afdd                 : %d\n", p_afd_status->afdd);
#ifdef _WITH_SERVER_SUPPORT
   (void)fprintf(stdout, "afds                 : %d\n", p_afd_status->afds);
#endif
#ifndef HAVE_MMAP
   (void)fprintf(stdout, "mapper               : %d\n", p_afd_status->mapper);
#endif
#ifdef _INPUT_LOG
   (void)fprintf(stdout, "input_log            : %d\n", p_afd_status->input_log);
#endif
#ifdef _OUTPUT_LOG
   (void)fprintf(stdout, "output_log           : %d\n", p_afd_status->output_log);
#endif
#ifdef _DELETE_LOG
   (void)fprintf(stdout, "delete_log           : %d\n", p_afd_status->delete_log);
#endif
#ifdef _PRODUCTION_LOG
   (void)fprintf(stdout, "production_log       : %d\n", p_afd_status->production_log);
#endif
#ifdef _DISTRIBUTION_LOG
   (void)fprintf(stdout, "distribution_log     : %d\n", p_afd_status->distribution_log);
#endif
#ifdef ALDAD_OFFSET
   (void)fprintf(stdout, "ALDA daemon          : %d\n", p_afd_status->aldad);
#endif
   (void)fprintf(stdout, "Receivelog indicator : %u <",
                 p_afd_status->receive_log_ec);
   for (i = 0; i < LOG_FIFO_SIZE; i++)
   {
      switch (p_afd_status->receive_log_fifo[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, " >\n");
   (void)fprintf(stdout, "Receive log history  :");
   for (i = 0; i < MAX_LOG_HISTORY; i++)
   {
      switch (p_afd_status->receive_log_history[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, "\n");
   (void)fprintf(stdout, "Syslog indicator     : %u <",
                 p_afd_status->sys_log_ec);
   for (i = 0; i < LOG_FIFO_SIZE; i++)
   {
      switch (p_afd_status->sys_log_fifo[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case CONFIG_ID :
            (void)fprintf(stdout, " C");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, " >\n");
   (void)fprintf(stdout, "System log history   :");
   for (i = 0; i < MAX_LOG_HISTORY; i++)
   {
      switch (p_afd_status->sys_log_history[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case CONFIG_ID :
            (void)fprintf(stdout, " C");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, "\n");
   (void)fprintf(stdout, "Translog indicator   : %u <",
                 p_afd_status->trans_log_ec);
   for (i = 0; i < LOG_FIFO_SIZE; i++)
   {
      switch (p_afd_status->trans_log_fifo[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case ERROR_OFFLINE_ID :
            (void)fprintf(stdout, " O");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, " >\n");
   (void)fprintf(stdout, "Transfer log history :");
   for (i = 0; i < MAX_LOG_HISTORY; i++)
   {
      switch (p_afd_status->trans_log_history[i])
      {
         case INFO_ID :
            (void)fprintf(stdout, " I");
            break;
         case ERROR_ID :
            (void)fprintf(stdout, " E");
            break;
         case WARNING_ID :
            (void)fprintf(stdout, " W");
            break;
         case ERROR_OFFLINE_ID :
            (void)fprintf(stdout, " O");
            break;
         case FAULTY_ID :
            (void)fprintf(stdout, " F");
            break;
         default :
            (void)fprintf(stdout, " ?");
            break;
      }
   }
   (void)fprintf(stdout, "\n");
   (void)fprintf(stdout, "Number of transfers  : %d\n", p_afd_status->no_of_transfers);
   (void)fprintf(stdout, "Number of retrieves  : %d\n", p_afd_status->no_of_retrieves);
#if SIZEOF_NLINK_T > 4
   (void)fprintf(stdout, "Jobs in queue        : %lld\n", (pri_nlink_t)p_afd_status->jobs_in_queue);
#else
   (void)fprintf(stdout, "Jobs in queue        : %d\n", (pri_nlink_t)p_afd_status->jobs_in_queue);
#endif
   (void)fprintf(stdout, "AMG fork() counter   : %u\n", p_afd_status->amg_fork_counter);
   (void)fprintf(stdout, "FD fork() counter    : %u\n", p_afd_status->fd_fork_counter);
   (void)fprintf(stdout, "Burst2 counter       : %u\n", p_afd_status->burst2_counter);
   (void)fprintf(stdout, "AMG child user time  : %ld.%ld\n", p_afd_status->amg_child_utime.tv_sec, p_afd_status->amg_child_utime.tv_usec);
   (void)fprintf(stdout, "AMG child system time: %ld.%ld\n", p_afd_status->amg_child_stime.tv_sec, p_afd_status->amg_child_stime.tv_usec);
   (void)fprintf(stdout, "FD child user time   : %ld.%ld\n", p_afd_status->fd_child_utime.tv_sec, p_afd_status->fd_child_utime.tv_usec);
   (void)fprintf(stdout, "FD child system time : %ld.%ld\n", p_afd_status->fd_child_stime.tv_sec, p_afd_status->fd_child_stime.tv_usec);
   (void)fprintf(stdout, "Max. FD queue length : %u\n", p_afd_status->max_queue_length);
   (void)fprintf(stdout, "Directories scanned  : %u\n", p_afd_status->dir_scans);
   (void)fprintf(stdout, "AFD start time       : %s", ctime(&p_afd_status->start_time));

   exit(SUCCESS);
}
예제 #4
0
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int            n,
                  status,
#ifdef WITHOUT_FIFO_RW_SUPPORT
                  aw_cmd_writefd,
#endif
                  aw_cmd_fd;
   time_t         diff_time,
                  next_report_time,
                  next_rescan_time = 0L,
                  now;
   char           archive_dir[MAX_PATH_LENGTH],
                  aw_cmd_fifo[MAX_PATH_LENGTH],
                  buffer[DEFAULT_BUFFER_SIZE],
                  work_dir[MAX_PATH_LENGTH];
   fd_set         rset;
   struct timeval timeout;
   struct stat    stat_buf;

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   else
   {
      char *ptr;

      p_work_dir = work_dir;

      /*
       * Lock archive_watch so no other archive_watch can be started!
       */
      if ((ptr = lock_proc(AW_LOCK_ID, NO)) != NULL)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    _("Process archive_watch already started by %s."), ptr);
         exit(INCORRECT);
      }
   }

   /* Initialize fifo to communicate with AFD. */
   (void)strcpy(aw_cmd_fifo, work_dir);
   (void)strcat(aw_cmd_fifo, FIFO_DIR);
   (void)strcat(aw_cmd_fifo, AW_CMD_FIFO);
   (void)strcpy(archive_dir, work_dir);
   (void)strcat(archive_dir, AFD_ARCHIVE_DIR);

   /* Now lets open the fifo to receive commands from the AFD. */
   if ((stat(aw_cmd_fifo, &stat_buf) < 0) || (!S_ISFIFO(stat_buf.st_mode)))
   {
      if (make_fifo(aw_cmd_fifo) < 0)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    _("Could not create fifo `%s'."), aw_cmd_fifo);
         exit(INCORRECT);
      }
   }

#ifdef WITHOUT_FIFO_RW_SUPPORT
   if (open_fifo_rw(aw_cmd_fifo, &aw_cmd_fd, &aw_cmd_writefd) == -1)
#else
   if ((aw_cmd_fd = coe_open(aw_cmd_fifo, O_RDWR)) == -1)
#endif
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 _(": Could not open fifo `%s' : %s"),
                 aw_cmd_fifo, strerror(errno));
      exit(INCORRECT);
   }

#ifdef HAVE_SETPRIORITY
   get_afd_config_value();
#endif

   /* Do some cleanups when we exit. */
   if (atexit(aw_exit) != 0)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 _("Could not register exit handler : %s"), strerror(errno));
      exit(INCORRECT);
   }
   if ((signal(SIGINT, sig_exit) == SIG_ERR) ||
       (signal(SIGQUIT, sig_exit) == SIG_ERR) ||
       (signal(SIGTERM, SIG_IGN) == SIG_ERR) ||
       (signal(SIGSEGV, sig_segv) == SIG_ERR) ||
       (signal(SIGBUS, sig_bus) == SIG_ERR) ||
       (signal(SIGHUP, SIG_IGN) == SIG_ERR))
   {
      system_log(WARN_SIGN, __FILE__, __LINE__,
                 _("Could not set signal handlers : %s"), strerror(errno));
   }

   system_log(INFO_SIGN, NULL, 0, "Starting %s (%s)",
              ARCHIVE_WATCH, PACKAGE_VERSION);

   next_report_time = (time(NULL) / 3600) * 3600 + 3600;
   FD_ZERO(&rset);

   for (;;)
   {
      if (time(&now) >= next_rescan_time)
      {
         next_rescan_time = (now / ARCHIVE_STEP_TIME) *
                            ARCHIVE_STEP_TIME + ARCHIVE_STEP_TIME;
      }

      /* Initialize descriptor set and timeout. */
      FD_SET(aw_cmd_fd, &rset);
      timeout.tv_usec = 0;
      if ((diff_time = (next_rescan_time - now)) < 0)
      {
         diff_time = 0L;
      }
      timeout.tv_sec = diff_time;

      /* Wait for message x seconds and then continue. */
      status = select(aw_cmd_fd + 1, &rset, NULL, NULL, &timeout);

      /* Report every hour how many archives have been deleted. */
#ifndef AFDBENCH_CONFIG
      if ((now + diff_time) >= next_report_time)
      {
         next_report_time = ((now + diff_time) / 3600) * 3600 + 3600;
#endif
#ifdef _NO_ZERO_DELETION_REPORT
         if ((removed_archives > 0) || (removed_files > 0))
         {
            system_log(INFO_SIGN, NULL, 0,
                      _("Removed %u archives with %u files."),
                      removed_archives, removed_files);
         }
#else
         system_log(INFO_SIGN, NULL, 0,
                   _("Removed %u archives with %u files."),
                   removed_archives, removed_files);
#endif
         removed_archives = removed_files = 0;
#ifndef AFDBENCH_CONFIG
      }
#endif

      /* Huh? Did we just sleep? */
      if (status == 0)
      {
         /* Lets go to work! */
         current_time = now + diff_time;
         inspect_archive(archive_dir);
      }
      else if (FD_ISSET(aw_cmd_fd, &rset))
           {
              /* Read the message. */
              if ((n = read(aw_cmd_fd, buffer, DEFAULT_BUFFER_SIZE)) > 0)
              {
                 while (n > 0)
                 {
#ifdef _FIFO_DEBUG
                    show_fifo_data('R', "aw_cmd", buffer, n, __FILE__, __LINE__);
#endif
                    if (buffer[0] == STOP)
                    {
                       system_log(INFO_SIGN, NULL, 0,
                                  _("Stopped %s"), ARCHIVE_WATCH);
                       exit(SUCCESS);
                    }
                    else if (buffer[0] == RETRY)
                         {
                            system_log(INFO_SIGN, NULL, 0,
                                       _("Rescaning archive directories."),
                                       ARCHIVE_WATCH);

                            /* Remember to set current_time, since the   */
                            /* function inspect_archive() depends on it. */
                            current_time = time(NULL);
                            inspect_archive(archive_dir);
                         }
                         else
                         {
                            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                                      _("Hmmm..., reading garbage [%d] on fifo `%s'."),
                                      buffer[0], AW_CMD_FIFO);
                         }
                    n--;
                 } /* while (n > 0) */
              }
           }
      else if (status < 0)
           {
              system_log(FATAL_SIGN, __FILE__, __LINE__,
                         _("select() error : %s"), strerror(errno));
              exit(INCORRECT);
           }
           else
           {
              system_log(FATAL_SIGN, __FILE__, __LINE__,
                         _("Huh? Maybe YOU have a clue whats going on here!"));
              exit(INCORRECT);
           }
   } /* for (;;) */

   exit(SUCCESS);
}
예제 #5
0
파일: fra_edit.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ fra_edit() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int          position = -1,
                leave_flag = NO,
                ret;
   unsigned int value;
   char         dir_alias[MAX_DIR_ALIAS_LENGTH + 1],
                work_dir[MAX_PATH_LENGTH];

   CHECK_FOR_VERSION(argc, argv);

   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   p_work_dir = work_dir;

   if (argc == 2)
   {
      if (isdigit((int)(argv[1][0])) != 0)
      {
         position = atoi(argv[1]);
      }
      else
      {
         (void)strcpy(dir_alias, argv[1]);
      }
   }
   else
   {
      usage(argv[0]);
      exit(INCORRECT);
   }

   if ((ret = fra_attach()) < 0)
   {
      if (ret == INCORRECT_VERSION)
      {
         (void)fprintf(stderr,
                       _("ERROR   : This program is not able to attach to the FRA due to incorrect version. (%s %d)\n"),
                       __FILE__, __LINE__);
      }
      else
      {
         (void)fprintf(stderr,
                       _("ERROR   : Failed to attach to FRA. (%s %d)\n"),
                       __FILE__, __LINE__);
      }
      exit(INCORRECT);
   }

   if (tcgetattr(STDIN_FILENO, &buf) < 0)
   {
      (void)fprintf(stderr, _("ERROR   : tcgetattr() error : %s (%s %d)\n"),
                    strerror(errno), __FILE__, __LINE__);
      exit(0);
   }

   if (position < 0)
   {
      if ((position = get_dir_position(fra, dir_alias, no_of_dirs)) < 0)
      {
         (void)fprintf(stderr,
                       _("ERROR   : Could not find directory %s in FRA. (%s %d)\n"),
                       dir_alias, __FILE__, __LINE__);
         exit(INCORRECT);
      }
   }

   for (;;)
   {
      menu(position);

      switch (get_key())
      {
         case 0   : break;
         case '1' : (void)fprintf(stderr, _("\n\n     Enter value [1] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].files_in_dir = (int)value;
                    break;
         case '2' : (void)fprintf(stderr, _("\n\n     Enter value [2] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].bytes_in_dir = value;
                    break;
         case '3' : (void)fprintf(stderr, _("\n\n     Enter value [3] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].files_queued = value;
                    break;
         case '4' : (void)fprintf(stderr, _("\n\n     Enter value [4] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].bytes_in_queue = value;
                    break;
         case '5' : (void)fprintf(stderr, _("\n\n     Enter value [5] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].error_counter = value;
                    break;
         case '6' : (void)fprintf(stdout, "\033[2J\033[3;1H");
                    (void)fprintf(stdout, "\n\n\n");
                    (void)fprintf(stdout, "     Reset to zero.................(0)\n");
                    (void)fprintf(stdout, "     MAX_COPIED [%d]...............(1)\n",
                                  (fra[position].dir_flag & MAX_COPIED) ? 1 : 0);
                    (void)fprintf(stdout, "     FILES_IN_QUEUE [%d]...........(2)\n",
                                  (fra[position].dir_flag & FILES_IN_QUEUE) ? 1 : 0);
                    (void)fprintf(stdout, "     ADD_TIME_ENTRY [%d]...........(3)\n",
                                  (fra[position].dir_flag & ADD_TIME_ENTRY) ? 1 : 0);
                    (void)fprintf(stdout, "     LINK_NO_EXEC [%d].............(4)\n",
                                  (fra[position].dir_flag & LINK_NO_EXEC) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_DISABLED [%d].............(5)\n",
                                  (fra[position].dir_flag & DIR_DISABLED) ? 1 : 0);
                    (void)fprintf(stdout, "     ACCEPT_DOT_FILES [%d].........(6)\n",
                                  (fra[position].dir_flag & ACCEPT_DOT_FILES) ? 1 : 0);
                    (void)fprintf(stdout, "     DONT_GET_DIR_LIST [%d]........(7)\n",
                                  (fra[position].dir_flag & DONT_GET_DIR_LIST) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_ERROR_SET [%d]............(8)\n",
                                  (fra[position].dir_flag & DIR_ERROR_SET) ? 1 : 0);
                    (void)fprintf(stdout, "     WARN_TIME_REACHED [%d]........(9)\n",
                                  (fra[position].dir_flag & WARN_TIME_REACHED) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_ERROR_ACKN [%d]...........(a)\n",
                                  (fra[position].dir_flag & DIR_ERROR_ACKN) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_ERROR_OFFLINE [%d]........(b)\n",
                                  (fra[position].dir_flag & DIR_ERROR_OFFLINE) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_ERROR_ACKN_T [%d].........(c)\n",
                                  (fra[position].dir_flag & DIR_ERROR_ACKN_T) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_ERROR_OFFL_T [%d].........(d)\n",
                                  (fra[position].dir_flag & DIR_ERROR_OFFL_T) ? 1 : 0);
                    (void)fprintf(stdout, "     DIR_STOPPED [%d]..............(e)\n",
                                  (fra[position].dir_flag & DIR_ERROR_OFFL_T) ? 1 : 0);
#ifdef WITH_INOTIFY
                    (void)fprintf(stdout, "     INOTIFY_RENAME [%d]...........(f)\n",
                                  (fra[position].dir_flag & INOTIFY_RENAME) ? 1 : 0);
                    (void)fprintf(stdout, "     INOTIFY_CLOSE [%d]............(g)\n",
                                  (fra[position].dir_flag & INOTIFY_CLOSE) ? 1 : 0);
                    (void)fprintf(stdout, "     INOTIFY_CREATE [%d]...........(h)\n",
                                  (fra[position].dir_flag & INOTIFY_CREATE) ? 1 : 0);
#endif
                    (void)fprintf(stdout, "     ALL_DISABLED [%d].............(i)\n",
                                  (fra[position].dir_flag & ALL_DISABLED) ? 1 : 0);
                    (void)fprintf(stdout, "     CREATE_R_SRC_DIR [%d].........(j)\n",
                                  (fra[position].dir_flag & CREATE_R_SRC_DIR) ? 1 : 0);
                    (void)fprintf(stderr, "     None..........................(Z) ");

                    switch (get_key())
                    {
                       case '0' : fra[position].dir_flag = 0;
                                  break;
                       case '1' : fra[position].dir_flag ^= MAX_COPIED;
                                  break;
                       case '2' : fra[position].dir_flag ^= FILES_IN_QUEUE;
                                  break;
                       case '3' : fra[position].dir_flag ^= ADD_TIME_ENTRY;
                                  break;
                       case '4' : fra[position].dir_flag ^= LINK_NO_EXEC;
                                  break;
                       case '5' : fra[position].dir_flag ^= DIR_DISABLED;
                                  break;
                       case '6' : fra[position].dir_flag ^= ACCEPT_DOT_FILES;
                                  break;
                       case '7' : fra[position].dir_flag ^= DONT_GET_DIR_LIST;
                                  break;
                       case '8' : fra[position].dir_flag ^= DIR_ERROR_SET;
                                  break;
                       case '9' : fra[position].dir_flag ^= WARN_TIME_REACHED;
                                  break;
                       case 'a' : fra[position].dir_flag ^= DIR_ERROR_ACKN;
                                  break;
                       case 'b' : fra[position].dir_flag ^= DIR_ERROR_OFFLINE;
                                  break;
                       case 'c' : fra[position].dir_flag ^= DIR_ERROR_ACKN_T;
                                  break;
                       case 'd' : fra[position].dir_flag ^= DIR_ERROR_OFFL_T;
                                  break;
                       case 'e' : fra[position].dir_flag ^= DIR_STOPPED;
                                  break;
#ifdef WITH_INOTIFY
                       case 'f' : fra[position].dir_flag ^= INOTIFY_RENAME;
                                  break;
                       case 'g' : fra[position].dir_flag ^= INOTIFY_CLOSE;
                                  break;
                       case 'h' : fra[position].dir_flag ^= INOTIFY_CREATE;
                                  break;
#endif
                       case 'i' : fra[position].dir_flag ^= ALL_DISABLED;
                                  break;
                       case 'j' : fra[position].dir_flag ^= CREATE_R_SRC_DIR;
                                  break;
                       case 'Z' : break;
                       default  : (void)printf(_("Wrong choice!\n"));
                                  (void)sleep(1);
                                  break;
                    }
                    break;
         case '7' : (void)fprintf(stderr, _("\n\n     Enter value [7] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fra[position].queued = (char)value;
                    break;
         case 'x' :
         case 'Q' :
         case 'q' : leave_flag = YES;
                    break;
         default  : (void)printf(_("Wrong choice!\n"));
                    (void)sleep(1);
                    break;
      }

      if (leave_flag == YES)
      {
         (void)fprintf(stdout, "\n\n");
         break;
      }
      else
      {
         (void)my_usleep(100000L);
      }
   } /* for (;;) */

   exit(SUCCESS);
}
예제 #6
0
파일: afd_stat.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   register int   i,
                  j;
   int            current_year,
                  hour,
                  new_year,
                  status,
                  test_sec_counter,
                  test_hour_counter;
   unsigned int   ui_value;          /* Temporary storage for uns. ints  */
   time_t         next_rescan_time = 0L,
                  now;
   long int       sleep_time;
   double         d_value[MAX_NO_PARALLEL_JOBS]; /* Temporary storage    */
                                                 /* for doubles.         */
   char           work_dir[MAX_PATH_LENGTH],
                  istatistic_file_name[MAX_FILENAME_LENGTH],
                  statistic_file_name[MAX_FILENAME_LENGTH];
   struct timeval timeout;
   struct stat    stat_buf;
   struct tm      *p_ts;

   CHECK_FOR_VERSION(argc, argv);

   /* Evaluate arguments */
   statistic_file_name[0] = istatistic_file_name[0] = '\0';
   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   eval_input_as(argc, argv, work_dir, statistic_file_name,
                 istatistic_file_name);
#ifdef HAVE_SETPRIORITY
   get_afd_config_value();
#endif

   /* Initialize variables */
   now = time(NULL);
   p_ts = gmtime(&now);

   /*
    * NOTE: We must put the hour into a temporary storage since
    *       function system_log() uses the function localtime which seems
    *       to overwrite our p_ts->tm_hour with local time!?
    */
   hour = p_ts->tm_hour;
   current_year = p_ts->tm_year + 1900;
   p_work_dir = work_dir;
   if (statistic_file_name[0] == '\0')
   {
      char str_year[6];

      (void)sprintf(str_year, ".%d", current_year);
      (void)strcpy(statistic_file, work_dir);
      (void)strcat(statistic_file, LOG_DIR);
      (void)strcpy(new_statistic_file, statistic_file);
      (void)strcat(new_statistic_file, NEW_STATISTIC_FILE);
      (void)strcat(new_statistic_file, str_year);
      (void)strcpy(new_istatistic_file, statistic_file);
      (void)strcat(new_istatistic_file, NEW_ISTATISTIC_FILE);
      (void)strcat(new_istatistic_file, str_year);
      (void)strcpy(istatistic_file, statistic_file);
      (void)strcat(istatistic_file, ISTATISTIC_FILE);
      (void)strcat(istatistic_file, str_year);
      (void)strcat(statistic_file, STATISTIC_FILE);
      (void)strcat(statistic_file, str_year);
   }
   else
   {
      (void)strcpy(statistic_file, statistic_file_name);
      (void)strcpy(new_statistic_file, statistic_file);
      (void)strcat(new_statistic_file, ".NEW");
      (void)strcpy(istatistic_file, istatistic_file_name);
      (void)strcpy(new_istatistic_file, istatistic_file);
      (void)strcat(new_istatistic_file, ".NEW");
   }

   if (other_file == NO)
   {
      char sys_log_fifo[MAX_PATH_LENGTH];

      (void)strcpy(sys_log_fifo, work_dir);
      (void)strcat(sys_log_fifo, FIFO_DIR);
      (void)strcat(sys_log_fifo, SYSTEM_LOG_FIFO);

      /* If the process AFD has not yet created the */
      /* system log fifo create it now.             */
      if ((stat(sys_log_fifo, &stat_buf) < 0) || (!S_ISFIFO(stat_buf.st_mode)))
      {
         if (make_fifo(sys_log_fifo) < 0)
         {
            (void)fprintf(stderr,
                          "ERROR   : Could not create fifo %s. (%s %d)\n",
                          sys_log_fifo, __FILE__, __LINE__);
            exit(INCORRECT);
         }
      }

      /* Open system log fifo */
#ifdef WITHOUT_FIFO_RW_SUPPORT
      if (open_fifo_rw(sys_log_fifo, &sys_log_readfd, &sys_log_fd) == -1)
#else
      if ((sys_log_fd = open(sys_log_fifo, O_RDWR)) == -1)
#endif
      {
         (void)fprintf(stderr, "ERROR   : Could not open fifo %s : %s (%s %d)\n",
                       sys_log_fifo, strerror(errno), __FILE__, __LINE__);
         exit(INCORRECT);
      }
   }

   /* Attach to FSA (output) and FRA (input) so we can */
   /* accumulate the statistics for both.              */
   if (fsa_attach(AFD_STAT) < 0)
   {
      system_log(FATAL_SIGN, __FILE__, __LINE__, "Failed to attach to FSA.");
      exit(INCORRECT);
   }
   if (fra_attach() < 0)
   {
      system_log(FATAL_SIGN, __FILE__, __LINE__, "Failed to attach to FRA.");
      exit(INCORRECT);
   }

   /*
    * Read old AFD statistics database file if it is there. If not creat it!
    */
   read_afd_stat_db(no_of_hosts);
   read_afd_istat_db(no_of_dirs);

   /* Tell user we are starting the AFD_STAT */
   if (other_file == NO)
   {
      system_log(INFO_SIGN, NULL, 0, "Starting %s (%s)",
                 AFD_STAT, PACKAGE_VERSION);
   }

   /* Do some cleanups when we exit */
   if (atexit(stat_exit) != 0)
   {
      system_log(FATAL_SIGN, __FILE__, __LINE__,
                 "Could not register exit handler : %s", strerror(errno));            
      exit(INCORRECT);
   }

   /* Ignore any SIGHUP signal. */
   if ((signal(SIGINT, sig_exit) == SIG_ERR) ||
       (signal(SIGQUIT, sig_exit) == SIG_ERR) ||
       (signal(SIGTERM, sig_exit) == SIG_ERR) ||
       (signal(SIGSEGV, sig_segv) == SIG_ERR) ||
       (signal(SIGBUS, sig_bus) == SIG_ERR) ||
       (signal(SIGHUP, SIG_IGN) == SIG_ERR))
   {
      system_log(DEBUG_SIGN, __FILE__, __LINE__,
                 "signal() error : %s", strerror(errno));
   }

   next_rescan_time = (now / STAT_RESCAN_TIME) *
                      STAT_RESCAN_TIME + STAT_RESCAN_TIME;

   /* Initialize sec_counter, hour_counter and day_counter. */
   test_sec_counter = (((p_ts->tm_min * 60) + p_ts->tm_sec) /
                       STAT_RESCAN_TIME) + 1;
   for (i = 0; i < no_of_hosts; i++)
   {
      stat_db[i].sec_counter = test_sec_counter;
      stat_db[i].hour_counter = hour;
      stat_db[i].day_counter = p_ts->tm_yday;
   }
   for (i = 0; i < no_of_dirs; i++)
   {
      istat_db[i].sec_counter = test_sec_counter;
      istat_db[i].hour_counter = hour;
      istat_db[i].day_counter = p_ts->tm_yday;
   }

   for (;;)
   {
      if ((sleep_time = (next_rescan_time - time(NULL))) < 0)
      {
         sleep_time = 0L;
      }
      timeout.tv_usec = 0;
      timeout.tv_sec = sleep_time;
      status = select(0, NULL, NULL, NULL, &timeout);

      /* Did we get a timeout? */
      if (status == 0)
      {
         now = time(NULL);
         if (now != next_rescan_time)
         {
            now = (now + (STAT_RESCAN_TIME / 2)) / STAT_RESCAN_TIME *
                  STAT_RESCAN_TIME;
         }
         next_rescan_time = (now / STAT_RESCAN_TIME) *
                            STAT_RESCAN_TIME + STAT_RESCAN_TIME;
         p_ts = gmtime(&now);
         test_sec_counter = ((p_ts->tm_min * 60) + p_ts->tm_sec) /
                            STAT_RESCAN_TIME;
         test_hour_counter = p_ts->tm_hour;
         if (test_sec_counter != stat_db[0].sec_counter)
         {
            if ((((stat_db[0].sec_counter - test_sec_counter) == 1) &&
                 (test_hour_counter == stat_db[0].hour_counter)) ||
                 ((stat_db[0].sec_counter == 0) && (test_sec_counter == 719)))
            {
               (void)sleep(STAT_RESCAN_TIME);
            }
            else
            {
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmmm..., second counter wrong [%d -> %d]. Correcting.",
                          stat_db[0].sec_counter, test_sec_counter);
               for (i = 0; i < no_of_hosts; i++)
               {
                  stat_db[i].sec_counter = test_sec_counter;
               }
               for (i = 0; i < no_of_dirs; i++)
               {
                  istat_db[i].sec_counter = test_sec_counter;
               }
            }
         }
         if (test_hour_counter != stat_db[0].hour_counter)
         {
            if ((((test_hour_counter + 1) == stat_db[0].hour_counter) ||
                 ((stat_db[0].hour_counter == 0) && (test_hour_counter == 23))) &&
                (p_ts->tm_min == 59) && (p_ts->tm_sec > 54))
            {
               /* Sometimes it happens that current time is just one  */
               /* second behind and when this is just before the hour */
               /* value changes we think we are an hour behind.       */;
            }
            else
            {
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmmm..., hour counter wrong [%d -> %d]. Correcting.",
                          stat_db[0].hour_counter, test_hour_counter);
               for (i = 0; i < no_of_hosts; i++)
               {
                  stat_db[i].hour_counter = test_hour_counter;
                  stat_db[i].day[stat_db[i].hour_counter].nfs = 0;
                  stat_db[i].day[stat_db[i].hour_counter].nbs = 0.0;
                  stat_db[i].day[stat_db[i].hour_counter].ne  = 0;
                  stat_db[i].day[stat_db[i].hour_counter].nc  = 0;
               }
               for (i = 0; i < no_of_dirs; i++)
               {
                  istat_db[i].hour_counter = test_hour_counter;
                  istat_db[i].day[istat_db[i].hour_counter].nfr = 0;
                  istat_db[i].day[istat_db[i].hour_counter].nbr = 0.0;
               }
            }
         }

         /*
          * If the FSA or FRA canges we have to reread everything. This
          * is easier then trying to find out where the change took
          * place and change only that part. This is not very effective.
          * But since changes in the FSA or FRA are very seldom and the
          * size of the status is relative small, it seems to be
          * the best solution at this point.
          */
         if (check_fsa(NO, AFD_STAT) == YES)
         {
            read_afd_stat_db(no_of_hosts);
         }
         if (check_fra(NO) == YES)
         {
            read_afd_istat_db(no_of_dirs);
         }

         /*
          * Now lets update the statistics. There are two methods that
          * can be used to update the data. The first one is to have
          * a pointer telling which is the newest data. In the second
          * method we always move everything in the array one position
          * backwards. The advantage of the first method is that we
          * don't have to move around any data. However it is more
          * difficult to evaluate the data when we want to display
          * the information graphicaly. This can be done better with the
          * second method.
          * Lets try the first method first and see how it works.
          */
         for (i = 0; i < no_of_hosts; i++)
         {
            /***********************************/
            /* Handle structure entry for day. */
            /***********************************/

            /* Store number of files send. */
            ui_value = fsa[i].file_counter_done;
            if (ui_value >= stat_db[i].prev_nfs)
            {
               stat_db[i].hour[stat_db[i].sec_counter].nfs = ui_value - stat_db[i].prev_nfs;
            }
            else
            {
               /* Check if an overflow has occured */
               if ((UINT_MAX - stat_db[i].prev_nfs) <= MAX_FILES_PER_SCAN)
               {
                  stat_db[i].hour[stat_db[i].sec_counter].nfs = ui_value + UINT_MAX - stat_db[i].prev_nfs;
               }
               else /* To large. Lets assume it was a reset of the AFD. */
               {
                  stat_db[i].hour[stat_db[i].sec_counter].nfs = ui_value;
               }
            }
            stat_db[i].day[stat_db[i].hour_counter].nfs += stat_db[i].hour[stat_db[i].sec_counter].nfs;
            stat_db[i].prev_nfs = ui_value;

            /* Store number of bytes send. */
            stat_db[i].hour[stat_db[i].sec_counter].nbs = 0.0;
            for (j = 0; j < MAX_NO_PARALLEL_JOBS; j++)
            {
               d_value[j] = (double)fsa[i].job_status[j].bytes_send;
               if (d_value[j] >= stat_db[i].prev_nbs[j])
               {
                  stat_db[i].hour[stat_db[i].sec_counter].nbs += d_value[j] - stat_db[i].prev_nbs[j];
               }
               else
               {
                  stat_db[i].hour[stat_db[i].sec_counter].nbs += d_value[j];
               }
               stat_db[i].prev_nbs[j] = d_value[j];
            }
            if (stat_db[i].hour[stat_db[i].sec_counter].nbs < 0.0)
            {
               stat_db[i].hour[stat_db[i].sec_counter].nbs = 0.0;
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmm.... Byte counter less then zero?!? [%d]", i);
            }
            stat_db[i].day[stat_db[i].hour_counter].nbs += stat_db[i].hour[stat_db[i].sec_counter].nbs;

            /* Store number of errors. */
            ui_value = fsa[i].total_errors;
            if (ui_value >= stat_db[i].prev_ne)
            {
               stat_db[i].hour[stat_db[i].sec_counter].ne = ui_value - stat_db[i].prev_ne;
            }
            else
            {
               stat_db[i].hour[stat_db[i].sec_counter].ne = ui_value;
            }
            stat_db[i].day[stat_db[i].hour_counter].ne += stat_db[i].hour[stat_db[i].sec_counter].ne;
            stat_db[i].prev_ne = ui_value;

            /* Store number of connections. */
            ui_value = fsa[i].connections;
            if (ui_value >= stat_db[i].prev_nc)
            {
               stat_db[i].hour[stat_db[i].sec_counter].nc = ui_value - stat_db[i].prev_nc;
            }
            else
            {
               stat_db[i].hour[stat_db[i].sec_counter].nc = ui_value;
            }
            stat_db[i].day[stat_db[i].hour_counter].nc += stat_db[i].hour[stat_db[i].sec_counter].nc;
            stat_db[i].prev_nc = ui_value;
            stat_db[i].sec_counter++;
         } /* for (i = 0; i < no_of_hosts; i++) */

         /* Now do the same thing for the input. */
         for (i = 0; i < no_of_dirs; i++)
         {
            /***********************************/
            /* Handle structure entry for day. */
            /***********************************/

            /* Store number of files received. */
            ui_value = fra[i].files_received;
            if (ui_value >= istat_db[i].prev_nfr)
            {
               istat_db[i].hour[istat_db[i].sec_counter].nfr = ui_value - istat_db[i].prev_nfr;
            }
            else
            {
               /* Check if an overflow has occured */
               if ((UINT_MAX - istat_db[i].prev_nfr) <= MAX_FILES_PER_SCAN)
               {
                  istat_db[i].hour[istat_db[i].sec_counter].nfr = ui_value + UINT_MAX - istat_db[i].prev_nfr;
               }
               else /* To large. Lets assume it was a reset of the AFD. */
               {
                  istat_db[i].hour[istat_db[i].sec_counter].nfr = ui_value;
               }
            }
            istat_db[i].day[istat_db[i].hour_counter].nfr += istat_db[i].hour[istat_db[i].sec_counter].nfr;
            istat_db[i].prev_nfr = ui_value;

            /* Store number of bytes received. */
            d_value[0] = (double)fra[i].bytes_received;
            if (d_value[0] >= istat_db[i].prev_nbr)
            {
               istat_db[i].hour[istat_db[i].sec_counter].nbr = d_value[0] - istat_db[i].prev_nbr;
            }
            else
            {
               istat_db[i].hour[istat_db[i].sec_counter].nbr = d_value[0];
            }
            if (istat_db[i].hour[istat_db[i].sec_counter].nbr < 0.0)
            {
               istat_db[i].hour[istat_db[i].sec_counter].nbr = 0.0;
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmm.... Byte counter less then zero?!? [%d: %f %f]",
                          i, d_value[0], istat_db[i].prev_nbr);
            }
            istat_db[i].day[istat_db[i].hour_counter].nbr += istat_db[i].hour[istat_db[i].sec_counter].nbr;
            istat_db[i].prev_nbr = d_value[0];
            istat_db[i].sec_counter++;
         } /* for (i = 0; i < no_of_dirs; i++) */

         /* Did we reach another hour? */
         if (stat_db[0].sec_counter >= SECS_PER_HOUR)
         {
            for (i = 0; i < no_of_hosts; i++)
            {
               /* Reset the counter for the day structure */
               stat_db[i].sec_counter = 0;
               stat_db[i].hour_counter++;

               if (stat_db[i].hour_counter >= HOURS_PER_DAY)
               {
                  stat_db[i].hour_counter = 0;
                  stat_db[i].year[stat_db[i].day_counter].nfs = 0;
                  stat_db[i].year[stat_db[i].day_counter].nbs = 0.0;
                  stat_db[i].year[stat_db[i].day_counter].ne  = 0;
                  stat_db[i].year[stat_db[i].day_counter].nc  = 0;
                  for (j = 0; j < HOURS_PER_DAY; j++)
                  {
                     stat_db[i].year[stat_db[i].day_counter].nfs += stat_db[i].day[j].nfs;
                     stat_db[i].year[stat_db[i].day_counter].nbs += stat_db[i].day[j].nbs;
                     stat_db[i].year[stat_db[i].day_counter].ne  += stat_db[i].day[j].ne;
                     stat_db[i].year[stat_db[i].day_counter].nc  += stat_db[i].day[j].nc;
                  }
                  stat_db[i].day_counter++;
               }
               stat_db[i].day[stat_db[i].hour_counter].nfs = 0;
               stat_db[i].day[stat_db[i].hour_counter].nbs = 0.0;
               stat_db[i].day[stat_db[i].hour_counter].ne  = 0;
               stat_db[i].day[stat_db[i].hour_counter].nc  = 0;
            }
            for (i = 0; i < no_of_dirs; i++)
            {
               /* Reset the counter for the day structure */
               istat_db[i].sec_counter = 0;
               istat_db[i].hour_counter++;

               if (istat_db[i].hour_counter >= HOURS_PER_DAY)
               {
                  istat_db[i].hour_counter = 0;
                  istat_db[i].year[istat_db[i].day_counter].nfr = 0;
                  istat_db[i].year[istat_db[i].day_counter].nbr = 0.0;
                  for (j = 0; j < HOURS_PER_DAY; j++)
                  {
                     istat_db[i].year[istat_db[i].day_counter].nfr += istat_db[i].day[j].nfr;
                     istat_db[i].year[istat_db[i].day_counter].nbr += istat_db[i].day[j].nbr;
                  }
                  istat_db[i].day_counter++;
               }
               istat_db[i].day[istat_db[i].hour_counter].nfr = 0;
               istat_db[i].day[istat_db[i].hour_counter].nbr = 0.0;
            }
         } /* if (stat_db[i].sec_counter >= SECS_PER_HOUR) */

         /* Did we reach another year? */
         new_year = p_ts->tm_year + 1900;
         if (current_year != new_year)
         {
            if (other_file == NO)
            {
               save_old_input_year(new_year);
               save_old_output_year(new_year);
            }
            current_year = new_year;

            /*
             * Reset all values in current memory mapped file. Watch out
             * for leap seconds and NTP!
             */
            if ((test_hour_counter == 23) && (p_ts->tm_min == 59) &&
                (p_ts->tm_yday >= 363))
            {
               test_sec_counter = 0;
               test_hour_counter = 0;
               j = 0;
            }
            else
            {
               test_sec_counter = ((p_ts->tm_min * 60) + p_ts->tm_sec) /
                                  STAT_RESCAN_TIME;
               j = p_ts->tm_yday;
            }
            for (i = 0; i < no_of_hosts; i++)
            {
               stat_db[i].sec_counter = test_sec_counter;
               stat_db[i].hour_counter = test_hour_counter;
               stat_db[i].day_counter = j;
               (void)memset(&stat_db[i].year, 0, (DAYS_PER_YEAR * sizeof(struct statistics)));
               (void)memset(&stat_db[i].day, 0, (HOURS_PER_DAY * sizeof(struct statistics)));
               (void)memset(&stat_db[i].hour, 0, (SECS_PER_HOUR * sizeof(struct statistics)));
            }
            for (i = 0; i < no_of_dirs; i++)
            {
               istat_db[i].sec_counter = test_sec_counter;
               istat_db[i].hour_counter = test_hour_counter;
               istat_db[i].day_counter = j;
               (void)memset(&istat_db[i].year, 0, (DAYS_PER_YEAR * sizeof(struct istatistics)));
               (void)memset(&istat_db[i].day, 0, (HOURS_PER_DAY * sizeof(struct istatistics)));
               (void)memset(&istat_db[i].hour, 0, (SECS_PER_HOUR * sizeof(struct istatistics)));
            }
         }

         if (stat_db[0].day_counter >= DAYS_PER_YEAR)
         {
            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                       "Hmmm..., day counter wrong [%d -> 0]. Correcting.",
                       stat_db[0].day_counter);
            for (i = 0; i < no_of_hosts; i++)
            {
               stat_db[i].day_counter = p_ts->tm_yday;
            }
            for (i = 0; i < no_of_dirs; i++)
            {
               istat_db[i].day_counter = p_ts->tm_yday;
            }
         }
      }
           /* An error has occured */
      else if (status < 0)
           {
              system_log(FATAL_SIGN, __FILE__, __LINE__,
                         "select() error : %s", strerror(errno));
              exit(INCORRECT);
           }
           else
           {
              system_log(FATAL_SIGN, __FILE__, __LINE__, "Unknown condition.");
              exit(INCORRECT);
           }
   } /* for (;;) */

   exit(SUCCESS);
}
예제 #7
0
파일: afd_load.c 프로젝트: hfs/afd
/*+++++++++++++++++++++++++++ init_afd_load() +++++++++++++++++++++++++++*/
static void
init_afd_load(int  *argc,
              char *argv[],
              char *font_name,
              char *window_title)
{
   register int i;
   char         fake_user[MAX_FULL_USER_ID_LENGTH],
                *perm_buffer,
                hostname[MAX_AFD_NAME_LENGTH];

   if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) ||
       (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) ||
       (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS))
   {
      usage(argv[0]);
      exit(SUCCESS);
   }
   if (get_afd_path(argc, argv, p_work_dir) < 0)
   {
      (void)fprintf(stderr,
                    "Failed to get working directory of AFD. (%s %d)\n",
                    __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Now lets see if user may use this program. */
   check_fake_user(argc, argv, AFD_CONFIG_FILE, fake_user);
   switch (get_permissions(&perm_buffer, fake_user))
   {
      case NO_ACCESS : /* Cannot access afd.users file. */
         {
            char afd_user_file[MAX_PATH_LENGTH];

            (void)strcpy(afd_user_file, p_work_dir);
            (void)strcat(afd_user_file, ETC_DIR);
            (void)strcat(afd_user_file, AFD_USER_FILE);

            (void)fprintf(stderr,
                          "Failed to access `%s', unable to determine users permissions.\n",
                          afd_user_file);
         }
         exit(INCORRECT);

      case NONE :
         (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR);
         exit(INCORRECT);

      case SUCCESS : /* The user may use this program. */
         free(perm_buffer);
         break;

      case INCORRECT : /* Hmm. Something did go wrong. Since we want to */
                       /* be able to disable permission checking let    */
                       /* the user have all permissions.                */
         break;

      default :
         (void)fprintf(stderr, "Impossible!! Remove the programmer!\n");
         exit(INCORRECT);
   }

   /* Attach to FSA to get values for chart. */
   if ((i = fsa_attach_passive(NO, AFD_LOAD)) < 0)
   {
      if (i == INCORRECT_VERSION)
      {
         (void)fprintf(stderr, "This program is not able to attach to the FSA due to incorrect version.\n");
      }
      else
      {
         (void)fprintf(stderr, "Failed to attach to FSA.\n");
      }
      exit(INCORRECT);
   }

   if (get_arg(argc, argv, SHOW_FILE_LOAD, NULL, 0) == SUCCESS)
   {
      chart_type = FILE_CHART;
      for (i = 0; i < no_of_hosts; i++)
      {
         prev_value += (double)fsa[i].file_counter_done;
      }
   }
   else if (get_arg(argc, argv, SHOW_KBYTE_LOAD, NULL, 0) == SUCCESS)
        {
           chart_type = KBYTE_CHART;
           for (i = 0; i < no_of_hosts; i++)
           {
              prev_value += (double)fsa[i].bytes_send;
           }
           prev_value /= 1024;
        }
   else if (get_arg(argc, argv, SHOW_CONNECTION_LOAD, NULL, 0) == SUCCESS)
        {
           chart_type = CONNECTION_CHART;
           for (i = 0; i < no_of_hosts; i++)
           {
              prev_value += (double)fsa[i].connections;
           }
        }
   else if (get_arg(argc, argv, SHOW_TRANSFER_LOAD, NULL, 0) == SUCCESS)
        {
           /* Attach to the AFD Status Area. */
           if (attach_afd_status(NULL, WAIT_AFD_STATUS_ATTACH) < 0)
           {
              (void)fprintf(stderr,
                            "Failed to map to AFD status area. (%s %d)\n",
                            __FILE__, __LINE__);
              exit(INCORRECT);
           }
           chart_type = TRANSFER_CHART;
           prev_value = p_afd_status->no_of_transfers;
        }
        else
        {
           (void)fsa_detach(NO);
           usage(argv[0]);
           exit(INCORRECT);
        }

   if (get_arg(argc, argv, "-f", font_name, 256) == INCORRECT)
   {
      (void)strcpy(font_name, "fixed");
   }

   /* Prepare title of this window. */
   (void)strcpy(window_title, "AFD Load ");
   if (get_afd_name(hostname) == INCORRECT)
   {
      if (gethostname(hostname, MAX_AFD_NAME_LENGTH) == 0)
      {
         hostname[0] = toupper((int)hostname[0]);
         (void)strcat(window_title, hostname);
      }
   }
   else
   {
      (void)strcat(window_title, hostname);
   }

   return;
}
예제 #8
0
파일: view_dc.c 프로젝트: hfs/afd
/*++++++++++++++++++++++++++++ init_view_dc() +++++++++++++++++++++++++++*/
static void
init_view_dc(int *argc, char *argv[])
{
    int  empty_lines,
         length,
         line_length;
    char cmd[MAX_PATH_LENGTH],
         *data_buffer,
         fake_user[MAX_FULL_USER_ID_LENGTH],
         *perm_buffer,
         *p_retr_send_sep;

    if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) ||
            (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) ||
            (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS))
    {
        usage(argv[0]);
        exit(SUCCESS);
    }
    if (get_afd_path(argc, argv, p_work_dir) < 0)
    {
        (void)fprintf(stderr,
                      "Failed to get working directory of AFD. (%s %d)\n",
                      __FILE__, __LINE__);
        exit(INCORRECT);
    }
    if (get_arg(argc, argv, "-f", font_name, 40) == INCORRECT)
    {
        (void)strcpy(font_name, "fixed");
    }
    if (get_arg(argc, argv, "-h", host_alias, MAX_HOSTNAME_LENGTH + 1) == INCORRECT)
    {
        if (get_arg(argc, argv, "-d", dir_alias, MAX_DIR_ALIAS_LENGTH + 1) == INCORRECT)
        {
            usage(argv[0]);
            exit(INCORRECT);
        }
        host_alias[0] = '\0';
    }
    else
    {
        dir_alias[0] = '\0';
    }

    /* Now lets see if user may use this program. */
    check_fake_user(argc, argv, AFD_CONFIG_FILE, fake_user);
    switch (get_permissions(&perm_buffer, fake_user))
    {
    case NO_ACCESS : /* Cannot access afd.users file. */
    {
        char afd_user_file[MAX_PATH_LENGTH];

        (void)strcpy(afd_user_file, p_work_dir);
        (void)strcat(afd_user_file, ETC_DIR);
        (void)strcat(afd_user_file, AFD_USER_FILE);

        (void)fprintf(stderr,
                      "Failed to access `%s', unable to determine users permissions.\n",
                      afd_user_file);
    }
    exit(INCORRECT);

    case NONE :
        (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR);
        exit(INCORRECT);

    case SUCCESS :
        /* Lets evaluate the permissions and see what */
        /* the user may do.                           */
        if ((perm_buffer[0] == 'a') && (perm_buffer[1] == 'l') &&
                (perm_buffer[2] == 'l') &&
                ((perm_buffer[3] == '\0') || (perm_buffer[3] == ' ') ||
                 (perm_buffer[3] == '\t')))
        {
            free(perm_buffer);
            break;
        }
        else if (posi(perm_buffer, VIEW_DIR_CONFIG_PERM) == NULL)
        {
            (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR);
            exit(INCORRECT);
        }
        free(perm_buffer);
        break;

    case INCORRECT:
        /* Hmm. Something did go wrong. Since we want to */
        /* be able to disable permission checking let    */
        /* the user have all permissions.                */
        break;

    default :
        (void)fprintf(stderr, "Impossible!! Remove the programmer!\n");
        exit(INCORRECT);
    }

    /*
     * Run get_dc_data program to get the data.
     */
    length = sprintf(cmd, "%s %s %s", GET_DC_DATA, WORK_DIR_ID, p_work_dir);
    if (fake_user[0] != '\0')
    {
        length += sprintf(&cmd[length], " -u %s", fake_user);
    }
    if (host_alias[0] != '\0')
    {
        length += sprintf(&cmd[length], " -h \"%s\"", host_alias);
    }
    else if (dir_alias[0] != '\0')
    {
        length += sprintf(&cmd[length], " -d \"%s\"", dir_alias);
    }
    data_buffer = NULL;
    if ((exec_cmd(cmd, &data_buffer, -1, NULL, 0,
#ifdef HAVE_SETPRIORITY
                  NO_PRIORITY,
#endif
                  "", 0L, NO, NO) != 0) ||
            (data_buffer == NULL))
    {
        (void)fprintf(stderr, "Failed to execute command: %s\n", cmd);
        (void)fprintf(stderr, "See SYSTEM_LOG for more information.\n");
        exit(INCORRECT);
    }

    length = 0;
    empty_lines = 0;
    max_x = 0;
    max_y = 0;
    while (data_buffer[length] != '\0')
    {
        line_length = 0;
        while ((data_buffer[length] != '\n') && (data_buffer[length] != '\0'))
        {
            length++;
            line_length++;
        }
        if (data_buffer[length] == '\n')
        {
            max_y++;
            length++;
            if (line_length > max_x)
            {
                max_x = line_length;
            }
            line_length = 0;
            if (data_buffer[length] == '\n')
            {
                length++;
                empty_lines++;
                max_y++;
            }
        }
    }
    if (length > 0)
    {
        int new_lines_removed = 0;

        while (data_buffer[length - 1] == '\n')
        {
            new_lines_removed++;
            length--;
        }
        empty_lines = empty_lines - (new_lines_removed / 2);
        data_buffer[length] = '\0';
        length++;
    }

    if ((length > 0) && (host_alias[0] != '\0'))
    {
        if (posi(data_buffer, DIR_IDENTIFIER) != NULL)
        {
            if ((p_retr_send_sep = posi(data_buffer,
                                        VIEW_DC_DIR_IDENTIFIER)) == NULL)
            {
                (void)strcpy(dir_alias, host_alias);
                host_alias[0] = '\0';
            }
            else
            {
                p_retr_send_sep -= (VIEW_DC_DIR_IDENTIFIER_LENGTH + 1);
            }
        }
        else
        {
            p_retr_send_sep = NULL;
        }
    }

    /*
     * For host alias, lets insert separator lines for empty
     * lines. This makes it more readable.
     */
    if (host_alias[0] != '\0')
    {
        if (length == 0)
        {
            view_buffer = data_buffer;
            max_x = sprintf(view_buffer,
                            "\n  No data found for host %s!\n\n",
                            host_alias);
            max_y = 3;
        }
        else
        {
            size_t new_size;
            char   *wptr;

            new_size = length + 1 + (empty_lines * (max_x + 1));

            if ((view_buffer = malloc(new_size)) == NULL)
            {
#if SIZEOF_SIZE_T == 4
                (void)fprintf(stderr, "Failed to malloc() %d bytes : %s",
#else
                (void)fprintf(stderr, "Failed to malloc() %lld bytes : %s",
#endif
                              (pri_size_t)new_size, strerror(errno));
                exit(INCORRECT);
            }

            if (p_retr_send_sep == NULL)
            {
                length = 0;
                wptr = view_buffer;
            }
            else
            {
                length = p_retr_send_sep - data_buffer;
                (void)memcpy(view_buffer, data_buffer, length);
                wptr = &view_buffer[length];
                (void)memset(wptr, '=', max_x);
                wptr += max_x;
                *wptr = '\n';
                wptr++;
            }
            while (data_buffer[length] != '\0')
            {
                while ((data_buffer[length] != '\n') && (data_buffer[length] != '\0'))
                {
                    *wptr = data_buffer[length];
                    length++;
                    wptr++;
                }
                if (data_buffer[length] == '\n')
                {
                    *wptr = '\n';
                    length++;
                    wptr++;
                    if (data_buffer[length] == '\n')
                    {
                        (void)memset(wptr, '-', max_x);
                        wptr += max_x;
                        *wptr = '\n';
                        length++;
                        wptr++;
                    }
                }
            }
            *wptr = '\0';
            free(data_buffer);
            max_y--;
        }
        p_title = host_alias;
    }
예제 #9
0
파일: set_counter.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int          counter,
                new_counter,
                fd;
   char         counter_file[MAX_PATH_LENGTH],
                work_dir[MAX_PATH_LENGTH];
   struct flock wlock = {F_WRLCK, SEEK_SET, 0, 1},
                ulock = {F_UNLCK, SEEK_SET, 0, 1};

   CHECK_FOR_VERSION(argc, argv);

   if ((argc < 2) || (strcmp(argv[1], "-w") == 0))
   {
      (void)fprintf(stderr, "%s: <new value> [-w <workdir>]\n", argv[0]);
      exit(INCORRECT);
   }
   new_counter = atoi(argv[1]);
   argc--; argv++;

   /* Open file that holds the counter. */
   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   (void)strcpy(counter_file, work_dir);
   (void)strcat(counter_file, FIFO_DIR);
   (void)strcat(counter_file, COUNTER_FILE);
#ifdef GROUP_CAN_WRITE
   if ((fd = open(counter_file, O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) < 0)
#else
   if ((fd = open(counter_file, O_RDWR, S_IRUSR | S_IWUSR)) < 0)
#endif
   {
      (void)fprintf(stderr, "Could not open %s : %s (%s %d)\n",
                    counter_file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Try to lock file which holds counter. */
   if (fcntl(fd, F_SETLKW, &wlock) < 0)
   {
      (void)fprintf(stderr, "Could not set write lock. (%s %d)\n",
                    __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Read the value of counter. */
   if (read(fd, &counter, sizeof(int)) < 0)
   {
      (void)fprintf(stderr, "Could not read value of counter : %s (%s %d)\n",
                    strerror(errno),  __FILE__, __LINE__);
      exit(INCORRECT);
   }

   (void)fprintf(stdout, "Befor changing AFD counter = %d\n", counter);

   /* Go to beginning in file. */
   if (lseek(fd, 0, SEEK_SET) < 0)
   {
      (void)fprintf(stderr, "Could not seek() : %s (%s %d)\n",
                    strerror(errno), __FILE__, __LINE__);
   }

   /* Write new value into counter file. */
   if (write(fd, &new_counter, sizeof(int)) != sizeof(int))
   {
      (void)fprintf(stderr, "Could not write value to counter file : %s (%s %d)\n",
                    strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   (void)fprintf(stdout, "Changed AFD counter to %d\n", new_counter);

   /* Unlock file which holds counter. */
   if (fcntl(fd, F_SETLKW, &ulock) < 0)
   {
      (void)fprintf(stderr, "Could not unset write lock : %s (%s %d)\n",
                    strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   /* Close the counter file. */
   (void)close(fd);

   exit(SUCCESS);
}
예제 #10
0
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int         fd,
               *no_of_jobs;
   char        file[MAX_PATH_LENGTH],
               *ptr,
               *tmp_ptr,
               work_dir[MAX_PATH_LENGTH];
   struct stat stat_buf;

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }

   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, CURRENT_MSG_LIST_FILE);
   if ((fd = open(file, O_RDONLY)) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to fstat() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ,
                   MAP_SHARED, fd, 0)) == (caddr_t)-1)
   {
      (void)fprintf(stderr,
                    _("Failed to mmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   tmp_ptr = ptr;
   no_of_jobs = (int *)ptr;
   ptr += sizeof(int);

   if (*no_of_jobs > 0)
   {
      int i;

      (void)fprintf(stdout, "No of jobs : %d\n", *no_of_jobs);
      for (i = 0; i < *no_of_jobs; i++)
      {
         (void)fprintf(stdout, "%x ", *(int *)ptr);
          ptr += sizeof(int);
      }
      (void)fprintf(stdout, "\n");
   }
   else
   {
      (void)fprintf(stdout, _("No messages cached.\n"));
   }

   if (munmap(tmp_ptr, stat_buf.st_size) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to munmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   (void)close(fd);

   exit(INCORRECT);
}
예제 #11
0
파일: del_cache.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int                  fd,
                        *no_msg_cached;
   char                 file[MAX_PATH_LENGTH],
                        *ptr,
                        work_dir[MAX_PATH_LENGTH];
   struct stat          stat_buf;
   struct msg_cache_buf *mb;

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }

   if (argc != 2)
   {
      (void)fprintf(stderr,
                    _("Usage: %s [-w <AFD work dir>] [--version] <cache pos>\n"),
                    argv[0]);
      exit(INCORRECT);
   }

   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, MSG_CACHE_FILE);
   if ((fd = open(file, O_RDWR)) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to open() `%s# : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to fstat() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if ((ptr = mmap(0, stat_buf.st_size, (PROT_READ | PROT_WRITE),
                   MAP_SHARED, fd, 0)) == (caddr_t)-1)
   {
      (void)fprintf(stderr,
                    _("Failed to mmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   no_msg_cached = (int *)ptr;
   ptr += AFD_WORD_OFFSET;
   mb = (struct msg_cache_buf *)ptr;

   if (*no_msg_cached > 0)
   {
      int del_pos = atoi(argv[1]);

      if (del_pos < *no_msg_cached)
      {
         size_t move_size = (*no_msg_cached - 1 - del_pos) *
                            sizeof(struct msg_cache_buf);

         (void)memmove(&mb[del_pos], &mb[del_pos + 1], move_size);
         (*no_msg_cached)--;
      }
      else
      {
         (void)fprintf(stderr,
                       _("Delete position (%d) to high, there are only %d elements.\n"),
                       del_pos, *no_msg_cached);
      }
   }
   else
   {
      (void)fprintf(stdout, _("No messages cached.\n"));
   }

   ptr -= AFD_WORD_OFFSET;
   if (munmap(ptr, stat_buf.st_size) == -1)
   {
      (void)fprintf(stderr,
                    _("Failed to munmap() %s : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   (void)close(fd);

   exit(SUCCESS);
}
예제 #12
0
파일: show_cmd.c 프로젝트: hfs/afd
/*+++++++++++++++++++++++++++++ init_cmd() ++++++++++++++++++++++++++++++*/
static void
init_cmd(int *argc, char *argv[], char *title_cmd)
{
   int  length = 0;
   char *ptr;

   if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) ||
       (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) ||
       (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS))
   {
      usage(argv[0]);
      exit(SUCCESS);
   }

   /* Get working directory for the AFD. */
   if (get_afd_path(argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   if (get_arg(argc, argv, "-f", font_name, 40) == INCORRECT)
   {
      (void)strcpy(font_name, "fixed");
   }
   if (get_arg(argc, argv, "-b", NULL, 0) == SUCCESS)
   {
      go_to_beginning = YES;
   }
   if (*argc < 2)
   {
      usage(argv[0]);
      exit(INCORRECT);
   }
   if (argv[1][0] == '"')
   {
      (void)my_strncpy(cmd, &argv[1][1], MAX_PATH_LENGTH);
      length = strlen(cmd);
      if (cmd[length - 1] == '"')
      {
         cmd[length - 1] = '\0';
      }
   }
   else
   {
      (void)my_strncpy(cmd, argv[1], MAX_PATH_LENGTH);
   }
   if (*argc > 2)
   {
      register int j;

      for (j = 1; j < *argc; j++)
      {
         argv[j] = argv[j + 1];
      }
      argv[j] = NULL;
   }
   else
   {
      argv[1] = NULL;
   }
   (*argc)--;

   /* Cut out command for title of window. */
   ptr = cmd;
   if ((cmd[0] == '/') || (cmd[0] == '.') || (cmd[0] == '~'))
   {
      char *p_end;

      while ((*ptr != ' ') && (*ptr != '\0'))
      {
         ptr++;
      }
      p_end = ptr;
      while ((*ptr != '/') && (*ptr != '.') && (*ptr != '~'))
      {
         ptr--;
      }
      ptr++;
      length = p_end - ptr;
      if (length > MAX_TITLE_CMD_LENGTH)
      {
         length = MAX_TITLE_CMD_LENGTH;
      }
      (void)my_strncpy(title_cmd, ptr, length + 1);
   }
   else
   {
      length = 0;
      while ((*ptr != ' ') && (*ptr != '\0') &&
             (length < MAX_TITLE_CMD_LENGTH))
      {
         title_cmd[length] = *ptr;
         ptr++; length++;
      }
   }
   title_cmd[length] = ' ';
   title_cmd[length + 1] = '\0';

   /* Cut out target hostname. */
   while (*ptr != '\0')
   {
      ptr++;
   }
   while ((*ptr != ' ') && (ptr != cmd))
   {
      ptr--;
   }
   if (*ptr == ' ')
   {
      *ptr = '\0';
      ptr++;
   }
   (void)strncat(title_cmd, ptr, 25);

   return;
}
예제 #13
0
파일: dc_proc_spy.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int                 fd,
                       *no_of_process;
   char                file[MAX_PATH_LENGTH],
                       *ptr,
                       work_dir[MAX_PATH_LENGTH];
   struct stat         stat_buf;
   struct dc_proc_list *dcpl;

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }

   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, DCPL_FILE_NAME);
   if ((fd = open(file, O_RDWR)) == -1)
   {
      (void)fprintf(stderr, _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr, _("Failed to fstat() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

#ifdef HAVE_MMAP
   if ((ptr = mmap(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE),
                   MAP_SHARED, fd, 0)) == (caddr_t)-1)
#else
   if ((ptr = mmap_emu(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE),
                       MAP_SHARED, file, 0)) == (caddr_t)-1)
#endif
   {
      (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   if (close(fd) == -1)
   {
      (void)fprintf(stderr, _("Failed to close() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   no_of_process = (int *)ptr;
   ptr += AFD_WORD_OFFSET;
   dcpl = (struct dc_proc_list *)ptr;

   if (*no_of_process > 0)
   {
      int i;

      (void)fprintf(stdout, _("No of dir_config process : %d\n"), *no_of_process);
      (void)fprintf(stdout, "Pid        fra_pos    Job ID\n");
      for (i = 0; i < *no_of_process; i++)
      {
         (void)fprintf(stdout, "%-10x %-10d %-10x\n",
                       dcpl[i].pid, dcpl[i].fra_pos, dcpl[i].job_id);
      }
   }
   else
   {
      (void)fprintf(stdout, _("No proccess currently active by dir_check.\n"));
   }

   ptr -= AFD_WORD_OFFSET;
#ifdef HAVE_MMAP
   if (munmap(ptr, stat_buf.st_size) == -1)
#else
   if (munmap(ptr) == -1)
#endif
   {
      (void)fprintf(stderr, _("Failed to munmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }

   exit(INCORRECT);
}
예제 #14
0
파일: dir_spy.c 프로젝트: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int                 fd,
                       *no_of_dir_names,
                       ret;
   unsigned int        search_dir_id;
   char                file[MAX_PATH_LENGTH + FIFO_DIR_LENGTH + DIR_NAME_FILE_LENGTH],
                       *ptr,
                       str_dir_id[MAX_INT_LENGTH + 1],
                       work_dir[MAX_PATH_LENGTH];
   struct stat         stat_buf;
   struct dir_name_buf *dnb;

   if ((get_arg(&argc, argv, "-?", NULL, 0) == SUCCESS) ||
       (get_arg(&argc, argv, "-help", NULL, 0) == SUCCESS) ||
       (get_arg(&argc, argv, "--help", NULL, 0) == SUCCESS))
   {
      usage(argv[0]);
      exit(SUCCESS);
   }

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }

   if (get_arg(&argc, argv, "-d", str_dir_id, MAX_INT_HEX_LENGTH) == INCORRECT)
   {
      search_dir_id = 0;
      str_dir_id[0] = '\0';
   }
   else
   {
      search_dir_id = (unsigned int)strtoul(str_dir_id, NULL, 16);
   }

   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, DIR_NAME_FILE);
   if ((fd = open(file, O_RDONLY)) == -1)
   {
      (void)fprintf(stderr, _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr, _("Failed to fstat() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

#ifdef HAVE_MMAP
   if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ,
                   MAP_SHARED, fd, 0)) == (caddr_t)-1)
#else
   if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ,
                       MAP_SHARED, file, 0)) == (caddr_t)-1)
#endif
   {
      (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   if (close(fd) == -1)
   {
      (void)fprintf(stderr, _("Failed to close() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   no_of_dir_names = (int *)ptr;
   ptr += AFD_WORD_OFFSET;
   dnb = (struct dir_name_buf *)ptr;

   if (*no_of_dir_names > 0)
   {
      int i;

      if (str_dir_id[0] == '\0')
      {
         (void)fprintf(stdout, _("No of directories : %d\n"), *no_of_dir_names);
         (void)fprintf(stdout, "Pos   Dir-ID     Dir-name [| Original name]\n");
         for (i = 0; i < *no_of_dir_names; i++)
         {
            if (CHECK_STRCMP(dnb[i].dir_name, dnb[i].orig_dir_name) == 0)
            {
               (void)fprintf(stdout, "%-5d %-*x %s\n",
                             i, MAX_INT_LENGTH, dnb[i].dir_id, dnb[i].dir_name);
            }
            else
            {
               (void)fprintf(stdout, "%-5d %-*x %s | %s\n",
                             i, MAX_INT_LENGTH, dnb[i].dir_id, dnb[i].dir_name,
                             dnb[i].orig_dir_name);
            }
         }
         ret = SUCCESS;
      }
      else
      {
         for (i = 0; i < *no_of_dir_names; i++)
         {
            if (dnb[i].dir_id == search_dir_id)
            {
               if (CHECK_STRCMP(dnb[i].dir_name, dnb[i].orig_dir_name) == 0)
               {
                  (void)fprintf(stdout, "%-5d %-*x %s\n",
                                i, MAX_INT_LENGTH, dnb[i].dir_id,
                                dnb[i].dir_name);
               }
               else
               {
                  (void)fprintf(stdout, "%-5d %-*x %s | %s\n",
                                i, MAX_INT_LENGTH, dnb[i].dir_id,
                                dnb[i].dir_name, dnb[i].orig_dir_name);
               }
               exit(SUCCESS);
            }
         }
         (void)fprintf(stdout, _("Directory ID %u not found.\n"), search_dir_id);
         ret = INCORRECT;
      }
   }
   else
   {
      (void)fprintf(stdout, _("No directories.\n"));
      ret = INCORRECT;
   }

   ptr -= AFD_WORD_OFFSET;
#ifdef HAVE_MMAP
   if (munmap(ptr, stat_buf.st_size) == -1)
#else
   if (munmap_emu(ptr) == -1)
#endif
   {
      (void)fprintf(stderr, _("Failed to munmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }

   exit(ret);
}
예제 #15
0
파일: fsa_edit.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ fsa_edit() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int          position = -1,
                leave_flag = NO,
                ret;
   unsigned int value;
   char         file_name[MAX_FILENAME_LENGTH + 1],
                hostname[MAX_HOSTNAME_LENGTH + 1],
                work_dir[MAX_PATH_LENGTH];

   CHECK_FOR_VERSION(argc, argv);

   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   p_work_dir = work_dir;

   if (argc == 2)
   {
      if (isdigit((int)(argv[1][0])) != 0)
      {
         position = atoi(argv[1]);
      }
      else
      {
         t_hostname(argv[1], hostname);
      }
   }
   else
   {
      usage(argv[0]);
      exit(INCORRECT);
   }

   if ((ret = fsa_attach("fsa_edit")) < 0)
   {
      if (ret == INCORRECT_VERSION)
      {
         (void)fprintf(stderr,
                       _("ERROR   : This program is not able to attach to the FSA due to incorrect version. (%s %d)\n"),
                       __FILE__, __LINE__);
      }
      else
      {
         (void)fprintf(stderr,
                       _("ERROR   : Failed to attach to FSA. (%s %d)\n"),
                       __FILE__, __LINE__);
      }
      exit(INCORRECT);
   }

   if (tcgetattr(STDIN_FILENO, &buf) < 0)
   {
      (void)fprintf(stderr, _("ERROR   : tcgetattr() error : %s (%s %d)\n"),
                    strerror(errno), __FILE__, __LINE__);
      exit(0);
   }

   if (position < 0)
   {
      if ((position = get_host_position(fsa, hostname, no_of_hosts)) < 0)
      {
         (void)fprintf(stderr,
                       _("ERROR   : Could not find host %s in FSA. (%s %d)\n"),
                       hostname, __FILE__, __LINE__);
         exit(INCORRECT);
      }
   }

   for (;;)
   {
      menu(position);

      switch (get_key())
      {
         case 0   : break;
         case '1' : (void)fprintf(stderr, _("\n\n     Enter value [1] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].total_file_counter = (int)value;
                    break;
         case '2' : (void)fprintf(stderr, _("\n\n     Enter value [2] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].total_file_size = value;
                    break;
         case '3' : (void)fprintf(stderr, _("\n\n     Enter value [3] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].error_counter = value;
                    break;
         case '4' : (void)fprintf(stderr, _("\n\n     Enter value [4] (0 - %d): "),
                                  fsa[position].allowed_transfers);
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    if (value <= fsa[position].allowed_transfers)
                    {
                       fsa[position].connections = value;
                    }
                    else
                    {
                       (void)printf(_("Wrong choice!\n"));
                       break;
                    }
                    break;
         case '5' : (void)fprintf(stdout, "\033[2J\033[3;1H");
                    (void)fprintf(stdout, "\n\n\n");
                    (void)fprintf(stdout, "     Start/Stop queue [%d]..........(1)\n",
                                  (fsa[position].host_status & PAUSE_QUEUE_STAT) ? 1 : 0);
                    (void)fprintf(stdout, "     Start/Stop transfer [%d].......(2)\n",
                                  (fsa[position].host_status & STOP_TRANSFER_STAT) ? 1 : 0);
                    (void)fprintf(stdout, "     Start/Stop auto queue [%d].....(3)\n",
                                  (fsa[position].host_status & AUTO_PAUSE_QUEUE_STAT) ? 1 : 0);
                    (void)fprintf(stdout, "     Start/Stop danger queue [%d]...(4)\n",
                                  (fsa[position].host_status & DANGER_PAUSE_QUEUE_STAT) ? 1 : 0);
#ifdef WITH_ERROR_QUEUE
                    (void)fprintf(stdout, "     Set/Unset error queue flag [%d](5)\n",
                                  (fsa[position].host_status & ERROR_QUEUE_SET) ? 1 : 0);
#endif
                    (void)fprintf(stdout, "     HOST_CONFIG host disabled [%d].(6)\n",
                                  (fsa[position].host_status & HOST_CONFIG_HOST_DISABLED) ? 1 : 0);
                    (void)fprintf(stdout, "     Pending errors [%d]............(7)\n",
                                  (fsa[position].host_status & PENDING_ERRORS) ? 1 : 0);
                    (void)fprintf(stdout, "     Host errors ackn [%d]..........(8)\n",
                                  (fsa[position].host_status & HOST_ERROR_ACKNOWLEDGED) ? 1 : 0);
                    (void)fprintf(stdout, "     Host errors offline [%d].......(9)\n",
                                  (fsa[position].host_status & HOST_ERROR_OFFLINE) ? 1 : 0);
                    (void)fprintf(stdout, "     Host errors ackn time [%d].....(a)\n",
                                  (fsa[position].host_status & HOST_ERROR_ACKNOWLEDGED_T) ? 1 : 0);
                    (void)fprintf(stdout, "     Host errors offline time [%d]..(b)\n",
                                  (fsa[position].host_status & HOST_ERROR_OFFLINE_T) ? 1 : 0);
                    (void)fprintf(stdout, "     Reset integer value to 0 [%d]..(c)\n",
                                  fsa[position].host_status);
                    (void)fprintf(stderr, "     None..........................(d) ");
#ifdef LOCK_DEBUG
                    lock_region_w(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS), __FILE__, __LINE__);
#else
                    lock_region_w(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS));
#endif
                    switch (get_key())
                    {
                       case '1' : fsa[position].host_status ^= PAUSE_QUEUE_STAT;
                                  break;
                       case '2' : fsa[position].host_status ^= STOP_TRANSFER_STAT;
                                  break;
                       case '3' : fsa[position].host_status ^= AUTO_PAUSE_QUEUE_STAT;
                                  break;
                       case '4' : fsa[position].host_status ^= DANGER_PAUSE_QUEUE_STAT;
                                  break;
#ifdef WITH_ERROR_QUEUE
                       case '5' : fsa[position].host_status ^= ERROR_QUEUE_SET;
                                  break;
#endif
                       case '6' : fsa[position].host_status ^= HOST_CONFIG_HOST_DISABLED;
                                  break;
                       case '7' : fsa[position].host_status ^= PENDING_ERRORS;
                                  break;
                       case '8' : fsa[position].host_status ^= HOST_ERROR_ACKNOWLEDGED;
                                  break;
                       case '9' : fsa[position].host_status ^= HOST_ERROR_OFFLINE;
                                  break;
                       case 'a' : fsa[position].host_status ^= HOST_ERROR_ACKNOWLEDGED_T;
                                  break;
                       case 'b' : fsa[position].host_status ^= HOST_ERROR_OFFLINE_T;
                                  break;
                       case 'c' : fsa[position].host_status = 0;
                                  break;
                       case 'd' : break;
                       default  : (void)printf(_("Wrong choice!\n"));
                                  (void)sleep(1);
                                  break;
                    }
#ifdef LOCK_DEBUG
                    unlock_region(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS), __FILE__, __LINE__);
#else
                    unlock_region(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS));
#endif
                    break;
         case '6' : (void)fprintf(stderr, _("\n\n     Enter value [6] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].max_errors = value;
                    break;
         case '7' : (void)fprintf(stderr, _("\n\n     Enter value [7] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].block_size = value;
                    break;
         case '8' : (void)fprintf(stderr, _("\n\n     Enter value [8] (1 - %d): "), MAX_NO_PARALLEL_JOBS);
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    if ((value > 0) && (value <= MAX_NO_PARALLEL_JOBS))
                    {
                       fsa[position].allowed_transfers = value;
                    }
                    else
                    {
                       (void)printf(_("Wrong choice!\n"));
                       (void)sleep(1);
                    }
                    break;
         case '9' : (void)fprintf(stderr, _("\n\n     Enter value [9] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].transfer_timeout = value;
                    break;
         case 'a' : (void)fprintf(stderr, _("\n\n     Enter hostname  : "));
                    if (scanf("%39s", fsa[position].real_hostname[0]) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    break;
         case 'b' : (void)fprintf(stderr, _("\n\nEnter hostdisplayname: "));
                    if (scanf("%7s", fsa[position].host_dsp_name) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    break;
         case 'c' : 
#ifdef LOCK_DEBUG
                    lock_region_w(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS), __FILE__, __LINE__);
#else
                    lock_region_w(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS));
#endif
                    fsa[position].host_status ^= HOST_ERROR_OFFLINE_STATIC;
#ifdef LOCK_DEBUG
                    unlock_region(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS), __FILE__, __LINE__);
#else
                    unlock_region(fsa_fd, (AFD_WORD_OFFSET + (position * sizeof(struct filetransfer_status)) + LOCK_HS));
#endif
                    break;
         case 'd' : (void)fprintf(stderr, _("\n\n     Enter value [d] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    if (value > MAX_NO_PARALLEL_JOBS)
                    {
                       (void)printf(_("The value must be between 0 and %d!\n"), MAX_NO_PARALLEL_JOBS);
                       (void)sleep(1);
                    }
                    else
                    {
                       fsa[position].active_transfers = value;
                    }
                    break;
         case 'e' : (void)fprintf(stderr, _("\n\n     Enter value [e] : "));
                    file_name[0] = '\0';
                    if (scanf("%256s", file_name) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    (void)strcpy(fsa[position].job_status[0].file_name_in_use, file_name);
                    break;
         case 'f' : (void)fprintf(stderr, _("\n\n     Enter value [f] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].jobs_queued = value;
                    break;
         case 'g' : (void)fprintf(stderr, _("\n\n     Enter value [g] : "));
                    if (scanf("%11u", &value) == EOF)
                    {
                       (void)fprintf(stderr,
                                     _("ERROR   : scanf() error, failed to read input : %s (%s %d)\n"),
                                     strerror(errno), __FILE__, __LINE__);
                       exit(INCORRECT);
                    }
                    fsa[position].transfer_rate_limit = value;
                    break;
         case 'h' : if ((fsa[position].auto_toggle == ON) &&
                        (fsa[position].original_toggle_pos != NONE))
                    {
                       if (fsa[position].original_toggle_pos == HOST_ONE)
                       {
                          fsa[position].original_toggle_pos = NONE;
                       }
                       else if (fsa[position].original_toggle_pos == HOST_TWO)
                            {
                               fsa[position].original_toggle_pos = NONE;
                            }
                    }
                    break;
         case 'x' :
         case 'Q' :
         case 'q' : leave_flag = YES;
                    break;
         default  : (void)printf(_("Wrong choice!\n"));
                    (void)sleep(1);
                    break;
      }

      if (leave_flag == YES)
      {
         (void)fprintf(stdout, "\n\n");
         break;
      }
      else
      {
         (void)my_usleep(100000L);
      }
   } /* for (;;) */

   exit(SUCCESS);
}
예제 #16
0
파일: jid_view.c 프로젝트: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int                  fd,
                        fml_offset,
                        i,
                        mask_offset,
                        no_of_dir_names,
                        no_of_file_masks_id,
                        no_of_job_ids,
                        no_of_search_ids;
   unsigned int         *job_id;
   off_t                dnb_size,
                        fmd_size,
                        jid_size;
   char                 file[MAX_PATH_LENGTH],
                        *fmd = NULL,
                        option_buffer[MAX_OPTION_LENGTH],
                        *ptr,
                        work_dir[MAX_PATH_LENGTH];
   struct stat          stat_buf;
   struct job_id_data  *jd;
   struct dir_name_buf *dnb;

   if ((get_arg(&argc, argv, "-?", NULL, 0) == SUCCESS) ||
       (get_arg(&argc, argv, "-help", NULL, 0) == SUCCESS) ||
       (get_arg(&argc, argv, "--help", NULL, 0) == SUCCESS))
   {
      (void)fprintf(stdout,
                    _("Usage: %s [-w <AFD work dir>] [--version] [<job ID> [...<job ID n>]]\n"),
                    argv[0]);
      exit(SUCCESS);
   }

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }
   if (argc > 1)
   {
      no_of_search_ids = argc - 1;
      if ((job_id = malloc(no_of_search_ids * sizeof(unsigned int))) != NULL)
      {
         for (i = 0; i < no_of_search_ids; i++)
         {
            job_id[i] = (unsigned int)strtoul(argv[i + 1], (char **)NULL, 16);
         }
      }
      else
      {
         (void)fprintf(stderr, _("malloc() error : %s (%s %d)\n"),
                       strerror(errno), __FILE__, __LINE__);
      }
   }
   else
   {
      no_of_search_ids = 0;
      job_id = NULL;
   }

   /* Map to JID file. */
   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, JOB_ID_DATA_FILE);
   if ((fd = open(file, O_RDONLY)) == -1)
   {
      (void)fprintf(stderr, _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   if (fstat(fd, &stat_buf) == -1)
   {
      (void)fprintf(stderr, _("Failed to fstat() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

#ifdef HAVE_MMAP
   if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ,
                   MAP_SHARED, fd, 0)) == (caddr_t)-1)
#else
   if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ,
                       MAP_SHARED, file, 0)) == (caddr_t)-1)
#endif
   {
      (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   if (close(fd) == -1)
   {
      (void)fprintf(stderr, _("Failed to close() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   if (*(ptr + SIZEOF_INT + 1 + 1 + 1) != CURRENT_JID_VERSION)
   {
      (void)fprintf(stderr, _("Incorrect JID version (data=%d current=%d)!\n"),
                    *(ptr + SIZEOF_INT + 1 + 1 + 1), CURRENT_JID_VERSION);
      exit(INCORRECT);
   }
   no_of_job_ids = *(int *)ptr;
   ptr += AFD_WORD_OFFSET;
   jd = (struct job_id_data *)ptr;
   jid_size = stat_buf.st_size;

   /* Map to file mask file. */
   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, FILE_MASK_FILE);
   if ((fd = open(file, O_RDONLY)) == -1)
   {
      (void)fprintf(stderr, _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   else
   {
      if (fstat(fd, &stat_buf) == -1)
      {
         (void)fprintf(stderr, _("Failed to fstat() `%s' : %s (%s %d)\n"),
                       file, strerror(errno), __FILE__, __LINE__);
      }
      else
      {
#ifdef HAVE_MMAP
         if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ,
                         MAP_SHARED, fd, 0)) == (caddr_t)-1)
#else
         if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ,
                             MAP_SHARED, file, 0)) == (caddr_t)-1)
#endif
         {
            (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                          file, strerror(errno), __FILE__, __LINE__);
            fmd = NULL;
         }
         else
         {
            no_of_file_masks_id = *(int *)ptr;
            ptr += AFD_WORD_OFFSET;
            fmd = ptr;
            fmd_size = stat_buf.st_size;
            fml_offset = sizeof(int) + sizeof(int);
            mask_offset = fml_offset + sizeof(int) + sizeof(unsigned int) +
                          sizeof(unsigned char);
         }
      }

      if (close(fd) == -1)
      {
         (void)fprintf(stderr, _("Failed to close() `%s' : %s (%s %d)\n"),
                       file, strerror(errno), __FILE__, __LINE__);
      }
   }

   /* Map to directory_names file. */
   (void)sprintf(file, "%s%s%s", work_dir, FIFO_DIR, DIR_NAME_FILE);
   if ((fd = open(file, O_RDONLY)) == -1)
   {
      (void)fprintf(stderr, _("Failed to open() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   else
   {
      if (fstat(fd, &stat_buf) == -1)
      {
         (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                       file, strerror(errno), __FILE__, __LINE__);
      }
      else
      {
#ifdef HAVE_MMAP
         if ((ptr = mmap(NULL, stat_buf.st_size, PROT_READ,
                         MAP_SHARED, fd, 0)) == (caddr_t)-1)
#else
         if ((ptr = mmap_emu(NULL, stat_buf.st_size, PROT_READ,
                             MAP_SHARED, file, 0)) == (caddr_t)-1)
#endif
         {
            (void)fprintf(stderr, _("Failed to mmap() `%s' : %s (%s %d)\n"),
                          file, strerror(errno), __FILE__, __LINE__);
            dnb = NULL;
         }
         else
         {
            no_of_dir_names = *(int *)ptr;
            ptr += AFD_WORD_OFFSET;
            dnb = (struct dir_name_buf *)ptr;
            dnb_size = stat_buf.st_size;
         }
      }

      if (close(fd) == -1)
      {
         (void)fprintf(stderr, _("Failed to close() `%s' : %s (%s %d)\n"),
                       file, strerror(errno), __FILE__, __LINE__);
      }
   }


   if (no_of_job_ids > 0)
   {
      int j;

      for (i = 0; i < no_of_job_ids; i++)
      {
         for (j = 0; j < no_of_search_ids; j++)
         {
            if (job_id[j] == jd[i].job_id)
            {
               break;
            }
         }
         if ((job_id == NULL) || (job_id[j] == jd[i].job_id))
         {
            (void)fprintf(stdout, "Job-ID       : %x\n", jd[i].job_id);
            (void)fprintf(stdout, "Dir-ID       : %x\n", jd[i].dir_id);
            (void)fprintf(stdout, "DIR_CONFIG ID: %x\n", jd[i].dir_config_id);
            (void)fprintf(stdout, "File-Mask-ID : %x\n", jd[i].file_mask_id);
            (void)fprintf(stdout, "Recipient-ID : %x\n", jd[i].recipient_id);
            (void)fprintf(stdout, "Host-Alias-ID: %x\n", jd[i].host_id);
            (void)fprintf(stdout, "Dir position : %d\n", jd[i].dir_id_pos);
            (void)fprintf(stdout, "Priority     : %c\n", jd[i].priority);
            if (dnb != NULL)
            {
               for (j = 0; j < no_of_dir_names; j++)
               {
                  if (dnb[j].dir_id == jd[i].dir_id)
                  {
                     (void)fprintf(stdout, "Directory    : %s\n",
                                   dnb[j].orig_dir_name);
                     break;
                  }
               }
            }
            if (fmd != NULL)
            {
               int j;

               ptr = fmd;

               for (j = 0; j < no_of_file_masks_id; j++)
               {
                  if (*(unsigned int *)(ptr + fml_offset + sizeof(int)) == jd[i].file_mask_id)
                  {
                     if (*(int *)ptr == 1)
                     {
                        (void)fprintf(stdout, "File filters : %s\n",
                                      (ptr + mask_offset));
                     }
                     else
                     {
                        char *p_file = ptr + mask_offset;

                        (void)fprintf(stdout, "File filters : %s\n", p_file);
                        NEXT(p_file);
                        for (j = 1; j < *(int *)ptr; j++)
                        {
                           (void)fprintf(stdout, "             : %s\n", p_file);
                           NEXT(p_file);
                        }
                     }
                     break;
                  }
                  ptr += (mask_offset + *(int *)(ptr + fml_offset) +
                          sizeof(char) + *(ptr + mask_offset - 1));
               }
            }
            if (jd[i].no_of_loptions > 0)
            {
               if (jd[i].no_of_loptions == 1)
               {
                  (void)fprintf(stdout, "AMG options  : %s\n", jd[i].loptions);
               }
               else
               {
                  char *ptr = jd[i].loptions;

                  (void)fprintf(stdout, "AMG options  : %s\n", ptr);
                  NEXT(ptr);
                  for (j = 1; j < jd[i].no_of_loptions; j++)
                  {
                     (void)fprintf(stdout, "             : %s\n", ptr);
                     NEXT(ptr);
                  }
               }
            }
            if (jd[i].no_of_soptions > 0)
            {
               if (jd[i].no_of_soptions == 1)
               {
                  (void)fprintf(stdout, "FD options   : %s\n", jd[i].soptions);
               }
               else
               {
                  char *ptr,
                       *ptr_start;

                  ptr = ptr_start = option_buffer;

                  (void)strcpy(option_buffer, jd[i].soptions);
                  while ((*ptr != '\n') && (*ptr != '\0'))
                  {
                     ptr++;
                  }
                  *ptr = '\0';
                  ptr++;
                  (void)fprintf(stdout, "FD options   : %s\n", ptr_start);
                  for (j = 1; j < jd[i].no_of_soptions; j++)
                  {
                     ptr_start = ptr;
                     while ((*ptr != '\n') && (*ptr != '\0'))
                     {
                        ptr++;
                     }
                     *ptr = '\0';
                     ptr++;
                     (void)fprintf(stdout, "             : %s\n", ptr_start);
                  }
               }
            }
            (void)fprintf(stdout, "Recipient    : %s\n", jd[i].recipient);
            (void)fprintf(stdout, "Host alias   : %s\n", jd[i].host_alias);
            if ((i + 1) < no_of_job_ids)
            {
               (void)fprintf(stdout, "--------------------------------------------------------------------------------\n");
            }
         }
      }
   }
   else
   {
      (void)fprintf(stdout, _("Job ID list is empty.\n"));
   }

   if (fmd != NULL)
   {
      if (munmap((char *)fmd - AFD_WORD_OFFSET, fmd_size) == -1)
      {
         (void)fprintf(stderr, _("Failed to munmap() `%s' : %s (%s %d)\n"),
                       FILE_MASK_FILE, strerror(errno), __FILE__, __LINE__);
      }
   }
   if (dnb != NULL)
   {
      if (munmap((char *)dnb - AFD_WORD_OFFSET, dnb_size) == -1)
      {
         (void)fprintf(stderr, _("Failed to munmap() `%s' : %s (%s %d)\n"),
                       DIR_NAME_FILE, strerror(errno), __FILE__, __LINE__);
      }
   }
   if (munmap((char *)jd - AFD_WORD_OFFSET, jid_size) == -1)
   {
      (void)fprintf(stderr, _("Failed to munmap() `%s' : %s (%s %d)\n"),
                    file, strerror(errno), __FILE__, __LINE__);
   }
   (void)close(fd);

   exit(INCORRECT);
}
예제 #17
0
파일: event_log.c 프로젝트: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int         log_number = 0,
               log_stat = START,
               max_event_log_files = MAX_EVENT_LOG_FILES,
               event_log_fd;
#ifdef WITHOUT_FIFO_RW_SUPPORT
   int         writefd;
#endif
   off_t       max_eve_logfile_size = MAX_EVE_LOGFILE_SIZE;
   char        *p_end = NULL,
               *work_dir,
               log_file[MAX_PATH_LENGTH],
               current_log_file[MAX_PATH_LENGTH];
   FILE        *p_log_file;
   struct stat stat_buf;

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, log_file) < 0)
   {
      exit(INCORRECT);
   }
   if ((work_dir = malloc((strlen(log_file) + 1))) == NULL)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Failed to malloc() memory : %s",
                 strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }
   (void)strcpy(work_dir, log_file);
   p_work_dir = work_dir;

   /* Initialise variables for fifo stuff. */
   (void)strcat(log_file, FIFO_DIR);
   (void)strcat(log_file, EVENT_LOG_FIFO);
#ifdef WITHOUT_FIFO_RW_SUPPORT
   if (open_fifo_rw(log_file, &event_log_fd, &writefd) == -1)
#else
   if ((event_log_fd = open(log_file, O_RDWR)) == -1)
#endif
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Failed to open() fifo %s : %s", log_file, strerror(errno));
      exit(INCORRECT);
   }
   if ((fifo_size = fpathconf(event_log_fd, _PC_PIPE_BUF)) < 0)
   {
      /* If we cannot determine the size of the fifo set default value. */
      fifo_size = DEFAULT_FIFO_SIZE;
   }
   if (((fifo_buffer = malloc((size_t)fifo_size)) == NULL) ||
       ((msg_str = malloc((size_t)fifo_size)) == NULL))
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Could not allocate memory for the fifo buffe : %s",
                strerror(errno));
      exit(INCORRECT);
   }

   /* Get the maximum number of logfiles we keep for history. */
   get_max_log_values(&max_event_log_files, MAX_EVENT_LOG_FILES_DEF,
                      MAX_EVENT_LOG_FILES, &max_eve_logfile_size,
                      MAX_EVE_LOGFILE_SIZE_DEF, MAX_EVE_LOGFILE_SIZE);

   /*
    * Set umask so that all log files have the permission 644.
    * If we do not set this here fopen() will create files with
    * permission 666 according to POSIX.1.
    */
#ifdef GROUP_CAN_WRITE
   (void)umask(S_IWOTH);
#else
   (void)umask(S_IWGRP | S_IWOTH);
#endif

   get_log_number(&log_number, (max_event_log_files - 1),
                  EVENT_LOG_NAME, EVENT_LOG_NAME_LENGTH, NULL);
   (void)snprintf(current_log_file, MAX_PATH_LENGTH, "%s%s/%s0",
                  p_work_dir, LOG_DIR, EVENT_LOG_NAME);
   p_end = log_file + snprintf(log_file, MAX_PATH_LENGTH, "%s%s/%s",
                               p_work_dir, LOG_DIR, EVENT_LOG_NAME);

   /* Ignore any SIGTERM + SIGHUP signal. */
   if ((signal(SIGTERM, SIG_IGN) == SIG_ERR) ||
       (signal(SIGHUP, SIG_IGN) == SIG_ERR))
   {
      system_log(DEBUG_SIGN, __FILE__, __LINE__,
                 "signal() error : %s", strerror(errno));
   }

   while (log_stat == START)
   {
      if (stat(current_log_file, &stat_buf) < 0)
      {
         /* The log file does not yet exist. */
         total_length = 0;
      }
      else
      {
         /* Check if we have to start a new log file */
         /* because the current one is large enough. */
         if (stat_buf.st_size > max_eve_logfile_size)
         {
            if (log_number < (max_event_log_files - 1))
            {
               log_number++;
            }
            if (max_event_log_files > 1)
            {
               reshuffel_log_files(log_number, log_file, p_end, 0, 0);
            }
            else
            {
               if (unlink(current_log_file) == -1)
               {
                  system_log(WARN_SIGN, __FILE__, __LINE__,
                             "Failed to unlink() current log file `%s' : %s",
                             current_log_file, strerror(errno));
               }
            }
            total_length = 0;
         }
         else
         {
            total_length = stat_buf.st_size;
         }
      }

      /* Open event log file for writing. */
      if ((p_log_file = fopen(current_log_file, "a+")) == NULL)
      {
         (void)fprintf(stderr, "ERROR   : Could not open %s : %s (%s %d)\n",
                       current_log_file, strerror(errno), __FILE__, __LINE__);
         exit(INCORRECT);
      }

      log_stat = event_logger(p_log_file, max_eve_logfile_size,
                              event_log_fd,  EVENT_LOG_RESCAN_TIME);

      if (fclose(p_log_file) == EOF)
      {
         system_log(DEBUG_SIGN, __FILE__, __LINE__,
                   "Could not fclose() %s : %s",
                   current_log_file, strerror(errno));
      }
   }

   exit(SUCCESS);
}
예제 #18
0
파일: afdipdbcmd.c 프로젝트: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int  ret = SUCCESS;
   char work_dir[MAX_PATH_LENGTH];

   CHECK_FOR_VERSION(argc, argv);

   /* First get working directory for the AFD. */
   if (get_afd_path(&argc, argv, work_dir) < 0) 
   {
      exit(INCORRECT);
   }
   p_work_dir = work_dir;

   if (argc == 1)
   {
      (void)print_ip_db(stdout, NULL);
   }
   else
   {
      if (get_arg(&argc, argv, "-a", NULL, 0) != SUCCESS)
      {
         if (get_arg(&argc, argv, "-r", NULL, 0) != SUCCESS)
         {
            if (argv[1][0] == '-')
            {
               usage(argv[0]);
               ret = INCORRECT;
            }
            else
            {
               (void)print_ip_db(stdout, argv[1]);
            }
         }
         else
         {
            if (argc == 2)
            {
               if (remove_from_ip_db(argv[1]) == SUCCESS)
               {
                  (void)fprintf(stdout, "Removed %s from database.\n",
                                argv[1]);
               }
               else
               {
                  (void)fprintf(stderr,
                                "Could not remove %s from database.\n",
                                argv[1]);
                  ret = INCORRECT;
               }
            }
            else
            {
               usage(argv[0]);
               ret = INCORRECT;
            }
         }
      }
      else
      {
         if (argc == 3)
         {
            set_store_ip(YES);
            add_to_ip_db(argv[1], argv[2]);
            (void)fprintf(stdout, "Added/modified %s in database.\n",
                          argv[1]);
         }
         else
         {
            usage(argv[0]);
            ret = INCORRECT;
         }
      }
   }

   exit(ret);
}
예제 #19
0
파일: fra_version.c 프로젝트: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$ fra_version() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int  ret,
        set_version;
   char *ptr,
        work_dir[MAX_PATH_LENGTH];

   CHECK_FOR_VERSION(argc, argv);

   if (get_afd_path(&argc, argv, work_dir) < 0)
   {
      exit(INCORRECT);
   }
   p_work_dir = work_dir;

   if (argc == 2)
   {
      if (isdigit((int)(argv[1][0])) != 0)
      {
         set_version = atoi(argv[1]);
      }
      else
      {
         usage();
         exit(INCORRECT);
      }
   }
   else
   {
      set_version = -1;
   }

   if ((ret = fra_attach()) != SUCCESS)
   {
      if (ret == INCORRECT_VERSION)
      {
         (void)fprintf(stderr,
                       _("ERROR   : This program is not able to attach to the FRA due to incorrect version. (%s %d)\n"),
                       __FILE__, __LINE__);
      }
      else
      {
         if (ret < 0)
         {
            (void)fprintf(stderr,
                          _("ERROR   : Failed to attach to FRA. (%s %d)\n"),
                          __FILE__, __LINE__);
         }
         else
         {
            (void)fprintf(stderr,
                          _("ERROR   : Failed to attach to FRA : %s (%s %d)\n"),
                          strerror(ret), __FILE__, __LINE__);
         }
      }
      exit(INCORRECT);
   }
   ptr = (char *)fra;
   ptr -= AFD_WORD_OFFSET;
   if (set_version > -1)
   {
      int current_version = (int)(*(ptr + SIZEOF_INT + 1 + 1 + 1));

      *(ptr + SIZEOF_INT + 1 + 1 + 1) = set_version;
      (void)fprintf(stdout, _("Changed FRA version number from %d to %d\n"),
                    current_version, set_version);
   }
   else
   {
      (void)fprintf(stdout, _("Current FRA version: %d\n"),
                    (int)(*(ptr + SIZEOF_INT + 1 + 1 + 1)));
   }
   (void)fra_detach();

   exit(SUCCESS);
}