int main(int argc, char** argv) { double lat, lon; event* events; int n_events; if (argc != 3) { printf("Usage: %s latitude longitude\n", argv[0]); exit(1); } lat = atof(argv[1]); lon = atof(argv[2]); n_events = generate_events(lat, lon, time(NULL), &events); print_events(events, n_events); printf("No more events."); return 0; }
static void run_child(void) { struct sigaction child_action; child_action.sa_handler = child_handler; sigemptyset(&child_action.sa_mask); child_action.sa_flags = SA_NOCLDSTOP; if (sigaction(SIGCHLD, &child_action, NULL) < 0) { tst_brkm(TBROK | TERRNO, cleanup, "sigaction(SIGCHLD, &child_action, NULL) failed"); } switch (child_pid = fork()) { case 0: /* Child will generate events now */ close(fd_notify); generate_events(); exit(0); case -1: tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); } }
static void fork_and_wait (int argc, const char **argv, unsigned int timeout_usec, int do_events, int expect_ok, int kill_child, const char * output, const char * error) { pid_t pid; int stdout_fd[2]; int stderr_fd[2]; int ret = 0; /* open a socketpair for stdout */ ret = socketpair (AF_UNIX, SOCK_STREAM, 0, stdout_fd); MY_ASSERT (ret == 0); /* open a socketpair for stderr */ ret = socketpair (AF_UNIX, SOCK_STREAM, 0, stderr_fd); MY_ASSERT (ret == 0); pid = fork (); MY_ASSERT (pid >= 0); if (pid == 0) { /* child */ int ret = 0; /* close stdin */ ret = close (0); MY_ASSERT (ret == 0); /* close then duplicate stdout and stderr */ ret = close (stdout_fd[1]); MY_ASSERT ( ret == 0); ret = close (stderr_fd[1]); MY_ASSERT ( ret == 0); ret = dup2 (stdout_fd[0], 1); MY_ASSERT ( ret != -1); ret = dup2 (stderr_fd[0], 2); MY_ASSERT ( ret != -1); ret = lwes_event_testing_emitter_main (argc, (char **) argv); exit (ret); } else { /* parent */ int status; pid_t child; int ret = 0; ret = close (stdout_fd[0]); MY_ASSERT (ret == 0); ret = close (stderr_fd[0]); MY_ASSERT (ret == 0); if (do_events) { usleep (timeout_usec); generate_events (); usleep (10 * timeout_usec); if (kill_child) { kill (pid, SIGINT); } } read_and_compare (output, stdout_fd[1]); read_and_compare (error, stderr_fd[1]); /* wait for the child to end */ child = wait (&status); MY_ASSERT (child == pid); ret = (WEXITSTATUS (status) == 0); MY_ASSERT (ret == expect_ok); (void) expect_ok; ret = close (stdout_fd[1]); MY_ASSERT (ret == 0); ret = close (stderr_fd[1]); MY_ASSERT (ret == 0); } }
static void update_maintenance_hosts(zbx_host_maintenance_t *hm, int hm_count, int now) { typedef struct { zbx_uint64_t hostid; int maintenance_from; void *next; } maintenance_t; const char *__function_name = "update_maintenance_hosts"; int i; zbx_uint64_t *ids = NULL, hostid; int ids_alloc = 0, ids_num = 0; DB_RESULT result; DB_ROW row; char *sql = NULL; size_t sql_alloc = ZBX_KIBIBYTE, sql_offset; maintenance_t *maintenances = NULL, *m; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); sql = zbx_malloc(sql, sql_alloc); DBbegin(); for (i = 0; i < hm_count; i++) { if (SUCCEED == uint64_array_exists(ids, ids_num, hm[i].hostid)) continue; if (hm[i].host_maintenanceid != hm[i].maintenanceid || HOST_MAINTENANCE_STATUS_ON != hm[i].host_maintenance_status || hm[i].host_maintenance_type != hm[i].maintenance_type || 0 == hm[i].host_maintenance_from) { zabbix_log(LOG_LEVEL_WARNING, "putting host [%s] into maintenance (with%s data collection)", hm[i].host, MAINTENANCE_TYPE_NORMAL == hm[i].maintenance_type ? "" : "out"); sql_offset = 0; zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update hosts" " set maintenanceid=" ZBX_FS_UI64 "," "maintenance_status=%d," "maintenance_type=%d", hm[i].maintenanceid, HOST_MAINTENANCE_STATUS_ON, hm[i].maintenance_type); if (0 == hm[i].host_maintenance_from) { zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, ",maintenance_from=%d", hm[i].maintenance_from); } zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where hostid=" ZBX_FS_UI64, hm[i].hostid); DBexecute("%s", sql); DCconfig_set_maintenance(&hm[i].hostid, 1, HOST_MAINTENANCE_STATUS_ON, hm[i].maintenance_type, hm[i].maintenance_from); } uint64_array_add(&ids, &ids_alloc, &ids_num, hm[i].hostid, 4); } sql_offset = 0; zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "select hostid,host,maintenance_type,maintenance_from" " from hosts" " where status=%d" " and flags<>%d" " and maintenance_status=%d", HOST_STATUS_MONITORED, ZBX_FLAG_DISCOVERY_PROTOTYPE, HOST_MAINTENANCE_STATUS_ON); if (NULL != ids && 0 != ids_num) { zbx_strcpy_alloc(&sql, &sql_alloc, &sql_offset, " and not"); DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "hostid", ids, ids_num); } result = DBselect("%s", sql); ids_num = 0; while (NULL != (row = DBfetch(result))) { zabbix_log(LOG_LEVEL_WARNING, "taking host [%s] out of maintenance", row[1]); ZBX_STR2UINT64(hostid, row[0]); uint64_array_add(&ids, &ids_alloc, &ids_num, hostid, 4); if (MAINTENANCE_TYPE_NORMAL != atoi(row[2])) continue; m = zbx_malloc(NULL, sizeof(maintenance_t)); m->hostid = hostid; m->maintenance_from = atoi(row[3]); m->next = maintenances; maintenances = m; } DBfree_result(result); sql_offset = 0; zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "update hosts" " set maintenanceid=null," "maintenance_status=%d," "maintenance_type=0," "maintenance_from=0" " where", HOST_MAINTENANCE_STATUS_OFF); if (NULL != ids && 0 != ids_num) { DBadd_condition_alloc(&sql, &sql_alloc, &sql_offset, "hostid", ids, ids_num); DBexecute("%s", sql); DCconfig_set_maintenance(ids, ids_num, HOST_MAINTENANCE_STATUS_OFF, 0, 0); } DBcommit(); zbx_free(sql); zbx_free(ids); for (m = maintenances; NULL != m; m = m->next) generate_events(m->hostid, m->maintenance_from, now); for (m = maintenances; NULL != m; m = maintenances) { maintenances = m->next; zbx_free(m); } zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); }
/*-- Main thread --------------------------------------------------------------*/ void *calo_simulator_thread(void *param) { //CALO_SIMULATOR_THREAD_INFO *info = (CALO_SIMULATOR_THREAD_INFO*) param; //u_int16_t *data = info->data; ADC_TYPE *data = calo_simulator_thread_info.data; printf("Calo simulator thread started\n"); while (1) { pthread_mutex_lock( &(calo_simulator_thread_info.mutex) ); // will be unlocked by MIDAS pthread_mutex_lock( &(calo_simulator_thread_info.mutex_data) ); printf("Calo simulator thread unlocked\n"); #if 1 static int first = 0; if ( first == 0 ) { // use MC event generator generate_events(); first = 1; } #else generate_events(); /* // simple data for testing for (unsigned int i=0; i<calo_simulator_thread_info.data_size; i++) { data[i] = 4000; } // Make one pulse in one calorimeter detector for (unsigned int i=0; i<100; i++) { data[i*1000+100] = 3000; data[i*1000+101] = 2000; data[i*1000+102] = 3000; } //usleep(200000); //sleep(2); */ #endif printf("Calo simulator thread finished\n"); pthread_mutex_unlock( &(calo_simulator_thread_info.mutex_data) ); } return param; }