int main (int argc, char *argv[]) { GError *error; int conflicting_options; GOptionContext *ctx; /* Initialize the i18n stuff */ bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); error = NULL; ctx = g_option_context_new (""); g_option_context_add_main_entries (ctx, options, GETTEXT_PACKAGE); if (! g_option_context_parse (ctx, &argc, &argv, &error)) { g_warning ("Unable to start: %s", error->message); g_error_free (error); exit (1); } g_option_context_free (ctx); conflicting_options = 0; if (opt_logout) conflicting_options++; if (opt_power_off) conflicting_options++; if (opt_reboot) conflicting_options++; if (conflicting_options > 1) display_error (_("Program called with conflicting options")); if (opt_power_off) { do_power_off ("Shutdown"); } else if (opt_reboot) { do_power_off ("Reboot"); } else { /* default to logout */ if (opt_force) do_logout (GSM_LOGOUT_MODE_FORCE); else if (opt_no_prompt) do_logout (GSM_LOGOUT_MODE_NO_CONFIRMATION); else do_logout (GSM_LOGOUT_MODE_NORMAL); } return 0; }
gint qq_logout(QQInfo *info, GError **err) { if(info == NULL){ return -1; } return do_logout(info, err);; }
void terminate_client(void) { if (srv_socket > 0) do_logout(); cli_socket = close(cli_socket); exit(0);
static unsigned int WINAPI worker_func (void *data) #endif { test_t *lpBenchInfo = (test_t *) data; #if defined(PTHREADS) unsigned long result = TRUE; #elif defined(WIN32) unsigned int result; #endif bench_msg_t msg; memset (&msg, '\0', sizeof (msg)); msg.Type = 'F'; msg.nConn = lpBenchInfo->tpc._.nConn; msg.nThread = lpBenchInfo->tpc._.nThreadNo; if (!do_cancel) { lpBenchInfo->ShowProgress = dummy_ShowProgress; lpBenchInfo->StopProgress = dummy_StopProgress; lpBenchInfo->SetWorkingItem = dummy_SetWorkingItem; lpBenchInfo->SetProgressText = threaded_SendProgress; lpBenchInfo->fCancel = threaded_fCancel; lpBenchInfo->hstmt = 0; lpBenchInfo->hdbc = 0; lpBenchInfo->tpc._.nThreads = 1; if (do_login (lpBenchInfo)) { result = FALSE; if (lpBenchInfo->hstmt) switch (lpBenchInfo->TestType) { case TPC_A: result = DoThreadsRun (lpBenchInfo); break; case TPC_C: result = tpcc_run_test (NULL, lpBenchInfo) ? TRUE : FALSE; break; } do_logout (lpBenchInfo); } } if (!signal_pipe[1] || sizeof (bench_msg_t) != write (signal_pipe[1], &msg, sizeof (bench_msg_t))) abort (); #if defined(PTHREADS) return ((void *) result); #elif defined(WIN32) return (result); #endif }
int f_logout( SNET *sn, int ac, char *av[], SNET *pushersn ) { struct cinfo ci; char path[ MAXPATHLEN ]; /* LOGOUT login_cookie ip */ if ( al->al_key != CGI ) { syslog( LOG_ERR, "f_logout: %s not allowed", al->al_hostname ); snet_writef( sn, "%d LOGOUT: %s not allowed to logout.\r\n", 410, al->al_hostname ); return( 1 ); } if ( ac != 3 ) { syslog( LOG_ERR, "f_logout: %s wrong number of args", al->al_hostname ); snet_writef( sn, "%d LOGOUT: Wrong number of args.\r\n", 510 ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, av[ 1 ], path, sizeof( path )) < 0 ) { syslog( LOG_ERR, "f_login: mkcookiepath error" ); snet_writef( sn, "%d LOGIN: Invalid cookie path.\r\n", 511 ); return( 1 ); } if ( read_cookie( path, &ci ) != 0 ) { snet_writef( sn, "%d LOGOUT error: Sorry\r\n", 513 ); return( 1 ); } /* double action policy?? */ if ( ci.ci_state == 0 ) { syslog( LOG_ERR, "f_logout: %s already logged out", av[ 1 ] ); snet_writef( sn, "%d LOGOUT: Already logged out\r\n", 411 ); return( 1 ); } if ( do_logout( path ) < 0 ) { syslog( LOG_ERR, "f_logout: %s: %m", path ); return( -1 ); } snet_writef( sn, "%d LOGOUT successful: cookie no longer valid\r\n", 210 ); if (( pushersn != NULL ) && ( !replicated )) { snet_writef( pushersn, "LOGOUT %s %s\r\n", av[ 1 ], av [ 2 ] ); } if ( !replicated ) { syslog( LOG_INFO, "LOGOUT %s %s %s", ci.ci_user, ci.ci_realm, av[ 2 ] ); } return( 0 ); }
int main(int argc, char* argv[]) { GError* error; int conflicting_options; /* Initialize the i18n stuff */ bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); error = NULL; if (!gtk_init_with_args(&argc, &argv, NULL, options, NULL, &error)) { g_warning("Unable to start: %s", error->message); g_error_free(error); exit(1); } conflicting_options = 0; if (kill_session) { conflicting_options++; } if (logout) { conflicting_options++; } if (force_logout) { conflicting_options++; } if (logout_dialog) { conflicting_options++; } if (shutdown_dialog) { conflicting_options++; } if (conflicting_options > 1) { display_error(_("Program called with conflicting options")); } if (kill_session) { if (no_interaction) { force_logout = TRUE; } else { logout_dialog = TRUE; } } if (logout) { do_logout(GSM_LOGOUT_MODE_NO_CONFIRMATION); } else if (force_logout) { do_logout(GSM_LOGOUT_MODE_FORCE); } else if (logout_dialog) { do_logout(GSM_LOGOUT_MODE_NORMAL); } else if (shutdown_dialog) { do_shutdown_dialog(); } return 0; }
int f_check( SNET *sn, int ac, char *av[], SNET *pushersn ) { struct cinfo ci; struct timeval tv; char login[ MAXCOOKIELEN ], path[ MAXPATHLEN ]; char rekeybuf[ 128 ], rcookie[ 256 ], scpath[ MAXPATHLEN ]; char *p; int status; double rate; /* * C: CHECK servicecookie * S: 231 ip principal realm */ /* * C: CHECK logincookie * S: 232 ip principal realm */ /* * C: REKEY servicecookie * S: 233 ip principal realm rekeyed-cookie */ if (( al->al_key != CGI ) && ( al->al_key != SERVICE )) { syslog( LOG_ERR, "f_check: %s not allowed", al->al_hostname ); snet_writef( sn, "%d %s: %s not allowed to check.\r\n", 430, av[ 0 ], al->al_hostname ); return( 1 ); } if ( ac < 2 || ac > 3 ) { syslog( LOG_ERR, "f_check: %s: wrong number of args. " "Expected 2 or 3, got %d", al->al_hostname, ac ); snet_writef( sn, "%d %s: Wrong number of args.\r\n", 530, av[ 0 ] ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, av[ 1 ], path, sizeof( path )) < 0 ) { syslog( LOG_ERR, "f_check: mkcookiepath error" ); snet_writef( sn, "%d %s: Invalid cookie name.\r\n", 531, av[ 0 ] ); return( 1 ); } if ( strncmp( av[ 1 ], "cosign-", 7 ) == 0 ) { if ( strict_checks && service_valid( av[ 1 ] ) == NULL ) { snet_writef( sn, "%d %s: Invalid cookie\r\n", 534, av[ 0 ] ); return( 1 ); } status = 231; if ( service_to_login( path, login ) != 0 ) { if (( rate = rate_tick( &checkunknown )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: UNKNOWN %.5f / sec", inet_ntoa( cosign_sin.sin_addr), rate ); } snet_writef( sn, "%d %s: cookie not in db!\r\n", 533, av[ 0 ] ); return( 1 ); } if ( COSIGN_PROTO_SUPPORTS_REKEY( protocol )) { if ( strcasecmp( av[ 0 ], "REKEY" ) == 0 ) { /* save service cookie path for rekeying below. */ if ( strlen( path ) >= sizeof( scpath )) { syslog( LOG_ERR, "f_check: %s exceeds bounds.", path ); snet_writef( sn, "%d %s: Invalid cookie name.\r\n", 531, av[ 0 ]); return( 1 ); } strcpy( scpath, path ); status = 233; } } if ( mkcookiepath( NULL, hashlen, login, path, sizeof( path )) < 0 ) { syslog( LOG_ERR, "f_check: mkcookiepath error.." ); snet_writef( sn, "%d %s: Invalid cookie name.\r\n", 532, av[ 0 ] ); return( 1 ); } } else if ( strncmp( av[ 1 ], "cosign=", 7 ) == 0 ) { status = 232; } else { syslog( LOG_ERR, "f_check: unknown cookie prefix." ); snet_writef( sn, "%d %s: unknown cookie prefix!\r\n", 432, av[ 0 ] ); return( 1 ); } if ( read_cookie( path, &ci ) != 0 ) { if (( rate = rate_tick( &checkunknown )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: UNKNOWN %.5f / sec", inet_ntoa( cosign_sin.sin_addr), rate); } snet_writef( sn, "%d %s: Who me? Dunno.\r\n", 534, av[ 0 ] ); return( 1 ); } if ( ci.ci_state == 0 ) { if (( rate = rate_tick( &checkfail )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: FAIL %.5f / sec", inet_ntoa( cosign_sin.sin_addr), rate); } snet_writef( sn, "%d %s: Already logged out\r\n", 430, av[ 0 ] ); return( 1 ); } /* check for idle timeout, and if so, log'em out */ if ( gettimeofday( &tv, NULL ) != 0 ){ syslog( LOG_ERR, "f_check: gettimeofday: %m" ); return( -1 ); } if ( tv.tv_sec - ci.ci_itime >= idle_out_time ) { if ( tv.tv_sec - ci.ci_itime < ( idle_out_time + grey_time )) { if (( rate = rate_tick( &checkunknown )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: UNKNOWN %.5f / sec", inet_ntoa( cosign_sin.sin_addr ), rate ); } syslog( LOG_NOTICE, "f_check: idle grey window" ); snet_writef( sn, "%d %s: Idle Grey Window\r\n", 531, av[ 0 ] ); return( 1 ); } if (( rate = rate_tick( &checkfail )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: FAIL %.5f / sec", inet_ntoa( cosign_sin.sin_addr), rate); } snet_writef( sn, "%d %s: Idle logged out\r\n", 431, av[ 0 ] ); if ( do_logout( path ) < 0 ) { syslog( LOG_ERR, "f_check: %s: %m", login ); return( -1 ); } return( 1 ); } /* prevent idle out if we are actually using it */ utime( path, NULL ); if (( rate = rate_tick( &checkpass )) != 0.0 ) { syslog( LOG_NOTICE, "STATS CHECK %s: PASS %.5f / sec", inet_ntoa( cosign_sin.sin_addr), rate); } if ( status == 233 ) { /* rekey service cookie. */ if ( mkcookie( sizeof( rekeybuf ), rekeybuf ) != 0 ) { syslog( LOG_ERR, "f_check: rekey: mkcookie failed" ); snet_writef( sn, "%d %s: rekey failed.\r\n", 536, av[ 0 ] ); return( 1 ); } if (( p = strchr( av[ 1 ], '=' )) == NULL ) { syslog( LOG_ERR, "f_check: rekey: bad service name \"%s\".", av[1]); snet_writef( sn, "%d %s rekey failed.\r\n", 536, av[ 0 ] ); return( 1 ); } *p = '\0'; if ( snprintf( rcookie, sizeof( rcookie ), "%s=%s", av[ 1 ], rekeybuf ) >= sizeof( rcookie )) { syslog( LOG_ERR, "f_check: rekey: new cookie too long." ); snet_writef( sn, "%d %s rekey failed.\r\n", 536, av[ 0 ] ); return( 1 ); } *p = '='; if ( mkcookiepath( NULL, hashlen, rcookie, path, sizeof( path )) < 0 ) { syslog( LOG_ERR, "f_check: rekey: mkcookiepath error." ); snet_writef( sn, "%d %s: rekey failed.\r\n", 536, av[ 0 ] ); return( 1 ); } if ( rename( scpath, path ) != 0 ) { syslog( LOG_ERR, "f_check: rekey: rename %s to %s failed: %s.", scpath, path, strerror( errno )); snet_writef( sn, "%d %s: rekey failed.\r\n", 536, av[ 0 ] ); return( 1 ); } } if ( COSIGN_PROTO_SUPPORTS_FACTORS( protocol )) { snet_writef( sn, "%d %s %s %s %s\r\n", status, ci.ci_ipaddr_cur, ci.ci_user, ci.ci_realm, ( status == 233 ? rcookie : "" )); } else { /* if there is more than one realm, we just give the first */ if (( p = strtok( ci.ci_realm, " " )) != NULL ) { snet_writef( sn, "%d %s %s %s\r\n", status, ci.ci_ipaddr, ci.ci_user, p ); } else { snet_writef( sn, "%d %s %s %s\r\n", status, ci.ci_ipaddr, ci.ci_user, ci.ci_realm ); } } return( 0 ); }
int f_register( SNET *sn, int ac, char *av[], SNET *pushersn ) { struct cinfo ci; struct timeval tv; int rc; char lpath[ MAXPATHLEN ], spath[ MAXPATHLEN ]; /* REGISTER login_cookie ip service_cookie */ if ( al->al_key != CGI ) { syslog( LOG_ERR, "f_register: %s not allowed", al->al_hostname ); snet_writef( sn, "%d REGISTER: %s not allowed to register.\r\n", 420, al->al_hostname ); return( 1 ); } if ( ac != 4 ) { syslog( LOG_ERR, "f_register: %s wrong number of args.", al->al_hostname ); snet_writef( sn, "%d REGISTER: Wrong number of args.\r\n", 520 ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, av[ 1 ], lpath, sizeof( lpath )) < 0 ) { syslog( LOG_ERR, "f_register: mkcookiepath login cookie error" ); snet_writef( sn, "%d REGISTER: Invalid cookie path.\r\n", 521 ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, av[ 3 ], spath, sizeof( spath )) < 0 ) { syslog( LOG_ERR, "f_register: mkcookiepath service cookie error" ); snet_writef( sn, "%d REGISTER: Invalid cookie path.\r\n", 522 ); return( 1 ); } if ( read_cookie( lpath, &ci ) != 0 ) { snet_writef( sn, "%d REGISTER error: Sorry\r\n", 523 ); return( 1 ); } if ( ci.ci_state == 0 ) { syslog( LOG_ERR, "f_register: %s logged out, can't register", ci.ci_user ); snet_writef( sn, "%d REGISTER: Already logged out\r\n", 421 ); return( 1 ); } /* check for idle timeout, and if so, log'em out */ if ( gettimeofday( &tv, NULL ) != 0 ){ syslog( LOG_ERR, "f_register: gettimeofday: %m" ); return( -1 ); } if ( tv.tv_sec - ci.ci_itime >= idle_out_time ) { if ( tv.tv_sec - ci.ci_itime < ( idle_out_time + grey_time )) { syslog( LOG_NOTICE, "f_register: idle grey window" ); snet_writef( sn, "%d REGISTER: Idle Grey Window\r\n", 521 ); return( 1 ); } snet_writef( sn, "%d REGISTER: Idle logged out\r\n", 422 ); if ( do_logout( lpath ) < 0 ) { syslog( LOG_ERR, "f_register: %s: %m", lpath ); return( -1 ); } return( 1 ); } if (( rc = do_register( av[ 1 ], lpath, spath )) < 0 ) { return( -1 ); } /* double action policy?? */ if ( rc > 0 ) { snet_writef( sn, "%d REGISTER error: Cookie already exists\r\n", 226 ); return( rc ); } snet_writef( sn, "%d REGISTER successful: Cookie Stored.\r\n", 220 ); if (( pushersn != NULL ) && ( !replicated )) { snet_writef( pushersn, "REGISTER %s %s %s\r\n", av[ 1 ], av[ 2 ], av [ 3 ] ); } if ( !replicated ) { /* just log service name, no need for full cookie */ (void)strtok( av[ 3 ], "=" ); syslog( LOG_INFO, "REGISTER %s %s %s %s", ci.ci_user, ci.ci_realm, ci.ci_ipaddr, av[ 3 ] ); } return( 0 ); }
int f_time( SNET *sn, int ac, char *av[], SNET *pushersn ) { struct utimbuf new_time; struct stat st; struct timeval tv; int timestamp, state; int total = 0, fail = 0; char *line, path[ MAXPATHLEN ]; /* TIME */ /* 3xx */ /* login_cookie timestamp state */ /* . */ if ( al->al_key != CGI ) { syslog( LOG_ERR, "%s not allowed to tell time", al->al_hostname ); snet_writef( sn, "%d TIME: %s not allowed to propogate time.\r\n", 460, al->al_hostname ); return( 1 ); } if ( ac != 1 ) { syslog( LOG_ERR, "f_time: expected 1 argument, got %d", ac ); snet_writef( sn, "%d TIME: Wrong number of args.\r\n", 560 ); return( 1 ); } snet_writef( sn, "%d TIME: Send timestamps.\r\n", 360 ); tv = cosign_net_timeout; while (( line = snet_getline( sn, &tv )) != NULL ) { tv = cosign_net_timeout; if (( ac = argcargv( line, &av )) < 0 ) { syslog( LOG_ERR, "argcargv: %m" ); break; } if ( strcmp( line, "." ) == 0 ) { break; } if ( ac != 3 ) { syslog( LOG_ERR, "f_time: wrong number of args" ); continue; } if ( strncmp( av[ 0 ], "cosign=", 7 ) != 0 ) { syslog( LOG_ERR, "f_time: cookie name malformat" ); continue; } if ( mkcookiepath( NULL, hashlen, av[ 0 ], path, sizeof( path )) < 0 ) { syslog( LOG_ERR, "f_time: path name malformat" ); continue; } total++; if ( stat( path, &st ) != 0 ) { /* record a missing cookie here */ fail++; continue; } timestamp = atoi( av[ 1 ] ); if ( timestamp > st.st_mtime ) { new_time.modtime = timestamp; utime( path, &new_time ); } state = atoi( av[ 2 ] ); if (( state == 0 ) && (( st.st_mode & S_ISGID ) != 0 )) { if ( do_logout( path ) < 0 ) { syslog( LOG_ERR, "f_time: %s should be logged out!", path ); } } } if ( total != 0 ) { syslog( LOG_NOTICE, "STATS TIME %s: %d tried, %d%% success", al->al_hostname, total, 100 * ( total - fail ) / total ); } snet_writef( sn, "%d TIME successful: we are now up-to-date\r\n", 260 ); return( 0 ); }
int f_retr( SNET *sn, int ac, char *av[], SNET *pushersn ) { struct servicelist *sl; struct cinfo ci; struct timeval tv; char lpath[ MAXPATHLEN ], spath[ MAXPATHLEN ]; char login[ MAXCOOKIELEN ]; if (( al->al_key != CGI ) && ( al->al_key != SERVICE )) { syslog( LOG_ERR, "f_retr: %s not allowed", al->al_hostname ); snet_writef( sn, "%d RETR: %s not allowed to retrieve.\r\n", 442, al->al_hostname ); return( 1 ); } if ( ac != 3 ) { syslog( LOG_ERR, "f_retr: %s Wrong number of args.", al->al_hostname ); snet_writef( sn, "%d RETR: Wrong number of args.\r\n", 540 ); return( 1 ); } if (( sl = service_valid( av[ 1 ] )) == NULL ) { snet_writef( sn, "%d RETR: Invalid cookie\r\n", 545 ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, av[ 1 ], spath, sizeof( spath )) < 0 ) { syslog( LOG_ERR, "f_retr: mkcookiepath error" ); snet_writef( sn, "%d RETR: Invalid cookie name.\r\n", 541 ); return( 1 ); } if ( service_to_login( spath, login ) != 0 ) { snet_writef( sn, "%d RETR: cookie not in db!\r\n", 543 ); return( 1 ); } if ( mkcookiepath( NULL, hashlen, login, lpath, sizeof( lpath )) < 0 ) { syslog( LOG_ERR, "f_retr: mkcookiepath error" ); snet_writef( sn, "%d RETR: Invalid cookie name.\r\n", 541 ); return( 1 ); } if ( read_cookie( lpath, &ci ) != 0 ) { snet_writef( sn, "%d RETR: Who me? Dunno.\r\n", 544 ); return( 1 ); } if ( ci.ci_state == 0 ) { snet_writef( sn, "%d RETR: Already logged out\r\n", 440 ); return( 1 ); } /* check for idle timeout, and if so, log'em out */ if ( gettimeofday( &tv, NULL ) != 0 ){ syslog( LOG_ERR, "f_retr: gettimeofday: %m" ); return( -1 ); } if ( tv.tv_sec - ci.ci_itime >= idle_out_time ) { if ( tv.tv_sec - ci.ci_itime < ( idle_out_time + grey_time )) { syslog( LOG_ERR, "f_retr: idle grey window" ); snet_writef( sn, "%d RETR: Idle Grey Window\r\n", 541 ); return( 1 ); } snet_writef( sn, "%d RETR: Idle logged out\r\n", 441 ); if ( do_logout( lpath ) < 0 ) { syslog( LOG_ERR, "f_retr: %s: %m", login ); return( -1 ); } return( 1 ); } if ( strcmp( av[ 2 ], "tgt") == 0 ) { return( retr_ticket( sn, sl, ci.ci_krbtkt )); } else if ( strcmp( av[ 2 ], "cookies") == 0 ) { return( retr_proxy( sn, login, pushersn )); } syslog( LOG_ERR, "f_retr: no such retrieve type: %s", av[ 1 ] ); snet_writef( sn, "%d RETR: No such retrieve type.\r\n", 441 ); return( 1 ); }
int do_threads_run (int nConnCount, OList * tests, int nMinutes, char *szTitle) { test_t *lpBenchInfo; test_t **data; int *n_threads, nThreads = 0, nThreadsWork; char szTemp[2048]; long nRuns = 0; FILE *fi; THREAD_T **workers; bench_msg_t msg; time_t start_time, now_time; long time_remaining; #ifdef WIN32 DWORD thrid; #endif int thr, conn; int rc = 0; void (*old_pane_log) (const char *format, ...) = pane_log; OList *iter; BOOL wasError = FALSE; nProgressIncrement = bench_get_long_pref (A_REFRESH_RATE); if (!nConnCount) return 0; if (pipe (signal_pipe)) { old_pane_log ("Can't open the pipe"); return rc; } fi = fdopen (signal_pipe[0], "rb"); lpBenchInfo = (test_t *) tests->data; do_cancel = FALSE; time (&start_time); sprintf (szTemp, "Running for %d minutes", nMinutes); lpBenchInfo->ShowProgress (NULL, szTitle, FALSE, nMinutes * 60); lpBenchInfo->SetWorkingItem (szTemp); data = (test_t **) calloc (nConnCount, sizeof (test_t *)); workers = (THREAD_T **) calloc (nConnCount, sizeof (THREAD_T *)); n_threads = (int *) calloc (nConnCount, sizeof (int)); pane_log = dummy_pane_log; for (iter = tests, conn = 0; iter; iter = o_list_next (iter), conn++) { test_t *test = (test_t *) iter->data; test->tpc._.nMinutes = nMinutes; if (do_login (test)) { get_dsn_data (test); if (test->hdbc && IS_A (*test)) { fExecuteSql (test, (SQLCHAR *) "delete from HISTORY"); SQLTransact (SQL_NULL_HENV, test->hdbc, SQL_COMMIT); } do_logout (test); n_threads[conn] = test->tpc._.nThreads ? test->tpc._.nThreads : 1; data[conn] = (test_t *) calloc (n_threads[conn], sizeof (test_t)); workers[conn] = (THREAD_T *) calloc (n_threads[conn], sizeof (THREAD_T)); nThreads += n_threads[conn]; memset (test->szSQLError, 0, sizeof (test->szSQLError)); memset (test->szSQLState, 0, sizeof (test->szSQLState)); for (thr = 0; thr < n_threads[conn]; thr++) { memcpy (&(data[conn][thr]), test, sizeof (test_t)); data[conn][thr].test = test; data[conn][thr].tpc._.nThreadNo = thr; data[conn][thr].tpc._.nConn = conn; START_THREAD (workers[conn][thr], worker_func, data[conn][thr]); } } } nThreadsWork = nThreads; while (nThreadsWork && fread (&msg, sizeof (bench_msg_t), 1, fi)) { if (lpBenchInfo->fCancel ()) do_cancel = TRUE; switch (msg.Type) { case 'F': if (gui.do_MarkFinished) gui.do_MarkFinished (msg.nConn, msg.nThread); sprintf (szTemp, "%s %3d threads running", szTitle, --nThreadsWork); lpBenchInfo->SetWorkingItem (szTemp); if (data[msg.nConn][msg.nThread].szSQLError[0]) { old_pane_log ("*** Error : Thread %3d in dsn %s : [%s] %s\r\n", msg.nThread + 1, data[msg.nConn][msg.nThread].szLoginDSN, data[msg.nConn][msg.nThread].szSQLState, data[msg.nConn][msg.nThread].szSQLError); strcpy ((char *) data[msg.nConn][msg.nThread].test->szSQLState, (char *) data[msg.nConn][msg.nThread].szSQLState); strcpy ((char *) data[msg.nConn][msg.nThread].test->szSQLError, (char *) data[msg.nConn][msg.nThread].szSQLError); wasError = TRUE; } break; case 'R': time (&now_time); time_remaining = nMinutes * 60 - (now_time - start_time); time_remaining = (time_remaining > 0 ? time_remaining : 0); sprintf (szTemp, "%10ld secs remaining", time_remaining); nRuns += 1; lpBenchInfo->SetProgressText (szTemp, msg.nConn, msg.nThread, msg.percent, msg.nTrnPerCall, time_remaining, msg.tpca_dDiffSum); break; } } fclose (fi); close (signal_pipe[1]); close (signal_pipe[0]); memset (signal_pipe, 0, sizeof (signal_pipe)); pane_log = old_pane_log; lpBenchInfo->StopProgress (); rc = ThreadedCalcStats (tests, workers, data, nConnCount, n_threads); for (iter = tests, conn = 0; iter; iter = o_list_next (iter), conn++) { XFREE (workers[conn]); XFREE (data[conn]); } XFREE (workers); XFREE (data); XFREE (n_threads); if (do_cancel || wasError) rc = 0; return rc; }
static int ThreadedCalcStats (OList * tests, THREAD_T ** workers, test_t ** data, int nConnCount, int *nThreads) { OList *iter; int nConn; int rc = 1; int rc1 = 1; for (iter = tests, nConn = 0; iter && nConn < nConnCount; nConn++, iter = o_list_next (iter)) { int nOkA = 0, nOkC = 0; int nA = 0, nC = 0; #if defined(PTHREADS) unsigned long result; #elif defined(WIN32) unsigned int result; #endif BOOL runStatus = TRUE; int i; test_t *test = (test_t *) iter->data; if (IS_A (*test)) { test->tpc.a.nTrnCnt = 0; test->tpc.a.nTrnCnt1Sec = 0; test->tpc.a.nTrnCnt2Sec = 0; test->tpc.a.dDiffSum = -1; } else { test->tpc.c.tpcc_sum = 0; test->tpc.c.run_time = 0; test->tpc.c.nRounds = 0; reset_times (test); } for (i = 0; i < nThreads[nConn]; i++) { GET_EXIT_STATUS (workers[nConn][i], &result); if (!result) runStatus = result; switch (data[nConn][i].TestType) { case TPC_A: nA++; if (!test->is_unsupported && result) { nOkA++; test->tpc.a.nTrnCnt += data[nConn][i].tpc.a.nTrnCnt; test->tpc.a.nTrnCnt1Sec += data[nConn][i].tpc.a.nTrnCnt1Sec; test->tpc.a.nTrnCnt2Sec += data[nConn][i].tpc.a.nTrnCnt2Sec; if (data[nConn][i].tpc.a.dDiffSum > test->tpc.a.dDiffSum) test->tpc.a.dDiffSum = data[nConn][i].tpc.a.dDiffSum; } break; case TPC_C: nC++; if (result) { nOkC++; test->tpc.c.tpcc_sum += data[nConn][i].tpc.c.tpcc_sum; test->tpc.c.run_time += data[nConn][i].tpc.c.run_time; test->tpc.c.nRounds += data[nConn][i].tpc.c.nRounds; /* individual transaction timings */ ta_merge (&(test->tpc.c.ten_pack_ta), &(data[nConn][i].tpc.c.ten_pack_ta)); ta_merge (&(test->tpc.c.new_order_ta), &(data[nConn][i].tpc.c.new_order_ta)); ta_merge (&(test->tpc.c.payment_ta), &(data[nConn][i].tpc.c.payment_ta)); ta_merge (&(test->tpc.c.delivery_ta), &(data[nConn][i].tpc.c.delivery_ta)); ta_merge (&(test->tpc.c.slevel_ta), &(data[nConn][i].tpc.c.slevel_ta)); ta_merge (&(test->tpc.c.ostat_ta), &(data[nConn][i].tpc.c.ostat_ta)); } break; } } if (nA || nOkC) rc1 = do_login (test); if (nA) { if (nOkA < nA) pane_log ("\r\n\r\n%s - %s(%s) - %d out of %d TPC-A Threads ended with errors.\r\n", test->szName, test->szDBMS, test->szDriverName, nA - nOkA, nA); else pane_log ("\r\n\r\n%s - %s(%s) - all %d TPC-A Threads completed successfully.\r\n", test->szName, test->szDBMS, test->szDriverName, nOkA); if (nOkA == 0 && !test->szSQLState[0] && !test->szSQLError[0]) { strcpy ((char *) test->szSQLState, "ERROR"); strcpy ((char *) test->szSQLError, "All Threads ended prematurely."); } if (test->hdbc) CalcStats (runStatus, nOkA, test, test->tpc.a.nTrnCnt, test->tpc.a.nTrnCnt1Sec, test->tpc.a.nTrnCnt2Sec, test->tpc.a.dDiffSum); } if (nOkC) { pane_log ("\r\n\r\n%s - %s(%s) - %d/%d TPC-C Threads ended with no errors.\r\n", test->szName, test->szDBMS, test->szDriverName, nOkC, nC); test->tpc.c.run_time /= nOkC; if (test->hdbc) add_tpcc_result (test); } if ((nA || nOkC) && rc1) do_logout (test); if (!(nOkA || nOkC)) { pane_log ("\r\n\r\n%s - %s(%s) - All Threads ended prematurely.\r\n", test->szName, test->szDBMS, test->szDriverName); rc = 0; } } return rc; }