unsigned int mergeStatus(ISC_STATUS* const dest, unsigned int space, const Firebird::IStatus* from) throw() { const ISC_STATUS* s; unsigned int copied = 0; const int state = from->getState(); ISC_STATUS* to = dest; if (state & Firebird::IStatus::STATE_ERRORS) { s = from->getErrors(); copied = copyStatus(to, space, s, statusLength(s)); to += copied; space -= copied; } if (state & Firebird::IStatus::STATE_WARNINGS) { if (!copied) { init_status(to); to += 2; space -= 2; copied += 2; } s = from->getWarnings(); copied += copyStatus(to, space, s, statusLength(s)); } if (!copied) init_status(dest); return copied; }
static void test_chgat(void) { STATUS st; init_status(stdscr, &st); do { switch (st.ch) { case '.': /* change from current position */ chgat(st.count, st.attr, st.pair, (void *) 0); touch_if_needed(stdscr, st.y_val); break; case ',': /* change from beginning of window */ mvchgat(0, 0, st.count, st.attr, st.pair, (void *) 0); touch_if_needed(stdscr, 0); move(st.y_val, st.x_val); break; case 'w': do_subwindow(stdscr, &st, test_wchgat); break; case 'q': return; default: update_status(stdscr, &st); break; } } while ((st.ch = getch()) != ERR); }
t_pipe *malloc_pipe_struct(t_pipe *list_pipe, int nb_cmd_pipe, char **str_pipe, char **env) { unsigned int i; i = 0; while (str_pipe[i]) i += 1; if ((list_pipe->status = (int*)malloc(sizeof(int) * nb_cmd_pipe)) == NULL || (list_pipe->list_in = (int*)malloc(sizeof(int) * nb_cmd_pipe)) == NULL || (list_pipe->list_out = (int*)malloc(sizeof(int) * nb_cmd_pipe)) == NULL || (list_pipe->list_fd = (int*)malloc(sizeof(int) * ((nb_cmd_pipe - 1) * 2))) == NULL || (list_pipe->cmd = (t_cmd**)malloc(sizeof(t_cmd*) * (i + 1))) == NULL) return (puterror_null("error: could not alloc\n")); i = 0; init_status(list_pipe->status, nb_cmd_pipe); while (str_pipe[i]) { if ((list_pipe->cmd[i] = str_to_cmd(str_pipe[i], env)) == NULL) return (NULL); i += 1; } list_pipe->cmd[i] = NULL; return (list_pipe); }
int test_status() { asic_t *asic = asic_init(TI83p, NULL); z80iodevice_t status = init_status(asic); // Test battery status asic->battery = BATTERIES_GOOD; asic->battery_remove_check = 0; uint8_t value = status.read_in(status.device); if (!(value & 1)) { asic_free(asic); return 1; } // Test flash asic->mmu->flash_unlocked = 1; value = status.read_in(status.device); if (!(value & 4)) { asic_free(asic); return 1; } asic->mmu->flash_unlocked = 0; value = status.read_in(status.device); if (value & 4) { asic_free(asic); return 1; } asic_free(asic); return 0; }
static void zvse_paging_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *pagingstr) { char *p; int ipagerate, pagingyellow, pagingred; float fpagerate=0.0; char pagingresult[100]; int pagingcolor = COL_GREEN; char msgline[4096]; strbuffer_t *upmsg; if (!pagingstr) return; /* * Looking for Paging rate in message * Page Rate=0.00 /sec */ *pagingresult = '\0'; ipagerate=0; p = strstr(pagingstr, "Page Rate=") + 10; if (p) { if (sscanf(p, "%f", &fpagerate) == 1) { ipagerate=fpagerate + 0.5; /* Rounding up */ sprintf(pagingresult, "z/VSE Paging Rate %d per second\n", ipagerate); } } else sprintf(pagingresult, "Can not find page rate value in:\n%s\n", pagingstr); get_paging_thresholds(hinfo, clientclass, &pagingyellow, &pagingred); upmsg = newstrbuffer(0); if (ipagerate > pagingred) { pagingcolor = COL_RED; addtobuffer(upmsg, "&red Paging Rate is CRITICAL\n"); } else if (ipagerate > pagingyellow) { pagingcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Paging Rate is HIGH\n"); } init_status(pagingcolor); sprintf(msgline, "status %s.paging %s %s %s %s\n", commafy(hostname), colorname(pagingcolor), (timestr ? timestr : "<no timestamp data>"), pagingresult, pagingstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
void spcs_s_kinit(spcs_s_info_t kstatus) { #ifdef UNISTAT_TRACE cmn_err(CE_WARN, "!spcs_s_kinit called"); #endif init_status((spcs_s_pinfo_t *)kstatus); }
void init_shader(Shader *s) { assert(s != NULL); init_status(&s->status); _set_shader_defaults(s); }
/** * menustate(void) * * @brief * @param void * @return void */ void menustate(void) { sbool run = TRUE; while(run){ if(widget_get_uip()->root->shown.count > 0 || widget_get_uip()->root->hidden.count > 0) widget_unload(widget_get_uip()->root); switch(menu_state){ case MENU_STATE_MAIN: init_main_menu();//initializes the first menu for use. main_menu();//Start the First Menu, Menu main loop. break; case MENU_STATE_CREDITS: init_credits(); credits(); break; case MENU_STATE_LOGIN: init_login(); login(); break; case MENU_STATE_CREATE: init_new_account(); new_account(); break; case MENU_STATE_INGAME: init_ingame(); ingame(); break; case MENU_STATE_STATUS: if(!statusloader) init_status("Log in successful."); else { init_status("Widget System Initialized."); statusloader = FALSE; } status(); break; case MENU_STATE_EXIT: run = FALSE; break; } } }
int main(void) { init_status(1); while (1) { print_status(); sleep(1); } return 0; }
static void zvm_paging_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cpuutilstr) { char *p; int pagerate, pagingyellow, pagingred; char pagingresult[100]; int pagingcolor = COL_GREEN; char msgline[256]; strbuffer_t *upmsg; if (!cpuutilstr) return; /* * Looking for Paging rate info in 'IND' command response * PAGING-0000/SEC */ *pagingresult = '\0'; /* Skip past three newlines in message to the PAGING text */ p=strstr(cpuutilstr,"PAGING-") + 7; if (sscanf(p, "%d/SEC", &pagerate) == 1) { sprintf(pagingresult, "z/VM Paging Rate %d per second\n", pagerate); } get_paging_thresholds(hinfo, clientclass, &pagingyellow, &pagingred); upmsg = newstrbuffer(0); if (pagerate > pagingred) { pagingcolor = COL_RED; addtobuffer(upmsg, "&red Paging Rate is CRITICAL\n"); } else if (pagerate > pagingyellow) { pagingcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Paging Rate is HIGH\n"); } init_status(pagingcolor); sprintf(msgline, "status %s.paging %s %s %s %s\n", commafy(hostname), colorname(pagingcolor), (timestr ? timestr : "<no timestamp data>"), pagingresult, cpuutilstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
/* * This function causes every status bar, both global and per-window to be * rebuilt, and marks every window as needing its status bar redrawn. * This function can be quite expensive. * * This function should be called whenever you change the global status format * (/SET STATUS_FORMAT*) or one of the sub-components (/SET STATUS_*) * * This function is a /SET callback, so it must always take a (char *) as an * argument even though we don't care about it. */ void build_status (const void *stuff) { Window *w = NULL; if (!main_status_init) init_status(); rebuild_a_status(w); while (traverse_all_windows(&w)) rebuild_a_status(w); update_all_status(); }
spcs_s_info_t spcs_s_kcreate() { spcs_s_pinfo_t *kstatus; #ifdef UNISTAT_TRACE cmn_err(CE_WARN, "!spcs_s_kcreate entry"); #endif kstatus = (spcs_s_pinfo_t *) kmem_alloc(sizeof (spcs_s_pinfo_t), KM_SLEEP); if (kstatus) init_status(kstatus); #ifdef UNISTAT_TRACE cmn_err(CE_WARN, "!spcs_s_kcreate exit"); #endif return ((spcs_s_info_t)kstatus); }
/* * Translate scanned MS options to Watcom options. */ void OptionsTranslate( OPT_STORAGE *cmdOpts, CmdLine *compCmdLine, CmdLine *linkCmdLine ) /****************************************************************/ { /*** Parse the /nologo switch now so we can print the banner ***/ init_status( &status ); if( cmdOpts->nologo ) { QuietModeMessage(); } else { BannerMessage(); } /*** Parse everything ***/ unsupported_opts( cmdOpts ); default_opts( &status, cmdOpts, compCmdLine, linkCmdLine ); compiler_opts( &status, cmdOpts, compCmdLine ); linker_opts( &status, cmdOpts, linkCmdLine ); merge_opts( &status, cmdOpts, compCmdLine, linkCmdLine ); }
/** Init MWM */ void init(void) { /* First init */ ewmh_init_hints(); init_conf(); init_gc(); init_font(); init_cursor(); init_key(); init_root(); screen_init_geo(); infobar_init(); systray_acquire(); init_status(); ewmh_update_current_tag_prop(); grabkeys(); return; }
void init_config(Config *c) { assert(c != NULL); init_status(&c->status); _init_app_config(&c->app); _init_object_config(&c->object); for (int i = 0; i < MAX_TEXTURE_COUNT; i++) { _init_texture_config(&c->textures[i]); } for (int i = 0; i < MAX_UNIFORM_COUNT; i++) { _init_uniform_config(&c->vert_uniforms[i]); } for (int i = 0; i < MAX_UNIFORM_COUNT; i++) { _init_uniform_config(&c->frag_uniforms[i]); } _set_config_defaults(c); }
int main (int argc, char *argv[]) { int n, m; int i; int *array; struct status *sta = NULL; n = atoi(argv[1]); m = atoi(argv[2]); array = (int *) malloc (sizeof (int) * n); init (array, n); sta = init_status (n); //output (sta->num, n + 1); for (i = 0; i < m; i++) { //output (array, n); int *next = next_n_permutation (array, n, 1, sta); if (!next) { init (array, n); } } return 0; }
static void test_insdelln(void) { STATUS st; int n; init_status(stdscr, &st); do { (void) attrset(st.attr | COLOR_PAIR(st.pair)); switch (st.ch) { case 'i': for (n = 0; n < st.count; ++n) insertln(); break; case 'd': for (n = 0; n < st.count; ++n) deleteln(); break; case 'I': insdelln(st.count); break; case 'D': insdelln(-st.count); break; case 'f': fill_window(stdscr); reshow_status(stdscr, &st); break; case 'w': do_subwindow(stdscr, &st, test_winsdelln); break; case 'q': return; default: update_status(stdscr, &st); break; } } while ((st.ch = getch()) != ERR); }
static void test_winsdelln(WINDOW *win) { STATUS st; int n; init_status(win, &st); do { (void) wattrset(win, st.attr | COLOR_PAIR(st.pair)); switch (st.ch) { case 'i': for (n = 0; n < st.count; ++n) winsertln(win); break; case 'd': for (n = 0; n < st.count; ++n) wdeleteln(win); break; case 'I': winsdelln(win, st.count); break; case 'D': winsdelln(win, -st.count); break; case 'f': fill_window(win); reshow_status(win, &st); break; case 'w': do_subwindow(win, &st, test_winsdelln); break; case 'q': return; default: update_status(win, &st); break; } } while ((st.ch = wgetch(win)) != ERR); }
void egoresult(int color, char *egocolumn) { char msgline[1024]; char *timestamps = NULL; init_timestamp(); combo_start(); init_status(color); sprintf(msgline, "status %s.%s %s snmpcollect %s\n\n", xgetenv("MACHINE"), egocolumn, colorname(color), timestamp); addtostatus(msgline); sprintf(msgline, "Variables : %d\n", varcount); addtostatus(msgline); sprintf(msgline, "PDUs : %d\n", pducount); addtostatus(msgline); sprintf(msgline, "Responses : %d\n", okcount); addtostatus(msgline); sprintf(msgline, "Timeouts : %d\n", timeoutcount); addtostatus(msgline); sprintf(msgline, "Too big : %d\n", toobigcount); addtostatus(msgline); sprintf(msgline, "Errors : %d\n", errorcount); addtostatus(msgline); show_timestamps(×tamps); if (timestamps) { addtostatus(timestamps); xfree(timestamps); } finish_status(); combo_end(); }
int main() { viewport_t *viewport; int last_x, last_y; pthread_attr_t attr; pthread_t tid; int i; GLfloat ratio; static GLfloat light_position[] = { 5.0, 5.0, 10.0, 0.0 }; static GLfloat diffuse_light[] = { 1.0, 1.0, 1.0, 1.0 }; //printf("main 1\n"); viewport = new_viewport(1280, 1024); //printf("main 2\n"); viewport->xrot = 20.0; viewport->yrot = 30.0; viewport->zoom = -40.0; //#if UNFINISHED // Initialize OpenGL // From the reshape event handler glViewport(0, 0, viewport->w, viewport->h); //printf("main 2\n"); glMatrixMode(GL_PROJECTION); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); ratio = (GLfloat)viewport->h / (GLfloat)viewport->w; //printf("main 2\n"); glFrustum(-1.0, 1.0, -ratio, ratio, 5.0, 600.0); //printf("main 2\n"); glMatrixMode(GL_MODELVIEW); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthMask(GL_FALSE); //printf("main 2\n"); // Initialize texture //#if 0 { png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); png_infop info_ptr = png_create_info_struct(png_ptr); FILE *fd = fopen(TEXTURE_FILE, "rb"); int w; int h; int color_model; unsigned char **row_pointers; unsigned char *data; if(!fd) { printf("Couldn't open %s.\n", TEXTURE_FILE); exit(1); } png_init_io(png_ptr, fd); png_read_info(png_ptr, info_ptr); w = png_get_image_width(png_ptr, info_ptr); h = png_get_image_height(png_ptr, info_ptr); color_model = png_get_color_type(png_ptr, info_ptr); row_pointers = (unsigned char**)calloc(1, sizeof(png_bytep) * h); data = (unsigned char*)calloc(1, w * h * 3); for(i = 0; i < h; i++) row_pointers[i] = data + w * 3 * i; png_read_image(png_ptr, row_pointers); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &viewport->texName); glBindTexture(GL_TEXTURE_2D, viewport->texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, row_pointers[0]); //printf("main 3\n"); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); free(row_pointers); free(data); fclose(fd); } //printf("main 4\n"); //#endif // 0 // Initialize status init_status(&viewport->status); pthread_attr_init(&attr); pthread_create(&tid, &attr, viewport_loop, viewport); // pthread_create(&tid, &attr, texture_loop, viewport); while(!viewport->done) { //printf("main 5\n"); viewport_draw(viewport); // SDL_ScanFrameBuffer(viewport->screen); //printf("main 6 press a key\n"); //getc(stdin); //exit(0); } //#endif // UNFINISHED //printf("main 8\n"); return 0; }
static void kevent(void *data) { struct usbnet *dev = (struct usbnet *)data; #else static void kevent(struct work_struct *work) { struct usbnet *dev = container_of(work, struct usbnet, kevent); #endif int status; /* usb_clear_halt() needs a thread context */ if (test_bit(EVENT_TX_HALT, &dev->flags)) { unlink_urbs(dev, &dev->txq); status = usb_clear_halt(dev->udev, dev->out); if (status < 0 && status != -EPIPE && status != -ESHUTDOWN) { if (netif_msg_tx_err(dev)) deverr(dev, "can't clear tx halt, status %d", status); } else { clear_bit(EVENT_TX_HALT, &dev->flags); if (status != -ESHUTDOWN) netif_wake_queue(dev->net); } } if (test_bit(EVENT_RX_HALT, &dev->flags)) { unlink_urbs(dev, &dev->rxq); status = usb_clear_halt(dev->udev, dev->in); if (status < 0 && status != -EPIPE && status != -ESHUTDOWN) { if (netif_msg_rx_err(dev)) deverr(dev, "can't clear rx halt, status %d", status); } else { clear_bit(EVENT_RX_HALT, &dev->flags); tasklet_schedule(&dev->bh); } } /* tasklet could resubmit itself forever if memory is tight */ if (test_bit(EVENT_RX_MEMORY, &dev->flags)) { struct urb *urb = NULL; if (netif_running(dev->net)) urb = usb_alloc_urb(0, GFP_KERNEL); else clear_bit(EVENT_RX_MEMORY, &dev->flags); if (urb != NULL) { clear_bit(EVENT_RX_MEMORY, &dev->flags); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) urb->transfer_flags |= URB_ASYNC_UNLINK; #endif rx_submit(dev, urb, GFP_KERNEL); tasklet_schedule(&dev->bh); } } if (test_bit(EVENT_LINK_RESET, &dev->flags)) { struct driver_info *info = dev->driver_info; int retval = 0; clear_bit(EVENT_LINK_RESET, &dev->flags); if (info->link_reset) { retval = info->link_reset(dev); if (retval < 0) { devinfo(dev, "link reset failed (%d) usbnet usb-%s-%s, %s", retval, dev->udev->bus->bus_name, dev->udev->devpath, info->description); } } } if (dev->flags) devdbg(dev, "kevent done, flags = 0x%lx", dev->flags); } /*-------------------------------------------------------------------------*/ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) static void tx_complete(struct urb *urb, struct pt_regs *regs) #else static void tx_complete(struct urb *urb) #endif { struct sk_buff *skb = (struct sk_buff *) urb->context; struct skb_data *entry = (struct skb_data *) skb->cb; struct usbnet *dev = entry->dev; if (urb->status == 0) { dev->stats.tx_packets++; dev->stats.tx_bytes += entry->length; } else { dev->stats.tx_errors++; switch (urb->status) { case -EPIPE: axusbnet_defer_kevent(dev, EVENT_TX_HALT); break; /* software-driven interface shutdown */ case -ECONNRESET: /* async unlink */ case -ESHUTDOWN: /* hardware gone */ break; /* like rx, tx gets controller i/o faults during khubd delays */ /* and so it uses the same throttling mechanism. */ case -EPROTO: case -ETIME: case -EILSEQ: if (!timer_pending(&dev->delay)) { mod_timer(&dev->delay, jiffies + THROTTLE_JIFFIES); if (netif_msg_link(dev)) devdbg(dev, "tx throttle %d", urb->status); } netif_stop_queue(dev->net); break; default: if (netif_msg_tx_err(dev)) devdbg(dev, "tx err %d", entry->urb->status); break; } } urb->dev = NULL; entry->state = tx_done; defer_bh(dev, skb, &dev->txq); } /*-------------------------------------------------------------------------*/ static void axusbnet_tx_timeout(struct net_device *net) { struct usbnet *dev = netdev_priv(net); unlink_urbs(dev, &dev->txq); tasklet_schedule(&dev->bh); /* FIXME: device recovery -- reset? */ } /*-------------------------------------------------------------------------*/ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) static int #else static netdev_tx_t #endif axusbnet_start_xmit(struct sk_buff *skb, struct net_device *net) { struct usbnet *dev = netdev_priv(net); int length; struct urb *urb = NULL; struct skb_data *entry; struct driver_info *info = dev->driver_info; unsigned long flags; int retval; /* some devices want funky USB-level framing, for */ /* win32 driver (usually) and/or hardware quirks */ if (info->tx_fixup) { skb = info->tx_fixup(dev, skb, GFP_ATOMIC); if (!skb) { if (netif_msg_tx_err(dev)) devdbg(dev, "can't tx_fixup skb"); goto drop; } } length = skb->len; urb = usb_alloc_urb(0, GFP_ATOMIC); if (!urb) { if (netif_msg_tx_err(dev)) devdbg(dev, "no urb"); goto drop; } entry = (struct skb_data *) skb->cb; entry->urb = urb; entry->dev = dev; entry->state = tx_start; entry->length = length; usb_fill_bulk_urb(urb, dev->udev, dev->out, skb->data, skb->len, tx_complete, skb); /* don't assume the hardware handles USB_ZERO_PACKET * NOTE: strictly conforming cdc-ether devices should expect * the ZLP here, but ignore the one-byte packet. */ if (!(info->flags & FLAG_SEND_ZLP) && (length % dev->maxpacket) == 0) { urb->transfer_buffer_length++; if (skb_tailroom(skb)) { skb->data[skb->len] = 0; __skb_put(skb, 1); } } spin_lock_irqsave(&dev->txq.lock, flags); switch ((retval = usb_submit_urb(urb, GFP_ATOMIC))) { case -EPIPE: netif_stop_queue(net); axusbnet_defer_kevent(dev, EVENT_TX_HALT); break; default: if (netif_msg_tx_err(dev)) devdbg(dev, "tx: submit urb err %d", retval); break; case 0: net->trans_start = jiffies; __skb_queue_tail(&dev->txq, skb); if (dev->txq.qlen >= TX_QLEN(dev)) netif_stop_queue(net); } spin_unlock_irqrestore(&dev->txq.lock, flags); if (retval) { if (netif_msg_tx_err(dev)) devdbg(dev, "drop, code %d", retval); drop: dev->stats.tx_dropped++; if (skb) dev_kfree_skb_any(skb); usb_free_urb(urb); } else if (netif_msg_tx_queued(dev)) { devdbg(dev, "> tx, len %d, type 0x%x", length, skb->protocol); } return NETDEV_TX_OK; } /*-------------------------------------------------------------------------*/ /* tasklet (work deferred from completions, in_irq) or timer */ static void axusbnet_bh(unsigned long param) { struct usbnet *dev = (struct usbnet *) param; struct sk_buff *skb; struct skb_data *entry; while ((skb = skb_dequeue(&dev->done))) { entry = (struct skb_data *) skb->cb; switch (entry->state) { case rx_done: entry->state = rx_cleanup; rx_process(dev, skb); continue; case tx_done: case rx_cleanup: usb_free_urb(entry->urb); dev_kfree_skb(skb); continue; default: devdbg(dev, "bogus skb state %d", entry->state); } } /* waiting for all pending urbs to complete? */ if (dev->wait) { if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) wake_up(dev->wait); /* or are we maybe short a few urbs? */ } else if (netif_running(dev->net) && netif_device_present(dev->net) && !timer_pending(&dev->delay) && !test_bit(EVENT_RX_HALT, &dev->flags)) { int temp = dev->rxq.qlen; int qlen = RX_QLEN(dev); if (temp < qlen) { struct urb *urb; int i; /* don't refill the queue all at once */ for (i = 0; i < 10 && dev->rxq.qlen < qlen; i++) { urb = usb_alloc_urb(0, GFP_ATOMIC); if (urb != NULL) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) urb->transfer_flags |= URB_ASYNC_UNLINK; #endif rx_submit(dev, urb, GFP_ATOMIC); } } if (temp != dev->rxq.qlen && netif_msg_link(dev)) devdbg(dev, "rxqlen %d --> %d", temp, dev->rxq.qlen); if (dev->rxq.qlen < qlen) tasklet_schedule(&dev->bh); } if (dev->txq.qlen < TX_QLEN(dev)) netif_wake_queue(dev->net); } } /*------------------------------------------------------------------------- * * USB Device Driver support * *-------------------------------------------------------------------------*/ /* precondition: never called in_interrupt */ static void axusbnet_disconnect(struct usb_interface *intf) { struct usbnet *dev; struct usb_device *xdev; struct net_device *net; dev = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); if (!dev) return; xdev = interface_to_usbdev(intf); if (netif_msg_probe(dev)) devinfo(dev, "unregister '%s' usb-%s-%s, %s", intf->dev.driver->name, xdev->bus->bus_name, xdev->devpath, dev->driver_info->description); net = dev->net; unregister_netdev(net); /* we don't hold rtnl here ... */ flush_scheduled_work(); if (dev->driver_info->unbind) dev->driver_info->unbind(dev, intf); free_netdev(net); usb_put_dev(xdev); } /*-------------------------------------------------------------------------*/ /* precondition: never called in_interrupt */ static int axusbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod) { struct usbnet *dev; struct net_device *net; struct usb_host_interface *interface; struct driver_info *info; struct usb_device *xdev; int status; const char *name; name = udev->dev.driver->name; info = (struct driver_info *) prod->driver_info; if (!info) { printk(KERN_ERR "blacklisted by %s\n", name); return -ENODEV; } xdev = interface_to_usbdev(udev); interface = udev->cur_altsetting; usb_get_dev(xdev); status = -ENOMEM; /* set up our own records */ net = alloc_etherdev(sizeof(*dev)); if (!net) { printk(KERN_ERR "can't kmalloc dev"); goto out; } dev = netdev_priv(net); dev->udev = xdev; dev->intf = udev; dev->driver_info = info; dev->driver_name = name; dev->msg_enable = netif_msg_init(msg_level, NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK); skb_queue_head_init(&dev->rxq); skb_queue_head_init(&dev->txq); skb_queue_head_init(&dev->done); dev->bh.func = axusbnet_bh; dev->bh.data = (unsigned long) dev; #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) INIT_WORK(&dev->kevent, kevent, dev); #else INIT_WORK(&dev->kevent, kevent); #endif dev->delay.function = axusbnet_bh; dev->delay.data = (unsigned long) dev; init_timer(&dev->delay); /* mutex_init(&dev->phy_mutex); */ dev->net = net; /* rx and tx sides can use different message sizes; * bind() should set rx_urb_size in that case. */ dev->hard_mtu = net->mtu + net->hard_header_len; #if 0 /* dma_supported() is deeply broken on almost all architectures */ /* possible with some EHCI controllers */ if (dma_supported(&udev->dev, DMA_BIT_MASK(64))) net->features |= NETIF_F_HIGHDMA; #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) net->open = axusbnet_open, net->stop = axusbnet_stop, net->hard_start_xmit = axusbnet_start_xmit, net->tx_timeout = axusbnet_tx_timeout, net->get_stats = axusbnet_get_stats; #endif net->watchdog_timeo = TX_TIMEOUT_JIFFIES; net->ethtool_ops = &axusbnet_ethtool_ops; /* allow device-specific bind/init procedures */ /* NOTE net->name still not usable ... */ status = info->bind(dev, udev); if (status < 0) { deverr(dev, "Binding device failed: %d", status); goto out1; } /* maybe the remote can't receive an Ethernet MTU */ if (net->mtu > (dev->hard_mtu - net->hard_header_len)) net->mtu = dev->hard_mtu - net->hard_header_len; status = init_status(dev, udev); if (status < 0) goto out3; if (!dev->rx_urb_size) dev->rx_urb_size = dev->hard_mtu; dev->maxpacket = usb_maxpacket(dev->udev, dev->out, 1); SET_NETDEV_DEV(net, &udev->dev); status = register_netdev(net); if (status) { deverr(dev, "net device registration failed: %d", status); goto out3; } if (netif_msg_probe(dev)) devinfo(dev, "register '%s' at usb-%s-%s, %s, %pM", udev->dev.driver->name, xdev->bus->bus_name, xdev->devpath, dev->driver_info->description, net->dev_addr); /* ok, it's ready to go. */ usb_set_intfdata(udev, dev); /* start as if the link is up */ netif_device_attach(net); return 0; out3: if (info->unbind) info->unbind(dev, udev); out1: free_netdev(net); out: usb_put_dev(xdev); return status; } /*-------------------------------------------------------------------------*/ /* * suspend the whole driver as soon as the first interface is suspended * resume only when the last interface is resumed */ static int axusbnet_suspend(struct usb_interface *intf, #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 10) pm_message_t message) #else u32 message) #endif { struct usbnet *dev = usb_get_intfdata(intf); if (!dev->suspend_count++) { /* * accelerate emptying of the rx and queues, to avoid * having everything error out. */ netif_device_detach(dev->net); (void) unlink_urbs(dev, &dev->rxq); (void) unlink_urbs(dev, &dev->txq); usb_kill_urb(dev->interrupt); /* * reattach so runtime management can use and * wake the device */ netif_device_attach(dev->net); } return 0; } static int axusbnet_resume(struct usb_interface *intf) { struct usbnet *dev = usb_get_intfdata(intf); int retval = 0; if (!--dev->suspend_count) tasklet_schedule(&dev->bh); retval = init_status(dev, intf); if (retval < 0) return retval; if (dev->interrupt) { retval = usb_submit_urb(dev->interrupt, GFP_KERNEL); if (retval < 0 && netif_msg_ifup(dev)) deverr(dev, "intr submit %d", retval); } return retval; }
int main(int argc, char *argv[]) { char *pagedir; bbgen_page_t *p; dispsummary_t *s; int i; char *pageset = NULL; char *nssidebarfilename = NULL; char *egocolumn = NULL; char *csvfile = NULL; char csvdelim = ','; int embedded = 0; int hobbitddump = 0; char *envarea = NULL; int do_normal_pages = 1; /* Setup standard header+footer (might be modified by option pageset) */ select_headers_and_footers("bb"); bb_color = bb2_color = bbnk_color = -1; pagedir = NULL; init_timestamp(); fqdn = get_fqdn(); /* Setup values from env. vars that may be overridden via commandline options */ if (xgetenv("MKBB2COLREPEAT")) { int i = atoi(xgetenv("MKBB2COLREPEAT")); if (i > 0) maxrowsbeforeheading = i; } for (i = 1; (i < argc); i++) { if ( (strcmp(argv[i], "--hobbitd") == 0) || (argnmatch(argv[i], "--purplelifetime=")) || (strcmp(argv[i], "--nopurple") == 0) ) { /* Deprecated */ } else if (argnmatch(argv[i], "--env=")) { char *lp = strchr(argv[i], '='); loadenv(lp+1, envarea); } else if (argnmatch(argv[i], "--area=")) { char *lp = strchr(argv[i], '='); envarea = strdup(lp+1); } else if (argnmatch(argv[i], "--hobbitddump")) { hobbitddump = 1; } else if (argnmatch(argv[i], "--ignorecolumns=")) { char *lp = strchr(argv[i], '='); ignorecolumns = (char *) malloc(strlen(lp)+2); sprintf(ignorecolumns, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--nk-reds-only")) { nkonlyreds = 1; } else if (argnmatch(argv[i], "--bb2-ignorecolumns=")) { char *lp = strchr(argv[i], '='); bb2ignorecolumns = (char *) malloc(strlen(lp)+2); sprintf(bb2ignorecolumns, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--bb2-colors=")) { char *lp = strchr(argv[i], '=') + 1; bb2colors = colorset(lp, (1 << COL_GREEN)); } else if (argnmatch(argv[i], "--bb2-ignorepurples")) { bb2colors = (bb2colors & ~(1 << COL_PURPLE)); } else if (argnmatch(argv[i], "--bb2-ignoredialups")) { bb2nodialups = 1; } else if (argnmatch(argv[i], "--includecolumns=")) { char *lp = strchr(argv[i], '='); includecolumns = (char *) malloc(strlen(lp)+2); sprintf(includecolumns, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--eventignore=")) { char *lp = strchr(argv[i], '='); eventignorecolumns = (char *) malloc(strlen(lp)+2); sprintf(eventignorecolumns, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--doccgi=")) { char *lp = strchr(argv[i], '='); char *url = (char *)malloc(strlen(xgetenv("CGIBINURL"))+strlen(lp+1)+2); sprintf(url, "%s/%s", xgetenv("CGIBINURL"), lp+1); setdocurl(url); xfree(url); } else if (argnmatch(argv[i], "--docurl=")) { char *lp = strchr(argv[i], '='); setdocurl(lp+1); } else if (argnmatch(argv[i], "--no-doc-window")) { /* This is a no-op now */ } else if (argnmatch(argv[i], "--doc-window")) { setdocurl("TARGET=\"_blank\""); } else if (argnmatch(argv[i], "--htmlextension=")) { char *lp = strchr(argv[i], '='); htmlextension = strdup(lp+1); } else if (argnmatch(argv[i], "--htaccess")) { char *lp = strchr(argv[i], '='); if (lp) htaccess = strdup(lp+1); else htaccess = ".htaccess"; } else if ((strcmp(argv[i], "--wml") == 0) || argnmatch(argv[i], "--wml=")) { char *lp = strchr(argv[i], '='); if (lp) { wapcolumns = (char *) malloc(strlen(lp)+2); sprintf(wapcolumns, ",%s,", (lp+1)); } enable_wmlgen = 1; } else if (argnmatch(argv[i], "--nstab=")) { char *lp = strchr(argv[i], '='); if (strlen(lp+1) > 0) { nssidebarfilename = strdup(lp+1); } else errprintf("--nstab requires a filename\n"); } else if (argnmatch(argv[i], "--nslimit=")) { char *lp = strchr(argv[i], '='); nssidebarcolorlimit = parse_color(lp+1); } else if (argnmatch(argv[i], "--rssversion=")) { char *lp = strchr(argv[i], '='); rssversion = strdup(lp+1); } else if (argnmatch(argv[i], "--rsslimit=")) { char *lp = strchr(argv[i], '='); rsscolorlimit = parse_color(lp+1); } else if (argnmatch(argv[i], "--rss")) { wantrss = 1; } else if (argnmatch(argv[i], "--rssextension=")) { char *lp = strchr(argv[i], '='); rssextension = strdup(lp+1); } else if (argnmatch(argv[i], "--reportopts=")) { char style[MAX_LINE_LEN]; unsigned int rstart, rend; int count = sscanf(argv[i], "--reportopts=%u:%u:%d:%s", &rstart, &rend, &dynamicreport, style); reportstart = rstart; reportend = rend; if (count < 2) { errprintf("Invalid --reportopts option: Must have start- and end-times\n"); return 1; } if (count < 3) dynamicreport = 1; if (count == 4) { if (strcmp(style, stylenames[STYLE_CRIT]) == 0) reportstyle = STYLE_CRIT; else if (strcmp(style, stylenames[STYLE_NONGR]) == 0) reportstyle = STYLE_NONGR; else reportstyle = STYLE_OTHER; } if (reportstart < 788918400) reportstart = 788918400; if (reportend > time(NULL)) reportend = time(NULL); if (xgetenv("BBREPWARN")) reportwarnlevel = atof(xgetenv("BBREPWARN")); if (xgetenv("BBREPGREEN")) reportgreenlevel = atof(xgetenv("BBREPGREEN")); if ((reportwarnlevel < 0.0) || (reportwarnlevel > 100.0)) reportwarnlevel = 97.0; if ((reportgreenlevel < 0.0) || (reportgreenlevel > 100.0)) reportgreenlevel = 99.995; select_headers_and_footers("bbrep"); sethostenv_report(reportstart, reportend, reportwarnlevel, reportgreenlevel); } else if (argnmatch(argv[i], "--csv=")) { char *lp = strchr(argv[i], '='); csvfile = strdup(lp+1); } else if (argnmatch(argv[i], "--csvdelim=")) { char *lp = strchr(argv[i], '='); csvdelim = *(lp+1); } else if (argnmatch(argv[i], "--snapshot=")) { char *lp = strchr(argv[i], '='); snapshot = atol(lp+1); select_headers_and_footers("bbsnap"); sethostenv_snapshot(snapshot); } else if (strcmp(argv[i], "--pages-first") == 0) { hostsbeforepages = 0; } else if (strcmp(argv[i], "--pages-last") == 0) { hostsbeforepages = 1; } else if (argnmatch(argv[i], "--subpagecolumns=")) { char *lp = strchr(argv[i], '='); subpagecolumns = atoi(lp+1); if (subpagecolumns < 1) subpagecolumns=1; } else if (argnmatch(argv[i], "--maxrows=")) { char *lp = strchr(argv[i], '='); maxrowsbeforeheading = atoi(lp+1); if (maxrowsbeforeheading < 0) maxrowsbeforeheading=0; } else if (strcmp(argv[i], "--recentgifs") == 0) { use_recentgifs = 1; } else if (argnmatch(argv[i], "--recentgifs=")) { char *lp = strchr(argv[i], '='); use_recentgifs = 1; recentgif_limit = 60*durationvalue(lp+1); } else if (strcmp(argv[i], "--sort-group-only-items") == 0) { sort_grouponly_items = 1; } else if (argnmatch(argv[i], "--page-title=")) { char *lp = strchr(argv[i], '='); defaultpagetitle = strdup(lp+1); } else if (argnmatch(argv[i], "--dialupskin=")) { char *lp = strchr(argv[i], '='); dialupskin = strdup(lp+1); } else if (argnmatch(argv[i], "--reverseskin=")) { char *lp = strchr(argv[i], '='); reverseskin = strdup(lp+1); } else if (strcmp(argv[i], "--pagetitle-links") == 0) { pagetitlelinks = 1; } else if (strcmp(argv[i], "--pagetext-headings") == 0) { pagetextheadings = 1; } else if (strcmp(argv[i], "--underline-headings") == 0) { underlineheadings = 1; } else if (strcmp(argv[i], "--no-underline-headings") == 0) { underlineheadings = 0; } else if (strcmp(argv[i], "--no-eventlog") == 0) { bb2eventlog = 0; } else if (argnmatch(argv[i], "--max-eventcount=")) { char *lp = strchr(argv[i], '='); bb2eventlogmaxcount = atoi(lp+1); } else if (argnmatch(argv[i], "--max-eventtime=")) { char *lp = strchr(argv[i], '='); bb2eventlogmaxtime = atoi(lp+1); } else if (argnmatch(argv[i], "--max-ackcount=")) { char *lp = strchr(argv[i], '='); bb2acklogmaxcount = atoi(lp+1); } else if (argnmatch(argv[i], "--max-acktime=")) { char *lp = strchr(argv[i], '='); bb2acklogmaxtime = atoi(lp+1); } else if (strcmp(argv[i], "--no-acklog") == 0) { bb2acklog = 0; } else if (strcmp(argv[i], "--no-pages") == 0) { do_normal_pages = 0; } else if (argnmatch(argv[i], "--noprop=")) { char *lp = strchr(argv[i], '='); nopropyellowdefault = (char *) malloc(strlen(lp)+2); sprintf(nopropyellowdefault, ",%s,", (lp+1)); errprintf("--noprop is deprecated - use --nopropyellow instead\n"); } else if (argnmatch(argv[i], "--nopropyellow=")) { char *lp = strchr(argv[i], '='); nopropyellowdefault = (char *) malloc(strlen(lp)+2); sprintf(nopropyellowdefault, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--nopropred=")) { char *lp = strchr(argv[i], '='); nopropreddefault = (char *) malloc(strlen(lp)+2); sprintf(nopropreddefault, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--noproppurple=")) { char *lp = strchr(argv[i], '='); noproppurpledefault = (char *) malloc(strlen(lp)+2); sprintf(noproppurpledefault, ",%s,", (lp+1)); } else if (argnmatch(argv[i], "--nopropack=")) { char *lp = strchr(argv[i], '='); nopropackdefault = (char *) malloc(strlen(lp)+2); sprintf(nopropackdefault, ",%s,", (lp+1)); } else if (strcmp(argv[i], "--bbpageONLY") == 0) { /* Deprecated */ errprintf("--bbpageONLY is deprecated - use --pageset=NAME to generate pagesets\n"); } else if (strcmp(argv[i], "--embedded") == 0) { embedded = 1; } else if (argnmatch(argv[i], "--pageset=")) { char *lp = strchr(argv[i], '='); pageset = strdup(lp+1); } else if (argnmatch(argv[i], "--template=")) { char *lp = strchr(argv[i], '='); lp++; select_headers_and_footers(lp); } else if (argnmatch(argv[i], "--purplelog=")) { char *lp = strchr(argv[i], '='); if (*(lp+1) == '/') purplelogfn = strdup(lp+1); else { purplelogfn = (char *) malloc(strlen(xgetenv("BBHOME"))+1+strlen(lp+1)+1); sprintf(purplelogfn, "%s/%s", xgetenv("BBHOME"), (lp+1)); } } else if (argnmatch(argv[i], "--report=") || (strcmp(argv[i], "--report") == 0)) { char *lp = strchr(argv[i], '='); if (lp) { egocolumn = strdup(lp+1); } else egocolumn = "bbgen"; timing = 1; } else if (argnmatch(argv[i], "--nklog=") || (strcmp(argv[i], "--nklog") == 0)) { char *lp = strchr(argv[i], '='); if (lp) { lognkstatus = strdup(lp+1); } else lognkstatus = "nk"; } else if (strcmp(argv[i], "--timing") == 0) { timing = 1; } else if (strcmp(argv[i], "--debug") == 0) { debug = 1; } else if (strcmp(argv[i], "--no-update") == 0) { dontsendmessages = 1; } else if (strcmp(argv[i], "--version") == 0) { printf("bbgen version %s\n", VERSION); printf("\n"); exit(0); } else if ((strcmp(argv[i], "--help") == 0) || (strcmp(argv[i], "-?") == 0)) { printf("bbgen for Hobbit version %s\n\n", VERSION); printf("Usage: %s [options] [WebpageDirectory]\n", argv[0]); printf("Options:\n"); printf(" --ignorecolumns=test[,test] : Completely ignore these columns\n"); printf(" --nk-reds-only : Only show red statuses on the NK page\n"); printf(" --bb2-ignorecolumns=test[,test]: Ignore these columns for the BB2 page\n"); printf(" --bb2-ignorepurples : Ignore all-purple hosts on BB2 page\n"); printf(" --includecolumns=test[,test]: Always include these columns on BB2 page\n"); printf(" --max-eventcount=N : Max number of events to include in eventlog\n"); printf(" --max-eventtime=N : Show events that occurred within the last N minutes\n"); printf(" --eventignore=test[,test] : Columns to ignore in bb2 event-log display\n"); printf(" --no-eventlog : Do not generate the bb2 eventlog display\n"); printf(" --no-acklog : Do not generate the bb2 ack-log display\n"); printf(" --no-pages : Generate only the bb2 and bbnk pages\n"); printf(" --docurl=documentation-URL : Hostnames link to a general (dynamic) web page for docs\n"); printf(" --no-doc-window : Open doc-links in same window\n"); printf(" --htmlextension=.EXT : Sets filename extension for generated file (default: .html\n"); printf(" --report[=COLUMNNAME] : Send a status report about the running of bbgen\n"); printf(" --reportopts=ST:END:DYN:STL : Run in Hobbit Reporting mode\n"); printf(" --csv=FILENAME : For Hobbit Reporting, output CSV file\n"); printf(" --csvdelim=CHARACTER : Delimiter in CSV file output (default: comma)\n"); printf(" --snapshot=TIME : Snapshot mode\n"); printf("\nPage layout options:\n"); printf(" --pages-first : Put page- and subpage-links before hosts (default)\n"); printf(" --pages-last : Put page- and subpage-links after hosts\n"); printf(" --subpagecolumns=N : Number of columns for links to pages and subpages\n"); printf(" --maxrows=N : Repeat column headings for every N hosts shown\n"); printf(" --recentgifs : Use xxx-recent.gif icons for newly changed tests\n"); printf(" --sort-group-only-items : Display group-only items in alphabetical order\n"); printf(" --page-title=TITLE : Set a default page title for all pages\n"); printf(" --dialupskin=URL : Use a different icon skin for dialup tests\n"); printf(" --reverseskin=URL : Use a different icon skin for reverse tests\n"); printf(" --pagetitle-links : Make page- and subpage-titles act as links\n"); printf(" --pagetext-headings : Use page texts as headings\n"); printf(" --no-underline-headings : Do not underline the page headings\n"); printf("\nStatus propagation control options:\n"); printf(" --noprop=test[,test] : Disable upwards status propagation when YELLOW\n"); printf(" --nopropred=test[,test] : Disable upwards status propagation when RED or YELLOW\n"); printf(" --noproppurple=test[,test] : Disable upwards status propagation when PURPLE\n"); printf("\nAlternate pageset generation support:\n"); printf(" --pageset=SETNAME : Generate non-standard pageset with tag SETNAME\n"); printf(" --template=TEMPLATE : template for header and footer files\n"); printf("\nAlternate output formats:\n"); printf(" --wml[=test1,test2,...] : Generate a small (bb2-style) WML page\n"); printf(" --nstab=FILENAME : Generate a Netscape Sidebar feed\n"); printf(" --nslimit=COLOR : Minimum color to include on Netscape sidebar\n"); printf(" --rss : Generate a RSS/RDF feed of alerts\n"); printf(" --rssextension=.EXT : Sets filename extension for RSS files (default: .rss\n"); printf(" --rssversion={0.91|0.92|1.0|2.0} : Specify RSS/RDF version (default: 0.91)\n"); printf(" --rsslimit=COLOR : Minimum color to include on RSS feed\n"); printf("\nDebugging/troubleshooting options:\n"); printf(" --timing : Collect timing information\n"); printf(" --debug : Debugging information\n"); printf(" --version : Show version information\n"); printf(" --purplelog=FILENAME : Create a log of purple hosts and tests\n"); exit(0); } else if (argnmatch(argv[i], "-")) { errprintf("Unknown option : %s\n", argv[i]); } else { /* Last argument is pagedir */ pagedir = strdup(argv[i]); } } /* In case they changed the name of our column ... */ if (egocolumn) setup_signalhandler(egocolumn); if (debug) { int i; printf("Command: bbgen"); for (i=1; (i<argc); i++) printf(" '%s'", argv[i]); printf("\n"); printf("Environment BBHOSTS='%s'\n", textornull(xgetenv("BBHOSTS"))); printf("\n"); } add_timestamp("Startup"); /* Check that all needed environment vars are defined */ envcheck(reqenv); /* Catch a SEGV fault */ setup_signalhandler("bbgen"); /* Set umask to 0022 so that the generated HTML pages have world-read access */ umask(0022); if (pagedir == NULL) { if (xgetenv("BBWWW")) { pagedir = strdup(xgetenv("BBWWW")); } else { pagedir = (char *) malloc(strlen(xgetenv("BBHOME"))+5); sprintf(pagedir, "%s/www", xgetenv("BBHOME")); } } if (xgetenv("BBHTACCESS")) bbhtaccess = strdup(xgetenv("BBHTACCESS")); if (xgetenv("BBPAGEHTACCESS")) bbpagehtaccess = strdup(xgetenv("BBPAGEHTACCESS")); if (xgetenv("BBSUBPAGEHTACCESS")) bbsubpagehtaccess = strdup(xgetenv("BBSUBPAGEHTACCESS")); /* * When doing alternate pagesets, disable some stuff: * No WML or RSS pages. */ if (pageset || embedded || snapshot) enable_wmlgen = wantrss = 0; if (embedded) { egocolumn = htaccess = NULL; /* * Need to have default SIGPIPE handling when doing embedded stuff. * We are probably run from a CGI script or something similar. */ signal(SIGPIPE, SIG_DFL); } /* Load all data from the various files */ load_all_links(); add_timestamp("Load links done"); pagehead = load_bbhosts(pageset); add_timestamp("Load bbhosts done"); if (!embedded) { /* Remove old acknowledgements */ delete_old_acks(); add_timestamp("ACK removal done"); } statehead = load_state(&dispsums); if (embedded || snapshot) dispsums = NULL; add_timestamp("Load STATE done"); if (hobbitddump) { dump_hobbitdchk(); return 0; } /* Calculate colors of hosts and pages */ calc_hostcolors(bb2ignorecolumns); calc_pagecolors(pagehead); /* Topmost page (background color for bb.html) */ for (p=pagehead; (p); p = p->next) { if (p->color > pagehead->color) pagehead->color = p->color; } bb_color = pagehead->color; if (xgetenv("SUMMARY_SET_BKG") && (strcmp(xgetenv("SUMMARY_SET_BKG"), "TRUE") == 0)) { /* * Displayed summaries affect the BB page only, * but should not go into the color we report to * others. */ for (s=dispsums; (s); s = s->next) { if (s->color > pagehead->color) pagehead->color = s->color; } } add_timestamp("Color calculation done"); if (debug) dumpall(pagehead); /* Generate pages */ if (chdir(pagedir) != 0) { errprintf("Cannot change to webpage directory %s\n", pagedir); exit(1); } if (embedded) { /* Just generate that one page */ do_one_page(pagehead, NULL, 1); return 0; } /* The main page - bb.html and pages/subpages thereunder */ add_timestamp("Hobbit pagegen start"); if (reportstart && csvfile) { csv_availability(csvfile, csvdelim); } else if (do_normal_pages) { do_page_with_subs(pagehead, dispsums); } add_timestamp("Hobbit pagegen done"); if (reportstart) { /* Reports end here */ return 0; } /* The full summary page - bb2.html */ bb2_color = do_bb2_page(nssidebarfilename, PAGE_BB2); add_timestamp("BB2 generation done"); /* Reduced summary (alerts) page - bbnk.html */ bbnk_color = do_bb2_page(NULL, PAGE_NK); add_timestamp("BBNK generation done"); if (snapshot) { /* Snapshots end here */ return 0; } /* Send summary notices - only once, so not on pagesets */ if (pageset == NULL) { send_summaries(sumhead); add_timestamp("Summary transmission done"); } /* Generate WML cards */ if (enable_wmlgen) { do_wml_cards(pagedir); add_timestamp("WML generation done"); } /* Need to do this before sending in our report */ add_timestamp("Run completed"); /* Tell about us */ if (egocolumn) { char msgline[4096]; char *timestamps; long bbsleep = (xgetenv("BBSLEEP") ? atol(xgetenv("BBSLEEP")) : 300); int color; /* Go yellow if it runs for too long */ if (total_runtime() > bbsleep) { errprintf("WARNING: Runtime %ld longer than BBSLEEP (%ld)\n", total_runtime(), bbsleep); } color = (errbuf ? COL_YELLOW : COL_GREEN); combo_start(); init_status(color); sprintf(msgline, "status %s.%s %s %s\n\n", xgetenv("MACHINE"), egocolumn, colorname(color), timestamp); addtostatus(msgline); sprintf(msgline, "bbgen for Hobbit version %s\n", VERSION); addtostatus(msgline); sprintf(msgline, "\nStatistics:\n Hosts : %5d\n Status messages : %5d\n Purple messages : %5d\n Pages : %5d\n", hostcount, statuscount, purplecount, pagecount); addtostatus(msgline); if (errbuf) { addtostatus("\n\nError output:\n"); addtostatus(errbuf); } show_timestamps(×tamps); addtostatus(timestamps); finish_status(); combo_end(); } else show_timestamps(NULL); return 0; }
int main(int argc, char *argv[]) { void *hwalk; int argi; strbuffer_t *statusmsg, *jrockout, *qout; for (argi = 1; (argi < argc); argi++) { if ((strcmp(argv[argi], "--help") == 0)) { printf("beastat version %s\n\n", VERSION); printf("Usage:\n%s [--debug] [--no-update] [--port=SNMPPORT] [--community=SNMPCOMMUNITY]\n", argv[0]); exit(0); } else if ((strcmp(argv[argi], "--version") == 0)) { printf("beastat version %s\n", VERSION); exit(0); } else if ((strcmp(argv[argi], "--debug") == 0)) { debug = 1; } else if ((strcmp(argv[argi], "--no-update") == 0)) { dontsendmessages = 1; } else if (argnmatch(argv[argi], "--timeout=")) { char *p = strchr(argv[argi], '='); extcmdtimeout = atoi(p+1); } else if (argnmatch(argv[argi], "--port=")) { char *p = strchr(argv[argi], '='); default_port = atoi(p+1); } else if (argnmatch(argv[argi], "--community=")) { char *p = strchr(argv[argi], '='); default_community = strdup(p+1); } } load_hostnames(xgetenv("BBHOSTS"), "netinclude", get_fqdn()); if (first_host() == NULL) { errprintf("Cannot load bb-hosts\n"); return 1; } if (xgetenv("BBLOCATION")) location = strdup(xgetenv("BBLOCATION")); init_timestamp(); combo_start(); statusmsg = newstrbuffer(0); jrockout = newstrbuffer(0); qout = newstrbuffer(0); for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { char *tspec = bbh_custom_item(hwalk, "bea="); char *snmpcommunity = default_community; char *beadomain = ""; int snmpport = default_port; char *p; char pipecmd[4096]; int jrockres, qres; clearstrbuffer(statusmsg); clearstrbuffer(jrockout); clearstrbuffer(qout); /* Check if we have a "bea" test for this host, and it is a host we want to test */ if (!tspec || !wanted_host(hwalk, location)) continue; /* Parse the testspec: bea=[SNMPCOMMUNITY@]BEADOMAIN[:SNMPPORT] */ tspec = strdup(tspec+strlen("bea=")); p = strchr(tspec, ':'); if (p) { *p = '\0'; snmpport = atoi(p+1); } p = strchr(tspec, '@'); if (p) { *p = '\0'; snmpcommunity = strdup(tspec); beadomain = strdup(p+1); } else { beadomain = strdup(tspec); } /* Prepare for the host status */ statuscolor = COL_GREEN; /* Setup the snmpwalk pipe-command for jrockit stats */ sprintf(pipecmd, "snmpwalk -m BEA-WEBLOGIC-MIB -c %s@%s -v 1 %s:%d enterprises.140.625.302.1", snmpcommunity, beadomain, bbh_item(hwalk, BBH_IP), snmpport); jrockres = run_command(pipecmd, NULL, jrockout, 0, extcmdtimeout); if (jrockres == 0) { find_idxes(STRBUF(jrockout), "BEA-WEBLOGIC-MIB::jrockitRuntimeIndex."); send_data(hwalk, beadomain, STRBUF(jrockout), jrockitems); } else { if (statuscolor < COL_YELLOW) statuscolor = COL_YELLOW; sprintf(msgline, "Could not retrieve BEA jRockit statistics from %s:%d domain %s (code %d)\n", bbh_item(hwalk, BBH_IP), snmpport, beadomain, jrockres); addtobuffer(statusmsg, msgline); } /* Setup the snmpwalk pipe-command for executeQueur stats */ sprintf(pipecmd, "snmpwalk -m BEA-WEBLOGIC-MIB -c %s@%s -v 1 %s:%d enterprises.140.625.180.1", snmpcommunity, beadomain, bbh_item(hwalk, BBH_IP), snmpport); qres = run_command(pipecmd, NULL, qout, 0, extcmdtimeout); if (qres == 0) { find_idxes(STRBUF(qout), "BEA-WEBLOGIC-MIB::executeQueueRuntimeIndex."); send_data(hwalk, beadomain, STRBUF(qout), qitems); } else { if (statuscolor < COL_YELLOW) statuscolor = COL_YELLOW; sprintf(msgline, "Could not retrieve BEA executeQueue statistics from %s:%d domain %s (code %d)\n", bbh_item(hwalk, BBH_IP), snmpport, beadomain, qres); addtobuffer(statusmsg, msgline); } /* FUTURE: Have the statuscolor/statusmsg be updated to check against thresholds */ /* Right now, the "bea" status is always green */ init_status(statuscolor); sprintf(msgline, "status %s.%s %s %s\n\n", commafy(bbh_item(hwalk, BBH_HOSTNAME)), "bea", colorname(statuscolor), timestamp); addtostatus(msgline); if (STRBUFLEN(statusmsg) == 0) addtobuffer(statusmsg, "All BEA monitors OK\n"); addtostrstatus(statusmsg); finish_status(); } combo_end(); freestrbuffer(statusmsg); freestrbuffer(jrockout); freestrbuffer(qout); return 0; }
static void zvm_users_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *psstr) { int pscolor = COL_GREEN; int pchecks; int cmdofs = -1; char msgline[4096]; strbuffer_t *monmsg; static strbuffer_t *countdata = NULL; int anycountdata = 0; char *group; if (!want_msgtype(hinfo, MSG_PROCS)) return; if (!psstr) return; if (!countdata) countdata = newstrbuffer(0); clearalertgroups(); monmsg = newstrbuffer(0); sprintf(msgline, "data %s.proccounts\n", commafy(hostname)); addtobuffer(countdata, msgline); cmdofs = 0; /* Command offset for z/VM isn't necessary */ pchecks = clear_process_counts(hinfo, clientclass); if (pchecks == 0) { /* Nothing to check */ sprintf(msgline, "&%s No process checks defined\n", colorname(noreportcolor)); addtobuffer(monmsg, msgline); pscolor = noreportcolor; } else if (cmdofs >= 0) { /* Count how many instances of each monitored process is running */ char *pname, *pid, *bol, *nl; int pcount, pmin, pmax, pcolor, ptrack; bol = psstr; while (bol) { nl = strchr(bol, '\n'); /* Take care - the ps output line may be shorter than what we look at */ if (nl) { *nl = '\0'; if ((nl-bol) > cmdofs) add_process_count(bol+cmdofs); *nl = '\n'; bol = nl+1; } else { if (strlen(bol) > cmdofs) add_process_count(bol+cmdofs); bol = NULL; } } /* Check the number found for each monitored process */ while ((pname = check_process_count(&pcount, &pmin, &pmax, &pcolor, &pid, &ptrack, &group)) != NULL) { char limtxt[1024]; if (pmax == -1) { if (pmin > 0) sprintf(limtxt, "%d or more", pmin); else if (pmin == 0) sprintf(limtxt, "none"); } else { if (pmin > 0) sprintf(limtxt, "between %d and %d", pmin, pmax); else if (pmin == 0) sprintf(limtxt, "at most %d", pmax); } if (pcolor == COL_GREEN) { sprintf(msgline, "&green %s (found %d, req. %s)\n", pname, pcount, limtxt); addtobuffer(monmsg, msgline); } else { if (pcolor > pscolor) pscolor = pcolor; sprintf(msgline, "&%s %s (found %d, req. %s)\n", colorname(pcolor), pname, pcount, limtxt); addtobuffer(monmsg, msgline); addalertgroup(group); } if (ptrack) { /* Save the count data for later DATA message to track process counts */ if (!pid) pid = "default"; sprintf(msgline, "%s:%u\n", pid, pcount); addtobuffer(countdata, msgline); anycountdata = 1; } } } else { pscolor = COL_YELLOW; sprintf(msgline, "&yellow Expected string not found in ps output header\n"); addtobuffer(monmsg, msgline); } /* Now we know the result, so generate a status message */ init_status(pscolor); group = getalertgroups(); if (group) sprintf(msgline, "status/group:%s ", group); else strcpy(msgline, "status "); addtostatus(msgline); sprintf(msgline, "%s.procs %s %s - Processes %s\n", commafy(hostname), colorname(pscolor), (timestr ? timestr : "<No timestamp data>"), ((pscolor == COL_GREEN) ? "OK" : "NOT ok")); addtostatus(msgline); /* And add the info about what's wrong */ if (STRBUFLEN(monmsg)) { addtostrstatus(monmsg); addtostatus("\n"); } /* And the full virtual machine names output for those who want it */ if (pslistinprocs) { /* * Format the list of virtual machines into four per line, * this list could be fairly long. */ char *tmpstr, *tok, *nm[4]; int nmidx = 0; /* Make a copy of psstr, strtok() will be changing it */ tmpstr = strdup(psstr); /* Use strtok() to split string into pieces delimited by newline */ tok = strtok(tmpstr, "\n"); while (tok) { nm[nmidx++] = tok; if (nmidx == 4) { sprintf(msgline, "%-8s %-8s %-8s %-8s\n", nm[0], nm[1], nm[2], nm[3]); addtostatus(msgline); nmidx = 0; nm[0] = nm[1] = nm[2] = nm[3] = " "; } tok = strtok(NULL, "\n"); } /* Print any remaining names */ if (nmidx > 0) { sprintf(msgline, "%-8s %-8s %-8s %-8s\n", nm[0], nm[1], nm[2], nm[3]); addtostatus(msgline); } free(tmpstr); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(monmsg); if (anycountdata) sendmessage(STRBUF(countdata), NULL, BBTALK_TIMEOUT, NULL); clearstrbuffer(countdata); }
static void zvm_cpu_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cpuutilstr, char *uptimestr) { char *p; float load1, loadyellow, loadred; int recentlimit, ancientlimit, maxclockdiff; int uphour, upmin; char loadresult[100]; char myupstr[100]; long uptimesecs = -1; long upday; int cpucolor = COL_GREEN; char msgline[1024]; strbuffer_t *upmsg; if (!want_msgtype(hinfo, MSG_CPU)) return; if (!cpuutilstr) return; if (!uptimestr) return; uptimesecs = 0; /* * z/VM: "Uptime: 1 Days, 13 Hours, 38 Minutes" */ sscanf(uptimestr,"Uptime: %ld Days, %d Hours, %d Minutes", &upday, &uphour, &upmin); uptimesecs = upday * 86400; uptimesecs += 60*(60*uphour + upmin); sprintf(myupstr, "%s\n", uptimestr); /* * Looking for average CPU Utilization in 'IND' command response * AVGPROC-000% */ *loadresult = '\0'; p = strstr(cpuutilstr, "AVGPROC-") + 8 ; if (p) { if (sscanf(p, "%f%%", &load1) == 1) { sprintf(loadresult, "z/VM CPU Utilization %3.0f%%\n", load1); } } get_cpu_thresholds(hinfo, clientclass, &loadyellow, &loadred, &recentlimit, &ancientlimit, &maxclockdiff); upmsg = newstrbuffer(0); if (load1 > loadred) { cpucolor = COL_RED; addtobuffer(upmsg, "&red Load is CRITICAL\n"); } else if (load1 > loadyellow) { cpucolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Load is HIGH\n"); } if ((uptimesecs != -1) && (recentlimit != -1) && (uptimesecs < recentlimit)) { if (cpucolor == COL_GREEN) cpucolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Machine recently rebooted\n"); } if ((uptimesecs != -1) && (ancientlimit != -1) && (uptimesecs > ancientlimit)) { if (cpucolor == COL_GREEN) cpucolor = COL_YELLOW; sprintf(msgline, "&yellow Machine has been up more than %d days\n", (ancientlimit / 86400)); addtobuffer(upmsg, msgline); } init_status(cpucolor); sprintf(msgline, "status %s.cpu %s %s %s %s %s\n", commafy(hostname), colorname(cpucolor), (timestr ? timestr : "<no timestamp data>"), loadresult, myupstr, cpuutilstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
SETUP() { init_status(&cfg); }
int main() { viewport_t *viewport; int last_x, last_y; pthread_attr_t attr; pthread_t tid; int i; GLfloat ratio; static GLfloat light_position[] = { 5.0, 5.0, 10.0, 0.0 }; static GLfloat diffuse_light[] = { 1.0, 1.0, 1.0, 1.0 }; //printf("main 1\n"); viewport = new_viewport(1280, 1024); //printf("main 2\n"); viewport->xrot = 20.0; viewport->yrot = 30.0; viewport->zoom = -40.0; viewport->x1 = 0; viewport->y1 = 0; viewport->y2 = TEXTURE_SIDE; viewport->x2 = TEXTURE_SIDE; viewport->tex_x1 = 0; viewport->tex_y1 = 0; viewport->tex_x2 = 1; viewport->tex_y2 = 1; //#if UNFINISHED // Initialize OpenGL // From the reshape event handler glViewport(0, 0, viewport->w, viewport->h); //printf("main 2\n"); glMatrixMode(GL_PROJECTION); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); ratio = (GLfloat)viewport->h / (GLfloat)viewport->w; //printf("main 2\n"); glFrustum(-1.0, 1.0, -ratio, ratio, 5.0, 600.0); //printf("main 2\n"); glMatrixMode(GL_MODELVIEW); //printf("main 2\n"); glLoadIdentity(); //printf("main 2\n"); glEnable(GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_light); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glEnable(GL_LIGHTING); // glShadeModel(GL_SMOOTH); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); // glDepthMask(GL_FALSE); //printf("main 2\n"); // Initialize movie { unsigned char **row_pointers; int j, w, h; viewport->frame_size = TEXTURE_SIDE * TEXTURE_SIDE * 4; viewport->total_frames = TOTAL_FRAMES; viewport->movie_data = calloc(1, TEXTURE_SIDE * TEXTURE_SIDE * 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for(i = 0; i < TEXTURE_COUNT; i++) { glGenTextures(1, &viewport->texture[i]); glBindTexture(GL_TEXTURE_2D, viewport->texture[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TEXTURE_SIDE, TEXTURE_SIDE, 0, GL_RGB, GL_UNSIGNED_BYTE, viewport->movie_data); } //printf("main 3\n"); } viewport->current_frame = 0; viewport->frame_step = 1; //printf("main 4\n"); //#endif // 0 // Initialize status init_status(&viewport->status); viewport_draw(viewport); pthread_attr_init(&attr); pthread_create(&tid, &attr, viewport_loop, viewport); pthread_join(tid, 0); //#endif // UNFINISHED //printf("main 8\n"); return 0; }
void send_content_results(service_t *httptest, testedhost_t *host, char *nonetpage, char *contenttestname, int failgoesclear) { testitem_t *t, *firsttest; int color = -1; char *nopagename; int nopage = 0; char *conttest; int contentnum = 0; conttest = (char *) malloc(128); if (host->firsthttp == NULL) return; /* Check if this service is a NOPAGENET service. */ nopagename = (char *) malloc(strlen(contenttestname)+3); sprintf(nopagename, ",%s,", contenttestname); nopage = (strstr(nonetpage, contenttestname) != NULL); xfree(nopagename); dbgprintf("Calc content color host %s : ", host->hostname); firsttest = host->firsthttp; for (t=firsttest; (t && (t->host == host)); t = nextcontenttest(httptest, host, t)) { http_data_t *req = (http_data_t *) t->privdata; char cause[100]; char *msgline; int got_data = 1; /* Skip the "data"-only messages */ if (t->senddata) continue; if (!req->contentcheck) continue; /* We have a content check */ strcpy(cause, "Content OK"); if (req->contstatus == 0) { /* The content check passed initial checks of regexp etc. */ color = statuscolor(t->host, req->httpstatus); if (color == COL_GREEN) { /* We got the data from the server */ int status = 0; switch (req->contentcheck) { case CONTENTCHECK_REGEX: if (req->output) { regmatch_t foo[1]; status = regexec((regex_t *) req->exp, req->output, 0, foo, 0); regfree((regex_t *) req->exp); } else { /* output may be null if we only got a redirect */ status = STATUS_CONTENTMATCH_FAILED; } break; case CONTENTCHECK_NOREGEX: if (req->output) { regmatch_t foo[1]; status = (!regexec((regex_t *) req->exp, req->output, 0, foo, 0)); regfree((regex_t *) req->exp); } else { /* output may be null if we only got a redirect */ status = STATUS_CONTENTMATCH_FAILED; } break; case CONTENTCHECK_DIGEST: if (req->digest == NULL) req->digest = strdup(""); if (strcmp(req->digest, (char *)req->exp) != 0) { status = STATUS_CONTENTMATCH_FAILED; } else status = 0; req->output = (char *) malloc(strlen(req->digest)+strlen((char *)req->exp)+strlen("Expected:\nGot :\n")+1); sprintf(req->output, "Expected:%s\nGot :%s\n", (char *)req->exp, req->digest); break; case CONTENTCHECK_CONTENTTYPE: if (req->contenttype && (strcasecmp(req->contenttype, (char *)req->exp) == 0)) { status = 0; } else { status = STATUS_CONTENTMATCH_FAILED; } if (req->contenttype == NULL) req->contenttype = strdup("No content-type provdied"); req->output = (char *) malloc(strlen(req->contenttype)+strlen((char *)req->exp)+strlen("Expected content-type: %s\nGot content-type : %s\n")+1); sprintf(req->output, "Expected content-type: %s\nGot content-type : %s\n", (char *)req->exp, req->contenttype); break; } req->contstatus = ((status == 0) ? 200 : STATUS_CONTENTMATCH_FAILED); color = statuscolor(t->host, req->contstatus); if (color != COL_GREEN) strcpy(cause, "Content match failed"); } else { /* * Failed to retrieve the webpage. * Report CLEAR, unless "alwaystrue" is set. */ if (failgoesclear && !t->alwaystrue) color = COL_CLEAR; got_data = 0; strcpy(cause, "Failed to get webpage"); } if (nopage && (color == COL_RED)) color = COL_YELLOW; } else { /* This only happens upon internal errors in Hobbit test system */ color = statuscolor(t->host, req->contstatus); strcpy(cause, "Internal Hobbit error"); } /* Send the content status message */ dbgprintf("Content check on %s is %s\n", req->url, colorname(color)); if (req->bburl.columnname) { strcpy(conttest, req->bburl.columnname); } else { if (contentnum > 0) sprintf(conttest, "%s%d", contenttestname, contentnum); else strcpy(conttest, contenttestname); contentnum++; } msgline = (char *)malloc(4096 + (2 * strlen(req->url))); init_status(color); sprintf(msgline, "status+%d %s.%s %s %s: %s\n", validity, commafy(host->hostname), conttest, colorname(color), timestamp, cause); addtostatus(msgline); if (!got_data) { if (host->hidehttp) { sprintf(msgline, "\nContent check failed\n"); } else { sprintf(msgline, "\nAn error occurred while testing <a href=\"%s\">URL %s</a>\n", req->url, req->url); } } else { if (host->hidehttp) { sprintf(msgline, "\n&%s Content check %s\n", colorname(color), ((color == COL_GREEN) ? "OK" : "Failed")); } else { sprintf(msgline, "\n&%s %s - Testing <a href=\"%s\">URL</a> yields:\n", colorname(color), req->url, req->url); } } addtostatus(msgline); xfree(msgline); if (req->output == NULL) { addtostatus("\nNo output received from server\n\n"); } else if (!host->hidehttp) { /* Dont flood hobbitd with data */ if (req->outlen > MAX_CONTENT_DATA) { *(req->output + MAX_CONTENT_DATA) = '\0'; req->outlen = MAX_CONTENT_DATA; } if ( (req->contenttype && (strncasecmp(req->contenttype, "text/html", 9) == 0)) || (strncasecmp(req->output, "<html", 5) == 0) ) { char *bodystart = NULL; char *bodyend = NULL; bodystart = strstr(req->output, "<body"); if (bodystart == NULL) bodystart = strstr(req->output, "<BODY"); if (bodystart) { char *p; p = strchr(bodystart, '>'); if (p) bodystart = (p+1); } else bodystart = req->output; bodyend = strstr(bodystart, "</body"); if (bodyend == NULL) bodyend = strstr(bodystart, "</BODY"); if (bodyend) { *bodyend = '\0'; } addtostatus("<div>\n"); addtostatus(bodystart); addtostatus("\n</div>\n"); } else { addtostatus(req->output); } } addtostatus("\n\n"); finish_status(); } xfree(conttest); }
int usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod) { struct usbnet *dev; struct net_device *net; struct usb_host_interface *interface; struct driver_info *info; struct usb_device *xdev; int status; const char *name; name = udev->dev.driver->name; info = (struct driver_info *) prod->driver_info; if (!info) { dev_dbg (&udev->dev, "blacklisted by %s\n", name); return -ENODEV; } xdev = interface_to_usbdev (udev); interface = udev->cur_altsetting; usb_get_dev (xdev); status = -ENOMEM; // set up our own records net = alloc_etherdev(sizeof(*dev)); if (!net) { dbg ("can't kmalloc dev"); goto out; } dev = netdev_priv(net); dev->udev = xdev; dev->intf = udev; dev->driver_info = info; dev->driver_name = name; dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK); skb_queue_head_init (&dev->rxq); skb_queue_head_init (&dev->txq); skb_queue_head_init (&dev->done); skb_queue_head_init(&dev->rxq_pause); dev->bh.func = usbnet_bh; dev->bh.data = (unsigned long) dev; INIT_WORK (&dev->kevent, kevent); init_usb_anchor(&dev->deferred); dev->delay.function = usbnet_bh; dev->delay.data = (unsigned long) dev; init_timer (&dev->delay); mutex_init (&dev->phy_mutex); dev->net = net; strcpy (net->name, "usb%d"); memcpy (net->dev_addr, node_id, sizeof node_id); /* rx and tx sides can use different message sizes; * bind() should set rx_urb_size in that case. */ dev->hard_mtu = net->mtu + net->hard_header_len; #if 0 // dma_supported() is deeply broken on almost all architectures // possible with some EHCI controllers if (dma_supported (&udev->dev, DMA_BIT_MASK(64))) net->features |= NETIF_F_HIGHDMA; #endif net->netdev_ops = &usbnet_netdev_ops; net->watchdog_timeo = TX_TIMEOUT_JIFFIES; net->ethtool_ops = &usbnet_ethtool_ops; // allow device-specific bind/init procedures // NOTE net->name still not usable ... if (info->bind) { status = info->bind (dev, udev); if (status < 0) goto out1; // heuristic: "usb%d" for links we know are two-host, // else "eth%d" when there's reasonable doubt. userspace // can rename the link if it knows better. if ((dev->driver_info->flags & FLAG_ETHER) != 0 && (net->dev_addr [0] & 0x02) == 0) strcpy (net->name, "eth%d"); /* WLAN devices should always be named "wlan%d" */ if ((dev->driver_info->flags & FLAG_WLAN) != 0) strcpy(net->name, "wlan%d"); /* WWAN devices should always be named "wwan%d" */ if ((dev->driver_info->flags & FLAG_WWAN) != 0) strcpy(net->name, "wwan%d"); /* maybe the remote can't receive an Ethernet MTU */ if (net->mtu > (dev->hard_mtu - net->hard_header_len)) net->mtu = dev->hard_mtu - net->hard_header_len; } else if (!info->in || !info->out) status = usbnet_get_endpoints (dev, udev); else { dev->in = usb_rcvbulkpipe (xdev, info->in); dev->out = usb_sndbulkpipe (xdev, info->out); if (!(info->flags & FLAG_NO_SETINT)) status = usb_set_interface (xdev, interface->desc.bInterfaceNumber, interface->desc.bAlternateSetting); else status = 0; } if (status >= 0 && dev->status) status = init_status (dev, udev); if (status < 0) goto out3; if (!dev->rx_urb_size) dev->rx_urb_size = dev->hard_mtu; dev->maxpacket = usb_maxpacket (dev->udev, dev->out, 1); SET_NETDEV_DEV(net, &udev->dev); if ((dev->driver_info->flags & FLAG_WLAN) != 0) SET_NETDEV_DEVTYPE(net, &wlan_type); if ((dev->driver_info->flags & FLAG_WWAN) != 0) SET_NETDEV_DEVTYPE(net, &wwan_type); status = register_netdev (net); if (status) goto out3; netif_info(dev, probe, dev->net, "register '%s' at usb-%s-%s, %s, %pM\n", udev->dev.driver->name, xdev->bus->bus_name, xdev->devpath, dev->driver_info->description, net->dev_addr); // ok, it's ready to go. usb_set_intfdata (udev, dev); netif_device_attach (net); if (dev->driver_info->flags & FLAG_LINK_INTR) netif_carrier_off(net); return 0; out3: if (info->unbind) info->unbind (dev, udev); out1: free_netdev(net); out: usb_put_dev(xdev); return status; }
void send_http_results(service_t *httptest, testedhost_t *host, testitem_t *firsttest, char *nonetpage, int failgoesclear) { testitem_t *t; int color = -1; char *svcname; strbuffer_t *msgtext; char *nopagename; int nopage = 0; int anydown = 0, totalreports = 0; if (firsttest == NULL) return; svcname = strdup(httptest->testname); if (httptest->namelen) svcname[httptest->namelen] = '\0'; /* Check if this service is a NOPAGENET service. */ nopagename = (char *) malloc(strlen(svcname)+3); sprintf(nopagename, ",%s,", svcname); nopage = (strstr(nonetpage, svcname) != NULL); xfree(nopagename); dbgprintf("Calc http color host %s : ", host->hostname); msgtext = newstrbuffer(0); for (t=firsttest; (t && (t->host == host)); t = t->next) { http_data_t *req = (http_data_t *) t->privdata; /* Skip the data-reports for now */ if (t->senddata) continue; /* Grab session cookies */ update_session_cookies(host->hostname, req->bburl.desturl->host, req->headers); totalreports++; if (req->bburl.okcodes || req->bburl.badcodes) { req->httpcolor = statuscolor_by_set(host, req->httpstatus, req->bburl.okcodes, req->bburl.badcodes); } else { req->httpcolor = statuscolor(host, req->httpstatus); } if (req->httpcolor == COL_RED) anydown++; /* Dialup hosts and dialup tests report red as clear */ if ((req->httpcolor != COL_GREEN) && (host->dialup || t->dialup)) req->httpcolor = COL_CLEAR; /* If ping failed, report CLEAR unless alwaystrue */ if ( ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) && /* Test failed */ (host->downcount > 0) && /* The ping check did fail */ (!host->noping && !host->noconn) && /* We are doing a ping test */ (failgoesclear) && (!t->alwaystrue) ) /* No "~testname" flag */ { req->httpcolor = COL_CLEAR; } /* If test we depend on has failed, report CLEAR unless alwaystrue */ if ( ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) && /* Test failed */ failgoesclear && !t->alwaystrue ) /* No "~testname" flag */ { char *faileddeps = deptest_failed(host, t->service->testname); if (faileddeps) { req->httpcolor = COL_CLEAR; req->faileddeps = strdup(faileddeps); } } dbgprintf("%s(%s) ", t->testspec, colorname(req->httpcolor)); if (req->httpcolor > color) color = req->httpcolor; /* Build the short msgtext which goes on line 1 of the status message. */ addtobuffer(msgtext, (STRBUFLEN(msgtext) ? " ; " : ": ") ); if (req->tcptest->errcode != CONTEST_ENOERROR) { switch (req->tcptest->errcode) { case CONTEST_ETIMEOUT: req->errorcause = "Server timeout"; break; case CONTEST_ENOCONN : req->errorcause = strdup(strerror(req->tcptest->connres)); break; case CONTEST_EDNS : switch (req->parsestatus) { case 1 : req->errorcause = "Invalid URL"; break; case 2 : req->errorcause = "Hostname not in DNS"; break; default: req->errorcause = "DNS error"; break; } break; case CONTEST_EIO : req->errorcause = "I/O error"; break; case CONTEST_ESSL : req->errorcause = "SSL error"; break; default: req->errorcause = "Xfer failed"; } addtobuffer(msgtext, req->errorcause); } else if (req->tcptest->open == 0) { req->errorcause = "Connect failed"; addtobuffer(msgtext, req->errorcause); } else if ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) { char m1[100]; if (req->bburl.okcodes || req->bburl.badcodes) { sprintf(m1, "Unwanted HTTP status %ld", req->httpstatus); } else if (req->headers) { char *p = req->headers; /* Skip past "HTTP/1.x 200 " and pick up the explanatory text, if any */ if (strncasecmp(p, "http/", 5) == 0) { p += 5; p += strspn(p, "0123456789. "); } strncpy(m1, p, sizeof(m1)-1); m1[sizeof(m1)-1] = '\0'; /* Only show the first line of the HTTP status description */ p = strchr(m1, '\n'); if (p) *p = '\0'; } else { sprintf(m1, "HTTP error %ld", req->httpstatus); } addtobuffer(msgtext, m1); req->errorcause = strdup(m1); } else { addtobuffer(msgtext, "OK"); if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtobuffer(msgtext, m1); } } } /* It could be that we have 0 http tests - if we only do the apache one */ if (totalreports > 0) { char msgline[4096]; if (anydown) { firsttest->downcount++; if(firsttest->downcount == 1) firsttest->downstart = getcurrenttime(NULL); } else firsttest->downcount = 0; /* Handle the "badtest" stuff for http tests */ if ((color == COL_RED) && (firsttest->downcount < firsttest->badtest[2])) { if (firsttest->downcount >= firsttest->badtest[1]) color = COL_YELLOW; else if (firsttest->downcount >= firsttest->badtest[0]) color = COL_CLEAR; else color = COL_GREEN; } if (nopage && (color == COL_RED)) color = COL_YELLOW; dbgprintf(" --> %s\n", colorname(color)); /* Send off the http status report */ init_status(color); sprintf(msgline, "status+%d %s.%s %s %s", validity, commafy(host->hostname), svcname, colorname(color), timestamp); addtostatus(msgline); addtostrstatus(msgtext); addtostatus("\n"); for (t=firsttest; (t && (t->host == host)); t = t->next) { char *urlmsg; http_data_t *req = (http_data_t *) t->privdata; /* Skip the "data" reports */ if (t->senddata) continue; urlmsg = (char *)malloc(1024 + strlen(req->url)); sprintf(urlmsg, "\n&%s %s - ", colorname(req->httpcolor), req->url); addtostatus(urlmsg); if (req->httpcolor == COL_GREEN) addtostatus("OK"); else { if (req->errorcause) addtostatus(req->errorcause); else addtostatus("failed"); } if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtostatus(m1); } addtostatus("\n"); if (req->headers) { addtostatus("\n"); addtostatus(req->headers); } if (req->faileddeps) addtostatus(req->faileddeps); sprintf(urlmsg, "\nSeconds: %5d.%02d\n\n", (unsigned int)req->tcptest->totaltime.tv_sec, (unsigned int)req->tcptest->totaltime.tv_nsec / 10000000 ); addtostatus(urlmsg); xfree(urlmsg); } addtostatus("\n\n"); finish_status(); } /* Send of any HTTP status tests in separate columns */ for (t=firsttest; (t && (t->host == host)); t = t->next) { int color; char msgline[4096]; char *urlmsg; http_data_t *req = (http_data_t *) t->privdata; if ((t->senddata) || (!req->bburl.columnname) || (req->contentcheck != CONTENTCHECK_NONE)) continue; /* Handle the "badtest" stuff */ color = req->httpcolor; if ((color == COL_RED) && (t->downcount < t->badtest[2])) { if (t->downcount >= t->badtest[1]) color = COL_YELLOW; else if (t->downcount >= t->badtest[0]) color = COL_CLEAR; else color = COL_GREEN; } if (nopage && (color == COL_RED)) color = COL_YELLOW; /* Send off the http status report */ init_status(color); sprintf(msgline, "status+%d %s.%s %s %s", validity, commafy(host->hostname), req->bburl.columnname, colorname(color), timestamp); addtostatus(msgline); addtostatus(" : "); addtostatus(req->errorcause ? req->errorcause : "OK"); if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtostatus(m1); } addtostatus("\n"); urlmsg = (char *)malloc(1024 + strlen(req->url)); sprintf(urlmsg, "\n&%s %s - ", colorname(req->httpcolor), req->url); addtostatus(urlmsg); xfree(urlmsg); if (req->httpcolor == COL_GREEN) addtostatus("OK"); else { if (req->errorcause) addtostatus(req->errorcause); else addtostatus("failed"); } addtostatus("\n"); if (req->headers) { addtostatus("\n"); addtostatus(req->headers); } if (req->faileddeps) addtostatus(req->faileddeps); sprintf(msgline, "\nSeconds: %5d.%02d\n\n", (unsigned int)req->tcptest->totaltime.tv_sec, (unsigned int)req->tcptest->totaltime.tv_nsec / 10000000 ); addtostatus(msgline); addtostatus("\n\n"); finish_status(); } /* Send off any "data" messages now */ for (t=firsttest; (t && (t->host == host)); t = t->next) { http_data_t *req; char *data = ""; char *msg; if (!t->senddata) continue; req = (http_data_t *) t->privdata; if (req->output) data = req->output; msg = (char *)malloc(1024 + strlen(host->hostname) + strlen(req->bburl.columnname) + strlen(data)); sprintf(msg, "data %s.%s\n%s", commafy(host->hostname), req->bburl.columnname, data); sendmessage(msg, NULL, BBTALK_TIMEOUT, NULL); xfree(msg); } xfree(svcname); freestrbuffer(msgtext); }