Esempio n. 1
0
/*!
  Send an internet message to \a port on the default host.

  If \a addr is non-zero, use that as the host.

  If \a msg is non-zero, use that as the message
*/
void send_message( int port, const char *addr, const char *msg )
{
    int sock;
    int rc;
    char buf[BUF_SZ];
    struct sockaddr_in client;
    struct sockaddr_in server;
    const int sa_sz = sizeof(struct sockaddr_in);
    client.sin_family = AF_INET;
    client.sin_addr.s_addr = INADDR_ANY;
    client.sin_port = INADDR_ANY;
    server.sin_family = AF_INET;
    if ( addr == 0 )
        addr = DEFAULT_ADDR;
    server.sin_addr.s_addr = inet_addr( addr );
    server.sin_port = htons( port );
    file_message( "Creating socket", addr );
    if (( sock = socket(AF_INET, SOCK_STREAM, 0)) == -1 )
        fatal( (char*)strerror( errno ));
    if ( connect( sock, (struct sockaddr*)&server, sa_sz ) == -1 )
        fatal( (char*)strerror( errno ));
    if ( msg == 0 )
        msg = NET_MESSAGE;
    int msg_sz = strlen( msg ) + 1;
    if ( send( sock, NET_MESSAGE, msg_sz, 0 ) == -1 )
        fatal( (char*)strerror( errno ));
    while (( rc = recv( sock, buf, BUF_SZ, 0 )))
        printf( buf );
    if ( rc == -1 )
        warning( (char*)strerror( errno ));
}
Esempio n. 2
0
/**
 *  This is where we send all the test messages. Depending o the
 *  argument, either we read a static XML evnt from a file (and thus
 *  there is no XML conversion overhead incurred), or we instantiate
 *  and populate a struct Query_struct for every message and convert
 *  it to XML format using a QMS_Remos_Msg object on the fly.
 */
void
generate_query(void)
{
  QMS_Trace ("generate_query", __LINE__, __FILE__);
  DEBUG0 (DEBUG_L_ENTER, "DEBUG Thread Created\n");
  ACE_Time_Value sleep_time (QMS_DEFAULT_retry_sleep_interval * ACE_OS::rand()%30, 0);
  DEBUG0 (DEBUG_L_CALL, "DEBUG Thread sleeping\n");
  ACE_Thread::yield();
  ACE_OS::sleep (sleep_time);
  DEBUG0 (DEBUG_L_CALL, "DEBUG Thread awake\n");

  if (filename_p)
   {
     file_message(filename_p);
   }
  else
   {
     mock_message();
   }
  DEBUG0 (DEBUG_L_LEAVE, "DEBUG Thread all done, exiting\n");
}
Esempio n. 3
0
/*!
  Do a range of I/O processing on the files in \a f_names

  If a file is a directory, then fork a new process to
  do that directory.

  Do good error reporting on failure.
*/
void process_files( char **file_names, int file_count )
{
    int fd;
    int f_index;
    int f_ptr;
    int doit = 1;
    struct stat statbuf;
    pid_t proc = -1;
    int dealloc_file_names = 0;
    DIR *dir = 0;
    struct dirent *entry = 0;
    while ( doit-- )
    {
        for ( f_index = 0; f_index < file_count; ++f_index )
        {
            if ( strcmp( file_names[f_index], ".." ) == 0 )
                continue;
            if ( strcmp( file_names[f_index], "." ) == 0 )
                continue;
            file_message( "accessing for stat", file_names[f_index] );
            fd = stat( file_names[f_index], &statbuf );
            if ( fd == -1 )
            {
                perror( file_names[f_index] );
                continue;
            }
            /* follow into subdirs by forking - unless its a symlink */
            if ( S_ISDIR( statbuf.st_mode ) && ! S_ISLNK( statbuf.st_mode ))
            {
                if (( proc = fork()) == 0 )
                {
                    /* zero = child */
                    doit = 1;
                    indent += 3;
                    file_message( "to handle dir", file_names[f_index] );
                    if (( fd = chdir( file_names[f_index] )) == -1 )
                        fatal( (char*)strerror( errno ));
                    if (( dir = opendir( "." )) == NULL )
                        fatal( (char*)strerror( errno ));
                    file_count = 0;
                    while (( entry = readdir( dir ))) { file_count++; }
                    /* setup so file_names & file_count reflect new directory */
                    file_names = (char **)malloc( file_count * sizeof( char * ));
                    if ( file_names == NULL )
                        fatal( "allocating file names array" );
                    rewinddir( dir );
                    f_ptr = 0;
                    while (( entry = readdir( dir )) && f_ptr < file_count )
                        file_names[ f_ptr++ ] = (char*)strdup( entry->d_name );
                    closedir( dir );
                    dealloc_file_names = 1;
                    break;
                }
                if ( proc == -1 ) /* fork failed */
                    warning( (char*)strerror( errno ));
            }
            else
            {
                file_message( "accessing for read", file_names[f_index] );
                fd = open( file_names[f_index], O_RDONLY );
                if ( fd == -1 )
                    perror( file_names[f_index] );
                else
                    close( fd );
                file_message( "accessing for read/write", file_names[f_index] );
                fd = open( file_names[f_index], O_RDWR );
                if ( fd == -1 )
                    warning( (char*)strerror( errno ));
                else
                    close( fd );
                sleep( 5 );
            }
        }
    }
    if ( dealloc_file_names )
    {
        for ( f_index = 0; f_index < file_count; ++f_index )
            free( file_names[f_index] );
        free( file_names );
    }
}