int main (int argc, char* argv[]) { args_t args = { 0, }; crypt_data_t crypt_data = { 0, }; ssize_t count = 0; crypt_init_t init_func = NULL; crypt_update_t update_func = NULL; crypt_final_t final_func = NULL; parse_args (argc, argv, &args); if (check_sanity (argv[0], &args)) exit (EXIT_FAILURE); /* set global flag */ verbose = args.verbose; if (verbose) dump_args (&args); crypt_data.keysize = get_key (args.keyfile, crypt_data.keybuf, EVP_MAX_KEY_LENGTH); if (crypt_data.keysize == -1) exit (EXIT_FAILURE); crypt_data.ivsize = crypt_data.keysize; if (args.encrypt) { crypt_data.ivsize = iv_write (&crypt_data, STDOUT_FILENO); if (crypt_data.ivsize == -1) exit (EXIT_FAILURE); init_func = &EVP_EncryptInit_ex; update_func = &EVP_EncryptUpdate; final_func = &EVP_EncryptFinal_ex; } if (args.decrypt) { crypt_data.ivsize = iv_read (&crypt_data, STDIN_FILENO); if (crypt_data.ivsize == -1) exit (EXIT_FAILURE); init_func = &EVP_DecryptInit_ex; update_func = &EVP_DecryptUpdate; final_func = &EVP_DecryptFinal_ex; } count = aes_init (&crypt_data, init_func); if (count == -1) exit (EXIT_FAILURE); count = proc_loop (&crypt_data, update_func, final_func); if (count == -1) exit (EXIT_FAILURE); if (verbose) fprintf (stderr, "successfully %s %d bytes of data\n", args.encrypt ? "encrypted" : "decrypted", count); exit (EXIT_SUCCESS); }
bool Dictionary::check_sanity() const { std::vector<std::string> messages; bool sane = check_sanity(messages); if ( sane == false ) { std::stringstream message; message << "Dictionary "+uri().string()+" is not sane:"<<std::endl; boost_foreach(const std::string& str, messages) { message << "- " << str << std::endl; }
int check_inode(check_context_t *ctx) { int i; int ret = 1; omfs_inode_t *inode = ctx->current_inode; if (test_bit(ctx->visited, ctx->block)) { fix_problem(E_LOOP, ctx); return 0; } for (i=0; i < swap_be32(ctx->omfs_info->super->s_mirrors); i++) set_bit(ctx->visited, ctx->block + i); if (!check_sanity(ctx)) { fix_problem(E_INSANE, ctx); return 0; } if (!check_header((u8 *)inode)) { fix_problem(E_HEADER_XOR, ctx); ret = 0; } if (!check_crc((u8 *)inode)) { fix_problem(E_HEADER_CRC, ctx); ret = 0; } if (swap_be64(inode->i_head.h_self) != ctx->block) { fix_problem(E_SELF_PTR, ctx); ret = 0; } if (swap_be64(inode->i_parent) != ctx->parent) { fix_problem(E_PARENT_PTR, ctx); ret = 0; } if (omfs_compute_hash(ctx->omfs_info, inode->i_name) != ctx->hash) { fix_problem(E_HASH_WRONG, ctx); ret = 0; } if (inode->i_type == OMFS_FILE) { visit_extents(ctx); } return ret; }
/* * Find a list of ibv_ports matching a set of criteria. */ opal_list_t *opal_common_verbs_find_ports(const char *if_include, const char *if_exclude, int flags, int stream) { int32_t num_devs; struct ibv_device **devices; struct ibv_device *device; struct ibv_context *device_context; struct ibv_device_attr device_attr; struct ibv_port_attr port_attr; char **if_include_list = NULL, **if_exclude_list = NULL, **if_sanity_list = NULL; opal_common_verbs_device_item_t *di; opal_common_verbs_port_item_t *pi; int rc; uint32_t j; opal_list_t *port_list = NULL; bool want; /* Sanity check the include/exclude params */ if (NULL != if_include && NULL != if_exclude) { return NULL; } /* Query all the IBV devices on the machine. Use an ompi compatibility function, because how to get this list changed over the history of the IBV API. */ devices = opal_ibv_get_device_list(&num_devs); if (0 == num_devs) { opal_output_verbose(5, stream, "no verbs interfaces found"); return NULL; } opal_output_verbose(5, stream, "found %d verbs interface%s", num_devs, (num_devs != 1) ? "s" : ""); /* Allocate a list to fill */ port_list = OBJ_NEW(opal_list_t); if (NULL == port_list) { return NULL; } if (NULL != if_include) { opal_output_verbose(5, stream, "finding verbs interfaces, including %s", if_include); if_include_list = opal_argv_split(if_include, ','); if_sanity_list = opal_argv_copy(if_include_list); } else if (NULL != if_exclude) { opal_output_verbose(5, stream, "finding verbs interfaces, excluding %s", if_exclude); if_exclude_list = opal_argv_split(if_exclude, ','); if_sanity_list = opal_argv_copy(if_exclude_list); } /* Now loop through all the devices. Get the attributes for each port on each device to see if they match our selection criteria. */ for (int32_t i = 0; (int32_t) i < num_devs; ++i) { /* See if this device is on the include/exclude sanity check list. If it is, remove it from the sanity check list (i.e., we should end up with an empty list at the end if all entries in the sanity check list exist) */ device = devices[i]; check_sanity(&if_sanity_list, ibv_get_device_name(device), -1); opal_output_verbose(5, stream, "examining verbs interface: %s", ibv_get_device_name(device)); device_context = ibv_open_device(device); if (NULL == device_context) { opal_show_help("help-opal-common-verbs.txt", "ibv_open_device fail", true, opal_proc_local_get()->proc_hostname, ibv_get_device_name(device), errno, strerror(errno)); goto err_free_port_list; } if (ibv_query_device(device_context, &device_attr)){ opal_show_help("help-opal-common-verbs.txt", "ibv_query_device fail", true, opal_proc_local_get()->proc_hostname, ibv_get_device_name(device), errno, strerror(errno)); goto err_free_port_list; } /* Now that we have the attributes of this device, remove all ports of this device from the sanity check list. Note that IBV ports are indexed from 1, not 0. */ for (j = 1; j <= device_attr.phys_port_cnt; j++) { check_sanity(&if_sanity_list, ibv_get_device_name(device), j); } /* Check the device-specific flags to see if we want this device */ want = false; if (flags & OPAL_COMMON_VERBS_FLAGS_TRANSPORT_IB && IBV_TRANSPORT_IB == device->transport_type) { opal_output_verbose(5, stream, "verbs interface %s has right type (IB)", ibv_get_device_name(device)); want = true; } if (flags & OPAL_COMMON_VERBS_FLAGS_TRANSPORT_IWARP && IBV_TRANSPORT_IWARP == device->transport_type) { opal_output_verbose(5, stream, "verbs interface %s has right type (IWARP)", ibv_get_device_name(device)); want = true; } /* Check for RC or UD QP support */ if (flags & OPAL_COMMON_VERBS_FLAGS_RC) { rc = opal_common_verbs_qp_test(device_context, flags); if (OPAL_SUCCESS == rc) { want = true; opal_output_verbose(5, stream, "verbs interface %s supports RC QPs", ibv_get_device_name(device)); } else { opal_output_verbose(5, stream, "verbs interface %s failed to make RC QP", ibv_get_device_name(device)); } } if (flags & OPAL_COMMON_VERBS_FLAGS_UD) { rc = opal_common_verbs_qp_test(device_context, flags); if (OPAL_SUCCESS == rc) { want = true; opal_output_verbose(5, stream, "verbs interface %s supports UD QPs", ibv_get_device_name(device)); } else if (OPAL_ERR_TYPE_MISMATCH == rc) { opal_output_verbose(5, stream, "verbs interface %s made an RC QP! we don't want RC-capable devices", ibv_get_device_name(device)); } else { opal_output_verbose(5, stream, "verbs interface %s failed to make UD QP", ibv_get_device_name(device)); } } /* If we didn't want it, go to the next device */ if (!want) { continue; } /* Make a device_item_t to hold the device information */ di = OBJ_NEW(opal_common_verbs_device_item_t); if (NULL == di) { goto err_free_port_list; } di->device = device; di->context = device_context; di->device_attr = device_attr; di->device_name = strdup(ibv_get_device_name(device)); /* Note IBV ports are 1 based (not 0 based) */ for (j = 1; j <= device_attr.phys_port_cnt; j++) { /* If we don't want this port (based on if_include / if_exclude lists), skip it */ if (!want_this_port(if_include_list, if_exclude_list, di, j)) { opal_output_verbose(5, stream, "verbs interface %s:%d: rejected by include/exclude", ibv_get_device_name(device), j); continue; } /* Query the port */ if (ibv_query_port(device_context, (uint8_t) j, &port_attr)) { opal_show_help("help-opal-common-verbs.txt", "ibv_query_port fail", true, opal_proc_local_get()->proc_hostname, ibv_get_device_name(device), errno, strerror(errno)); goto err_free_port_list; } /* We definitely only want ACTIVE ports */ if (IBV_PORT_ACTIVE != port_attr.state) { opal_output_verbose(5, stream, "verbs interface %s:%d: not ACTIVE", ibv_get_device_name(device), j); continue; } /* Check the port-specific flags to see if we want this port */ want = false; if (0 == flags) { want = true; } if ((flags & (OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_IB | OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_ETHERNET)) == (OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_IB | OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_ETHERNET)) { /* If they specified both link layers, then we want this port */ want = true; } else if ((flags & (OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_IB | OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_ETHERNET)) == 0) { /* If they specified neither link layer, then we want this port */ want = true; } #if HAVE_DECL_IBV_LINK_LAYER_ETHERNET else if (flags & OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_IB) { if (IBV_LINK_LAYER_INFINIBAND == port_attr.link_layer) { want = true; } else { opal_output_verbose(5, stream, "verbs interface %s:%d has wrong link layer (has %s, want IB)", ibv_get_device_name(device), j, link_layer_to_str(port_attr.link_layer)); } } else if (flags & OPAL_COMMON_VERBS_FLAGS_LINK_LAYER_ETHERNET) { if (IBV_LINK_LAYER_ETHERNET == port_attr.link_layer) { want = true; } else { opal_output_verbose(5, stream, "verbs interface %s:%d has wrong link layer (has %s, want Ethernet)", ibv_get_device_name(device), j, link_layer_to_str(port_attr.link_layer)); } } #endif if (!want) { continue; } /* If we got this far, we want the port. Make an item for it. */ pi = OBJ_NEW(opal_common_verbs_port_item_t); if (NULL == pi) { goto err_free_port_list; } pi->device = di; pi->port_num = j; pi->port_attr = port_attr; OBJ_RETAIN(di); /* Add the port item to the list */ opal_list_append(port_list, &pi->super); opal_output_verbose(5, stream, "found acceptable verbs interface %s:%d", ibv_get_device_name(device), j); } /* We're done with the device; if some ports are using it, its ref count will be > 0, and therefore the device won't be deleted here. */ OBJ_RELEASE(di); } /* Sanity check that the devices specified in the if_include / if_exclude lists actually existed. If this is true, then the sanity list will now be empty. If there are still items left on the list, then they didn't exist. Bad. Print a warning (if the warning is not disabled). */ if (0 != opal_argv_count(if_sanity_list)) { if (opal_common_verbs_warn_nonexistent_if) { char *str = opal_argv_join(if_sanity_list, ','); opal_show_help("help-opal-common-verbs.txt", "nonexistent port", true, opal_proc_local_get()->proc_hostname, ((NULL != if_include) ? "in" : "ex"), str); free(str); /* Only warn once per process */ opal_common_verbs_warn_nonexistent_if = false; } } if (NULL != if_sanity_list) { opal_argv_free(if_sanity_list); } opal_argv_free(if_include_list); opal_argv_free(if_exclude_list); /* All done! */ opal_ibv_free_device_list(devices); return port_list; err_free_port_list: OPAL_LIST_RELEASE(port_list); opal_ibv_free_device_list(devices); if (NULL != if_sanity_list) { opal_argv_free(if_sanity_list); } opal_argv_free(if_include_list); opal_argv_free(if_exclude_list); return NULL; }
/* The code */ int main (int argc, char* argv []) { char* interfaceName; char buffer [MAXLEN]; ulong ledVal; char* tmpPointer; char** list; pid_t pid; int sleeptime; int wasInDeepSleep; struct timeval sleeptimeval; interfaceName = NULL; sleeptime = 0; handle_my_argvs(&interfaceName, &sleeptime, argc, argv); check_sanity(); /* Checks and maybe changes the option flags. */ #ifdef DEBUG opt_b = TRUE; /* We are debugging so don't go to the background */ #endif if (opt_v && !opt_q) fprintf(stderr, "%s version %s, GPL (c) 1997 [email protected]\n", MYNAME, VERSION); strcpy(pidFileName, _PATH_TMP); strcpy(rootPidFileName, _PATH_VARRUN); strcat(pidFileName, MYNAME); /* Was argv[0]. Probs coz/if path. */ strcat(rootPidFileName, MYNAME); strcat(pidFileName, ".pid"); strcat(rootPidFileName, ".pid"); if (opt_k) { return kill_old_process(); } if (opt_h) { usage(argv[0]); return 0; } if (! opt_q) { printf("Setting keyboard LEDs based on %s %s %s %s\n", "changes of Receive/Transmit\npackets of", interfaceName, "in", devFileName); printf("Delay between updates is %d milliseconds.\n", sleeptime); } if (! find_device_line(buffer, interfaceName) && !opt_q) { printf( "There is currently no such interface as %s in %s.\n%s\n", interfaceName, devFileName, "Maybe later there will be. Kill me (-k) if ya want."); } if(! opt_b) { if (-1 == (pid = fork())) { perror("tleds: fork"); return 1; } } else { pid = getpid(); } if (pid) { create_pid_file(pid, argv[0]); if (! opt_q) printf("Running in %sground. Pid: %ld\n", (opt_b ? "fore" : "back"), (long)pid); if (! opt_b) exit(0); } if (atexit(my_exit)) { perror("tleds: atexit() failed"); return 1; } if (! opt_b) { signal(SIGUSR1, parent_wants_me_dead); } signal(SIGHUP, SIG_IGN); signal(SIGTERM, my_signal_handler); signal(SIGINT, my_signal_handler); signal(SIGQUIT, my_signal_handler); signal(SIGTSTP, my_signal_handler); signal(SIGUSR2, SIG_IGN); signal(SIGPIPE, my_signal_handler); if (! geteuid()) { /* We are running as EUID root - CONSOLE */ if (-1 == (keyboardDevice = open(KEYBOARDDEVICE, O_RDONLY))) { perror("tleds"); fprintf(stderr, "%s:%s", KEYBOARDDEVICE, TERMINATESTR); exit(1); } } else { /* EUID not root */ #if (! REMOVE_X_CODE) if (! (myDisplay = XOpenDisplay(NULL)) /* X */ && ioctl(0, KDGETLED, &ledVal) ) { /* VT */ perror( "tleds: Can't open X DISPLAY on the current host."); #else if (ioctl(0, KDGETLED, &ledVal) ) { perror("tleds: KDGETLED"); fprintf(stderr, "Error reading current led setting.\n%s\n", "Maybe stdin is not a VT?"); #endif fprintf(stderr, TERMINATESTR); exit (1); } } sleeptimeval.tv_sec = (int)((long)sleeptime * 1000L) / 1000000L; sleeptimeval.tv_usec = (int)((long)sleeptime * 1000L) % 1000000L; wasInDeepSleep = TRUE; /* The main loop */ while (1) { if ((tmpPointer = find_device_line(buffer, interfaceName))) { if (wasInDeepSleep) { wasInDeepSleep = FALSE; detach_vt_leds(TRUE); } list = split_on_blank(tmpPointer); report_traffic(list); my_sleep(sleeptimeval); } else { if (! wasInDeepSleep) { wasInDeepSleep = TRUE; detach_vt_leds(FALSE); previousActive = (ushort)(MAXVT + 1); } sleep(DEEPSLEEP); } } return 0; /* Yeah right, never gets this far. */ } char* find_device_line (char* buffer, char* netDeviceName) { static long fileOffset = 0L; register FILE* devFile; if (! (devFile = fopen(devFileName, "r")) ) { perror(devFileName); exit(1); } /* Skip two lines. (the header) */ /* Two choices how to do this. Didn't find any differences in speed. */ #if 0 fgets(buffer, MAXLEN, devFile); fgets(buffer, MAXLEN, devFile); #else if (fileOffset) { fseek(devFile, fileOffset, SEEK_SET); } else { fgets(buffer, MAXLEN, devFile); fileOffset += (long)strlen(buffer); fgets(buffer, MAXLEN, devFile); fileOffset += (long)strlen(buffer); } #endif while ( fgets(buffer, MAXLEN, devFile) ) { while(isblank(*buffer)) buffer++; if (buffer == strstr(buffer, netDeviceName)) { fclose(devFile); return buffer; } } fclose(devFile); return NULL; } void my_sleep (struct timeval sleeptimeval) { #if 1 select(1, NULL, NULL, NULL, &sleeptimeval); #else usleep(sleeptimeval.tv_usec); #endif }