static void top(void) { xenstat_domain **domains; unsigned int i, num_domains = 0; /* Now get the node information */ if (prev_node != NULL) xenstat_free_node(prev_node); prev_node = cur_node; cur_node = xenstat_get_node(xhandle, XENSTAT_ALL); if (cur_node == NULL) fail("Failed to retrieve statistics from libxenstat\n"); /* dump summary top information */ if (!batch) do_summary(); /* Count the number of domains for which to report data */ num_domains = xenstat_node_num_domains(cur_node); domains = calloc(num_domains, sizeof(xenstat_domain *)); if(domains == NULL) fail("Failed to allocate memory\n"); for (i=0; i < num_domains; i++) domains[i] = xenstat_node_domain_by_index(cur_node, i); /* Sort */ qsort(domains, num_domains, sizeof(xenstat_domain *), (int(*)(const void *, const void *))compare_domains); if(first_domain_index >= num_domains) first_domain_index = num_domains-1; for (i = first_domain_index; i < num_domains; i++) { if(!batch && current_row() == lines()-1) break; if (i == first_domain_index || repeat_header) do_header(); do_domain(domains[i]); if (show_vcpus) do_vcpu(domains[i]); if (show_networks) do_network(domains[i]); if (show_vbds) do_vbd(domains[i]); if (show_tmem) do_tmem(domains[i]); } if (!batch) do_bottom_line(); free(domains); }
/*}}}*/ static void do_fragment(struct data *d, struct micro *frag)/*{{{*/ { do_network(d, 2, &frag->g2); do_network(d, 3, &frag->g3); }
int main(int argc, char** argv) { printf("haltestelle built <%s %s> version %s\n", __DATE__, __TIME__, VERSION); if(argc < 5) { fprintf(stderr, "usage: %s <designation> <busfarhn_host> <busfarhn_port> <serialport>\n", argv[0]); exit(-1); } /*global*/ designation = argv[1]; /*global*/ busfarhn_host = argv[2]; /*global*/ busfarhn_port = atoi(argv[3]); char* serialport = argv[4]; /*global*/ sockfd = start_socket(); if(connect_to_busfarhn(designation) != 0) { fprintf(stderr, "[ERROR] connecting to %s:%d failed\n", busfarhn_host, busfarhn_port); return -1; } #ifdef USE_SERIAL #ifdef SERIAL_IS_A_FILE printf("%s is a FILE\n", serialport); #elif defined SERIAL_IS_A_ATH0 printf("%s is a SERIAL PORT (ATH style)\n", serialport); #else printf("%s is a SERIAL PORT\n", serialport); #endif #else printf("WARNING: NOT USING THE SERIAL PORT\n"); #endif printf("[STARTUP] connected to %s:%i with designation %s\n", busfarhn_host, busfarhn_port, designation); #ifdef USE_SERIAL #ifdef SERIAL_IS_A_FILE /*global*/ serialfd = fopen(serialport, "rw"); #elif defined SERIAL_IS_A_ATH0 /*global*/ serialfd = open(serialport, O_RDWR); #else /*global*/ serialfd = open(serialport, O_RDWR | O_NOCTTY | O_SYNC); #endif if (serialfd < 0) { fprintf(stderr, "error %d opening %s: %s", errno, serialport, strerror (errno)); return; } #if !(defined SERIAL_IS_A_FILE || defined SERIAL_IS_A_ATH0) set_interface_attribs (serialfd, SERIAL_BAUDRATE, 0); // set speed to 115,200 bps, 8n1 (no parity) set_blocking (serialfd, 0); // set no blocking #endif #endif hs_startup(); char netbuf[MAXBUFLEN]; unsigned int netbufpos = 0; struct sockaddr_storage their_addr; socklen_t addr_len; #ifdef USE_SERIAL pthread_t pth; pthread_create(&pth, NULL, thread_read_serial, NULL); #endif while(1) { // network int numbytes; addr_len = sizeof their_addr; if ((numbytes = recvfrom(sockfd, (netbuf + netbufpos), MAXBUFLEN - (netbufpos + 1), MSG_DONTWAIT, (struct sockaddr *)&their_addr, &addr_len)) > 0) { printf("[NET] received %i bytes\n", numbytes); int i = 0; for(i = 0; i < numbytes; i++) if(netbuf[netbufpos + i] == '\n') break; netbufpos += numbytes; if(i < numbytes) { // found breakline netbuf[netbufpos - 1] = '\0'; netbufpos = 0; printf("CMD <%s>\n", netbuf); JSON_Value* json = json_parse_string(netbuf); if(json_value_get_type(json) == JSONObject) { JSON_Object* obj = json_value_get_object(json); const char* msgtype = json_object_dotget_string(obj, "type"); if(strcmp(msgtype, "io.tcp.ping") == 0) do_ping(); else do_network(json, netbuf); } json_value_free(json); } if(netbufpos + 1 == MAXBUFLEN) { printf("[NET] ERROR: received %i bytes and still no breakline. Discarding the message.\n", MAXBUFLEN); netbufpos = 0; } } else if(numbytes == 0) { break; } } hs_shutdown(); close(sockfd); return 0; }