static int one_shot(int keycode, t_mdata *mdata) { if (keycode == ECHAP) exit(0); else if (keycode == NUM_0 || keycode == NUMPAD_0) reset_values(mdata); else if (keycode == SPACE) mdata->debug = (mdata->debug ? 0 : 1); else if (keycode == NUM_1 || keycode == NUMPAD_1) mdata->shadows = (mdata->shadows ? 0 : 1); else if (keycode == 47) { mdata->keys->more_angle = (mdata->keys->more_angle ? 0 : 1); mdata->keys->less_angle = 0; } else if (keycode == 46) { mdata->keys->less_angle = (mdata->keys->less_angle ? 0 : 1); mdata->keys->more_angle = 0; } else return (0); expose(mdata); return (1); }
/* * Construct an device_values_t and set all of its values to known states */ static void device_values_constructor(device_values_t *s) { s->section_name = NULL; s->vendor_id = 0; s->vendor_part_id = 0; reset_values(&s->values); }
static void tick() { struct timeval t; struct tm *timeofday; gettimeofday(&t, 0); timeofday = localtime((const time_t *) &t.tv_sec); reset_values(timeofday->tm_hour, timeofday->tm_min, timeofday->tm_sec); }
/* * The component found a device and is querying to see if an INI file * specified any parameters for it. */ int ompi_btl_openib_ini_query(uint32_t vendor_id, uint32_t vendor_part_id, ompi_btl_openib_ini_values_t *values) { int ret; device_values_t *h; opal_list_item_t *item; if (!initialized) { if (OMPI_SUCCESS != (ret = ompi_btl_openib_ini_init())) { return ret; } } if (mca_btl_openib_component.verbose) { BTL_OUTPUT(("Querying INI files for vendor 0x%04x, part ID %d", vendor_id, vendor_part_id)); } reset_values(values); /* Iterate over all the saved devices */ for (item = opal_list_get_first(&devices); item != opal_list_get_end(&devices); item = opal_list_get_next(item)) { h = (device_values_t*) item; if (vendor_id == h->vendor_id && vendor_part_id == h->vendor_part_id) { /* Found it! */ /* NOTE: There is a bug in the PGI 6.2 series that causes the compiler to choke when copying structs containing bool members by value. So do a memcpy here instead. */ memcpy(values, &h->values, sizeof(h->values)); if (mca_btl_openib_component.verbose) { BTL_OUTPUT(("Found corresponding INI values: %s", h->section_name)); } return OMPI_SUCCESS; } } /* If we fall through to here, we didn't find it */ if (mca_btl_openib_component.verbose) { BTL_OUTPUT(("Did not find corresponding INI values")); } return OMPI_ERR_NOT_FOUND; }
/* for findSplit */ void AzReg_TsrSib::reset_forNewLeaf(const AzTrTree_ReadOnly *inp_tree, const AzRegDepth *inp_reg_depth) { tree = inp_tree; forNewLeaf = true; focus_nx = -1; reg_depth = inp_reg_depth; int node_num = tree->nodeNum(); /*--- set v ---*/ v_v.reform(node_num); int nx; for (nx = 0; nx < node_num; ++nx) { if (!tree->node(nx)->isLeaf()) continue; deriv_v(tree, nx, false, NULL, &v_v); } reset_values(); }
void get_burning_ship(t_fract *fract, t_pos c) { int i; i = 0; fract->c.real = 1.5 * (c.x - WW / 2) / (1 * fract->zoom * WW) + fract->move.x; fract->c.imag = (c.y - WH / 2) / (1 * fract->zoom * WH) + fract->move.y; reset_values(&fract->n, &fract->o); while (i < fract->max_i && (sqr(fract->n.real) + sqr(fract->n.imag)) < 4) { fract->o.real = fract->n.real; fract->o.imag = fract->n.imag; fract->n.real = sqr(fract->o.real) - sqr(fract->o.imag) + fract->c.real; fract->n.imag = 2.0 * fabs(fract->o.real * fract->o.imag) + (1.5 * fract->c.imag); i++; } fract->color = i; }
/* * Reset a parsed section; free any memory that it may have had */ static void reset_section(bool had_previous_value, parsed_section_values_t *s) { if (had_previous_value) { if (NULL != s->name) { free(s->name); } if (NULL != s->vendor_ids) { free(s->vendor_ids); } if (NULL != s->vendor_part_ids) { free(s->vendor_part_ids); } } s->name = NULL; s->vendor_ids = NULL; s->vendor_ids_len = 0; s->vendor_part_ids = NULL; s->vendor_part_ids_len = 0; reset_values(&s->values); }
static inline void retrieve_more_op (uint8_t insum) { if (readingopcode) { theopcode = insum; if (theopcode == 4) { dobreak = true; return; } argswaiting_count(); readingopcode = false; } else { *sp++ = insum; --argswaiting; } if (!argswaiting) { readingopcode = true; execute(); if (dobreak) { return; // An op can propogate a dobreak. } } reset_values(); }
/* for optimization */ void AzReg_TsrSib::reset(const AzTrTree_ReadOnly *inp_tree, const AzRegDepth *inp_reg_depth) { tree = inp_tree; forNewLeaf = false; focus_nx = -1; reg_depth = inp_reg_depth; if (tree == NULL) { throw new AzException("AzReg_TsrSib::reset", "null tree"); } int node_num = tree->nodeNum(); av_dv.reset(node_num); v_v.reform(node_num); int nx; for (nx = 0; nx < node_num; ++nx) { if (!tree->node(nx)->isLeaf()) continue; deriv_v(tree, nx, false, av_dv.point_u(nx), &v_v); } reset_values(); }
void grg_pref_dialog (GtkWidget * parent) { GtkWidget *prefs, *notebook, *tab1, *tab2, *tab3; GtkWidget *frame1, *frame2, *frame3; GtkWidget *crypt_box, *hash_box, *comp_box; GtkWidget *frame_font; GtkWidget *frame_file, *but_file, *box_file, *but_file_clear; GtkWidget *frame_save, *box_save; GtkWidget *frame_misc, *box_misc; GtkWidget *frame_xpire, *box_xpire, *xpire_lbl; GtkWidget *frame_passes, *box_passes, *lbl_passes; GtkWidget *frame_clip, *box_clip; gint response; PangoFontDescription *fdesc; if (active_flag) return; prefs = gtk_dialog_new_with_buttons (_("Preferences"), GTK_WINDOW (parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); //first page: algorithms tab1 = gtk_table_new (3, 2, FALSE); frame1 = gtk_frame_new (_("Encryption")); gtk_table_attach_defaults (GTK_TABLE (tab1), frame1, 0, 1, 0, 3); crypt_box = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame1), crypt_box); NEW_RADIO_BUTTON (rij1_but, NULL, modify_crypto, GRG_AES, "AES (Rijndael 128)", crypt_box); NEW_RADIO_BUTTON (ser_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_SERPENT, "Serpent", crypt_box); NEW_RADIO_BUTTON (twof_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_TWOFISH, "Twofish", crypt_box); NEW_RADIO_BUTTON (cast_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_CAST_256, "Cast 256", crypt_box); NEW_RADIO_BUTTON (safer_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_SAFERPLUS, "Safer+", crypt_box); NEW_RADIO_BUTTON (loki_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_LOKI97, "Loki97", crypt_box); NEW_RADIO_BUTTON (tdes_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_3DES, "3-DES", crypt_box); NEW_RADIO_BUTTON (rij2_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (rij1_but)), modify_crypto, GRG_RIJNDAEL_256, "Rijndael 256", crypt_box); NEW_ROW_SEPARATOR (crypt_box); NEW_LABEL (crypto_block_lbl, crypt_box, ""); NEW_LABEL (crypto_key_lbl, crypt_box, ""); update_crypto_label (); frame2 = gtk_frame_new (_("Hashing")); gtk_table_attach_defaults (GTK_TABLE (tab1), frame2, 1, 2, 0, 1); hash_box = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame2), hash_box); NEW_RADIO_BUTTON (sha_but, NULL, modify_hash, GRG_SHA1, "SHA1", hash_box); NEW_RADIO_BUTTON (ripe_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (sha_but)), modify_hash, GRG_RIPEMD_160, "RIPEMD 160", hash_box); frame3 = gtk_frame_new (_("Compression")); gtk_table_attach_defaults (GTK_TABLE (tab1), frame3, 1, 2, 1, 2); comp_box = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame3), comp_box); NEW_RADIO_BUTTON (zlib_but, NULL, modify_comp, GRG_ZLIB, "ZLib", comp_box); NEW_RADIO_BUTTON (bz_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (zlib_but)), modify_comp, GRG_BZIP, "BZip2", comp_box); NEW_ROW_SEPARATOR (comp_box); NEW_RADIO_BUTTON (r0_but, NULL, modify_ratio, GRG_LVL_NONE, _("None"), comp_box); NEW_RADIO_BUTTON (r3_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (r0_but)), modify_ratio, GRG_LVL_FAST, _("Fast"), comp_box); NEW_RADIO_BUTTON (r6_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (r0_but)), modify_ratio, GRG_LVL_GOOD, _("Good"), comp_box); NEW_RADIO_BUTTON (r9_but, gtk_radio_button_get_group (GTK_RADIO_BUTTON (r0_but)), modify_ratio, GRG_LVL_BEST, _("Best"), comp_box); notebook = gtk_notebook_new (); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), tab1, gtk_label_new (_("Algorithms"))); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prefs)->vbox), notebook, TRUE, TRUE, GRG_PAD); //second page: General options tab2 = gtk_vbox_new (FALSE, GRG_PAD); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), tab2, gtk_label_new (_("General options"))); frame_font = gtk_frame_new (_("Editor font")); gtk_box_pack_start (GTK_BOX (tab2), frame_font, FALSE, TRUE, 1); but_font = gtk_button_new_with_label (_ ("Click to change the editor font")); gtk_container_add (GTK_CONTAINER (frame_font), but_font); fdesc = pango_font_description_from_string (grg_prefs_editor_font); gtk_widget_modify_font (but_font, fdesc); g_free (fdesc); g_signal_connect (G_OBJECT (but_font), "clicked", G_CALLBACK (modify_font), prefs); frame_misc = gtk_frame_new (_("Decorations")); gtk_box_pack_start (GTK_BOX (tab2), frame_misc, FALSE, TRUE, 1); box_misc = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_misc), box_misc); NEW_ROW_SEPARATOR (tab2); splash_check = gtk_check_button_new_with_label (_("Splash screen")); g_signal_connect (G_OBJECT (splash_check), "toggled", G_CALLBACK (modify_splash), NULL); gtk_box_pack_start (GTK_BOX (box_misc), splash_check, FALSE, TRUE, 1); frame_file = gtk_frame_new (_("File to open at startup")); gtk_box_pack_start (GTK_BOX (tab2), frame_file, FALSE, TRUE, 1); box_file = gtk_hbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_file), box_file); file_entry = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (box_file), file_entry, FALSE, TRUE, 1); but_file = gtk_button_new_from_stock (GTK_STOCK_OPEN); gtk_box_pack_start (GTK_BOX (box_file), but_file, FALSE, TRUE, 1); g_signal_connect (G_OBJECT (but_file), "clicked", G_CALLBACK (meta_open_startup_file), (gpointer) prefs); but_file_clear = gtk_button_new_from_stock (GTK_STOCK_CLEAR); gtk_box_pack_start (GTK_BOX (box_file), but_file_clear, FALSE, TRUE, 1); g_signal_connect (G_OBJECT (but_file_clear), "clicked", G_CALLBACK (clear_file), NULL); frame_save = gtk_frame_new (_("File saving")); gtk_box_pack_start (GTK_BOX (tab2), frame_save, FALSE, TRUE, 1); box_save = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_save), box_save); bak_check = gtk_check_button_new_with_label (_("Make backups of files")); g_signal_connect (G_OBJECT (bak_check), "toggled", G_CALLBACK (modify_bak), NULL); gtk_box_pack_start (GTK_BOX (box_save), bak_check, FALSE, TRUE, 1); over_check = gtk_check_button_new_with_label (_ ("Ask when overwriting files")); g_signal_connect (G_OBJECT (over_check), "toggled", G_CALLBACK (modify_over), NULL); gtk_box_pack_start (GTK_BOX (box_save), over_check, FALSE, TRUE, 1); //third page: Security tab3 = gtk_vbox_new (FALSE, GRG_PAD); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), tab3, gtk_label_new (_("Security"))); frame_xpire = gtk_frame_new (_("Password expiration")); gtk_box_pack_start (GTK_BOX (tab3), frame_xpire, FALSE, TRUE, 1); box_xpire = gtk_hbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_xpire), box_xpire); xpire_check = gtk_check_button_new_with_label (_("Password expires in")); xpire_spin = gtk_spin_button_new_with_range (EXP_TIME_MIN, EXP_TIME_MAX, 1); xpire_lbl = gtk_label_new (_("days")); g_signal_connect (G_OBJECT (xpire_check), "toggled", G_CALLBACK (modify_xpire), xpire_spin); g_signal_connect (G_OBJECT (xpire_spin), "value-changed", G_CALLBACK (modify_xpin), xpire_check); gtk_box_pack_start (GTK_BOX (box_xpire), xpire_check, FALSE, TRUE, 1); gtk_box_pack_start (GTK_BOX (box_xpire), xpire_spin, FALSE, TRUE, 1); gtk_box_pack_start (GTK_BOX (box_xpire), xpire_lbl, FALSE, TRUE, 1); //this means "passes in wiping a file", not "wipe the passes" :) frame_passes = gtk_frame_new (_("Wipe passes")); gtk_box_pack_start (GTK_BOX (tab3), frame_passes, FALSE, TRUE, 1); box_passes = gtk_hbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_passes), box_passes); lbl_passes = gtk_label_new (_("Number of overwritings with random\n" "data, when wiping a file:")); gtk_box_pack_start (GTK_BOX (box_passes), lbl_passes, FALSE, TRUE, 1); passes_spin = gtk_spin_button_new_with_range (WIPE_PASSES_MIN, WIPE_PASSES_MAX, 1); gtk_box_pack_start (GTK_BOX (box_passes), passes_spin, FALSE, TRUE, 1); g_signal_connect (G_OBJECT (passes_spin), "value-changed", G_CALLBACK (modify_passes), NULL); frame_clip = gtk_frame_new (_("Clipboard")); gtk_box_pack_start (GTK_BOX (tab3), frame_clip, FALSE, TRUE, 1); box_clip = gtk_vbox_new (FALSE, GRG_PAD); gtk_container_add (GTK_CONTAINER (frame_clip), box_clip); cclip_check = gtk_check_button_new_with_label (_ ("Clear clipboard on closing file")); g_signal_connect (G_OBJECT (cclip_check), "toggled", G_CALLBACK (modify_cclip), NULL); gtk_box_pack_start (GTK_BOX (box_clip), cclip_check, FALSE, TRUE, 1); qclip_check = gtk_check_button_new_with_label (_ ("Clear clipboard on exit")); g_signal_connect (G_OBJECT (qclip_check), "toggled", G_CALLBACK (modify_qclip), NULL); gtk_box_pack_start (GTK_BOX (box_clip), qclip_check, FALSE, TRUE, 1); //end of last tab active_flag = TRUE; reset_values (prefs); update_buttons (); gtk_widget_show_all (prefs); while (TRUE) { gboolean exit = TRUE; response = gtk_dialog_run (GTK_DIALOG (prefs)); switch (response) { case GTK_RESPONSE_OK: apply_values (); break; case GTK_RESPONSE_APPLY: apply_values (); exit = FALSE; break; case GTK_RESPONSE_CANCEL: default: break; } if (exit) { gtk_widget_destroy (prefs); active_flag = FALSE; break; } } }
int main(int argc, char** argv) { if(argc > 1) { int* basis_serial; int* basis_parallel; int basis_count1, basis_count2; image_height=atoi(argv[1]); image_width=atoi(argv[1]); create_image(); image = (char*)malloc(sizeof(char)*image_height*image_width); meet=(ConsensusGrid*)malloc(sizeof(ConsensusGrid)*image_height*image_width); basis = (int*)malloc(sizeof(int)*image_height*image_width); read_raw_image("image.raw",image,image_height,image_width); struct timeval t_s, t_e; gettimeofday(&t_s, NULL); /// For serial implementation for(int i=0; i<image_height; i++) { for(int j = 0; j<image_width; j++) { meet[i*image_width+j]=consensus(i, j, image,image_height,image_width); } } printf("Calculating list for serial\n"); calculate_list(); printf("Calculating basis for serial\n"); calculate_basis(); gettimeofday(&t_e, NULL); double t1 = (((double)t_e.tv_sec-(double)t_s.tv_sec)*1000) + ((double)t_e.tv_usec - (double)t_s.tv_usec)/1000; basis_serial = basis; basis_count1 = basis_count; cout << "Serial Basis count = " << basis_count << endl << endl;; reset_values(); /// For parallel implementation struct timeval t_s2, t_e2; gettimeofday(&t_s2, NULL); for(int i=0; i<image_height; i++) { for(int j = 0; j<image_width; j++) { meet[i*image_width+j]=consensus_parallel(i, j, image,image_height,image_width); } } printf("Calculating list for parallel\n"); calculate_list(); printf("Calculating basis for parallel\n"); calculate_basis(); gettimeofday(&t_e2, NULL); double t2 = (((double)t_e2.tv_sec-(double)t_s2.tv_sec)*1000) + ((double)t_e2.tv_usec - (double)t_s2.tv_usec)/1000; basis_parallel = basis; basis_count2 = basis_count; cout << "Parallel Basis count = " << basis_count << endl << endl; Assert_Output(basis_serial, basis_parallel, basis_count1, basis_count2); } else { cout << "Insufficient arguments\n" << endl; cout << "First argument = Image Size" << endl; } }
/* Main execution loop in live mode. Builds the list of processes, * collects statistics, and prints using curses. Repeats after some * delay, also catching key presses. */ static int live_mode(struct process_list* proc_list, screen_t* screen) { WINDOW* help_win = NULL; WINDOW* error_win = NULL; fd_set fds; struct process** p; int num_iter = 0; int with_colors = 0; int pos; /* start curses */ initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); /* Prepare help window */ help_win = prepare_help_win(screen); if (has_colors()) { /* initialize curses colors */ with_colors = 1; start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_WHITE, COLOR_BLACK); init_pair(3, COLOR_GREEN, COLOR_BLACK); init_pair(4, COLOR_YELLOW, COLOR_BLACK); init_pair(5, COLOR_RED, COLOR_BLACK); attron(COLOR_PAIR(0)); } tv.tv_sec = 0; tv.tv_usec = 200000; /* 200 ms for first iteration */ header = gen_header(screen, &options, COLS - 1, active_col); pos = screen_pos(screen); for(num_iter=0; !options.max_iter || num_iter<options.max_iter; num_iter++) { int i, zz, printed, num_fd, num_dead; /* print various info */ erase(); mvprintw(0, 0, "tiptop -"); if ((num_errors() > 0) && (COLS >= 37)) mvprintw(LINES-1, 30, "[errors]"); if ((options.config_file == 1) && (COLS >= 60)) mvprintw(0, COLS-60, "[conf]"); if ((options.euid == 0) && (COLS >= 54)) mvprintw(0, COLS-54, "[root]"); if ((options.watch_uid != -1) && (COLS >= 48)) mvprintw(0, COLS-48, "[uid]"); if ((options.only_pid || options.only_name) && (COLS >= 43)) mvprintw(0, COLS-43, "[pid]"); if (options.show_kernel && (COLS >= 38)) mvprintw(0, COLS-38, "[kernel]"); if (options.sticky && (COLS >= 30)) mvprintw(0, COLS-30, "[sticky]"); if (options.show_threads && (COLS >= 22)) mvprintw(0, COLS-22, "[threads]"); if (options.idle && (COLS >= 13)) mvprintw(0, COLS-13, "[idle]"); if (options.debug && (COLS >= 7)) mvprintw(0, COLS-7, "[debug]"); if (options.show_epoch && (COLS >= 18)) mvprintw(LINES-1, COLS-18, "Epoch: %u", time(NULL)); if (options.show_timestamp) mvprintw(LINES-1, 0, "Iteration: %u", num_iter); /* print main header */ if (with_colors) attron(COLOR_PAIR(1)); mvprintw(3, 0, "%s", header); for(zz=strlen(header); zz < COLS-1; zz++) printw(" "); printw("\n"); if (with_colors) attroff(COLOR_PAIR(1)); /* update the list of processes/threads and accumulate info if needed */ num_dead = update_proc_list(proc_list, screen, &options); if (!options.show_threads) accumulate_stats(proc_list); p = proc_list->proc_ptrs; /* prepare for select */ FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); /* generate the text version of all rows */ build_rows(proc_list, screen, COLS - 1); /* sort by %CPU */ qsort(p, proc_list->num_tids, sizeof(struct process*), sorting_fun); printed = 0; /* Iterate over all threads */ for(i=0; i < proc_list->num_tids; i++) { if (p[i]->skip) continue; /* highlight watched process, if any */ if (with_colors) { if (p[i]->dead) { attron(COLOR_PAIR(5)); } else if ((p[i]->tid == options.watch_pid) || (options.watch_name && options.show_cmdline && strstr(p[i]->cmdline, options.watch_name)) || (options.watch_name && !options.show_cmdline && strstr(p[i]->name, options.watch_name))) attron(COLOR_PAIR(3)); } if (options.show_threads || (p[i]->pid == p[i]->tid)) { printw("%s\n", p[i]->txt); printed++; } if (with_colors) attroff(COLOR_PAIR(3)); if (printed >= LINES - 5) /* stop printing at bottom of window */ break; } mvprintw(1, 0, "Tasks: %3d total, %3d displayed", proc_list->num_tids, printed); if (options.sticky) printw(", %3d dead", num_dead); /* print the screen name, make sure it fits, or truncate */ if (with_colors) attron(COLOR_PAIR(4)); if (35 + 20 + 11 + strlen(screen->name) < COLS) { mvprintw(1, COLS - 11 - strlen(screen->name), "screen %2d: %s\n", pos, screen->name); } else if (COLS >= 35 + 20 + 11) { char screen_str[50] = { 0 }; snprintf(screen_str, sizeof(screen_str) - 1, "%s\n", screen->name); screen_str[COLS - 35 - 20 - 11] = '\0'; /* truncate */ mvprintw(1, 35+20, "screen %2d: %s", pos, screen_str); } if (with_colors) attroff(COLOR_PAIR(4)); /* print message if any */ if (message) { if (with_colors) attron(COLOR_PAIR(1)); mvprintw(2, 0, "%s", message); if (with_colors) attroff(COLOR_PAIR(1)); message = NULL; /* reset message */ } refresh(); /* display everything */ if (options.error) { if (options.error == 1) { options.error = 2; show_error_win(error_win, printed); } else show_error_win(error_win, -1); } if (options.help) show_help_win(help_win, screen); if ((num_dead) && (!options.sticky)) compact_proc_list(proc_list); /* wait some delay, or until a key is pressed */ num_fd = select(1 + STDIN_FILENO, &fds, NULL, NULL, &tv); if (num_fd > 0) { int c = handle_key(); if (c == 'q') break; if (c == '>') { if (active_col < screen->num_columns ) active_col++; free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if (c == '<') { if (active_col > -1) active_col--; free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if (c == 'H') { if (options.show_threads) { reset_values(proc_list); message = "Show threads On"; } else message = "Show threads Off"; } if (c == 'U') { free(header); header = gen_header(screen, &options, COLS - 1, active_col); } if ((c == '+') || (c == '-') || (c == KEY_LEFT) || (c == KEY_RIGHT)) return c; if ((c == 'u') || (c == 'K') || (c == 'p')) /* need to rebuild tasks list */ return c; if (c == 'e') { if (options.error > 0) { options.error = 0; delwin(error_win); error_win = NULL; } else options.error = 1; } } tv.tv_sec = options.delay; tv.tv_usec = (options.delay - tv.tv_sec) * 1000000.0; } free(header); delwin(help_win); endwin(); /* stop curses */ return 'q'; }
/* This function allows to change the behavior of the device. * */ int readstats_ioctl_dev (struct inode *i, struct file *f, unsigned int arg1, unsigned long arg2){ int result, argument2; struct task_struct *task; struct my_thread *thinfo_stats; argument2=(signed int) arg2; /* Depending on the first parameter, different functions will be * selected. */ switch (arg1){ case 0: /* CHANGE_PROCESS (arg1=0): in this case arg2 indicates, by reference, the PID * of the process we want to analyze. * If arg2 == NULL: the PID used for the opening of the device will be used. * If no process with PID==arg2 exists, an error will be returned. */ if (argument2 < 0) return -EINVAL; /* We search for the process and, if it doesn't exist, an error is returned */ task = find_task_by_pid ((pid_t) argument2); if (task == NULL){ // Process to be monitored will be the one used during the opening of the device proc_monitored = open_pid; return -ESRCH; } else{ /* Obtains statistics structure of the process */ thinfo_stats = (struct my_thread *) task->thread_info; /* Controls for consistency in statistics of process */ if (argument2 != thinfo_stats->pid) // if they are not consistent, we reset them reset_stats ((pid_t) argument2, thinfo_stats); // Sets the new process to be monitored proc_monitored = argument2; } break; case 1: /* CHANGE_SYSCALL (arg1=1): this changes the syscall monitored and read by readstats_read_dev * arg2 indicates which syscall will be monitored: * OPEN -> 0 * CLOSE -> 1 * WRITE -> 2 * CLONE -> 3 * LSEEK -> 4 */ if (argument2 < 0 || argument2 >= N_CALLS) return -EINVAL; // Sets the new syscall to be monitored sysc_monitored = argument2; break; case 2: /* RESET_VALUES (arg1=2): resets the statistics of the process monitored */ result = reset_values (proc_monitored); break; case 3: /* RESET_VALUES_ALL_PROCESSES (arg1=3): resets the statistics of every process */ complete_reset (); break; case 4: /* ENABLE_SYS_CALL (arg1=4): enables the monitoring for the syscall indicated by arg2. * If arg2 < 0, all the syscalls will be activated.*/ if (argument2 >= N_CALLS) return -EINVAL; activate_syscall_mon (argument2); break; case 5: /* DISABLE SYS_CALL (arg1=5): disables the monitoring for the syscall indicated by arg2. * If arg2 < 0, all the syscalls will be disabled.*/ if (argument2 >= N_CALLS) return -EINVAL; deactivate_syscall_mon (argument2); break; default: /* Unknown parameters */ return -EINVAL; break; } return 0; }