示例#1
0
int COracleDB::oracle_close( void )
{
	ORACLE_HANDLE* handle = ( ORACLE_HANDLE* ) _handle;

	if ( handle == NULL )
		return DB_ERR_SUCCESS;

	int status;
	if ( handle->svchp != NULL ) {
		while ( ( status = OCISessionEnd( handle->svchp, handle->errhp, handle->authp, OCI_DEFAULT ) )
				== OCI_STILL_EXECUTING ) {
			my_usleep();
		}
	}

	if ( handle->srvhp != NULL ) {
		while ( ( status = OCIServerDetach( handle->srvhp, handle->errhp, OCI_DEFAULT ) ) == OCI_STILL_EXECUTING ) {
			my_usleep();
		}
	}

	if ( handle->envhp != NULL ) {
		OCIHandleFree( ( dvoid * ) ( handle->envhp ), OCI_HTYPE_ENV );
	}

	if ( handle != NULL ) {
		delete handle;
		handle = NULL;
	}

	return 0;
}
示例#2
0
int COracleDB::oracle_exec( const char* sql, bool commit )
{
	if ( _handle == NULL )
		return DB_ERR_NOCONNECTION;

	if ( sql == NULL )
		return DB_ERR_PARAMERROR;

	int status = 0;

	int errcode = DB_ERR_SUCCESS;

	ORACLE_HANDLE* handle = ( ORACLE_HANDLE* ) _handle;

	status = OCIStmtPrepare( handle->stmthp, handle->errhp, ( text * ) sql, ( ub4 ) strlen( sql ),
			( ub4 ) OCI_NTV_SYNTAX, ( ub4 ) OCI_DEFAULT );

	if ( status == OCI_STILL_EXECUTING ) {
		my_usleep();
	}

	time_t t1 = time( NULL );

	status = OCIStmtExecute( handle->svchp, handle->stmthp, handle->errhp, 1, 0, NULL, NULL, OCI_DEFAULT );

	if ( status == OCI_STILL_EXECUTING ) {
		my_usleep();
	}

	if ( time( NULL ) - t1 > 60 ) {
		// timeout
		errcode = DB_ERR_TIMEOUT;
	}

	if ( errcode == DB_ERR_SUCCESS && status != OCI_SUCCESS_WITH_INFO && status != OCI_SUCCESS ) {
		errcode = checkerr( handle->errhp, status, _errinfo, sql );
		if ( errcode == 1012 || errcode == 12705 || errcode == 3113 || errcode == 3114 || errcode == 12541
				|| errcode == 12547 ) {
			errcode = DB_ERR_NOCONNECTION;
		} else {
			errcode = DB_ERR_FAILED;
		}
	}

	if ( commit )
		oracle_commit();

	// printf("%s ret: %d \n", sql, errcode);

	return errcode;
}
示例#3
0
int COracleDB::oracle_rollback( void )
{
	ORACLE_HANDLE* handle = ( ORACLE_HANDLE* ) _handle;

	int status = 0;

	int errcode = 0;

	time_t t1 = time( NULL );

	while ( ( status = OCITransRollback( handle->svchp, handle->errhp, 0 ) ) == OCI_STILL_EXECUTING ) {
		if ( time( NULL ) - t1 > 60 ) {
			// timeout
			errcode = DB_ERR_TIMEOUT;
			break;
		}
		my_usleep();
	}

	if ( errcode != DB_ERR_TIMEOUT && status ) {
		errcode = checkerr( handle->errhp, status, _errinfo );

		if ( errcode == 1012 || errcode == 12705 || errcode == 3113 || errcode == 3114 || errcode == 12541
				|| errcode == 12547 ) {
			errcode = DB_ERR_NOCONNECTION;
		} else {
			errcode = DB_ERR_FAILED;
		}
	}

	return errcode;
}
示例#4
0
int decode_task() {
	OutputBuffer * cb = &(getPlayerData()->buffer);
	PlayerControl * pc = &(getPlayerData()->playerControl);
	DecoderControl * dc = &(getPlayerData()->decoderControl);
	
	unblockSignals();
	
	mpm_enter(MPM_DECODE);	
	
			fprintf(stderr,"0 In the decode_task:\r\n");
	/* CHILD TASK */
	while(1) {
		if(dc->cycleLogFiles) {
			myfprintfCloseAndOpenLogFile();
			dc->cycleLogFiles = 0;
		}
		else if(dc->start || dc->seek)
				{
					fprintf(stderr,"CAlling decodestart func :\r\n");
					 decodeStart(pc, cb, dc);
				}
		else if(dc->stop) {
			dc->state = DECODE_STATE_STOP;
			dc->stop = 0;
		}
		else{
			 my_usleep(10000);
	//		fprintf(stderr,"in the decode_task sleep:\r\n");
			}
	}
	return EXIT_SUCCESS;
	/* END OF CHILD TASK */
}
示例#5
0
int	main()
{
    int	percent;
    int	equals;

    percent = 0;
    equals = 0;
    while (percent <= 100)
    {
        equals = percent / 10;
        my_printf(CYAN);
        my_printf("\r [ %d%% ] [", percent);
        while (equals--)
            my_putstr("==");
        equals = percent / 10;
        while (10 - equals++)
            my_putstr("  ");
        my_putchar(']');
        percent = percent + 1;
        my_usleep();
    }
    my_putchar('\n');
    my_printf(WHITE);
    return (0);
}
示例#6
0
void sys_sleep(int us)
{
	if (us <= 0) return;
#ifdef HAVE_USLEEP
	usleep(us);
#else
	my_usleep(us);
#endif
}
示例#7
0
int
nanosleep (const struct timespec *requested_delay,
           struct timespec *remaining_delay)
{
  static bool initialized;

  if (requested_delay->tv_nsec < 0 || BILLION <= requested_delay->tv_nsec)
    {
      errno = EINVAL;
      return -1;
    }

  /* set up sig handler */
  if (! initialized)
    {
      struct sigaction oldact;

      sigaction (SIGCONT, NULL, &oldact);
      if (get_handler (&oldact) != SIG_IGN)
        {
          struct sigaction newact;

          newact.sa_handler = sighandler;
          sigemptyset (&newact.sa_mask);
          newact.sa_flags = 0;
          sigaction (SIGCONT, &newact, NULL);
        }
      initialized = true;
    }

  suspended = 0;

  if (my_usleep (requested_delay) == -1)
    {
      if (suspended)
        {
          /* Calculate time remaining.  */
          /* FIXME: the code in sleep doesn't use this, so there's no
             rush to implement it.  */

          errno = EINTR;
        }
      return -1;
    }

  /* FIXME: Restore sig handler?  */

  return 0;
}
示例#8
0
int
rpl_nanosleep (const struct timespec *requested_delay,
	       struct timespec *remaining_delay)
{
  static bool initialized;

  /* set up sig handler */
  if (! initialized)
    {
#ifdef SA_NOCLDSTOP
      struct sigaction oldact, newact;
      newact.sa_handler = sighandler;
      sigemptyset (&newact.sa_mask);
      newact.sa_flags = 0;

      sigaction (SIGCONT, NULL, &oldact);
      if (oldact.sa_handler != SIG_IGN)
	sigaction (SIGCONT, &newact, NULL);
#else
      if (signal (SIGCONT, SIG_IGN) != SIG_IGN)
	{
	  signal (SIGCONT, sighandler);
	  siginterrupt (SIGCONT, 1);
	}
#endif
      initialized = true;
    }

  suspended = 0;

  my_usleep (requested_delay);

  if (suspended)
    {
      /* Calculate time remaining.  */
      /* FIXME: the code in sleep doesn't use this, so there's no
	 rush to implement it.  */

      errno = EINTR;
    }

  /* FIXME: Restore sig handler?  */

  return suspended;
}
示例#9
0
/*######################## limit_transfer_rate() ########################*/
void
limit_transfer_rate(int bytes, off_t limit_rate, clock_t clktck)
{
   double delta_time,
          elapsed_time,
          expected;

   elapsed_time = time_elapsed(clktck);
   delta_time = elapsed_time - chunk_start;
   chunk_bytes += bytes;

   /* Calculate the time it should take to download at the given rate. */
   expected = 1000.0 * (double)chunk_bytes / (double)limit_rate;

   if (expected > delta_time)
   {
      double sleep_time;

      sleep_time = expected - delta_time + sleep_adjust;
      if (sleep_time >= (double)(2 * clktck))
      {
         double t0, t1;

         t0 = elapsed_time;
         (void)my_usleep((unsigned long)(1000 * sleep_time));
         t1 = time_elapsed(clktck);

         sleep_adjust = sleep_time - (t1 - t0);
         elapsed_time = t1;
      }
      else
      {
         return;
      }
   }
   chunk_bytes = 0;
   chunk_start = elapsed_time;

   return;
}
示例#10
0
文件: lock_region_w.c 项目: hfs/afd
lock_region_w(int fd, off_t offset)
#endif
{
   int          count = 0,
                ret;
   struct flock wlock;

   wlock.l_type   = F_WRLCK;
   wlock.l_whence = SEEK_SET;
   wlock.l_start  = offset;
   wlock.l_len    = (off_t)1;
#ifdef LOCK_DEBUG
   system_log(DEBUG_SIGN, NULL, 0,
# if SIZEOF_OFF_T == 4
              "lock_region_w(): fd=%d start=%ld length=1 file=%s line=%d",
# else
              "lock_region_w(): fd=%d start=%lld length=1 file=%s line=%d",
# endif
              fd, (pri_off_t)offset, file, line);
#endif

   while (((ret = fcntl(fd, F_SETLKW, &wlock)) == -1) && (errno == EAGAIN) &&
          (count < 20))
   {
      my_usleep(50000L);
      count++;
   }
   if (ret == -1)
   {
      system_log(FATAL_SIGN, __FILE__, __LINE__,
                 _("fcntl() error : %s"), strerror(errno));
      exit(LOCK_REGION_ERROR);
   }

   return;
}
示例#11
0
文件: sf_exec.c 项目: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
#ifdef _WITH_BURST_2
   int              cb2_ret;
#endif
   int              exec_done,
                    exit_status = TRANSFER_SUCCESS,
                    ii,
                    k,
                    last_k,
                    length,
                    length_start,
                    mask_file_name,
#ifdef HAVE_SETPRIORITY
                    sched_priority,
#endif
                    ret;
   time_t           last_update_time,
                    now,
                    *p_file_mtime_buffer;
   char             command_str[MAX_PATH_LENGTH + MAX_RECIPIENT_LENGTH],
                    file_name[MAX_FILENAME_LENGTH],
                    file_path[MAX_PATH_LENGTH],
                    *fnp,
                    *insert_list[MAX_EXEC_FILE_SUBSTITUTION],
                    job_str[4],
                    *p_command,
                    *p_source_file,
                    *p_file_name_buffer,
                    *return_str = NULL,
                    source_file[MAX_PATH_LENGTH],
                    tmp_char,
                    tmp_option[MAX_PATH_LENGTH + MAX_RECIPIENT_LENGTH];
   struct job       *p_db;
#ifdef SA_FULLDUMP
   struct sigaction sact;
#endif
#ifdef WITH_FAST_MOVE
   nlink_t          nlink;
#endif
#ifdef _OUTPUT_LOG
   clock_t          end_time = 0,
                    start_time = 0;
   struct tms       tmsdummy;
#endif

   CHECK_FOR_VERSION(argc, argv);

#ifdef SA_FULLDUMP
   /*
    * When dumping core sure we do a FULL core dump!
    */
   sact.sa_handler = SIG_DFL;
   sact.sa_flags = SA_FULLDUMP;
   sigemptyset(&sact.sa_mask);
   if (sigaction(SIGSEGV, &sact, NULL) == -1)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "sigaction() error : %s", strerror(errno));
      exit(INCORRECT);
   }
#endif

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

   /* Initialise variables. */
   local_file_counter = 0;
   files_to_send = init_sf(argc, argv, file_path, EXEC_FLAG);
   p_db = &db;

   if ((signal(SIGINT, sig_kill) == 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(ERROR_SIGN, __FILE__, __LINE__,
                 "Failed to set signal handlers : %s", strerror(errno));
      exit(INCORRECT);
   }

   /* Inform FSA that we have are ready to copy the files. */
   if (gsf_check_fsa(p_db) != NEITHER)
   {
      fsa->job_status[(int)db.job_no].connect_status = EXEC_ACTIVE;
      fsa->job_status[(int)db.job_no].no_of_files = files_to_send;
   }

   /* Init job_str for exec_cmd(). */
   job_str[0] = '[';
   job_str[1] = db.job_no + '0';
   job_str[2] = ']';
   job_str[3] = '\0';

#ifdef _WITH_BURST_2
   do
   {
      if (burst_2_counter > 0)
      {
         if (fsa->debug > NORMAL_MODE)
         {
            trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL, "Bursting.");
         }
      }
#endif /* _WITH_BURST_2 */
      /* Prepare pointers and directory name. */
      (void)strcpy(source_file, file_path);
      p_source_file = source_file + strlen(source_file);
      *p_source_file++ = '/';

#ifdef HAVE_SETPRIORITY
      if (db.exec_base_priority != NO_PRIORITY)
      {
         sched_priority = db.exec_base_priority;
         if (db.add_afd_priority == YES)
         {
            sched_priority += (int)(fsa->job_status[(int)db.job_no].unique_name[MAX_MSG_NAME_LENGTH - 1]);
            if (sched_priority > db.min_sched_priority)
            {
               sched_priority = db.min_sched_priority;
            }
            else if (sched_priority < db.max_sched_priority)
                 {
                    sched_priority = db.max_sched_priority;
                 }
         }
         if ((sched_priority == db.current_priority) ||
             ((db.current_priority > sched_priority) && (geteuid() != 0)))
         {
            sched_priority = NO_PRIORITY;
         }
      }
      else
      {
         sched_priority = NO_PRIORITY;
      }
#endif

      p_command = db.exec_cmd;
      while ((*p_command == ' ') || (*p_command == '\t'))
      {
         p_command++;
      }
      if ((db.special_flag & EXEC_ONCE_ONLY) == 0)
      {
         char *p_end;

         /* Prepare insert list. */
         p_end = p_command;
         k = 0;
         ii = 0;
         while ((*p_end != '\0') && (ii < MAX_EXEC_FILE_SUBSTITUTION))
         {
            if ((*p_end == '%') && (*(p_end + 1) == 's'))
            {
               tmp_option[k] = *p_end;
               tmp_option[k + 1] = *(p_end + 1);
               insert_list[ii] = &tmp_option[k];
               ii++;
               p_end += 2;
               k += 2;
            }
            else
            {
               tmp_option[k] = *p_end;
               p_end++; k++;
            }
         }
         if (ii >= MAX_EXEC_FILE_SUBSTITUTION)
         {
            trans_log(WARN_SIGN, __FILE__, __LINE__, NULL, NULL,
                      "To many %%s in pexec option. Can oly handle %d.",
                      MAX_EXEC_FILE_SUBSTITUTION);
         }
         tmp_option[k] = '\0';
         p_command = tmp_option;
         last_k = k;
      }

      p_file_name_buffer = file_name_buffer;
      p_file_size_buffer = file_size_buffer;
      p_file_mtime_buffer = file_mtime_buffer;
      last_update_time = time(NULL);
      local_file_size = 0;
      exec_done = NO;
      for (files_send = 0; files_send < files_to_send; files_send++)
      {
         (void)strcpy(p_source_file, p_file_name_buffer);

         if (db.special_flag & EXEC_ONCE_ONLY)
         {
            if (exec_done == NO)
            {
#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  start_time = times(&tmsdummy);
               }
#endif
               (void)sprintf(command_str, "cd %s && %s",
                             file_path, p_command);
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Executing command `%s' to send file `%s'",
                               command_str, p_file_name_buffer);
               }
               if ((ret = exec_cmd(command_str, &return_str, transfer_log_fd,
                                   fsa->host_dsp_name, MAX_HOSTNAME_LENGTH,
#ifdef HAVE_SETPRIORITY
                                   sched_priority,
#endif
                                   job_str,
                                   (fsa->protocol_options & TIMEOUT_TRANSFER) ? (time_t)transfer_timeout : 0L,
                                   YES, YES)) != 0)
               {
                  trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                            "Failed to execute command %s [Return code = %d]",
                            command_str, ret);
                  if ((return_str != NULL) && (return_str[0] != '\0'))
                  {
                     char *end_ptr = return_str,
                          *start_ptr;

                     do
                     {
                        start_ptr = end_ptr;
                        while ((*end_ptr != '\n') && (*end_ptr != '\0'))
                        {
                           end_ptr++;
                        }
                        if (*end_ptr == '\n')
                        {
                           *end_ptr = '\0';
                           end_ptr++;
                        }
                        trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                                  "%s", start_ptr);
                     } while (*end_ptr != '\0');
                  }
                  exit(EXEC_ERROR);
               }
#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  end_time = times(&tmsdummy);
               }
#endif
               free(return_str);
               return_str = NULL;
               exec_done = YES;
            }
         }
         else
         {
            /* Write status to FSA? */
            if (gsf_check_fsa(p_db) != NEITHER)
            {
               fsa->job_status[(int)db.job_no].file_size_in_use = *p_file_size_buffer;
               (void)strcpy(fsa->job_status[(int)db.job_no].file_name_in_use,
                            p_file_name_buffer);
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               start_time = times(&tmsdummy);
            }
#endif

            insert_list[ii] = &tmp_option[last_k];
            tmp_char = *insert_list[0];
            *insert_list[0] = '\0';
            length_start = sprintf(command_str, "cd %s && %s",
                                   file_path, p_command);
            *insert_list[0] = tmp_char;

            fnp = p_file_name_buffer;
            mask_file_name = NO;
            do
            {
               if ((*fnp == ';') || (*fnp == ' '))
               {
                  mask_file_name = YES;
                  break;
               }
               fnp++;
            } while (*fnp != '\0');

            /* Generate command string with file name(s). */
            length = 0;
            for (k = 1; k < (ii + 1); k++)
            {
               tmp_char = *insert_list[k];
               *insert_list[k] = '\0';
               if (mask_file_name == YES)
               {
                  length += sprintf(command_str + length_start + length,
                                    "\"%s\"%s", p_file_name_buffer,
                                    insert_list[k - 1] + 2);
               }
               else
               {
                  length += sprintf(command_str + length_start + length,
                                    "%s%s", p_file_name_buffer,
                                    insert_list[k - 1] + 2);
               }
               *insert_list[k] = tmp_char;
            }

            if ((ret = exec_cmd(command_str, &return_str, transfer_log_fd,
                                fsa->host_dsp_name, MAX_HOSTNAME_LENGTH,
#ifdef HAVE_SETPRIORITY
                                sched_priority,
#endif
                                job_str,
                                (fsa->protocol_options & TIMEOUT_TRANSFER) ? (time_t)transfer_timeout : 0L,
                                YES, YES)) != 0) /* ie != SUCCESS */
            {
               trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                         "Failed to execute command %s [Return code = %d]",
                         command_str, ret);
               if ((return_str != NULL) && (return_str[0] != '\0'))
               {
                  char *end_ptr = return_str,
                       *start_ptr;

                  do
                  {
                     start_ptr = end_ptr;
                     while ((*end_ptr != '\n') && (*end_ptr != '\0'))
                     {
                        end_ptr++;
                     }
                     if (*end_ptr == '\n')
                     {
                        *end_ptr = '\0';
                        end_ptr++;
                     }
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "%s", start_ptr);
                  } while (*end_ptr != '\0');
               }
               exit(EXEC_ERROR);
            }
            free(return_str);
            return_str = NULL;

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               end_time = times(&tmsdummy);
            }
#endif
         }

         /* Tell FSA we have done a file. */
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            fsa->job_status[(int)db.job_no].file_name_in_use[0] = '\0';
            fsa->job_status[(int)db.job_no].no_of_files_done++;
            fsa->job_status[(int)db.job_no].file_size_in_use = 0;
            fsa->job_status[(int)db.job_no].file_size_in_use_done = 0;
            fsa->job_status[(int)db.job_no].file_size_done += *p_file_size_buffer;
            fsa->job_status[(int)db.job_no].bytes_send += *p_file_size_buffer;
            local_file_size += *p_file_size_buffer;
            local_file_counter += 1;

            now = time(NULL);
            if (now >= (last_update_time + LOCK_INTERVAL_TIME))
            {
               last_update_time = now;
               update_tfc(local_file_counter, local_file_size,
                          p_file_size_buffer, files_to_send, files_send);
               local_file_size = 0;
               local_file_counter = 0;
            }
         }

#ifdef _WITH_TRANS_EXEC
         if (db.special_flag & TRANS_EXEC)
         {
            trans_exec(file_path, source_file, p_file_name_buffer);
         }
#endif

#ifdef _OUTPUT_LOG
         if (db.output_log == YES)
         {
            if (ol_fd == -2)
            {
# ifdef WITHOUT_FIFO_RW_SUPPORT
               output_log_fd(&ol_fd, &ol_readfd);
# else
               output_log_fd(&ol_fd);
# endif
            }
            if ((ol_fd > -1) && (ol_data == NULL))
            {
               output_log_ptrs(&ol_retries, &ol_job_number, &ol_data,
                               &ol_file_name, &ol_file_name_length,
                               &ol_archive_name_length, &ol_file_size,
                               &ol_unl, &ol_size, &ol_transfer_time,
                               &ol_output_type, db.host_alias, 0, EXEC);
            }
         }
#endif

         /* Now archive file if necessary. */
         if ((db.archive_time > 0) &&
             (p_db->archive_dir[0] != FAILED_TO_CREATE_ARCHIVE_DIR))
         {
            /*
             * By telling the function archive_file() that this
             * is the first time to archive a file for this job
             * (in struct p_db) it does not always have to check
             * whether the directory has been created or not. And
             * we ensure that we do not create duplicate names
             * when adding db.archive_time to msg_name.
             */
            if (archive_file(file_path, p_file_name_buffer, p_db) < 0)
            {
               trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                         "Failed to archive file `%s'", file_name);

               /*
                * NOTE: We _MUST_ delete the file we just send,
                *       else the file directory will run full!
                */
               if (unlink(source_file) == -1)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "Could not unlink() local file `%s' after copying it successfully : %s",
                             source_file, strerror(errno));
               }

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  if (db.trans_rename_rule[0] != '\0')
                  {
                     *ol_file_name_length = (unsigned short)sprintf(ol_file_name + db.unl,
                                                                    "%s%c/%s",
                                                                    p_file_name_buffer,
                                                                    SEPARATOR_CHAR,
                                                                    p_file_name_buffer) +
                                                                    db.unl;
                  }
                  else
                  {
                     (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                     *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                     ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                     ol_file_name[*ol_file_name_length + 1] = '\0';
                     (*ol_file_name_length)++;
                  }
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = 0;
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
            else
            {
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Archived file `%s'.", file_name);
               }

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  if (db.trans_rename_rule[0] != '\0')
                  {
                     *ol_file_name_length = (unsigned short)sprintf(ol_file_name + db.unl,
                                                                    "%s%c/%s",
                                                                    p_file_name_buffer,
                                                                    SEPARATOR_CHAR,
                                                                    p_file_name_buffer) +
                                                                    db.unl;
                  }
                  else
                  {
                     (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                     *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                     ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                     ol_file_name[*ol_file_name_length + 1] = '\0';
                     (*ol_file_name_length)++;
                  }
                  (void)strcpy(&ol_file_name[*ol_file_name_length + 1], &db.archive_dir[db.archive_offset]);
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = (unsigned short)strlen(&ol_file_name[*ol_file_name_length + 1]);
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length +
                                 *ol_archive_name_length + 1 + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
         }
         else
         {
#ifdef WITH_UNLINK_DELAY
            int unlink_loops = 0;

try_again_unlink:
#endif
            /* Delete the file we just have executed. */
            if (unlink(source_file) == -1)
            {
#ifdef WITH_UNLINK_DELAY
               if ((errno == EBUSY) && (unlink_loops < 20))
               {
                  (void)my_usleep(100000L);
                  unlink_loops++;
                  goto try_again_unlink;
               }
#endif
               system_log(ERROR_SIGN, __FILE__, __LINE__,
                          "Could not unlink() local file %s after copying it successfully : %s",
                          source_file, strerror(errno));
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
               if (db.trans_rename_rule[0] != '\0')
               {
                  *ol_file_name_length = (unsigned short)sprintf(ol_file_name + db.unl,
                                                                 "%s%c/%s",
                                                                 p_file_name_buffer,
                                                                 SEPARATOR_CHAR,
                                                                 p_file_name_buffer) +
                                                                 db.unl;
               }
               else
               {
                  (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                  *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                  ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                  ol_file_name[*ol_file_name_length + 1] = '\0';
                  (*ol_file_name_length)++;
               }
               *ol_file_size = *p_file_size_buffer;
               *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
               *ol_retries = db.retries;
               *ol_unl = db.unl;
               *ol_transfer_time = end_time - start_time;
               *ol_archive_name_length = 0;
               *ol_output_type = OT_NORMAL_DELIVERED + '0';
               ol_real_size = *ol_file_name_length + ol_size;
               if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "write() error : %s", strerror(errno));
               }
            }
#endif
         }

         /*
          * After each successful transfer set error counter to zero,
          * so that other jobs can be started.
          */
         if (fsa->error_counter > 0)
         {
            int  fd,
#ifdef WITHOUT_FIFO_RW_SUPPORT
                 readfd,
#endif
                 j;
            char fd_wake_up_fifo[MAX_PATH_LENGTH];

#ifdef LOCK_DEBUG
            lock_region_w(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
            lock_region_w(fsa_fd, db.lock_offset + LOCK_EC);
#endif
            fsa->error_counter = 0;

            /*
             * Wake up FD!
             */
            (void)sprintf(fd_wake_up_fifo, "%s%s%s",
                          p_work_dir, FIFO_DIR, FD_WAKE_UP_FIFO);
#ifdef WITHOUT_FIFO_RW_SUPPORT
            if (open_fifo_rw(fd_wake_up_fifo, &readfd, &fd) == -1)
#else
            if ((fd = open(fd_wake_up_fifo, O_RDWR)) == -1)
#endif
            {
               system_log(WARN_SIGN, __FILE__, __LINE__,
                          "Failed to open() FIFO %s : %s",
                          fd_wake_up_fifo, strerror(errno));
            }
            else
            {
               if (write(fd, "", 1) != 1)
               {
                  system_log(WARN_SIGN, __FILE__, __LINE__,
                             "Failed to write() to FIFO %s : %s",
                             fd_wake_up_fifo, strerror(errno));
               }
#ifdef WITHOUT_FIFO_RW_SUPPORT
               if (close(readfd) == -1)
               {
                  system_log(DEBUG_SIGN, __FILE__, __LINE__,
                             "Failed to close() FIFO %s : %s",
                             fd_wake_up_fifo, strerror(errno));
               }
#endif
               if (close(fd) == -1)
               {
                  system_log(DEBUG_SIGN, __FILE__, __LINE__,
                             "Failed to close() FIFO %s : %s",
                             fd_wake_up_fifo, strerror(errno));
               }
            }

            /*
             * Remove the error condition (NOT_WORKING) from all jobs
             * of this host.
             */
            for (j = 0; j < fsa->allowed_transfers; j++)
            {
               if ((j != db.job_no) &&
                   (fsa->job_status[j].connect_status == NOT_WORKING))
               {
                  fsa->job_status[j].connect_status = DISCONNECT;
               }
            }
            fsa->error_history[0] = 0;
            fsa->error_history[1] = 0;
#ifdef LOCK_DEBUG
            unlock_region(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
            unlock_region(fsa_fd, db.lock_offset + LOCK_EC);
#endif

            /*
             * Since we have successfully transmitted a file, no need to
             * have the queue stopped anymore.
             */
            if (fsa->host_status & AUTO_PAUSE_QUEUE_STAT)
            {
               char *sign;

#ifdef LOCK_DEBUG
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS);
#endif
               fsa->host_status &= ~AUTO_PAUSE_QUEUE_STAT;
               if (fsa->host_status & HOST_ERROR_EA_STATIC)
               {
                  fsa->host_status &= ~EVENT_STATUS_STATIC_FLAGS;
               }
               else
               {
                  fsa->host_status &= ~EVENT_STATUS_FLAGS;
               }
               fsa->host_status &= ~PENDING_ERRORS;
#ifdef LOCK_DEBUG
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS);
#endif
               error_action(fsa->host_alias, "stop", HOST_ERROR_ACTION);
               event_log(0L, EC_HOST, ET_EXT, EA_ERROR_END, "%s",
                         fsa->host_alias);
               if ((fsa->host_status & HOST_ERROR_OFFLINE_STATIC) ||
                   (fsa->host_status & HOST_ERROR_OFFLINE) ||
                   (fsa->host_status & HOST_ERROR_OFFLINE_T))
               {
                  sign = OFFLINE_SIGN;
               }
               else
               {
                  sign = INFO_SIGN;
               }
               trans_log(sign, __FILE__, __LINE__, NULL, NULL,
                         "Starting input queue that was stopped by init_afd.");
               event_log(0L, EC_HOST, ET_AUTO, EA_START_QUEUE, "%s",
                         fsa->host_alias);
            }
         } /* if (fsa->error_counter > 0) */
#ifdef WITH_ERROR_QUEUE
         if (fsa->host_status & ERROR_QUEUE_SET)
         {
            remove_from_error_queue(db.job_id, fsa, db.fsa_pos, fsa_fd);
         }
#endif
         if (fsa->host_status & HOST_ACTION_SUCCESS)
         {
            error_action(fsa->host_alias, "start", HOST_SUCCESS_ACTION);
         }

         p_file_name_buffer += MAX_FILENAME_LENGTH;
         p_file_size_buffer++;
         if (file_mtime_buffer != NULL)
         {
            p_file_mtime_buffer++;
         }
      } /* for (files_send = 0; files_send < files_to_send; files_send++) */

      if (local_file_counter)
      {
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            update_tfc(local_file_counter, local_file_size,
                       p_file_size_buffer, files_to_send, files_send);
            local_file_size = 0;
            local_file_counter = 0;
         }
      }

      /* Do not forget to remove lock file if we have created one. */
      if ((db.lock == LOCKFILE) && (fsa->active_transfers == 1))
      {
         if (unlink(db.lock_file_name) == -1)
         {
            trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                      "Failed to unlink() lock file `%s' : %s",
                      db.lock_file_name, strerror(errno));
            exit(REMOVE_LOCKFILE_ERROR);
         }
         else
         {
            if (fsa->debug > NORMAL_MODE)
            {
               trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                            "Removed lock file `%s'.", db.lock_file_name);
            }
         }
      }

      /*
       * Remove file directory with everything in it.
       */
      if (rec_rmdir(file_path) == INCORRECT)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    "Failed to rec_rmdir() `%s' : %s",
                    file_path, strerror(errno));
         exit_status = STILL_FILES_TO_SEND;
      }

#ifdef _WITH_BURST_2
      burst_2_counter++;
   } while ((cb2_ret = check_burst_2(file_path, &files_to_send, 0,
# ifdef _WITH_INTERRUPT_JOB
                                     0,
# endif
# ifdef _OUTPUT_LOG
                                     &ol_fd,
# endif
# ifndef AFDBENCH_CONFIG
                                     NULL,
# endif
                                     NULL)) == YES);
   burst_2_counter--;

   if (cb2_ret == NEITHER)
   {
      exit_status = STILL_FILES_TO_SEND;
   }
#endif /* _WITH_BURST_2 */

   exitflag = 0;
   exit(exit_status);
}
示例#12
0
文件: scpcmd.c 项目: holger24/AFD
/*############################## scp_quit() #############################*/
void
scp_quit(void)
{
   /* Close pipe for read/write data connection. */
   if (data_fd != -1)
   {
      if (close(data_fd) == -1)
      {
         trans_log(WARN_SIGN, __FILE__, __LINE__, "scp_quit", NULL,
                   _("Failed to close() write pipe to ssh process : %s"),
                   strerror(errno));
      }
      data_fd = -1;
   }

   /* Remove ssh process for writing data. */
   if (data_pid > 0)
   {
      int   loop_counter,
            max_waitpid_loops,
            status;
      pid_t return_pid;

      loop_counter = 0;
      max_waitpid_loops = (transfer_timeout / 2) * 10;
      while (((return_pid = waitpid(data_pid, &status, WNOHANG)) != data_pid) &&
             (return_pid != -1) &&
             (loop_counter < max_waitpid_loops))
      {
         my_usleep(100000L);
         loop_counter++;
      }
      if ((return_pid == -1) || (loop_counter >= max_waitpid_loops))
      {
         msg_str[0] = '\0';
         if (return_pid == -1)
         {
            trans_log(WARN_SIGN, __FILE__, __LINE__, "scp_quit", NULL,
                      _("Failed to catch zombie of data ssh process : %s"),
                      strerror(errno));
         }
         if (data_pid > 0)
         {
            if (kill(data_pid, SIGKILL) == -1)
            {
               trans_log(ERROR_SIGN, __FILE__, __LINE__, "scp_quit", NULL,
#if SIZEOF_PID_T == 4
                         _("Failed to kill() data ssh process %d : %s"),
#else
                         _("Failed to kill() data ssh process %lld : %s"),
#endif
                         (pri_pid_t)data_pid, strerror(errno));
            }
            else
            {
               trans_log(WARN_SIGN, __FILE__, __LINE__, "scp_quit", NULL,
#if SIZEOF_PID_T == 4
                         _("Killing hanging data ssh process %d."),
#else
                         _("Killing hanging data ssh process %lld."),
#endif
                         (pri_pid_t)data_pid);
            }
         }
         else
         {
            trans_log(DEBUG_SIGN, __FILE__, __LINE__, "scp_quit", NULL,
#if SIZEOF_PID_T == 4
                      _("Hmm, pid is %d!!!"), (pri_pid_t)data_pid);
#else
                      _("Hmm, pid is %lld!!!"), (pri_pid_t)data_pid);
#endif
         }
      }
示例#13
0
文件: main.c 项目: kinnalru/x2wintray
/* main() for controlling stalonetray remotely */
int remote_main(int argc, char **argv)
{
	Window tray, icon = None;
	int rc;
	int x, y, depth = 0, idummy, i;
	Window win, root;
	unsigned int udummy, w, h;
	tray_init_selection_atoms();
	tray_create_phony_window();
	LOG_TRACE(("name=\"%s\" btn=%d cnt=%d x=%d y=%d\n", 
				settings.remote_click_name,
				settings.remote_click_btn,
				settings.remote_click_cnt,
				settings.remote_click_pos.x,
				settings.remote_click_pos.y));
	tray = XGetSelectionOwner(tray_data.dpy, tray_data.xa_tray_selection);
	if (tray == None) return 255;
	/* 1. find window matching requested name */
	icon = x11_find_subwindow_by_name(tray_data.dpy, tray, settings.remote_click_name);
	if (icon == None) return 127;
	/* 2. form a message to tray requesting it to show the icon */
	rc = x11_send_client_msg32(tray_data.dpy, /* display */
			tray, /* destination */
			icon, /* window */ 
			tray_data.xa_tray_opcode, /* atom */
			settings.remote_click_cnt, /* data0 */
			STALONE_TRAY_REMOTE_CONTROL, /* data1 */
			settings.remote_click_btn, /* data2 */
			settings.remote_click_pos.x, /* data3 */
			settings.remote_click_pos.y /* data4 */
			);
	if (!rc) return 63;
	/* 3. Execute the click */
	/* 3.1. Sort out click position */
	XGetGeometry(tray_data.dpy, icon, &root, 
			&idummy, &idummy, 
			&w, &h, &udummy, &udummy);
	LOG_TRACE(("wid=0x%x w=%d h=%d\n", icon, w, h));
	x = (settings.remote_click_pos.x == REMOTE_CLICK_POS_DEFAULT) ? w / 2 : settings.remote_click_pos.x;
	y = (settings.remote_click_pos.y == REMOTE_CLICK_POS_DEFAULT) ? h / 2 : settings.remote_click_pos.y;
	/* 3.2. Find subwindow to execute click on */
	win = x11_find_subwindow_at(tray_data.dpy, icon, &x, &y, depth);
	/* 3.3. Send mouse click(s) to target */
	LOG_TRACE(("wid=0x%x btn=%d x=%d y=%d\n", 
				win, settings.remote_click_btn, x, y));
#define SEND_BTN_EVENT(press, time) do { \
	x11_send_button(tray_data.dpy, /* dispslay */ \
			press, /* event type */ \
			win, /* target window */ \
			root, /* root window */ \
			time, /* time */ \
			settings.remote_click_btn, /* button */ \
			Button1Mask << (settings.remote_click_btn - 1), /* state mask */ \
			x, /* x coord (relative) */ \
			y); /* y coord (relative) */ \
} while (0)
	for (i = 0; i < settings.remote_click_cnt; i++) {
		SEND_BTN_EVENT(1, x11_get_server_timestamp(tray_data.dpy, tray_data.tray));
		my_usleep(250);
		SEND_BTN_EVENT(0, x11_get_server_timestamp(tray_data.dpy, tray_data.tray));
	}
#undef SEND_BTN_EVENT
	return 0;
}
示例#14
0
文件: main.c 项目: kinnalru/x2wintray
/* main() for usual operation */
int tray_main(int argc, char **argv)
{
	XEvent		ev;
	/* Interpret those settings that need an open display */
	interpret_settings();
#ifdef DEBUG
	ewmh_list_supported_atoms(tray_data.dpy);
#endif
	/* Create and show tray window */
	tray_create_window(argc, argv);
	tray_acquire_selection();
	tray_show_window();
#ifndef NO_NATIVE_KDE
	kde_tray_init(tray_data.dpy);
#endif
	xembed_init();
#ifndef NO_NATIVE_KDE
	kde_icons_update();
#endif
	/* Main event loop */
	while ("my guitar gently wheeps") {
		/* This is ugly and extra dependency. But who cares?
		 * Rationale: we want to block unless absolutely needed.
		 * This way we ensure that stalonetray does not show up
		 * in powertop (i.e. does not eat unnecessary power and
		 * CPU cycles) 
		 * Drawback: handling of signals is very limited. XNextEvent()
		 * does not if signal occurs. This means that graceful
		 * exit on e.g. Ctrl-C cannot be implemented without hacks. */
		while (XPending(tray_data.dpy) || tray_data.scrollbars_data.scrollbar_down == -1) {
			XNextEvent(tray_data.dpy, &ev);
			xembed_handle_event(ev);
			scrollbars_handle_event(ev);
			switch (ev.type) {
			case VisibilityNotify:
				LOG_TRACE(("VisibilityNotify (0x%x, state=%d)\n", ev.xvisibility.window, ev.xvisibility.state));
				visibility_notify(ev.xvisibility);
				break;
			case Expose:
				LOG_TRACE(("Expose (0x%x)\n", ev.xexpose.window));
				expose(ev.xexpose);
				break;
			case PropertyNotify:
				LOG_TRACE(("PropertyNotify(0x%x)\n", ev.xproperty.window));
				property_notify(ev.xproperty);
				break;
			case DestroyNotify:
				LOG_TRACE(("DestroyNotify(0x%x)\n", ev.xdestroywindow.window));
				destroy_notify(ev.xdestroywindow);
				break;
			case ClientMessage:
				LOG_TRACE(("ClientMessage(from 0x%x?)\n", ev.xclient.window));
				client_message(ev.xclient);
				break;
			case ConfigureNotify:
				LOG_TRACE(("ConfigureNotify(0x%x)\n", ev.xconfigure.window));
				configure_notify(ev.xconfigure);
				break;
			case MapNotify:
				LOG_TRACE(("MapNotify(0x%x)\n", ev.xmap.window));
				map_notify(ev.xmap);
				break;
			case ReparentNotify:
				LOG_TRACE(("ReparentNotify(0x%x to 0x%x)\n", ev.xreparent.window, ev.xreparent.parent));
				reparent_notify(ev.xreparent);
				break;
			case SelectionClear:
				LOG_TRACE(("SelectionClear (0x%x has lost selection)\n", ev.xselectionclear.window));
				selection_clear(ev.xselectionclear);
				break;
			case SelectionNotify:
				LOG_TRACE(("SelectionNotify\n"));
				break;
			case SelectionRequest:
				LOG_TRACE(("SelectionRequest (from 0x%x to 0x%x)\n", ev.xselectionrequest.requestor, ev.xselectionrequest.owner));
				break;
			case UnmapNotify:
				LOG_TRACE(("UnmapNotify(0x%x)\n", ev.xunmap.window));
				unmap_notify(ev.xunmap);
				break;
			default:
#if defined(DEBUG) && defined(TRACE_EVENTS)
				LOG_TRACE(("Unhandled event: %s, serial: %d, window: 0x%x\n", x11_event_names[ev.type], ev.xany.serial, ev.xany.window));
#endif
				break;
			}
			if (tray_data.terminated) goto bailout;
			/* Perform all periodic tasks but for scrollbars */
			perform_periodic_tasks(PT_MASK_ALL & (~PT_MASK_SB));
		}
		perform_periodic_tasks(PT_MASK_ALL);
                my_usleep(500000L);
	}
bailout:
	LOG_TRACE(("Clean exit\n"));
	return 0;
}
示例#15
0
文件: main.c 项目: kinnalru/x2wintray
void client_message(XClientMessageEvent ev)
{
	int cmode = CM_FDO;
	struct TrayIcon *ti;
#ifdef DEBUG
	/* Print neat message(s) about this event to aid debugging */
	char *msg_type_name;
	msg_type_name = XGetAtomName(tray_data.dpy, ev.message_type);
	if (msg_type_name != NULL) {
		LOG_TRACE(("message \"%s\"\n", msg_type_name));
		XFree(msg_type_name);
	}
	if (ev.message_type == tray_data.xa_wm_protocols) {
		msg_type_name = XGetAtomName(tray_data.dpy, ev.data.l[0]);
		if (msg_type_name != NULL) {
			LOG_TRACE(("WM_PROTOCOLS message type: %s\n", msg_type_name));
			XFree(msg_type_name);
		}
	}
#endif
	/* Graceful exit */
	if (ev.message_type == tray_data.xa_wm_protocols &&
		ev.data.l[0] == tray_data.xa_wm_delete_window && 
		ev.window == tray_data.tray)
	{
		LOG_TRACE(("got WM_DELETE message, will now exit\n"));
		exit(0); // atexit will call cleanup()
	} 
	/* Handle _NET_SYSTEM_TRAY_* messages */
	if (ev.message_type == tray_data.xa_tray_opcode && tray_data.is_active) {
		LOG_TRACE(("this is the _NET_SYSTEM_TRAY_OPCODE(%lu) message\n", ev.data.l[1]));
		switch (ev.data.l[1]) {
			/* This is the starting point of NET SYSTEM TRAY protocol */
			case SYSTEM_TRAY_REQUEST_DOCK:
				LOG_TRACE(("dockin' requested by window 0x%x, serving in a moment\n", ev.data.l[2]));
#ifndef NO_NATIVE_KDE
				if (kde_tray_check_for_icon(tray_data.dpy, ev.data.l[2])) cmode = CM_KDE;
				if (kde_tray_is_old_icon(ev.data.l[2])) kde_tray_old_icons_remove(ev.data.l[2]);
#endif
				add_icon(ev.data.l[2], cmode);
				break;
			/* We ignore these messages, since we do not show
			 * any baloons anyways */
			case SYSTEM_TRAY_BEGIN_MESSAGE:
			case SYSTEM_TRAY_CANCEL_MESSAGE:
				break;
			/* Below are special cases added by this implementation */
			/* STALONETRAY_TRAY_DOCK_CONFIRMED is sent by stalonetray 
			 * to itself. (see embed.c) */
			case STALONE_TRAY_DOCK_CONFIRMED:
				ti = icon_list_find(ev.data.l[2]);
				if (ti != NULL && !ti->is_embedded) {
					ti->is_embedded = True;
					LOG_TRACE(("embedding confirmed for icon 0x%x\n", ti->wid));
#ifdef DEBUG
					dump_tray_status();
#endif
				}
				tray_update_window_props();
				break;
			/* Dump tray status on request */
			case STALONE_TRAY_STATUS_REQUESTED:
				dump_tray_status();
				break;
			/* Find icon and scroll to it if necessary */
			case STALONE_TRAY_REMOTE_CONTROL:
				ti = icon_list_find(ev.window);
				if (ti == NULL) break;
				scrollbars_scroll_to(ti);
#if 0
				/* Quick hack */
				{
					Window icon = ev.window;
					int rc;
					int x = ev.data.l[3], y = ev.data.l[4], depth = 0, idummy, i;
					int btn = ev.data.l[2];
					Window win, root;
					unsigned int udummy, w, h;
					XGetGeometry(tray_data.dpy, icon, &root, 
							&idummy, &idummy, 
							&w, &h, &udummy, &udummy);
					LOG_TRACE(("wid=0x%x w=%d h=%d\n", icon, w, h));
					x = (x == REMOTE_CLICK_POS_DEFAULT) ? w / 2 : x;
					y = (y == REMOTE_CLICK_POS_DEFAULT) ? h / 2 : y;
					/* 3.2. Find subwindow to execute click on */
					win = x11_find_subwindow_at(tray_data.dpy, icon, &x, &y, depth);
					/* 3.3. Send mouse click(s) to target */
					LOG_TRACE(("wid=0x%x btn=%d x=%d y=%d\n", 
								win, btn, x, y));
#define SEND_BTN_EVENT(press, time) do { \
					x11_send_button(tray_data.dpy, /* dispslay */ \
							press, /* event type */ \
							win, /* target window */ \
							root, /* root window */ \
							time, /* time */ \
							btn, /* button */ \
							Button1Mask << (btn - 1), /* state mask */ \
							x, /* x coord (relative) */ \
							y); /* y coord (relative) */ \
				} while (0)
					for (i = 0; i < ev.data.l[0]; i++) {
						SEND_BTN_EVENT(1, x11_get_server_timestamp(tray_data.dpy, tray_data.tray));
						my_usleep(250);
						SEND_BTN_EVENT(0, x11_get_server_timestamp(tray_data.dpy, tray_data.tray));
					}
#undef SEND_BTN_EVENT
				}
#endif
				break;
			default:
				break;
		}
	}
#ifdef DEBUG
	if (ev.message_type == tray_data.xa_tray_opcode && !tray_data.is_active)
		LOG_TRACE(("ignoring _NET_SYSTEM_TRAY_OPCODE(%lu) message because tray is not active\n", tray_data.is_active));
#endif
}
示例#16
0
/*######################### attach_afd_status() #########################*/
int
attach_afd_status(int *fd, int timeout)
{
   int         local_fd,
               loop_counter,
               max_loops,
               *ptr_fd;
   char        *ptr,
               afd_status_file[MAX_PATH_LENGTH];
   struct stat stat_buf;

   if (fd == NULL)
   {
      ptr_fd = &local_fd;
   }
   else
   {
      ptr_fd = fd;
   }

   (void)strcpy(afd_status_file, p_work_dir);
   (void)strcat(afd_status_file, FIFO_DIR);
   (void)strcat(afd_status_file, STATUS_SHMID_FILE);
   loop_counter = 0;
   max_loops = (timeout * 100) / (AAS_SLEEP_INTERVAL / 10000);
   while ((*ptr_fd = coe_open(afd_status_file, O_RDWR)) < 0)
   {
      my_usleep(AAS_SLEEP_INTERVAL);
      loop_counter++;
      if (loop_counter > max_loops)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    _("Failed to open() `%s' : %s"),
                    afd_status_file, strerror(errno));
         return(INCORRECT);
      }
   }
   if (fstat(*ptr_fd, &stat_buf) == -1)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 _("Failed to fstat() `%s' : %s"),
                 afd_status_file, strerror(errno));
      (void)close(*ptr_fd);
      return(INCORRECT);
   }
   if (stat_buf.st_size != sizeof(struct afd_status))
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
#if SIZEOF_OFF_T == 4
                 _("Incorrect size, `%s' is %ld bytes and not %u bytes."),
#else
                 _("Incorrect size, `%s' is %lld bytes and not %u bytes."),
#endif
                 afd_status_file, (pri_off_t)stat_buf.st_size,
                 sizeof(struct afd_status));
      (void)close(*ptr_fd);
      return(INCORRECT);
   }
#ifdef HAVE_MMAP
   if ((ptr = mmap(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE), MAP_SHARED,
                   *ptr_fd, 0)) == (caddr_t) -1)
#else
   if ((ptr = mmap_emu(NULL, stat_buf.st_size, (PROT_READ | PROT_WRITE),
                       MAP_SHARED, afd_status_file, 0)) == (caddr_t) -1)
#endif
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 _("mmap() error : %s"), strerror(errno));
      (void)close(*ptr_fd);
      return(INCORRECT);
   }
   if (fd == NULL)
   {
      if (close(*ptr_fd) == -1)
      {
         system_log(DEBUG_SIGN, __FILE__, __LINE__,
                    _("close() error : %s"), strerror(errno));
      }
   }
   p_afd_status = (struct afd_status *)ptr;

   return(SUCCESS);
}
示例#17
0
// 数据库查询操作
int COracleDB::oracle_select( const char *sql, OracleResult *sql_result )
{
	int ret = DB_ERR_SUCCESS;

	if ( _handle == NULL )
		return DB_ERR_NOCONNECTION;

	ORACLE_HANDLE* handle = ( ORACLE_HANDLE* ) _handle;

	sb2 ind[MAX_COL];
	ub2 collen[MAX_COL];

	text * colbuf[MAX_COL];
	OCIDefine *defhp[MAX_COL];

	int i = 0;
	int status = 0;
	ub4 col_num = 0;

	OCIParam * colhp;

	while ( 1 ) {
		status = OCIStmtPrepare( handle->stmthp, handle->errhp, ( text * ) sql, ( ub4 ) strlen( ( const char * ) sql ),
				( ub4 ) OCI_NTV_SYNTAX, ( ub4 ) OCI_DEFAULT );
		if ( status != OCI_STILL_EXECUTING )
			break;

		my_usleep();
	}

	time_t t1 = time( NULL );

	while ( 1 ) {
		status = OCIStmtExecute( handle->svchp, handle->stmthp, handle->errhp, 0, 0, NULL, NULL, OCI_DEFAULT );

		if ( status != OCI_STILL_EXECUTING )
			break;

		if ( time( NULL ) - t1 > 60 ) {
			// timeout
			ret = DB_ERR_TIMEOUT;
			break;
		}

		my_usleep();

	}

	if ( ret == DB_ERR_SUCCESS && status != OCI_SUCCESS_WITH_INFO && status != OCI_SUCCESS ) {
		if ( status == OCI_NO_DATA ) {

		} else {
			int errcode = checkerr( handle->errhp, status, _errinfo, sql );

			if ( errcode == 1012 || errcode == 12705 || errcode == 3113 || errcode == 3114 || errcode == 12541
					|| errcode == 12547 ) {
				ret = DB_ERR_NOCONNECTION;
			} else {
				ret = DB_ERR_FAILED;
			}

		}
	}

	if ( ret != DB_ERR_SUCCESS )
		return ret;

	while ( 1 ) {
		status = OCIAttrGet( handle->stmthp, OCI_HTYPE_STMT, & col_num, 0, OCI_ATTR_PARAM_COUNT, handle->errhp );

		if ( status != OCI_STILL_EXECUTING )
			break;

		my_usleep();

	}

	if ( status ) {
		int errcode = checkerr( handle->errhp, status, _errinfo, sql );

		if ( errcode == 1012 || errcode == 12705 || errcode == 3113 || errcode == 3114 || errcode == 12541
				|| errcode == 12547 ) {
			ret = DB_ERR_NOCONNECTION;
		} else {
			ret = DB_ERR_FAILED;
		}
	}

	if ( ret != DB_ERR_SUCCESS )
		return ret;

	for ( i = 1; i <= (int)col_num ; i ++ ) {
		while ( 1 ) {
			status = OCIParamGet( handle->stmthp, OCI_HTYPE_STMT, handle->errhp, ( dvoid ** ) & colhp, i );

			if ( status != OCI_STILL_EXECUTING )
				break;

			my_usleep();
		}

		text *name;
		ub4 namelen = 128;

		while ( 1 ) {
			status = OCIAttrGet( ( dvoid* ) colhp, OCI_DTYPE_PARAM, & name, & namelen, OCI_ATTR_NAME, handle->errhp );

			if ( status != OCI_STILL_EXECUTING )
				break;

			my_usleep();
		}

		while ( 1 ) {
			status = OCIAttrGet( ( dvoid* ) colhp, OCI_DTYPE_PARAM, & collen[i - 1], 0, OCI_ATTR_DATA_SIZE,
					handle->errhp );

			if ( status != OCI_STILL_EXECUTING )
				break;

			my_usleep();
		}

		colbuf[i - 1] = ( text * ) malloc( ( int ) collen[i - 1] + 1 );

		while ( 1 ) {
			status = OCIDefineByPos( handle->stmthp, & defhp[i - 1], handle->errhp, i, ( ub1* ) colbuf[i - 1],
					collen[i - 1] + 1, SQLT_STR, & ind[i - 1], 0, ( ub2* ) 0, OCI_DEFAULT );

			if ( status != OCI_STILL_EXECUTING )
				break;

			my_usleep();
		}

	}

	int j = 0;

	t1 = time( NULL );

	int count = 0;

	// 设置取数据列数
	sql_result->SetColumn( col_num );

	while ( 1 ) {
		status = OCIStmtFetch( handle->stmthp, handle->errhp, 1, OCI_FETCH_NEXT, OCI_DEFAULT );
		if ( status == OCI_NO_DATA ) {
			break;
		}
		if ( status == OCI_STILL_EXECUTING ) {
			if ( time( NULL ) - t1 > 60 ) {
				ret = DB_ERR_TIMEOUT;
				break;
			}

			count ++;
			if ( count > 100 ) {
				my_usleep();
				count = 0;
			}
			continue;
		}

		int errcode = 0;
		errcode = checkerr( handle->errhp, status, _errinfo, sql );
		if ( 0 == errcode || 1406 == errcode ) {
			for ( i = 0; i < (int)col_num ; i ++ ) {
				if ( ind[i] == - 1 )
					colbuf[i][0] = '\0';

				sql_result->AddValue( j, i, ( const char * ) colbuf[i] );
			}
			j ++;

			t1 = time( NULL );

		} else {
			if ( errcode == 1012 || errcode == 12705 || errcode == 3113 || errcode == 3114 || errcode == 12541
					|| errcode == 12547 ) {
				ret = DB_ERR_NOCONNECTION;
			} else {
				ret = DB_ERR_FAILED;
			}

			break;
		}
	}

	// 释放所有列名称
	for ( i = 0; i < (int)col_num ; i ++ ) {
		if ( colbuf[i] )
			free( colbuf[i] );
	}

	return ret;
}
示例#18
0
/*############################ check_changes() ##########################*/
void
check_changes(FILE *p_data)
{
   static int          old_amg_status = PROC_INIT_VALUE,
                       old_archive_watch_status = PROC_INIT_VALUE,
                       old_fd_status = PROC_INIT_VALUE,
                       old_max_connections;
   static unsigned int old_sys_log_ec;
   static time_t       next_stat_time,
                       old_st_mtime;
   static char         old_receive_log_history[MAX_LOG_HISTORY],
                       old_sys_log_history[MAX_LOG_HISTORY],
                       old_trans_log_history[MAX_LOG_HISTORY];
   register int        i;
   time_t              now;

   if (check_fsa(YES, AFDD) == YES)
   {
      int loop_counter = 0,
          status;

retry_check:
      if (old_error_history != NULL)
      {
         FREE_RT_ARRAY(old_error_history);
         old_error_history = NULL;
      }

      if (check_fsa(YES, AFDD) == YES)
      {
         loop_counter++;
         if (loop_counter < 10)
         {
            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                       _("Hmm, FSA has changed again!"));
            my_usleep(500000L);
            goto retry_check;
         }
      }

      status = 0;
      while (p_afd_status->amg_jobs & WRITTING_JID_STRUCT)
      {
         (void)my_usleep(100000L);
         status++;
         if ((status > 1) && ((status % 100) == 0))
         {
            system_log(INFO_SIGN, __FILE__, __LINE__,
                       _("AFDD: Timeout arrived for waiting for AMG to finish writting to JID structure."));
         }
      }

      RT_ARRAY(old_error_history, no_of_hosts, ERROR_HISTORY_LENGTH,
               unsigned char);
      for (i = 0; i < no_of_hosts; i++)
      {
         if (fsa[i].real_hostname[0][0] == GROUP_IDENTIFIER)
         {
            (void)memset(old_error_history[i], 0, ERROR_HISTORY_LENGTH);
         }
         else
         {
            (void)memcpy(old_error_history[i], fsa[i].error_history,
                         ERROR_HISTORY_LENGTH);
         }
      }
      host_config_counter = (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT);
      show_host_list(p_data);
      show_job_list(p_data);
   }
   else
   {
      if (host_config_counter != (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT))
      {
         FREE_RT_ARRAY(old_error_history);
         RT_ARRAY(old_error_history, no_of_hosts, ERROR_HISTORY_LENGTH,
                  unsigned char);
         for (i = 0; i < no_of_hosts; i++)
         {
            if (fsa[i].real_hostname[0][0] == GROUP_IDENTIFIER)
            {
               (void)memset(old_error_history[i], 0, ERROR_HISTORY_LENGTH);
            }
            else
            {
               (void)memcpy(old_error_history[i], fsa[i].error_history,
                            ERROR_HISTORY_LENGTH);
            }
         }
         host_config_counter = (int)*(unsigned char *)((char *)fsa - AFD_WORD_OFFSET + SIZEOF_INT);
         show_host_list(p_data);
      }
   }
   if (check_fra(YES) == YES)
   {
      show_dir_list(p_data);
   }

   /*
    * It costs too much system performance to constantly stat()
    * the AFD_CONFIG file to see if the modification time has
    * changed. For this reason lets only stat() this file at a
    * reasonable interval of say STAT_INTERVAL seconds.
    */
   now = time(NULL);
   if (next_stat_time < now)
   {
      struct stat stat_buf;

      next_stat_time = now + STAT_INTERVAL;
      if (stat(afd_config_file, &stat_buf) == 0)
      {
         if (stat_buf.st_mtime != old_st_mtime)
         {
            char *buffer;

            old_st_mtime = stat_buf.st_mtime;
            if ((eaccess(afd_config_file, F_OK) == 0) &&
                (read_file_no_cr(afd_config_file, &buffer, YES, __FILE__, __LINE__) != INCORRECT))
            {
               int  max_connections = 0;
               char value[MAX_INT_LENGTH];

               if (get_definition(buffer,
                                  MAX_CONNECTIONS_DEF,
                                  value, MAX_INT_LENGTH) != NULL)
               {
                  max_connections = atoi(value);
               }
               if ((max_connections < 1) ||
                   (max_connections > MAX_CONFIGURABLE_CONNECTIONS))
               {
                  max_connections = MAX_DEFAULT_CONNECTIONS;
               }
               if (max_connections != old_max_connections)
               {
                  old_max_connections = max_connections;
                  (void)fprintf(p_data, "MC %d\r\n", old_max_connections);
               }
               free(buffer);
            }
         }
      }
      else
      {
         if (errno != ENOENT)
         {
            system_log(DEBUG_SIGN, __FILE__, __LINE__,
                      _("Failed to stat() `%s' : %s"),
                      afd_config_file, strerror(errno));
         }
      }
   }

   if (old_sys_log_ec != p_afd_status->sys_log_ec)
   {
      char buf[LOG_FIFO_SIZE + 1];

      old_sys_log_ec = p_afd_status->sys_log_ec;
      for (i = 0; i < LOG_FIFO_SIZE; i++)
      {
         buf[i] = p_afd_status->sys_log_fifo[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "SR %u %s\r\n", old_sys_log_ec, buf);
   }

   if (memcmp(old_receive_log_history, p_afd_status->receive_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_receive_log_history, p_afd_status->receive_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->receive_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "RH %s\r\n", buf);
   }
   if (memcmp(old_sys_log_history, p_afd_status->sys_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_sys_log_history, p_afd_status->sys_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->sys_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "SH %s\r\n", buf);
   }
   if (memcmp(old_trans_log_history, p_afd_status->trans_log_history,
              MAX_LOG_HISTORY) != 0)
   {
      char buf[MAX_LOG_HISTORY + 1];

      (void)memcpy(old_trans_log_history, p_afd_status->trans_log_history,
                   MAX_LOG_HISTORY);
      for (i = 0; i < MAX_LOG_HISTORY; i++)
      {
         buf[i] = p_afd_status->trans_log_history[i] + ' ';
      }
      buf[i] = '\0';
      (void)fprintf(p_data, "TH %s\r\n", buf);
   }
   for (i = 0; i < no_of_hosts; i++)
   {
      if (fsa[i].real_hostname[0][0] != GROUP_IDENTIFIER)
      {
         if (memcmp(old_error_history[i], fsa[i].error_history,
                    ERROR_HISTORY_LENGTH) != 0)
         {
            int k;

            (void)memcpy(old_error_history[i], fsa[i].error_history,
                         ERROR_HISTORY_LENGTH);
            (void)fprintf(p_data, "EL %d %d", i, old_error_history[i][0]);
            for (k = 1; k < ERROR_HISTORY_LENGTH; k++)
            {
               (void)fprintf(p_data, " %d", old_error_history[i][k]);
            }
            (void)fprintf(p_data, "\r\n");
         }
      }
   }

   /*
    * Check if status of any of the main process (AMG, FD and
    * archive_watch) have changed.
    */
   if (old_amg_status != p_afd_status->amg)
   {
      old_amg_status = p_afd_status->amg;
      (void)fprintf(p_data, "AM %d\r\n", old_amg_status);
   }
   if (old_fd_status != p_afd_status->fd)
   {
      old_fd_status = p_afd_status->fd;
      (void)fprintf(p_data, "FD %d\r\n", old_fd_status);
   }
   if (old_archive_watch_status != p_afd_status->archive_watch)
   {
      old_archive_watch_status = p_afd_status->archive_watch;
      (void)fprintf(p_data, "AW %d\r\n", old_archive_watch_status);
   }

   (void)fflush(p_data);

   return;
}
示例#19
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);
}
示例#20
0
文件: watch_dir.c 项目: hfs/afd
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$ watch_dir() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
   int           gotcha,
                 ret;
   off_t         filesize = 0;
   char          *ptr,
                 filename[MAX_FILENAME_LENGTH],
                 watch_dir[MAX_PATH_LENGTH];
   struct stat   stat_buf;
   struct dirent *dirp;
   DIR           *dp;

   if (argc == 2)
   {
      (void)my_strncpy(watch_dir, argv[1], MAX_PATH_LENGTH);
   }
   else
   {
      usage(argv[0]);
      exit(0);
   }

   if ((dp = opendir(watch_dir)) == NULL)
   {
      (void)fprintf(stderr, "ERROR   : Failed to opendir() %s : %s (%s %d)\n",
                    watch_dir, strerror(errno), __FILE__, __LINE__);
      exit(INCORRECT);
   }

   ptr = watch_dir + strlen(watch_dir);
   *ptr++ = '/';

   (void)printf("               File name                | File size |        File date\n");
   (void)printf("----------------------------------------+-----------+-------------------------\n");
   for (;;)
   {
      gotcha = 0;
      while ((dirp = readdir(dp)) != NULL)
      {
         if ((strcmp(dirp->d_name, ".") == 0) ||
             (strcmp(dirp->d_name, "..") == 0))
         {
            continue;
         }

         (void)strcpy(ptr, dirp->d_name);
         if (stat(watch_dir, &stat_buf) < 0)
         {
            (void)fprintf(stderr, "WARNING : Failed to stat() %s : %s (%s %d)\n",
                          watch_dir, strerror(errno), __FILE__, __LINE__);
            continue;
         }

         /* Make sure it's NOT a directory. */
         if (S_ISDIR(stat_buf.st_mode) == 0)
         {
            if (((ret = strcmp(dirp->d_name, filename)) != 0) ||
                ((ret == 0) && (filesize != stat_buf.st_size)))
            {
               (void)printf("%-39s |%10d | %s",
                            dirp->d_name, (int)stat_buf.st_size,
                            ctime(&stat_buf.st_mtime));
               (void)strcpy(filename, dirp->d_name);
               filesize = stat_buf.st_size;
               gotcha = 1;
            }
         }
      }

      rewinddir(dp);

      if (gotcha)
      {
         (void)printf("----------------------------------------+-----------+-------------------------\n");
      }

      (void)my_usleep(10000L);
   }

   exit(0);
}
示例#21
0
void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer * cb) {
	int pause = 0;
	int quit = 0;
	int bbp = buffered_before_play;
	int doCrossFade = 0;
	int crossFadeChunks = 0;
	int fadePosition;
	int nextChunk = -1;
	int test;
        int decodeWaitedOn = 0;
	char silence[CHUNK_SIZE] = { 0 };
	int previousMetadataChunk = -1;
	MetadataChunk currentMetadataChunk;
	int currentChunkSent = 1;
	int end;
	int next = -1;

//		fprintf(stderr,"In decode.c decodeParent func :\r\n");
	if(waitOnDecode(pc,dc,cb,&decodeWaitedOn)<0) return;

        pc->elapsedTime = 0;
	pc->state = PLAYER_STATE_PLAY;
	pc->play = 0;
	kill(getppid(),SIGUSR1);

	while(mpm_get_id(MPM_DECODE)>0 && cb->end-cb->begin<bbp && 
				cb->end!=buffered_chunks-1 &&
				dc->state!=DECODE_STATE_STOP) 
	{
		processDecodeInput();
		if(quit) return;
		playSilenceOrSleep();
	}

	while(!quit) {
		processDecodeInput();
                handleDecodeStart();
		handleMetadata(cb, pc, &previousMetadataChunk, 
				&currentChunkSent, &currentMetadataChunk);
		if(dc->state==DECODE_STATE_STOP && 
			pc->queueState==PLAYER_QUEUE_FULL &&
			pc->queueLockState==PLAYER_QUEUE_UNLOCKED) 
		{
			next = cb->end;
			dc->start = 1;
			pc->queueState = PLAYER_QUEUE_DECODE;
			kill(getppid(),SIGUSR1);
		}
		if(next>=0 && doCrossFade==0 && !dc->start && 
				dc->state!=DECODE_STATE_START) 
		{
			nextChunk = -1;
			if(isCurrentAudioFormat(&(cb->audioFormat))) {
				doCrossFade = 1;
				crossFadeChunks = 
				calculateCrossFadeChunks(pc,
                                        &(cb->audioFormat));
				if(!crossFadeChunks ||
						pc->crossFade>=dc->totalTime) 
				{
					doCrossFade = -1;
				}
			}
			else doCrossFade = -1;
		}

		/* copy thse to locale variables to prevent any potential
			race conditions and weirdness */
		end = cb->end;

		if(pause) my_usleep(10000);
		else if(cb->begin!=end && cb->begin!=next) {
			if(doCrossFade==1 && next>=0 &&
					((next>cb->begin && 
					(fadePosition=next-cb->begin)
					<=crossFadeChunks) || 
					(cb->begin>next &&
					(fadePosition=next-cb->begin+
					buffered_chunks)<=crossFadeChunks)))
			{
				if(nextChunk<0) {
					crossFadeChunks = fadePosition;
				}
				test = end;
				if(end < cb->begin) test+=buffered_chunks;
				nextChunk = cb->begin+crossFadeChunks;
				if(nextChunk<test) {
					if(nextChunk>=buffered_chunks)
					{
						nextChunk -=  buffered_chunks;  
					}
					pcm_mix(cb->chunks+cb->begin*CHUNK_SIZE,
							cb->chunks+nextChunk*
							CHUNK_SIZE,
							cb->chunkSize[
								cb->begin],
							cb->chunkSize[
								nextChunk],
							&(cb->audioFormat),
							((float)fadePosition)/
							crossFadeChunks);
					if(cb->chunkSize[nextChunk]>
							cb->chunkSize[cb->begin]
							)
					{
						cb->chunkSize[cb->begin]
								= cb->chunkSize
								[nextChunk];
					}
				}
				else {
					if(dc->state==DECODE_STATE_STOP)
					{
						doCrossFade = -1;
					}
					else continue;
				}
			}
			pc->elapsedTime = cb->times[cb->begin];
			pc->bitRate = cb->bitRate[cb->begin];
			pcm_volumeChange(cb->chunks+cb->begin*
				CHUNK_SIZE,
				cb->chunkSize[cb->begin],
				&(cb->audioFormat),
				pc->softwareVolume);
			if(playAudio(cb->chunks+cb->begin*CHUNK_SIZE,
				cb->chunkSize[cb->begin])<0) 
			{
				quit = 1;
			}
			if( cb->begin+1 >= buffered_chunks ) {
				cb->begin = 0;
			}
			else cb->begin++;
		}
		else if(next==cb->begin) {
			if(doCrossFade==1 && nextChunk>=0) {
				nextChunk = cb->begin+crossFadeChunks;
				test = cb->end;
				if(end < cb->begin) test+=buffered_chunks;
				if(nextChunk<test) {
					if(nextChunk>=buffered_chunks)
					{
						nextChunk -= buffered_chunks;
					}
					advanceOutputBufferTo(cb, pc, 
						&previousMetadataChunk,
						&currentChunkSent, 
						&currentMetadataChunk, 
						nextChunk);
				}	
			}
			while(pc->queueState==PLAYER_QUEUE_DECODE ||
					pc->queueLockState==PLAYER_QUEUE_LOCKED)
			{
				processDecodeInput();
				if(quit) {
					quitDecode(pc,dc);
					return;
				}
		fprintf(stderr,"In decode.c decodeParent while loop with my_usleep\r\n");
//				my_usleep(10000);
			}
			if(pc->queueState!=PLAYER_QUEUE_PLAY) {
				quit = 1;
				break;
			}
			else {
				next = -1;
				if(waitOnDecode(pc,dc,cb,&decodeWaitedOn)<0) {
                                        return;
                                }
				nextChunk = -1;
				doCrossFade = 0;
				crossFadeChunks = 0;
				pc->queueState = PLAYER_QUEUE_EMPTY;
				kill(getppid(),SIGUSR1);
			}
		}
		else if(mpm_get_id(MPM_DECODE)<=0 || 
				(dc->state==DECODE_STATE_STOP && !dc->start)) 
		{
			quit = 1;
			break;
		}
		else {
			if(playAudio(silence, CHUNK_SIZE) < 0) quit = 1;
		}
	}

	quitDecode(pc,dc);
}
示例#22
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);
}
/*################## get_remote_file_names_ftp_list() ###################*/
int
get_remote_file_names_ftp_list(off_t *file_size_to_retrieve,
                               int   *more_files_in_list)
{
   int              files_to_retrieve = 0,
                    i = 0;

   *file_size_to_retrieve = 0;
#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
   if ((*more_files_in_list == YES) ||
       (db.special_flag & DISTRIBUTED_HELPER_JOB) ||
       ((db.special_flag & OLD_ERROR_JOB) && (db.retries < 30) &&
        (fra[db.fra_pos].stupid_mode != YES) &&
        (fra[db.fra_pos].remove != YES)))
#else
   if (rl_fd == -1)
   {
try_attach_again:
      if (attach_ls_data(db.fra_pos, db.fsa_pos, db.special_flag, YES) == INCORRECT)
      {
         (void)ftp_quit();
         exit(INCORRECT);
      }
      if ((db.special_flag & DISTRIBUTED_HELPER_JOB) &&
          ((fra[db.fra_pos].stupid_mode == YES) ||
           (fra[db.fra_pos].remove == YES)))
      {
# ifdef LOCK_DEBUG
         if (rlock_region(rl_fd, LOCK_RETR_PROC,
                          __FILE__, __LINE__) == LOCK_IS_SET)
# else
         if (rlock_region(rl_fd, LOCK_RETR_PROC) == LOCK_IS_SET)
# endif
         {
            if (i == 0)
            {
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmm, lock is set. Assume ls_data file was just modified. Lets try it again. (job_no=%d fsa_pos=%d)",
                          (int)db.job_no, db.fsa_pos);
            }
            else
            {
               if (i == 30)
               {
                  trans_log(DEBUG_SIGN, __FILE__, __LINE__, NULL, NULL,
                            "Have waited %d seconds, but unable to get a lock. Terminating.",
                            (i * 100000) / 1000000);
                  (void)ftp_quit();
                  exit(SUCCESS);
               }
               my_usleep(100000L);
            }
            detach_ls_data(NO);
            i++;
            goto try_attach_again;
         }
      }
   }

   if ((*more_files_in_list == YES) ||
       (db.special_flag & DISTRIBUTED_HELPER_JOB) ||
       ((db.special_flag & OLD_ERROR_JOB) && (db.retries < 30)))
#endif
   {
#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
      if (rl_fd == -1)
      {
         if (attach_ls_data(db.fra_pos, db.fsa_pos, db.special_flag, YES) == INCORRECT)
         {
            (void)ftp_quit();
            exit(INCORRECT);
         }
      }
#endif
      *more_files_in_list = NO;
      for (i = 0; i < no_of_listed_files; i++)
      {
         if ((rl[i].retrieved == NO) && (rl[i].assigned == 0))
         {
#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
            if ((fra[db.fra_pos].stupid_mode == YES) ||
                (fra[db.fra_pos].remove == YES) ||
                ((files_to_retrieve < fra[db.fra_pos].max_copied_files) &&
                 (*file_size_to_retrieve < fra[db.fra_pos].max_copied_file_size)))
#else
            if ((files_to_retrieve < fra[db.fra_pos].max_copied_files) &&
                (*file_size_to_retrieve < fra[db.fra_pos].max_copied_file_size))
#endif
            {
               /* Lock this file in list. */
#ifdef LOCK_DEBUG
               if (lock_region(rl_fd, (off_t)(LOCK_RETR_FILE + i),
                               __FILE__, __LINE__) == LOCK_IS_NOT_SET)
#else
               if (lock_region(rl_fd, (off_t)(LOCK_RETR_FILE + i)) == LOCK_IS_NOT_SET)
#endif
               {
                  if ((fra[db.fra_pos].ignore_size == -1) ||
                      ((fra[db.fra_pos].gt_lt_sign & ISIZE_EQUAL) &&
                       (fra[db.fra_pos].ignore_size == rl[i].size)) ||
                      ((fra[db.fra_pos].gt_lt_sign & ISIZE_LESS_THEN) &&
                       (fra[db.fra_pos].ignore_size < rl[i].size)) ||
                      ((fra[db.fra_pos].gt_lt_sign & ISIZE_GREATER_THEN) &&
                       (fra[db.fra_pos].ignore_size > rl[i].size)))
                  {
                     if ((rl[i].got_date == NO) ||
                         (fra[db.fra_pos].ignore_file_time == 0))
                     {
                        files_to_retrieve++;
                        if ((fra[db.fra_pos].stupid_mode == APPEND_ONLY) &&
                            (rl[i].size > rl[i].prev_size))
                        {
                           *file_size_to_retrieve += (rl[i].size - rl[i].prev_size);
                        }
                        else
                        {
                           *file_size_to_retrieve += rl[i].size;
                        }
                        rl[i].assigned = (unsigned char)db.job_no + 1;
                     }
                     else
                     {
                        time_t diff_time;

                        diff_time = current_time - rl[i].file_mtime;
                        if (((fra[db.fra_pos].gt_lt_sign & IFTIME_EQUAL) &&
                             (fra[db.fra_pos].ignore_file_time == diff_time)) ||
                            ((fra[db.fra_pos].gt_lt_sign & IFTIME_LESS_THEN) &&
                             (fra[db.fra_pos].ignore_file_time < diff_time)) ||
                            ((fra[db.fra_pos].gt_lt_sign & IFTIME_GREATER_THEN) &&
                             (fra[db.fra_pos].ignore_file_time > diff_time)))
                        {
                           files_to_retrieve++;
                           if ((fra[db.fra_pos].stupid_mode == APPEND_ONLY) &&
                               (rl[i].size > rl[i].prev_size))
                           {
                              *file_size_to_retrieve += (rl[i].size - rl[i].prev_size);
                           }
                           else
                           {
                              *file_size_to_retrieve += rl[i].size;
                           }
                           rl[i].assigned = (unsigned char)db.job_no + 1;
                        }
                     }
#ifdef DEBUG_ASSIGNMENT
                     trans_log(DEBUG_SIGN, __FILE__, __LINE__, NULL, NULL,
# if SIZEOF_OFF_T == 4
                               "%s assigned %d: file_name=%s assigned=%d size=%ld",
# else
                               "%s assigned %d: file_name=%s assigned=%d size=%lld",
# endif
                               (fra[db.fra_pos].ls_data_alias[0] == '\0') ? fra[db.fra_pos].dir_alias : fra[db.fra_pos].ls_data_alias,
                               i, rl[i].file_name, (int)rl[i].assigned,
                               (pri_off_t)rl[i].size);
#endif /* DEBUG_ASSIGNMENT */
                  }
#ifdef LOCK_DEBUG
                  unlock_region(rl_fd, (off_t)(LOCK_RETR_FILE + i),
                                __FILE__, __LINE__);
#else
                  unlock_region(rl_fd, (off_t)(LOCK_RETR_FILE + i));
#endif
               }
            }
            else
            {
               *more_files_in_list = YES;
               break;
            }
         }
      }
   }
   else
   {
      unsigned int     files_deleted = 0,
                       list_length = 0;
      int              gotcha,
                       j,
                       k,
                       nfg,           /* Number of file mask. */
                       status,
                       type;
      char             file_name[MAX_FILENAME_LENGTH + 1],
                       *list = NULL,
                       *p_end,
                       *p_mask,
                       *p_start;
      time_t           file_mtime;
      off_t            file_size,
                       file_size_deleted = 0,
                       list_size = 0;
      struct ftpparse  fp;
      struct file_mask *fml = NULL;
      struct tm        *p_tm;

      /*
       * Get a directory listing from the remote site so we can see
       * what files are there.
       */
#ifdef WITH_SSL
      if (db.auth == BOTH)
      {
         type = LIST_CMD | BUFFERED_LIST | ENCRYPT_DATA;
      }
      else
      {
#endif
         type = LIST_CMD | BUFFERED_LIST;
#ifdef WITH_SSL
      }
#endif

      if ((status = ftp_list(db.mode_flag, type, &list)) != SUCCESS)
      {
         trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, msg_str,
                   "Failed to send LIST command (%d).", status);
         (void)ftp_quit();
         exit(LIST_ERROR);
      }

      if (list != NULL)
      {
         /* Get all file masks for this directory. */
         if ((j = read_file_mask(fra[db.fra_pos].dir_alias, &nfg, &fml)) == INCORRECT)
         {
            if (j == LOCKFILE_NOT_THERE)
            {
               system_log(ERROR_SIGN, __FILE__, __LINE__,
                          "Failed to set lock in file masks for %s, because the file is not there.",
                          fra[db.fra_pos].dir_alias);
            }
            else if (j == LOCK_IS_SET)
                 {
                    system_log(ERROR_SIGN, __FILE__, __LINE__,
                               "Failed to get the file masks for %s, because lock is already set",
                               fra[db.fra_pos].dir_alias);
                 }
                 else
                 {
                    system_log(ERROR_SIGN, __FILE__, __LINE__,
                               "Failed to get the file masks for %s. (%d)",
                               fra[db.fra_pos].dir_alias, j);
                 }
            if (fml != NULL)
            {
               free(fml);
            }
            (void)ftp_quit();
            exit(INCORRECT);
         }

#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
         if ((fra[db.fra_pos].stupid_mode == YES) ||
             (fra[db.fra_pos].remove == YES))
         {
            if (reset_ls_data(db.fra_pos) == INCORRECT)
            {
               (void)ftp_quit();
               exit(INCORRECT);
            }
         }
         else
         {
            if (rl_fd == -1)
            {
               if (attach_ls_data(db.fra_pos, db.fsa_pos, db.special_flag,
                                  YES) == INCORRECT)
               {
                  (void)ftp_quit();
                  exit(INCORRECT);
               }
            }
         }
#else
         if (rl_fd == -1)
         {
            if (attach_ls_data(db.fra_pos, db.fsa_pos, db.special_flag,
                               YES) == INCORRECT)
            {
               (void)ftp_quit();
               exit(INCORRECT);
            }
         }
         if ((fra[db.fra_pos].stupid_mode == YES) ||
             (fra[db.fra_pos].remove == YES))
         {
            /*
             * If all files from the previous listing have been
             * collected, lets reset the ls_data structure or otherwise
             * it keeps on growing forever.
             */
# ifdef LOCK_DEBUG
            if (lock_region(rl_fd, LOCK_RETR_PROC,
                            __FILE__, __LINE__) == LOCK_IS_NOT_SET)
# else
            if (lock_region(rl_fd, LOCK_RETR_PROC) == LOCK_IS_NOT_SET)
# endif
            {
               if (reset_ls_data(db.fra_pos) == INCORRECT)
               {
                  (void)ftp_quit();
                  exit(INCORRECT);
               }
            }
# ifdef LOCK_DEBUG
            unlock_region(rl_fd, LOCK_RETR_PROC, __FILE__, __LINE__);
# else
            unlock_region(rl_fd, LOCK_RETR_PROC);
# endif
         }
#endif

         if ((fra[db.fra_pos].ignore_file_time != 0) ||
             (fra[db.fra_pos].delete_files_flag & UNKNOWN_FILES))
         {
            /* Note: FTP returns GMT so we need to convert this to GMT! */
            current_time = time(NULL);
            p_tm = gmtime(&current_time);
            current_time = mktime(p_tm);
         }

         /*
          * Evaluate the list from the LIST command.
          */
         p_end = list;
         do
         {
            p_start = p_end;
            while ((*p_end != '\r') && (*p_end != '\n') && (*p_end != '\0'))
            {
               p_end++;
            }

            if ((ftpparse(&fp, &file_size, &file_mtime, p_start, p_end - p_start) == 1) &&
                ((fp.flagtryretr == 1) &&
                 ((fp.name[0] != '.') ||
                  (fra[db.fra_pos].dir_flag & ACCEPT_DOT_FILES))))
            {
               list_length++;
               list_size += file_size;

               if (fp.namelen < MAX_FILENAME_LENGTH)
               {
                  /* Store file name */
                  (void)memcpy(file_name, fp.name, fp.namelen);
                  file_name[fp.namelen] = '\0';

                  if (fra[db.fra_pos].dir_flag == ALL_DISABLED)
                  {
                     delete_remote_file(FTP, file_name, fp.namelen,
#ifdef _DELETE_LOG
                                        DELETE_HOST_DISABLED,
#endif
                                        &files_deleted,
                                        &file_size_deleted, file_size);
                  }
                  else
                  {
                     gotcha = NO;
                     for (k = 0; k < nfg; k++)
                     {
                        p_mask = fml[k].file_list;
                        for (j = 0; j < fml[k].fc; j++)
                        {
                           if ((status = pmatch(p_mask, file_name, NULL)) == 0)
                           {
                              if (check_list(file_name, file_size, file_mtime,
                                             &files_to_retrieve,
                                             file_size_to_retrieve,
                                             more_files_in_list) == 0)
                              {
                                 gotcha = YES;
                              }
                              else
                              {
                                 gotcha = NEITHER;
                              }
                              break;
                           }
                           else if (status == 1)
                                {
                                   /* This file is definitly NOT wanted! */
                                   /* Lets skip the rest of this group.  */
                                   break;
                                }
#ifdef SHOW_FILTER_MISSES
                           if ((status == -1) ||
                               (fsa->debug > NORMAL_MODE))
                           {
                              char tmp_mask[MAX_FILENAME_LENGTH];

                              if (expand_filter(p_mask, tmp_mask, time(NULL)) == YES)
                              {
                                 trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                                              "%s (%s) not fitting %s",
                                              p_mask, tmp_mask, file_name);
                              }
                              else
                              {
                                 trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                                              "%s not fitting %s",
                                              p_mask, file_name);
                              }
                           }
#endif
                           NEXT(p_mask);
                        }
                        if ((gotcha == YES) || (gotcha == NEITHER))
                        {
                           break;
                        }
                     }

                     if ((gotcha == NO) && (status != 0) &&
                         (fra[db.fra_pos].delete_files_flag & UNKNOWN_FILES))
                     {
                        time_t diff_time = current_time - file_mtime;

                        if ((fra[db.fra_pos].unknown_file_time == -2) ||
                            ((diff_time > fra[db.fra_pos].unknown_file_time) &&
                             (diff_time > DEFAULT_TRANSFER_TIMEOUT)))
                        {
                           delete_remote_file(FTP, file_name, fp.namelen,
#ifdef _DELETE_LOG
                                              DEL_UNKNOWN_FILE,
#endif
                                              &files_deleted,
                                              &file_size_deleted, file_size);
                        }
                     }
                  }
               }
               else
               {
                  (void)memcpy(file_name, fp.name, MAX_FILENAME_LENGTH);
                  file_name[MAX_FILENAME_LENGTH] = '\0';
                  trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                            "Remote file name `%s' is to long, it may only be %d bytes long.",
                            file_name, MAX_FILENAME_LENGTH);
               }
            }
            while ((*p_end == '\r') || (*p_end == '\n'))
            {
               p_end++;
            }
         } while (*p_end != '\0');

         free(list);

         /* Free file mask list. */
         for (i = 0; i < nfg; i++)
         {
            free(fml[i].file_list);
         }
         free(fml);
      }

      if (files_deleted > 0)
      {
         trans_log(DEBUG_SIGN, NULL, 0, NULL, NULL,
#if SIZEOF_OFF_T == 4
                   "%d files %ld bytes found for retrieving %s[%u files with %ld bytes in %s (deleted %u files with %ld bytes)]. @%x",
#else
                   "%d files %lld bytes found for retrieving %s[%u files with %lld bytes in %s (deleted %u files with %lld bytes)]. @%x",
#endif
                   files_to_retrieve, (pri_off_t)(*file_size_to_retrieve),
                   (*more_files_in_list == YES) ? "(+) " : "",
                   list_length, (pri_off_t)list_size,
                   (db.target_dir[0] == '\0') ? "home dir" : db.target_dir,
                   files_deleted, (pri_off_t)file_size_deleted, db.id.dir);
      }
      else
      {
         trans_log(DEBUG_SIGN, NULL, 0, NULL, NULL,
#if SIZEOF_OFF_T == 4
                   "%d files %ld bytes found for retrieving %s[%u files with %ld bytes in %s]. @%x",
#else
                   "%d files %lld bytes found for retrieving %s[%u files with %lld bytes in %s]. @%x",
#endif
                   files_to_retrieve, (pri_off_t)(*file_size_to_retrieve),
                   (*more_files_in_list == YES) ? "(+) " : "",
                   list_length, (pri_off_t)list_size,
                   (db.target_dir[0] == '\0') ? "home dir" : db.target_dir,
                   db.id.dir);
      }

      /*
       * Remove all files from the remote_list structure that are not
       * in the current buffer.
       */
      if ((fra[db.fra_pos].stupid_mode != YES) &&
          (fra[db.fra_pos].remove == NO))
      {
         int    files_removed = 0,
                i;
         size_t move_size;

         for (i = 0; i < (no_of_listed_files - files_removed); i++)
         {
            if (rl[i].in_list == NO)
            {
               int j = i;

               while ((rl[j].in_list == NO) &&
                      (j < (no_of_listed_files - files_removed)))
               {
                  j++;
               }
               if (j != (no_of_listed_files - files_removed))
               {
                  move_size = (no_of_listed_files - files_removed - j) *
                              sizeof(struct retrieve_list);
                  (void)memmove(&rl[i], &rl[j], move_size);
               }
               files_removed += (j - i);
            }
         }

         if (files_removed > 0)
         {
            int    current_no_of_listed_files = no_of_listed_files;
            size_t new_size,
                   old_size;

            no_of_listed_files -= files_removed;
            if (no_of_listed_files < 0)
            {
               system_log(DEBUG_SIGN, __FILE__, __LINE__,
                          "Hmmm, no_of_listed_files = %d", no_of_listed_files);
               no_of_listed_files = 0;
            }
            if (no_of_listed_files == 0)
            {
               new_size = (RETRIEVE_LIST_STEP_SIZE * sizeof(struct retrieve_list)) +
                          AFD_WORD_OFFSET;
            }
            else
            {
               new_size = (((no_of_listed_files / RETRIEVE_LIST_STEP_SIZE) + 1) *
                           RETRIEVE_LIST_STEP_SIZE * sizeof(struct retrieve_list)) +
                          AFD_WORD_OFFSET;
            }
            old_size = (((current_no_of_listed_files / RETRIEVE_LIST_STEP_SIZE) + 1) *
                        RETRIEVE_LIST_STEP_SIZE * sizeof(struct retrieve_list)) +
                       AFD_WORD_OFFSET;

            if (old_size != new_size)
            {
               char *ptr;

               ptr = (char *)rl - AFD_WORD_OFFSET;
#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
               if ((fra[db.fra_pos].stupid_mode == YES) ||
                   (fra[db.fra_pos].remove == YES))
               {
                  if ((ptr = realloc(ptr, new_size)) == NULL)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "realloc() error : %s", strerror(errno));
                     (void)ftp_quit();
                     exit(INCORRECT);
                  }
               }
               else
               {
#endif
                  if ((ptr = mmap_resize(rl_fd, ptr, new_size)) == (caddr_t) -1)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "mmap_resize() error : %s", strerror(errno));
                     (void)ftp_quit();
                     exit(INCORRECT);
                  }
                  rl_size = new_size;
#ifdef DO_NOT_PARALLELIZE_ALL_FETCH
               }
#endif
               ptr += AFD_WORD_OFFSET;
               rl = (struct retrieve_list *)ptr;
            }
            *(int *)((char *)rl - AFD_WORD_OFFSET) = no_of_listed_files;
         }
      }
   }

   return(files_to_retrieve);
}
示例#24
0
文件: sf_wmo.c 项目: holger24/AFD
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ main() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
int
main(int argc, char *argv[])
{
#ifdef _WITH_BURST_2
   int              cb2_ret;
#endif
   int              current_toggle,
                    exit_status = TRANSFER_SUCCESS,
                    j,
                    fd,
                    status,
                    loops,
                    rest,
                    blocksize,
                    *wmo_counter,
                    wmo_counter_fd = -1;
#ifdef WITH_ARCHIVE_COPY_INFO
   unsigned int     archived_copied = 0;
#endif
   off_t            no_of_bytes;
   time_t           connected,
#ifdef _WITH_BURST_2
                    diff_time,
#endif
                    end_transfer_time_file,
                    start_transfer_time_file = 0,
                    last_update_time,
                    now;
#ifdef _OUTPUT_LOG
   clock_t          end_time = 0,
                    start_time = 0;
   struct tms       tmsdummy;
#endif
   char             *p_file_name_buffer,
                    *buffer,
                    fullname[MAX_PATH_LENGTH + 1],
                    file_path[MAX_PATH_LENGTH];
   clock_t          clktck;
   struct stat      stat_buf;
   struct job       *p_db;
#ifdef SA_FULLDUMP
   struct sigaction sact;
#endif

   CHECK_FOR_VERSION(argc, argv);

#ifdef SA_FULLDUMP
   /*
    * When dumping core sure we do a FULL core dump!
    */
   sact.sa_handler = SIG_DFL;
   sact.sa_flags = SA_FULLDUMP;
   sigemptyset(&sact.sa_mask);
   if (sigaction(SIGSEGV, &sact, NULL) == -1)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "sigaction() error : %s", strerror(errno));
      exit(INCORRECT);
   }
#endif

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

   /* Initialise variables. */
   local_file_counter = 0;
   files_to_send = init_sf(argc, argv, file_path, WMO_FLAG);
   p_db = &db;
   if ((clktck = sysconf(_SC_CLK_TCK)) <= 0)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "Could not get clock ticks per second : %s",
                 strerror(errno));
      exit(INCORRECT);
   }
   if (fsa->trl_per_process > 0)
   {
      if (fsa->trl_per_process < fsa->block_size)
      {
         blocksize = fsa->trl_per_process;
      }
      else
      {
         blocksize = fsa->block_size;
      }
   }
   else
   {
      blocksize = fsa->block_size;
   }

   if ((signal(SIGINT, sig_kill) == 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) ||
       (signal(SIGPIPE, SIG_IGN) == SIG_ERR))
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "signal() error : %s", strerror(errno));
      exit(INCORRECT);
   }

   /* Now determine the real hostname. */
   if (db.toggle_host == YES)
   {
      if (fsa->host_toggle == HOST_ONE)
      {
         (void)strcpy(db.hostname, fsa->real_hostname[HOST_TWO - 1]);
         current_toggle = HOST_TWO;
      }
      else
      {
         (void)strcpy(db.hostname, fsa->real_hostname[HOST_ONE - 1]);
         current_toggle = HOST_ONE;
      }
   }
   else
   {
      (void)strcpy(db.hostname,
                   fsa->real_hostname[(int)(fsa->host_toggle - 1)]);
      current_toggle = (int)fsa->host_toggle;
   }

   /* Connect to remote WMO-server. */
#ifdef FTP_CTRL_KEEP_ALIVE_INTERVAL
   if (fsa->protocol_options & AFD_TCP_KEEPALIVE)
   {
      timeout_flag = transfer_timeout - 5;
      if (timeout_flag < MIN_KEEP_ALIVE_INTERVAL)
      {
         timeout_flag = MIN_KEEP_ALIVE_INTERVAL;
      }
   }
#else
   timeout_flag = OFF;
#endif
   if ((status = wmo_connect(db.hostname, db.port, db.sndbuf_size)) != SUCCESS)
   {
      trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                "WMO connection to <%s> at port %d failed (%d).",
                db.hostname, db.port, status);
      exit(eval_timeout(CONNECT_ERROR));
   }
   else
   {
      if (fsa->debug > NORMAL_MODE)
      {
         trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                      "Connected to port %d.", db.port);
      }
   }
   connected = time(NULL);

   /* Inform FSA that we have finished connecting and */
   /* will now start to transfer data.                */
   if (gsf_check_fsa(p_db) != NEITHER)
   {
#ifdef LOCK_DEBUG
      lock_region_w(fsa_fd, db.lock_offset + LOCK_CON, __FILE__, __LINE__);
#else
      lock_region_w(fsa_fd, db.lock_offset + LOCK_CON);
#endif
      fsa->job_status[(int)db.job_no].connect_status = WMO_ACTIVE;
      fsa->job_status[(int)db.job_no].no_of_files = files_to_send;
      fsa->connections += 1;
#ifdef LOCK_DEBUG
      unlock_region(fsa_fd, db.lock_offset + LOCK_CON, __FILE__, __LINE__);
#else
      unlock_region(fsa_fd, db.lock_offset + LOCK_CON);
#endif
   }

   /* Allocate buffer to read data from the source file. */
   if ((buffer = malloc(blocksize + 1 + 4 /* For bulletin end. */)) == NULL)
   {
      system_log(ERROR_SIGN, __FILE__, __LINE__,
                 "malloc() error : %s", strerror(errno));
      exit(ALLOC_ERROR);
   }

   if (db.special_flag & WITH_SEQUENCE_NUMBER)
   {
      char counter_file_name[MAX_FILENAME_LENGTH];

      (void)snprintf(counter_file_name, MAX_FILENAME_LENGTH, "/%s.%d", db.host_alias, db.port);
      if ((wmo_counter_fd = open_counter_file(counter_file_name, &wmo_counter)) < 0)
      {
         system_log(ERROR_SIGN, __FILE__, __LINE__,
                    "Failed to open counter file `%s'.", counter_file_name);
      }
   }

#ifdef _WITH_BURST_2
   do
   {
      if (burst_2_counter > 0)
      {
         if (fsa->debug > NORMAL_MODE)
         {
            trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL, "WMO Bursting.");
         }
      }
#endif

      /* Send all files. */
      p_file_name_buffer = file_name_buffer;
      p_file_size_buffer = file_size_buffer;
      last_update_time = time(NULL);
      local_file_size = 0;
      for (files_send = 0; files_send < files_to_send; files_send++)
      {
         (void)snprintf(fullname, MAX_PATH_LENGTH + 1, "%s/%s",
                        file_path, p_file_name_buffer);

         if (*p_file_size_buffer > 0)
         {
            int end_length = 0,
                header_length = 0,
                length_type_indicator = 10;

            if (gsf_check_fsa(p_db) != NEITHER)
            {
               fsa->job_status[(int)db.job_no].file_size_in_use = *p_file_size_buffer;
               (void)strcpy(fsa->job_status[(int)db.job_no].file_name_in_use,
                            p_file_name_buffer);
            }

            /* Open local file. */
#ifdef O_LARGEFILE
            if ((fd = open(fullname, O_RDONLY | O_LARGEFILE)) == -1)
#else
            if ((fd = open(fullname, O_RDONLY)) == -1)
#endif
            {
               trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                         "Failed to open local file `%s' : %s",
                         fullname, strerror(errno));
               wmo_quit();
               exit(OPEN_LOCAL_ERROR);
            }
            if (fsa->debug > NORMAL_MODE)
            {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Open local file `%s'", fullname);
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               start_time = times(&tmsdummy);
            }
#endif

            /*
             * When the contents does not contain a bulletin header
             * it must be stored in the file name.
             */
            if (db.special_flag & FILE_NAME_IS_HEADER)
            {
               int  space_count;
               char *ptr = p_file_name_buffer;

               buffer[length_type_indicator] = 1; /* SOH */
               buffer[length_type_indicator + 1] = '\015'; /* CR */
               buffer[length_type_indicator + 2] = '\015'; /* CR */
               buffer[length_type_indicator + 3] = '\012'; /* LF */
               header_length = 4;
               space_count = 0;

               if (wmo_counter_fd > 0)
               {
                  if (next_counter(wmo_counter_fd, wmo_counter,
                                   MAX_WMO_COUNTER) < 0)
                  {
                     close_counter_file(wmo_counter_fd, &wmo_counter);
                     wmo_counter_fd = -1;
                     wmo_counter = NULL;
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "Failed to get next WMO counter.");
                  }
                  else
                  {
                     if (*wmo_counter < 10)
                     {
                        buffer[length_type_indicator + header_length] = '0';
                        buffer[length_type_indicator + header_length + 1] = '0';
                        buffer[length_type_indicator + header_length + 2] = *wmo_counter + '0';
                     }
                     else if (*wmo_counter < 100)
                          {
                             buffer[length_type_indicator + header_length] = '0';
                             buffer[length_type_indicator + header_length + 1] = (*wmo_counter / 10) + '0';
                             buffer[length_type_indicator + header_length + 2] = (*wmo_counter % 10) + '0';
                          }
                     else if (*wmo_counter < 1000)
                          {
                             buffer[length_type_indicator + header_length] = ((*wmo_counter / 100) % 10) + '0';
                             buffer[length_type_indicator + header_length + 1] = ((*wmo_counter / 10) % 10) + '0';
                             buffer[length_type_indicator + header_length + 2] = (*wmo_counter % 10) + '0';
                          }
                     buffer[length_type_indicator + header_length + 3] = '\015'; /* CR */
                     buffer[length_type_indicator + header_length + 4] = '\015'; /* CR */
                     buffer[length_type_indicator + header_length + 5] = '\012'; /* LF */
                     header_length += 6;
                  }
               } /* if (wmo_counter_fd > 0) */

               for (;;)
               {
                  while ((*ptr != '_') && (*ptr != '-') && (*ptr != ' ') &&
                         (*ptr != '\0') && (*ptr != '.') && (*ptr != ';'))
                  {
                     buffer[length_type_indicator + header_length] = *ptr;
                     header_length++; ptr++;
                  }
                  if ((*ptr == '\0') || (*ptr == '.') || (*ptr == ';'))
                  {
                     break;
                  }
                  else
                  {
                     if (space_count == 2)
                     {
                        if ((isalpha((int)(*(ptr + 1)))) &&
                            (isalpha((int)(*(ptr + 2)))) &&
                            (isalpha((int)(*(ptr + 3)))))
                        {
                           buffer[length_type_indicator + header_length] = ' ';
                           buffer[length_type_indicator + header_length + 1] = *(ptr + 1);
                           buffer[length_type_indicator + header_length + 2] = *(ptr + 2);
                           buffer[length_type_indicator + header_length + 3] = *(ptr + 3);
                           header_length += 4;
                        }
                        break;
                     }
                     else
                     {
                        buffer[length_type_indicator + header_length] = ' ';
                        header_length++; ptr++; space_count++;
                     }
                  }
               } /* for (;;) */
               buffer[length_type_indicator + header_length] = '\015'; /* CR */
               buffer[length_type_indicator + header_length + 1] = '\015'; /* CR */
               buffer[length_type_indicator + header_length + 2] = '\012'; /* LF */
               header_length += 3;
               end_length = 4;
            }

            /* Read (local) and write (remote) file. */
            no_of_bytes = 0;
            loops = (length_type_indicator + header_length + *p_file_size_buffer) / blocksize;
            rest = (length_type_indicator + header_length + *p_file_size_buffer) % blocksize;

            if ((db.special_flag & FILE_NAME_IS_HEADER) && (rest == 0))
            {
               loops--;
               rest = blocksize;
            }

            /* Write length and type indicator. */
            (void)snprintf(buffer, 9, "%08lu",
                           (unsigned long)(*p_file_size_buffer + header_length + end_length));
            if (db.transfer_mode == 'I')
            {
               buffer[length_type_indicator - 2] = 'B';
               buffer[length_type_indicator - 1] = 'I';
            }
            else if (db.transfer_mode == 'A')
                 {
                    buffer[length_type_indicator - 2] = 'A';
                    buffer[length_type_indicator - 1] = 'N';
                 }
                 else
                 {
                    buffer[length_type_indicator - 2] = 'F';
                    buffer[length_type_indicator - 1] = 'X';
                 }

            if (fsa->trl_per_process > 0)
            {
               init_limit_transfer_rate();
            }
            if (fsa->protocol_options & TIMEOUT_TRANSFER)
            {
               start_transfer_time_file = time(NULL);
            }

            for (;;)
            {
               for (j = 0; j < loops; j++)
               {
#ifdef _SIMULATE_SLOW_TRANSFER
                  (void)sleep(_SIMULATE_SLOW_TRANSFER);
#endif
                  if ((status = read(fd,
                                     (buffer + length_type_indicator + header_length),
                                     (blocksize - length_type_indicator - header_length))) != (blocksize - length_type_indicator - header_length))
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Could not read() local file `%s' : %s",
                               fullname, strerror(errno));
                     wmo_quit();
                     exit(READ_LOCAL_ERROR);
                  }
                  if ((status = wmo_write(buffer, blocksize)) != SUCCESS)
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Failed to write block from file `%s' to remote port %d [%d].",
                               p_file_name_buffer, db.port, status);
                     wmo_quit();
                     exit(eval_timeout(WRITE_REMOTE_ERROR));
                  }
                  if (fsa->trl_per_process > 0)
                  {
                     limit_transfer_rate(blocksize, fsa->trl_per_process,
                                         clktck);
                  }

                  no_of_bytes += blocksize;

                  if (gsf_check_fsa(p_db) != NEITHER)
                  {
                     fsa->job_status[(int)db.job_no].file_size_in_use_done = no_of_bytes;
                     fsa->job_status[(int)db.job_no].file_size_done += blocksize;
                     fsa->job_status[(int)db.job_no].bytes_send += blocksize;
                     if (fsa->protocol_options & TIMEOUT_TRANSFER)
                     {
                        end_transfer_time_file = time(NULL);
                        if (end_transfer_time_file < start_transfer_time_file)
                        {
                           start_transfer_time_file = end_transfer_time_file;
                        }
                        else
                        {
                           if ((end_transfer_time_file - start_transfer_time_file) > transfer_timeout)
                           {
                              trans_log(INFO_SIGN, __FILE__, __LINE__, NULL, NULL,
#if SIZEOF_TIME_T == 4
                                        "Transfer timeout reached for `%s' after %ld seconds.",
#else
                                        "Transfer timeout reached for `%s' after %lld seconds.",
#endif
                                        fsa->job_status[(int)db.job_no].file_name_in_use,
                                        (pri_time_t)(end_transfer_time_file - start_transfer_time_file));
                              wmo_quit();
                              exitflag = 0;
                              exit(STILL_FILES_TO_SEND);
                           }
                        }
                     }
                  }
                  if (length_type_indicator > 0)
                  {
                     length_type_indicator = 0;
                     header_length = 0;
                  }
               } /* for (j = 0; j < loops; j++) */

               if (rest > 0)
               {
                  if ((status = read(fd,
                                     (buffer + length_type_indicator + header_length),
                                     (rest - length_type_indicator - header_length))) != (rest - length_type_indicator - header_length))
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Could not read() local file `%s' : %s",
                               fullname, strerror(errno));
                     wmo_quit();
                     exit(READ_LOCAL_ERROR);
                  }
                  if (end_length == 4)
                  {
                     buffer[rest] = '\015';
                     buffer[rest + 1] = '\015';
                     buffer[rest + 2] = '\012';
                     buffer[rest + 3] = 3;  /* ETX */
                  }
                  if ((status = wmo_write(buffer, rest + end_length)) != SUCCESS)
                  {
                     trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                               "Failed to write rest of file to remote port %d [%d].",
                               p_file_name_buffer, db.port, status);
                     wmo_quit();
                     exit(eval_timeout(WRITE_REMOTE_ERROR));
                  }
                  if (fsa->trl_per_process > 0)
                  {
                     limit_transfer_rate(rest + end_length,
                                         fsa->trl_per_process, clktck);
                  }

                  no_of_bytes += rest + end_length;

                  if (gsf_check_fsa(p_db) != NEITHER)
                  {
                     fsa->job_status[(int)db.job_no].file_size_in_use_done = no_of_bytes;
                     fsa->job_status[(int)db.job_no].file_size_done += rest;
                     fsa->job_status[(int)db.job_no].bytes_send += rest;
                  }
               }

               /*
                * Since there are always some users sending files to the
                * AFD not in dot notation, lets check here if this is really
                * the EOF.
                * If not lets continue so long until we hopefully have reached
                * the EOF.
                * NOTE: This is NOT a fool proof way. There must be a better
                *       way!
                */
               if (fstat(fd, &stat_buf) == -1)
               {
                  (void)rec(transfer_log_fd, DEBUG_SIGN,
                            "Hmmm. Failed to stat() `%s' : %s (%s %d)\n",
                            fullname, strerror(errno), __FILE__, __LINE__);
                  break;
               }
               else
               {
                  if (stat_buf.st_size > *p_file_size_buffer)
                  {
                     char sign[LOG_SIGN_LENGTH];

                     if (db.special_flag & SILENT_NOT_LOCKED_FILE)
                     {
                        (void)memcpy(sign, DEBUG_SIGN, LOG_SIGN_LENGTH);
                     }
                     else
                     {
                        (void)memcpy(sign, WARN_SIGN, LOG_SIGN_LENGTH);
                     }

                     loops = (stat_buf.st_size - *p_file_size_buffer) / blocksize;
                     rest = (stat_buf.st_size - *p_file_size_buffer) % blocksize;
                     *p_file_size_buffer = stat_buf.st_size;

                     /*
                      * Give a warning in the receive log, so some action
                      * can be taken against the originator.
                      */
                     receive_log(sign, __FILE__, __LINE__, 0L, db.id.job,
                                 "File `%s' for host %s was DEFINITELY send without any locking. #%x",
                                 p_file_name_buffer, fsa->host_dsp_name, db.id.job);
                  }
                  else
                  {
                     break;
                  }
               }
            } /* for (;;) */

            if (db.special_flag & WMO_CHECK_ACKNOWLEDGE)
            {
               int ret;

               if ((ret = wmo_check_reply()) == INCORRECT)
               {
                  trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                            "Failed to receive reply from port %d for file %s.",
                            db.port, p_file_name_buffer);
                  wmo_quit();
                  exit(eval_timeout(CHECK_REPLY_ERROR));
               }
               else if (ret == NEGATIV_ACKNOWLEDGE)
                    {
                       trans_log(ERROR_SIGN, __FILE__, __LINE__, NULL, NULL,
                                 "Received negative acknowledge from remote port %d for file %s.",
                                 db.port, p_file_name_buffer);
                    }
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               end_time = times(&tmsdummy);
            }
#endif

            /* Close local file. */
            if (close(fd) == -1)
            {
               (void)rec(transfer_log_fd, WARN_SIGN,
                         "%-*s[%d]: Failed to close() local file %s : %s (%s %d)\n",
                         MAX_HOSTNAME_LENGTH, tr_hostname, (int)db.job_no,
                         p_file_name_buffer, strerror(errno),
                         __FILE__, __LINE__);
               /*
                * Since we usually do not send more then 100 files and
                * sf_wmo() will exit(), there is no point in stopping
                * the transmission.
                */
            }
         }
         else
         {
            trans_log(INFO_SIGN, __FILE__, __LINE__, NULL, NULL,
                      "File `%s' is of zero length, ignoring.",
                      p_file_name_buffer);
         }

         /* Update FSA, one file transmitted. */
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            fsa->job_status[(int)db.job_no].file_name_in_use[0] = '\0';
            fsa->job_status[(int)db.job_no].no_of_files_done++;
            fsa->job_status[(int)db.job_no].file_size_in_use = 0;
            fsa->job_status[(int)db.job_no].file_size_in_use_done = 0;
            local_file_size += *p_file_size_buffer;
            local_file_counter += 1;

            now = time(NULL);
            if (now >= (last_update_time + LOCK_INTERVAL_TIME))
            {
               last_update_time = now;
               update_tfc(local_file_counter, local_file_size,
                          p_file_size_buffer, files_to_send,
                          files_send, now);
               local_file_size = 0;
               local_file_counter = 0;
            }
         }

#ifdef _WITH_TRANS_EXEC
         if (db.special_flag & TRANS_EXEC)
         {
            trans_exec(file_path, fullname, p_file_name_buffer, clktck);
         }
#endif

#ifdef _OUTPUT_LOG
         if (db.output_log == YES)
         {
            if (ol_fd == -2)
            {
# ifdef WITHOUT_FIFO_RW_SUPPORT
               output_log_fd(&ol_fd, &ol_readfd, &db.output_log);
# else
               output_log_fd(&ol_fd, &db.output_log);
# endif
            }
            if ((ol_fd > -1) && (ol_data == NULL))
            {
               output_log_ptrs(&ol_retries,
                               &ol_job_number,
                               &ol_data,              /* Pointer to buffer.      */
                               &ol_file_name,
                               &ol_file_name_length,
                               &ol_archive_name_length,
                               &ol_file_size,
                               &ol_unl,
                               &ol_size,
                               &ol_transfer_time,
                               &ol_output_type,
                               db.host_alias,
                               (current_toggle - 1),
                               WMO,
                               &db.output_log);
            }
         }
#endif

         /* Now archive file if necessary. */
         if ((db.archive_time > 0) &&
             (p_db->archive_dir[0] != FAILED_TO_CREATE_ARCHIVE_DIR))
         {
#ifdef WITH_ARCHIVE_COPY_INFO
            int ret;
#endif

            /*
             * By telling the function archive_file() that this
             * is the first time to archive a file for this job
             * (in struct p_db) it does not always have to check
             * whether the directory has been created or not. And
             * we ensure that we do not create duplicate names
             * when adding db.archive_time to msg_name.
             */
#ifdef WITH_ARCHIVE_COPY_INFO
            if ((ret = archive_file(file_path, p_file_name_buffer, p_db)) < 0)
#else
            if (archive_file(file_path, p_file_name_buffer, p_db) < 0)
#endif
            {
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(ERROR_SIGN, __FILE__, __LINE__, NULL,
                               "Failed to archive file `%s'",
                               p_file_name_buffer);
               }

               /*
                * NOTE: We _MUST_ delete the file we just send,
                *       else the file directory will run full!
                */
               if (unlink(fullname) == -1)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "Could not unlink() local file `%s' after sending it successfully : %s",
                             fullname, strerror(errno));
               }

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                  *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                  ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                  ol_file_name[*ol_file_name_length + 1] = '\0';
                  (*ol_file_name_length)++;
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = 0;
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
            else
            {
               if (fsa->debug > NORMAL_MODE)
               {
                  trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                               "Archived file `%s'", p_file_name_buffer);
               }
#ifdef WITH_ARCHIVE_COPY_INFO
               if (ret == DATA_COPIED) 
               {
                  archived_copied++;
               }
#endif

#ifdef _OUTPUT_LOG
               if (db.output_log == YES)
               {
                  (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
                  (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
                  *ol_file_name_length = (unsigned short)strlen(ol_file_name);
                  ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
                  ol_file_name[*ol_file_name_length + 1] = '\0';
                  (*ol_file_name_length)++;
                  (void)strcpy(&ol_file_name[*ol_file_name_length + 1],
                               &db.archive_dir[db.archive_offset]);
                  *ol_file_size = *p_file_size_buffer;
                  *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
                  *ol_retries = db.retries;
                  *ol_unl = db.unl;
                  *ol_transfer_time = end_time - start_time;
                  *ol_archive_name_length = (unsigned short)strlen(&ol_file_name[*ol_file_name_length + 1]);
                  *ol_output_type = OT_NORMAL_DELIVERED + '0';
                  ol_real_size = *ol_file_name_length +
                                 *ol_archive_name_length + 1 + ol_size;
                  if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
                  {
                     system_log(ERROR_SIGN, __FILE__, __LINE__,
                                "write() error : %s", strerror(errno));
                  }
               }
#endif
            }
         }
         else
         {
#ifdef WITH_UNLINK_DELAY
            int unlink_loops = 0;

try_again_unlink:
#endif
            /* Delete the file we just have send. */
            if (unlink(fullname) == -1)
            {
#ifdef WITH_UNLINK_DELAY
               if ((errno == EBUSY) && (unlink_loops < 20))
               {
                  (void)my_usleep(100000L);
                  unlink_loops++;
                  goto try_again_unlink;
               }
#endif
               system_log(ERROR_SIGN, __FILE__, __LINE__,
                          "Could not unlink() local file %s after sending it successfully : %s",
                          fullname, strerror(errno));
            }

#ifdef _OUTPUT_LOG
            if (db.output_log == YES)
            {
               (void)memcpy(ol_file_name, db.p_unique_name, db.unl);
               (void)strcpy(ol_file_name + db.unl, p_file_name_buffer);
               *ol_file_name_length = (unsigned short)strlen(ol_file_name);
               ol_file_name[*ol_file_name_length] = SEPARATOR_CHAR;
               ol_file_name[*ol_file_name_length + 1] = '\0';
               (*ol_file_name_length)++;
               *ol_file_size = *p_file_size_buffer;
               *ol_job_number = fsa->job_status[(int)db.job_no].job_id;
               *ol_retries = db.retries;
               *ol_unl = db.unl;
               *ol_transfer_time = end_time - start_time;
               *ol_archive_name_length = 0;
               *ol_output_type = OT_NORMAL_DELIVERED + '0';
               ol_real_size = *ol_file_name_length + ol_size;
               if (write(ol_fd, ol_data, ol_real_size) != ol_real_size)
               {
                  system_log(ERROR_SIGN, __FILE__, __LINE__,
                             "write() error : %s", strerror(errno));
               }
            }
#endif
         }

         /*
          * After each successful transfer set error
          * counter to zero, so that other jobs can be
          * started.
          */
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            if ((*p_file_size_buffer > 0) && (fsa->error_counter > 0))
            {
               int  fd,
#ifdef WITHOUT_FIFO_RW_SUPPORT
                    readfd,
#endif
                    j;
               char fd_wake_up_fifo[MAX_PATH_LENGTH];

#ifdef LOCK_DEBUG
               lock_region_w(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
               lock_region_w(fsa_fd, db.lock_offset + LOCK_EC);
#endif
               fsa->error_counter = 0;

               /*
                * Wake up FD!
                */
               (void)snprintf(fd_wake_up_fifo, MAX_PATH_LENGTH, "%s%s%s",
                              p_work_dir, FIFO_DIR, FD_WAKE_UP_FIFO);
#ifdef WITHOUT_FIFO_RW_SUPPORT
               if (open_fifo_rw(fd_wake_up_fifo, &readfd, &fd) == -1)
#else
               if ((fd = open(fd_wake_up_fifo, O_RDWR)) == -1)
#endif
               {
                  system_log(WARN_SIGN, __FILE__, __LINE__,
                             "Failed to open() FIFO %s : %s",
                             fd_wake_up_fifo, strerror(errno));
               }
               else
               {
                  if (write(fd, "", 1) != 1)
                  {
                     system_log(WARN_SIGN, __FILE__, __LINE__,
                                "Failed to write() to FIFO %s : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
#ifdef WITHOUT_FIFO_RW_SUPPORT
                  if (close(readfd) == -1)
                  {
                     system_log(DEBUG_SIGN, __FILE__, __LINE__,
                                "Failed to close() FIFO %s (read) : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
#endif
                  if (close(fd) == -1)
                  {
                     system_log(DEBUG_SIGN, __FILE__, __LINE__,
                                "Failed to close() FIFO %s : %s",
                                fd_wake_up_fifo, strerror(errno));
                  }
               }

               /*
                * Remove the error condition (NOT_WORKING) from all jobs
                * of this host.
                */
               for (j = 0; j < fsa->allowed_transfers; j++)
               {
                  if ((j != db.job_no) &&
                      (fsa->job_status[j].connect_status == NOT_WORKING))
                  {
                     fsa->job_status[j].connect_status = DISCONNECT;
                  }
               }
               fsa->error_history[0] = 0;
               fsa->error_history[1] = 0;
#ifdef LOCK_DEBUG
               unlock_region(fsa_fd, db.lock_offset + LOCK_EC, __FILE__, __LINE__);
#else
               unlock_region(fsa_fd, db.lock_offset + LOCK_EC);
#endif

#ifdef LOCK_DEBUG
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               lock_region_w(fsa_fd, db.lock_offset + LOCK_HS);
#endif
               now = time(NULL);
               if (now > fsa->end_event_handle)
               {
                  fsa->host_status &= ~(EVENT_STATUS_FLAGS | AUTO_PAUSE_QUEUE_STAT);
                  if (fsa->end_event_handle > 0L)
                  {
                     fsa->end_event_handle = 0L;
                  }
                  if (fsa->start_event_handle > 0L)
                  {
                     fsa->start_event_handle = 0L;
                  }
               }
               else
               {
                  fsa->host_status &= ~(EVENT_STATUS_STATIC_FLAGS | AUTO_PAUSE_QUEUE_STAT);
               }
#ifdef LOCK_DEBUG
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS, __FILE__, __LINE__);
#else
               unlock_region(fsa_fd, db.lock_offset + LOCK_HS);
#endif

               /*
                * Since we have successfully transmitted a file, no need to
                * have the queue stopped anymore.
                */
               if (fsa->host_status & AUTO_PAUSE_QUEUE_STAT)
               {
                  char sign[LOG_SIGN_LENGTH];

                  error_action(fsa->host_alias, "stop", HOST_ERROR_ACTION);
                  event_log(0L, EC_HOST, ET_EXT, EA_ERROR_END, "%s",
                            fsa->host_alias);
                  if ((fsa->host_status & HOST_ERROR_OFFLINE_STATIC) ||
                      (fsa->host_status & HOST_ERROR_OFFLINE) ||
                      (fsa->host_status & HOST_ERROR_OFFLINE_T))
                  {
                     (void)memcpy(sign, OFFLINE_SIGN, LOG_SIGN_LENGTH);
                  }
                  else
                  {
                     (void)memcpy(sign, INFO_SIGN, LOG_SIGN_LENGTH);
                  }
                  trans_log(sign, __FILE__, __LINE__, NULL, NULL,
                            "Starting input queue that was stopped by init_afd.");
                  event_log(0L, EC_HOST, ET_AUTO, EA_START_QUEUE, "%s",
                            fsa->host_alias);
               }
            } /* if (fsa->error_counter > 0) */
#ifdef WITH_ERROR_QUEUE
            if (fsa->host_status & ERROR_QUEUE_SET)
            {
               remove_from_error_queue(db.id.job, fsa, db.fsa_pos, fsa_fd);
            }
#endif
            if (fsa->host_status & HOST_ACTION_SUCCESS)
            {
               error_action(fsa->host_alias, "start", HOST_SUCCESS_ACTION);
            }
         }

         p_file_name_buffer += MAX_FILENAME_LENGTH;
         p_file_size_buffer++;
      } /* for (files_send = 0; files_send < files_to_send; files_send++) */

#ifdef WITH_ARCHIVE_COPY_INFO
      if (archived_copied > 0)
      {
         trans_log(DEBUG_SIGN, __FILE__, __LINE__, NULL, NULL,
                   "Copied %u files to archive.", archived_copied);
         archived_copied = 0;
      }
#endif

      if (local_file_counter)
      {
         if (gsf_check_fsa(p_db) != NEITHER)
         {
            update_tfc(local_file_counter, local_file_size,
                       p_file_size_buffer, files_to_send, files_send,
                       time(NULL));
            local_file_size = 0;
            local_file_counter = 0;
         }
      }

      /*
       * Remove file directory, but only when all files have
       * been transmitted.
       */
      if ((files_to_send == files_send) || (files_to_send < 1))
      {
         if (rmdir(file_path) < 0)
         {
            system_log(ERROR_SIGN, __FILE__, __LINE__,
                       "Failed to remove directory %s : %s",
                       file_path, strerror(errno));
         }
      }
      else
      {
         system_log(WARN_SIGN, __FILE__, __LINE__,
                    "There are still %d files for %s. Will NOT remove this job!",
                    files_to_send - files_send, file_path);
         exit_status = STILL_FILES_TO_SEND;
      }

#ifdef _WITH_BURST_2
      burst_2_counter++;
      diff_time = time(NULL) - connected;
      if (((fsa->protocol_options & KEEP_CONNECTED_DISCONNECT) &&
           (db.keep_connected > 0) && (diff_time > db.keep_connected)) ||
          ((db.disconnect > 0) && (diff_time > db.disconnect)))
      {
         cb2_ret = NO;
         break;
      }
   } while ((cb2_ret = check_burst_sf(file_path, &files_to_send, 0,
# ifdef _WITH_INTERRUPT_JOB
                                      0,
# endif
# ifdef _OUTPUT_LOG
                                      &ol_fd,
# endif
# ifndef AFDBENCH_CONFIG
                                      NULL,
# endif
                                      NULL)) == YES);
   burst_2_counter--;

   if (cb2_ret == NEITHER)
   {
      exit_status = STILL_FILES_TO_SEND;
   }
#endif /* _WITH_BURST_2 */

   free(buffer);

   /* Disconnect from remote port. */
   wmo_quit();
   if ((fsa != NULL) && (fsa->debug > NORMAL_MODE))
   {
      trans_db_log(INFO_SIGN, __FILE__, __LINE__, NULL,
                   "Disconnected from port %d.", db.port);
   }

   if (wmo_counter_fd > 0)
   {
      close_counter_file(wmo_counter_fd, &wmo_counter);
   }

   exitflag = 0;
   exit(exit_status);
}