//******************************************** // AEM.cpp // ------------------------------------------- // Implementation of the AEM (AE Monitor) tool. // // This tool issues commands of operations to // AE by sending SIGUSER2 signal. The operation // parameters are passed through shared memory. // // Author: Leiwen Deng // Date: 12/10/2005 //******************************************** #include "AEM.h" int main( int argc, char * argv[] ) { if ( argc < 2 ) { Die( "Usage: AEM \n" ); } const char * AE_pid_file = AE_PID_FILE_NAME; FILE * fp; if( ( fp = fopen( AE_pid_file, "r" ) ) == NULL ) { Die( "AE pid file does not exist\n" ); } int AE_pid; if ( fscanf( fp, "%d", &AE_pid ) != 1 ) { Die( "File \"%s\" is corrupt\n", AE_pid_file ); } fclose( fp ); int shmid; key_t key = SHM_AEM_KEY; if ( ( shmid = shmget( key, sizeof( SHM_AEM ), 0666) ) < 0 ) { Die( "Error: fail to locate the shared memory for AEM handler\n" ); } SHM_AEM * shm_aem; if ( ( shm_aem = (SHM_AEM *)shmat( shmid, NULL, 0) ) == (SHM_AEM *)-1 ) { Die( "Error: fail to attach to the shared memory for AEM handler\n" ); } if ( argv[1][0] == '1' ) shm_aem->operation = AEM_SHOW_TABLE; else if ( argv[1][0] == '2' ) shm_aem->operation = AEM_SHOW_TABLE_STRUCTURE; else shm_aem->operation = AEM_NO_OPERATION; if ( kill( AE_pid, SIGUSR2 ) != 0 ) { const char * reason = "Unknown reason"; switch ( errno ) { case EPERM: reason = "Operation is not permitted"; break; case ESRCH: reason = "AE process is not found"; break; } fprintf( stderr, "AEM operation fails because: %s\n", reason ); } else { const char * result = "No AEM operation is performed"; switch ( shm_aem->operation ) { case AEM_SHOW_TABLE: result = "Table is successfully dumped"; break; case AEM_SHOW_TABLE_STRUCTURE: result = "Table structure is successfully dumped"; break; } fprintf( stderr, "%s\n", result ); } return 0; } void Die( const char * format, ... ) { va_list param_list; va_start( param_list, format ); vfprintf( stderr, format, param_list ); exit( 1 ); }