int main(int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY; int rc = 0; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } while (1) { if ((!params.no_header) && (params.iterate || params.verbose || params.long_output)) print_date(); if (!params.clusters) { if (_get_info(false)) rc = 1; } else if (_multi_cluster(params.clusters) != 0) rc = 1; if (params.iterate) { printf("\n"); sleep(params.iterate); } else break; } exit(rc); }
static int _handle_reconfig(int fd, slurmd_job_t *job, uid_t uid) { int rc = SLURM_SUCCESS; int errnum = 0; if (!_slurm_authorized_user(uid)) { debug("job step reconfigure request from uid %ld " "for job %u.%u ", (long)uid, job->jobid, job->stepid); rc = -1; errnum = EPERM; goto done; } /* We just want to make sure the file handle is correct on a reconfigure since the file could had rolled thus making the currect fd incorrect. */ log_alter(conf->log_opts, SYSLOG_FACILITY_DAEMON, conf->logfile); debug("_handle_reconfigure for job %u.%u successful", job->jobid, job->stepid); done: /* Send the return code and errno */ safe_write(fd, &rc, sizeof(int)); safe_write(fd, &errnum, sizeof(int)); return SLURM_SUCCESS; rwfail: return SLURM_FAILURE; }
int main(int argc, char *argv[]) { int rc = 0; log_options_t opts = LOG_OPTS_STDERR_ONLY; log_init("strigger", opts, SYSLOG_FACILITY_DAEMON, NULL); slurm_conf_init(NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_DAEMON, NULL); } if (params.mode_set) rc = _set_trigger(); else if (params.mode_get) rc = _get_trigger(); else if (params.mode_clear) rc = _clear_trigger(); else { error("Invalid mode"); rc = 1; } exit(rc); }
static int handle_spank_mode (int argc, char *argv[]) { char prefix[64] = "spank-"; const char *mode = argv[2]; uid_t uid = (uid_t) -1; uint32_t jobid = (uint32_t) -1; log_options_t lopts = LOG_OPTS_INITIALIZER; /* * Not necessary to log to syslog */ lopts.syslog_level = LOG_LEVEL_QUIET; /* * Make our log prefix into spank-prolog: or spank-epilog: */ strcat (prefix, mode); log_init(prefix, lopts, LOG_DAEMON, NULL); /* * When we are started from slurmd, a lightweight config is * sent over the stdin fd. If we are able to read this conf * use it to reinitialize the log. * It is not a fatal error if we fail to read the conf file. * This could happen if slurmstepd is run standalone for * testing. */ if ((conf = read_slurmd_conf_lite (STDIN_FILENO))) log_alter (conf->log_opts, 0, conf->logfile); close (STDIN_FILENO); if (slurm_conf_init(NULL) != SLURM_SUCCESS) return error ("Failed to read slurm config"); if (get_jobid_uid_from_env (&jobid, &uid) < 0) return error ("spank environment invalid"); verbose ("Running spank/%s for jobid [%u] uid [%u]", mode, jobid, uid); if (strcmp (mode, "prolog") == 0) { if (spank_job_prolog (jobid, uid) < 0) return (-1); } else if (strcmp (mode, "epilog") == 0) { if (spank_job_epilog (jobid, uid) < 0) return (-1); } else { error ("Invalid mode %s specified!", mode); return (-1); } return (0); }
int main(int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY; log_init("sbcast", opts, SYSLOG_FACILITY_DAEMON, NULL); #ifdef HAVE_ALPS_CRAY error("The sbcast command is not supported on Cray systems"); return 1; #endif #ifdef HAVE_BG error("The sbcast command is not supported on IBM BlueGene systems"); return 1; #endif slurm_conf_init(NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_DAEMON, NULL); } /* validate the source file */ if ((fd = open(params.src_fname, O_RDONLY)) < 0) { error("Can't open `%s`: %s", params.src_fname, strerror(errno)); exit(1); } if (fstat(fd, &f_stat)) { error("Can't stat `%s`: %s", params.src_fname, strerror(errno)); exit(1); } verbose("modes = %o", (unsigned int) f_stat.st_mode); verbose("uid = %d", (int) f_stat.st_uid); verbose("gid = %d", (int) f_stat.st_gid); verbose("atime = %s", slurm_ctime(&f_stat.st_atime)); verbose("mtime = %s", slurm_ctime(&f_stat.st_mtime)); verbose("ctime = %s", slurm_ctime(&f_stat.st_ctime)); verbose("size = %ld", (long) f_stat.st_size); verbose("-----------------------------"); /* identify the nodes allocated to the job */ _get_job_info(); /* transmit the file */ _bcast_file(); /* slurm_free_sbcast_cred_msg(sbcast_cred); */ exit(0); }
/* Reset slurmdbd logging based upon configuration parameters */ static void _update_logging(bool startup) { /* Preserve execute line arguments (if any) */ if (debug_level) { slurmdbd_conf->debug_level = MIN( (LOG_LEVEL_INFO + debug_level), (LOG_LEVEL_END - 1)); } log_opts.stderr_level = slurmdbd_conf->debug_level; log_opts.logfile_level = slurmdbd_conf->debug_level; log_opts.syslog_level = slurmdbd_conf->debug_level; if (foreground) { log_opts.syslog_level = LOG_LEVEL_QUIET; } else { log_opts.stderr_level = LOG_LEVEL_QUIET; if (!slurmdbd_conf->log_file && (slurmdbd_conf->syslog_debug == LOG_LEVEL_QUIET)) { /* Insure fatal errors get logged somewhere */ log_opts.syslog_level = LOG_LEVEL_FATAL; } else { log_opts.syslog_level = slurmdbd_conf->syslog_debug; } } log_alter(log_opts, SYSLOG_FACILITY_DAEMON, slurmdbd_conf->log_file); log_set_timefmt(slurmdbd_conf->log_fmt); if (startup && slurmdbd_conf->log_file) { int rc; gid_t slurm_user_gid; slurm_user_gid = gid_from_uid(slurmdbd_conf->slurm_user_id); rc = chown(slurmdbd_conf->log_file, slurmdbd_conf->slurm_user_id, slurm_user_gid); if (rc) { error("chown(%s, %d, %d): %m", slurmdbd_conf->log_file, (int) slurmdbd_conf->slurm_user_id, (int) slurm_user_gid); } } debug("Log file re-opened"); }
int main (int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY ; int error_code = SLURM_SUCCESS; log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL); parse_command_line( argc, argv ); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } max_line_size = _get_window_width( ); if (params.clusters) working_cluster_rec = list_peek(params.clusters); while (1) { if ((!params.no_header) && (params.iterate || params.verbose || params.long_list)) _print_date (); if (!params.clusters) { if (_get_info(false)) error_code = 1; } else if (_multi_cluster(params.clusters) != 0) error_code = 1; if ( params.iterate ) { printf( "\n"); sleep( params.iterate ); } else break; } if ( error_code != SLURM_SUCCESS ) exit (error_code); else exit (0); }
int main (int argc, char *argv[]) { log_options_t log_opts = LOG_OPTS_STDERR_ONLY ; int rc = 0; slurm_conf_init(NULL); log_init (xbasename(argv[0]), log_opts, SYSLOG_FACILITY_DAEMON, NULL); initialize_and_process_args(argc, argv); if (opt.verbose) { log_opts.stderr_level += opt.verbose; log_alter (log_opts, SYSLOG_FACILITY_DAEMON, NULL); } if (opt.clusters) rc = _multi_cluster(opt.clusters); else rc = _proc_cluster(); exit(rc); }
/* Reset slurmctld logging based upon configuration parameters */ static void _update_logging(bool startup) { /* Preserve execute line arguments (if any) */ if (debug_level) { slurmdbd_conf->debug_level = MIN( (LOG_LEVEL_INFO + debug_level), (LOG_LEVEL_END - 1)); } log_opts.stderr_level = slurmdbd_conf->debug_level; log_opts.logfile_level = slurmdbd_conf->debug_level; log_opts.syslog_level = slurmdbd_conf->debug_level; if (foreground) log_opts.syslog_level = LOG_LEVEL_QUIET; else { log_opts.stderr_level = LOG_LEVEL_QUIET; if (slurmdbd_conf->log_file) log_opts.syslog_level = LOG_LEVEL_QUIET; } log_alter(log_opts, SYSLOG_FACILITY_DAEMON, slurmdbd_conf->log_file); if (startup && slurmdbd_conf->log_file) { int rc; gid_t slurm_user_gid; slurm_user_gid = gid_from_uid(slurmdbd_conf->slurm_user_id); rc = chown(slurmdbd_conf->log_file, slurmdbd_conf->slurm_user_id, slurm_user_gid); if (rc) { error("chown(%s, %d, %d): %m", slurmdbd_conf->log_file, (int) slurmdbd_conf->slurm_user_id, (int) slurm_user_gid); } } }
int main(int argc, char **argv) { log_options_t opts = LOG_OPTS_STDERR_ONLY; node_info_msg_t *node_info_ptr = NULL; node_info_msg_t *new_node_ptr = NULL; int error_code; int height = 40; int width = 100; int startx = 0; int starty = 0; int end = 0; int i; int rc; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (params.cluster_dims == 4) { min_screen_width = 92; } else if (params.cluster_dims == 3) min_screen_width = 92; /* no need for this if you are resolving */ while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) { if (params.resolve || (params.display == COMMANDS)) { new_node_ptr = NULL; break; /* just continue */ } error_code = slurm_get_errno(); printf("slurm_load_node: %s\n", slurm_strerror(error_code)); if (params.iterate == 0) exit(1); sleep(10); /* keep trying to reconnect */ } select_g_ba_init(new_node_ptr, 0); if (dim_size == NULL) { dim_size = get_cluster_dims(new_node_ptr); if ((dim_size == NULL) || (dim_size[0] < 1)) fatal("Invalid system dimensions"); } _init_colors(); if (params.resolve) { char *ret_str = resolve_mp(params.resolve, new_node_ptr); if (ret_str) { printf("%s", ret_str); xfree(ret_str); } _smap_exit(0); /* Calls exit(), no return */ } if (!params.commandline) { int check_width = min_screen_width; initscr(); init_grid(new_node_ptr, COLS); signal(SIGWINCH, (void (*)(int))_resize_handler); if (params.cluster_dims == 4) { height = dim_size[2] * dim_size[3] + dim_size[2] + 3; width = (dim_size[1] + dim_size[3] + 1) * dim_size[0] + 2; check_width += width; } else if (params.cluster_dims == 3) { height = dim_size[1] * dim_size[2] + dim_size[1] + 3; width = dim_size[0] + dim_size[2] + 3; check_width += width; } else { height = 10; width = COLS; } if ((COLS < check_width) || (LINES < height)) { endwin(); error("Screen is too small make sure the screen " "is at least %dx%d\n" "Right now it is %dx%d\n", check_width, height, COLS, LINES); _smap_exit(1); /* Calls exit(), no return */ } raw(); keypad(stdscr, true); noecho(); cbreak(); curs_set(0); nodelay(stdscr, true); start_color(); _set_pairs(); grid_win = newwin(height, width, starty, startx); max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1); if (params.cluster_dims == 4) { startx = width; width = COLS - width - 2; height = LINES; } else if (params.cluster_dims == 3) { startx = width; width = COLS - width - 2; height = LINES; } else { startx = 0; starty = height; height = LINES - height; } text_win = newwin(height, width, starty, startx); } while (!end) { if (!params.commandline) { _get_option(); redraw: clear_window(text_win); clear_window(grid_win); move(0, 0); update_grid(new_node_ptr); main_xcord = 1; main_ycord = 1; } if (!params.no_header) print_date(); clear_grid(); switch (params.display) { case JOBS: get_job(); break; case RESERVATIONS: get_reservation(); break; case SLURMPART: get_slurm_part(); break; case COMMANDS: #ifdef HAVE_BG wclear(text_win); get_command(); #else error("Must be on a real BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ #endif break; case BGPART: if (params.cluster_flags & CLUSTER_FLAG_BG) get_bg_part(); else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; } if (!params.commandline) { box(text_win, 0, 0); wnoutrefresh(text_win); print_grid(); box(grid_win, 0, 0); wnoutrefresh(grid_win); doupdate(); node_info_ptr = new_node_ptr; if (node_info_ptr) { error_code = slurm_load_node( node_info_ptr->last_update, &new_node_ptr, SHOW_ALL); if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg( node_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = node_info_ptr; } } else { error_code = slurm_load_node( (time_t) NULL, &new_node_ptr, SHOW_ALL); } if (error_code && (quiet_flag != 1)) { if (!params.commandline) { mvwprintw( text_win, main_ycord, 1, "slurm_load_node: %s", slurm_strerror( slurm_get_errno())); main_ycord++; } else { printf("slurm_load_node: %s", slurm_strerror( slurm_get_errno())); } } } if (params.iterate) { for (i = 0; i < params.iterate; i++) { sleep(1); if (!params.commandline) { if ((rc = _get_option()) == 1) goto redraw; else if (resize_screen) { resize_screen = 0; goto redraw; } } } } else break; } if (!params.commandline) { nodelay(stdscr, false); getch(); endwin(); } _smap_exit(0); /* Calls exit(), no return */ exit(0); /* Redundant, but eliminates compiler warning */ }
int main(int argc, char** argv) { select_ba_request_t *request = xmalloc(sizeof(select_ba_request_t)); log_options_t log_opts = LOG_OPTS_INITIALIZER; int debug_level = 5; List results; // List results2; // int i,j; log_opts.stderr_level = debug_level; log_opts.logfile_level = debug_level; log_opts.syslog_level = debug_level; log_alter(log_opts, LOG_DAEMON, "/dev/null"); DIM_SIZE[X]=0; DIM_SIZE[Y]=0; DIM_SIZE[Z]=0; slurm_conf_reinit(NULL); ba_init(NULL, 1); /* [010x831] */ /* results = list_create(NULL); */ /* request->geometry[0] = 9; */ /* request->geometry[1] = 3; */ /* request->geometry[2] = 2; */ /* request->start[0] = 0; */ /* request->start[1] = 1; */ /* request->start[2] = 0; */ /* request->start_req = 1; */ /* // request->size = 16; */ /* request->rotate = 0; */ /* request->elongate = 0; */ /* request->conn_type = SELECT_TORUS; */ /* new_ba_request(request); */ /* print_ba_request(request); */ /* if (!allocate_block(request, results)) { */ /* debug("couldn't allocate %c%c%c", */ /* alpha_num[request->geometry[0]], */ /* alpha_num[request->geometry[1]], */ /* alpha_num[request->geometry[2]]); */ /* } */ /* list_destroy(results); */ /* /\* [001x801] *\/ */ /* results = list_create(NULL); */ /* request->geometry[0] = 9; */ /* request->geometry[1] = 1; */ /* request->geometry[2] = 1; */ /* request->start[0] = 0; */ /* request->start[1] = 0; */ /* request->start[2] = 1; */ /* request->start_req = 1; */ /* // request->size = 1; */ /* request->rotate = 0; */ /* request->elongate = 0; */ /* request->conn_type = SELECT_TORUS; */ /* new_ba_request(request); */ /* print_ba_request(request); */ /* if (!allocate_block(request, results)) { */ /* debug("couldn't allocate %c%c%c", */ /* request->geometry[0], */ /* request->geometry[1], */ /* request->geometry[2]); */ /* } */ /* list_destroy(results); */ /* [001x801] */ results = list_create(NULL); request->geometry[0] = 7; request->geometry[1] = 4; request->geometry[2] = 2; request->start[0] = 0; request->start[1] = 0; request->start[2] = 0; request->start_req = 0; // request->size = 1; request->rotate = 1; request->elongate = 1; request->conn_type[0] = SELECT_TORUS; new_ba_request(request); print_ba_request(request); if (!allocate_block(request, results)) { debug("couldn't allocate %c%c%c", request->geometry[0], request->geometry[1], request->geometry[2]); } list_destroy(results); int dim,j; int x,y,z; int startx=0; int starty=0; int startz=0; int endx=DIM_SIZE[X]; int endy=1;//DIM_SIZE[Y]; int endz=1;//DIM_SIZE[Z]; for(x=startx;x<endx;x++) { for(y=starty;y<endy;y++) { for(z=startz;z<endz;z++) { ba_mp_t *curr_node = &(ba_main_grid[x][y][z]); info("Node %c%c%c Used = %d", alpha_num[x],alpha_num[y],alpha_num[z], curr_node->used); for(dim=0;dim<1;dim++) { info("Dim %d",dim); ba_switch_t *wire = &curr_node->axis_switch[dim]; for(j=0;j<NUM_PORTS_PER_NODE;j++) info("\t%d -> %d -> %c%c%c %d " "Used = %d", j, wire->int_wire[j]. port_tar, alpha_num[wire->ext_wire[ wire->int_wire[j]. port_tar]. mp_tar[X]], alpha_num[wire->ext_wire[ wire->int_wire[j]. port_tar]. mp_tar[Y]], alpha_num[wire->ext_wire[ wire->int_wire[j]. port_tar]. mp_tar[Z]], wire->ext_wire[ wire->int_wire[j]. port_tar]. port_tar, wire->int_wire[j].used); } } } } /* list_destroy(results); */ /* ba_fini(); */ /* delete_ba_request(request); */ return 0; }
int main (int argc, char *argv[]) { char *prio_type = NULL; int error_code = SLURM_SUCCESS; priority_factors_request_msg_t req_msg; priority_factors_response_msg_t *resp_msg = NULL; log_options_t opts = LOG_OPTS_STDERR_ONLY ; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL); parse_command_line( argc, argv ); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (working_cluster_rec) { slurm_ctl_conf_info_msg_t *slurm_ctl_conf_ptr; error_code = slurm_load_ctl_conf((time_t) NULL, &slurm_ctl_conf_ptr); if (error_code) { slurm_perror ("slurm_load_ctl_conf error"); exit(error_code); } weight_age = slurm_ctl_conf_ptr->priority_weight_age; weight_fs = slurm_ctl_conf_ptr->priority_weight_fs; weight_js = slurm_ctl_conf_ptr->priority_weight_js; weight_part = slurm_ctl_conf_ptr->priority_weight_part; weight_qos = slurm_ctl_conf_ptr->priority_weight_qos; weight_tres = slurm_ctl_conf_ptr->priority_weight_tres; prio_type = xstrdup(slurm_ctl_conf_ptr->priority_type); slurm_free_ctl_conf(slurm_ctl_conf_ptr); } else { weight_age = slurm_get_priority_weight_age(); weight_fs = slurm_get_priority_weight_fairshare(); weight_js = slurm_get_priority_weight_job_size(); weight_part = slurm_get_priority_weight_partition(); weight_qos = slurm_get_priority_weight_qos(); weight_tres = slurm_get_priority_weight_tres(); prio_type = slurm_get_priority_type(); } /* Check to see if we are running a supported accounting plugin */ if (xstrcasecmp(prio_type, "priority/basic") == 0) { fprintf (stderr, "You are not running a supported " "priority plugin\n(%s).\n" "Only 'priority/multifactor' is supported.\n", prio_type); exit(1); } xfree(prio_type); memset(&req_msg, 0, sizeof(priority_factors_request_msg_t)); if (params.jobs) req_msg.job_id_list = params.job_list; else req_msg.job_id_list = NULL; if (params.users) req_msg.uid_list = params.user_list; else req_msg.uid_list = NULL; error_code = _get_info(&req_msg, &resp_msg); if (error_code) { slurm_perror("Couldn't get priority factors from controller"); exit(error_code); } if (params.format == NULL) { if (params.normalized) { if (params.long_list) params.format = "%.15i %.8u %10y %10a %10f " "%10j %10p %10q %20t"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %10y"); if (weight_age) xstrcat(params.format, " %10a"); if (weight_fs) xstrcat(params.format, " %10f"); if (weight_js) xstrcat(params.format, " %10j"); if (weight_part) xstrcat(params.format, " %10p"); if (weight_qos) xstrcat(params.format, " %10q"); if (weight_tres) xstrcat(params.format, " %20t"); } } else { if (params.long_list) params.format = "%.15i %.8u %.10Y %.10A %.10F " "%.10J %.10P %.10Q %.6N %.20T"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %.10Y"); if (weight_age) xstrcat(params.format, " %.10A"); if (weight_fs) xstrcat(params.format, " %.10F"); if (weight_js) xstrcat(params.format, " %.10J"); if (weight_part) xstrcat(params.format, " %.10P"); if (weight_qos) xstrcat(params.format, " %.10Q"); if (weight_tres) xstrcat(params.format, " %.20T"); } } } /* create the format list from the format */ parse_format(params.format); if (params.jobs && (!resp_msg || !resp_msg->priority_factors_list || !list_count(resp_msg->priority_factors_list))) { printf("Unable to find jobs matching user/id(s) specified\n"); } else if (resp_msg) { print_jobs_array(resp_msg->priority_factors_list, params.format_list); } #if 0 /* Free storage here if we want to verify that logic. * Since we exit next, this is not important */ FREE_NULL_LIST(params.format_list); slurm_free_priority_factors_response_msg(resp_msg); #endif exit (error_code); }
int main (int argc, char **argv) { log_options_t logopt = LOG_OPTS_STDERR_ONLY; slurm_ctl_conf_t *conf = NULL; shares_response_msg_t resp; log_init(xbasename(argv[0]), logopt, 0, NULL); xfree(slurmctld_conf.priority_type); //logopt.stderr_level += 5; logopt.prefix_level = 1; log_alter(logopt, 0, NULL); print_fields_have_header = 0; print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; conf = slurm_conf_lock(); /* force priority type to be multifactor */ xfree(conf->priority_type); conf->priority_type = xstrdup("priority/multifactor"); conf->priority_flags = PRIORITY_FLAGS_FAIR_TREE; /* force accounting type to be slurmdbd (It doesn't really talk * to any database, but needs this to work with fairshare * calculation). */ xfree(conf->accounting_storage_type); conf->accounting_storage_type = xstrdup("accounting_storage/slurmdbd"); /* set up a known environment to test against. Since we are * only concerned about the fairshare we won't look at the other * factors here. */ conf->priority_decay_hl = 1; conf->priority_favor_small = 0; conf->priority_max_age = conf->priority_decay_hl; conf->priority_reset_period = 0; conf->priority_weight_age = 0; conf->priority_weight_fs = 10000; conf->priority_weight_js = 0; conf->priority_weight_part = 0; conf->priority_weight_qos = 0; slurm_conf_unlock(); /* we don't want to do any decay here so make the save state * to /dev/null */ xfree(slurmctld_conf.state_save_location); slurmctld_conf.state_save_location = "/dev/null"; /* now set up the association tree */ _setup_assoc_list(); /* now set up the job list */ job_list = list_create(_list_delete_job); /* now init the priorities of the associations */ if (slurm_priority_init() != SLURM_SUCCESS) fatal("failed to initialize priority plugin"); /* on some systems that don't have multiple cores we need to * sleep to make sure the thread gets started. */ sleep(1); memset(&resp, 0, sizeof(shares_response_msg_t)); resp.assoc_shares_list = assoc_mgr_get_shares(NULL, 0, NULL, NULL); process(&resp, 0); /* free memory */ if (slurm_priority_fini() != SLURM_SUCCESS) fatal("failed to finalize priority plugin"); if (job_list) list_destroy(job_list); if (resp.assoc_shares_list) list_destroy(resp.assoc_shares_list); if (assoc_mgr_assoc_list) list_destroy(assoc_mgr_assoc_list); if (assoc_mgr_qos_list) list_destroy(assoc_mgr_qos_list); return 0; }
int main(int argc, char **argv) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; int local_exit_code = 0; char *temp = NULL; int option_index; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"usage", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"noheader",0, 0, 'n'}, {"oneliner", 0, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2", 0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"readonly", 0, 0, 'r'}, {"associations", 0, 0, 's'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; rollback_flag = 1; exit_code = 0; exit_flag = 0; input_field_count = 0; quiet_flag = 0; readonly_flag = 0; verbosity = 0; slurm_conf_init(NULL); log_init("sacctmgr", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "hionpPQrsvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sacctmgr --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'i': rollback_flag = 0; break; case (int)'o': one_liner = 1; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'r': readonly_flag = 1; break; case (int)'s': with_assoc_flag = 1; break; case (int)'v': quiet_flag = -1; verbosity++; break; case (int)'V': _print_version(); exit(exit_code); break; default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (xstrcasecmp(temp, "accounting_storage/slurmdbd") && xstrcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); errno = 0; db_conn = slurmdb_connection_get(); if (errno != SLURM_SUCCESS) { int tmp_errno = errno; if ((input_field_count == 2) && (!strncasecmp(argv[2], "Configuration", strlen(argv[1]))) && ((!strncasecmp(argv[1], "list", strlen(argv[0]))) || (!strncasecmp(argv[1], "show", strlen(argv[0]))))) { if (tmp_errno == ESLURM_DB_CONNECTION) { tmp_errno = 0; sacctmgr_list_config(true); } else sacctmgr_list_config(false); } errno = tmp_errno; if (errno) error("Problem talking to the database: %m"); exit(1); } my_uid = getuid(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); /* This is here so if someone made a mistake we allow * them to fix it and let the process happen since there * are checks for global exit_code we need to reset it. */ if (exit_code) { local_exit_code = exit_code; exit_code = 0; } } /* readline library writes \n when echoes the input string, it does * not when it sees the EOF, so in that case we have to print it to * align the terminal prompt. */ if (exit_flag == 2) putchar('\n'); if (local_exit_code) exit_code = local_exit_code; acct_storage_g_close_connection(&db_conn); slurm_acct_storage_fini(); FREE_NULL_LIST(g_qos_list); FREE_NULL_LIST(g_res_list); FREE_NULL_LIST(g_tres_list); exit(exit_code); }
/* Become a daemon (child of init) and * "cd" to the LogFile directory (if one is configured) */ static void _daemonize(void) { if (daemon(1, 1)) error("daemon(): %m"); log_alter(log_opts, LOG_DAEMON, slurmdbd_conf->log_file); }
int main(int argc, char *argv[]) { log_options_t logopt = LOG_OPTS_STDERR_ONLY; job_desc_msg_t desc; resource_allocation_response_msg_t *alloc; time_t before, after; allocation_msg_thread_t *msg_thr; char **env = NULL; int status = 0; int retries = 0; pid_t pid = getpid(); pid_t tpgid = 0; pid_t rc_pid = 0; int i, rc = 0; static char *msg = "Slurm job queue full, sleeping and retrying."; slurm_allocation_callbacks_t callbacks; log_init(xbasename(argv[0]), logopt, 0, NULL); _set_exit_code(); if (spank_init_allocator() < 0) { error("Failed to initialize plugin stack"); exit(error_exit); } /* Be sure to call spank_fini when salloc exits */ if (atexit((void (*) (void)) spank_fini) < 0) error("Failed to register atexit handler for plugins: %m"); if (initialize_and_process_args(argc, argv) < 0) { error("salloc parameter parsing"); exit(error_exit); } /* reinit log with new verbosity (if changed by command line) */ if (opt.verbose || opt.quiet) { logopt.stderr_level += opt.verbose; logopt.stderr_level -= opt.quiet; logopt.prefix_level = 1; log_alter(logopt, 0, NULL); } if (spank_init_post_opt() < 0) { error("Plugin stack post-option processing failed"); exit(error_exit); } _set_spank_env(); _set_submit_dir_env(); if (opt.cwd && chdir(opt.cwd)) { error("chdir(%s): %m", opt.cwd); exit(error_exit); } if (opt.get_user_env_time >= 0) { char *user = uid_to_string(opt.uid); if (strcmp(user, "nobody") == 0) { error("Invalid user id %u: %m", (uint32_t)opt.uid); exit(error_exit); } env = env_array_user_default(user, opt.get_user_env_time, opt.get_user_env_mode); xfree(user); if (env == NULL) exit(error_exit); /* error already logged */ _set_rlimits(env); } /* * Job control for interactive salloc sessions: only if ... * * a) input is from a terminal (stdin has valid termios attributes), * b) controlling terminal exists (non-negative tpgid), * c) salloc is not run in allocation-only (--no-shell) mode, * NOTE: d and e below are configuration dependent * d) salloc runs in its own process group (true in interactive * shells that support job control), * e) salloc has been configured at compile-time to support background * execution and is not currently in the background process group. */ if (tcgetattr(STDIN_FILENO, &saved_tty_attributes) < 0) { /* * Test existence of controlling terminal (tpgid > 0) * after first making sure stdin is not redirected. */ } else if ((tpgid = tcgetpgrp(STDIN_FILENO)) < 0) { if (!opt.no_shell) { error("no controlling terminal: please set --no-shell"); exit(error_exit); } #ifdef SALLOC_RUN_FOREGROUND } else if ((!opt.no_shell) && (pid == getpgrp())) { if (tpgid == pid) is_interactive = true; while (tcgetpgrp(STDIN_FILENO) != pid) { if (!is_interactive) { error("Waiting for program to be placed in " "the foreground"); is_interactive = true; } killpg(pid, SIGTTIN); } } #else } else if ((!opt.no_shell) && (getpgrp() == tcgetpgrp(STDIN_FILENO))) {
static void _set_options(const int argc, char **argv) { int option_index = 0, c; log_options_t logopt = LOG_OPTS_STDERR_ONLY; char *next_str = NULL; uid_t uid = -1; static struct option long_options[] = { {"extract", no_argument, 0, 'E'}, {"help", no_argument, 0, 'h'}, {"job", required_argument, 0, 'j'}, {"input", required_argument, 0, 'i'}, {"level", required_argument, 0, 'l'}, {"node", required_argument, 0, 'N'}, {"output", required_argument, 0, 'o'}, {"profiledir", required_argument, 0, 'p'}, {"series", required_argument, 0, 's'}, {"savefiles", no_argument, 0, 'S'}, {"usage", 0, ¶ms.help, 3}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}}; log_init(xbasename(argv[0]), logopt, 0, NULL); _init_opts(); while (1) { /* now cycle through the command line */ c = getopt_long(argc, argv, "Ehi:j:l:N:o:p:s:Su:vV", long_options, &option_index); if (c == -1) break; switch (c) { case 'E': params.mode = SH5UTIL_MODE_EXTRACT; break; case 'h': params.help = 1; break; case 'i': params.input = xstrdup(optarg); break; case 'j': params.job_id = strtol(optarg, &next_str, 10); if (next_str[0] == '.') params.step_id = strtol(next_str+1, NULL, 10); break; case 'l': params.level = xstrdup(optarg); break; case 'N': params.node = xstrdup(optarg); break; case 'o': params.output = xstrdup(optarg); break; case 'p': params.dir = xstrdup(optarg); break; case 's': params.series = xstrdup(optarg); break; case 'S': params.keepfiles = 1; break; case 'u': if (uid_from_string (optarg, &uid) < 0) { error("--uid=\"%s\" invalid", optarg); exit(1); } break; case (int)'v': params.verbose++; break; case (int)'V': print_slurm_version(); exit(0); break; case ':': case '?': /* getopt() has explained it */ exit(1); } } if (params.help) { switch (params.help) { case 1: case 3: _help_msg(); break; default: fprintf(stderr, "bug: --help=%d\n", params.help); } exit(0); } if (params.job_id == -1) fatal("You need to supply a --jobs value."); if (uid == -1) uid = getuid(); params.user = uid_to_string(uid); if (!params.dir) acct_gather_profile_g_get(ACCT_GATHER_PROFILE_DIR, ¶ms.dir); if (!params.dir) fatal("You need to supply a --profiledir or be on a " "node with a valid acct_gather.conf"); if (params.verbose) { logopt.stderr_level += params.verbose; log_alter(logopt, SYSLOG_FACILITY_USER, NULL); } /* FIXME : For now all these only work for extract. Seems * like it would be easy to add the logic to "merge" as well. */ if (params.input || params.level || params.node || (params.step_id != -1) || params.series) params.mode = SH5UTIL_MODE_EXTRACT; if (params.mode == SH5UTIL_MODE_EXTRACT) { if (!params.level) params.level = xstrdup("Node:Totals"); if (!params.input) params.input = xstrdup_printf( "./job_%d.h5", params.job_id); if (!params.output) params.output = xstrdup_printf( "./extract_%d.csv", params.job_id); } if (!params.output) params.output = xstrdup_printf("./job_%d.h5", params.job_id); }
int main(int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY; node_info_msg_t *node_info_ptr = NULL; node_info_msg_t *new_node_ptr = NULL; int error_code; int height = 40; int width = 100; int startx = 0; int starty = 0; int end = 0; int i; int rc; int mapset = 0; log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (params.cluster_dims == 4) { min_screen_width = 92; } else if (params.cluster_dims == 3) min_screen_width = 92; while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) { error_code = slurm_get_errno(); printf("slurm_load_node: %s\n", slurm_strerror(error_code)); if (params.display == COMMANDS) { new_node_ptr = NULL; break; /* just continue */ } if (params.iterate == 0) _smap_exit(1); /* Calls exit(), no return */ sleep(10); /* keep trying to reconnect */ } _init_colors(); select_g_ba_init(new_node_ptr, 0); init_grid(new_node_ptr); if (params.resolve) { #if defined HAVE_BG_FILES && defined HAVE_BG_L_P #if 1 error("this doesn't work in the current 2.3 code. FIXME"); #else if (!have_db2) { printf("Required libraries can not be found " "to access the Bluegene system.\nPlease " "set your LD_LIBRARY_PATH correctly to " "point to them.\n"); goto part_fini; } if (!mapset) mapset = 1; if (params.resolve[0] != 'R') { i = strlen(params.resolve); i -= 3; if (i < 0) { printf("No real block was entered\n"); goto part_fini; } char *rack_mid = find_bp_rack_mid(params.resolve+i); if (rack_mid) { printf("X=%c Y=%c Z=%c resolves to %s\n", params.resolve[0+i], params.resolve[1+i], params.resolve[2+i], rack_mid); } else { printf("X=%c Y=%c Z=%c has no resolve\n", params.resolve[0+i], params.resolve[1+i], params.resolve[2+i]); } } else { uint16_t *coord = find_bp_loc(params.resolve); if (coord) { printf("%s resolves to X=%d Y=%d Z=%d\n", params.resolve, coord[0], coord[1], coord[2]); } else { printf("%s has no resolve.\n", params.resolve); } } part_fini: #endif #else printf("Must be physically on a BlueGene system for support " "of resolve option.\n"); #endif _smap_exit(0); /* Calls exit(), no return */ } if (!params.commandline) { int check_width = min_screen_width; signal(SIGWINCH, (void (*)(int))_resize_handler); initscr(); if (params.cluster_dims == 4) { height = dim_size[2] * dim_size[3] + dim_size[2] + 3; width = (dim_size[1] + dim_size[3] + 1) * dim_size[0] + 2; check_width += width; } else if (params.cluster_dims == 3) { height = dim_size[1] * dim_size[2] + dim_size[1] + 3; width = dim_size[0] + dim_size[2] + 3; check_width += width; } else { height = 10; width = COLS; } if ((COLS < check_width) || (LINES < height)) { endwin(); error("Screen is too small make sure the screen " "is at least %dx%d\n" "Right now it is %dx%d\n", check_width, height, COLS, LINES); _smap_exit(1); /* Calls exit(), no return */ } raw(); keypad(stdscr, TRUE); noecho(); cbreak(); curs_set(0); nodelay(stdscr, TRUE); start_color(); _set_pairs(); grid_win = newwin(height, width, starty, startx); max_display = grid_win->_maxy * grid_win->_maxx; if (params.cluster_dims == 4) { startx = width; COLS -= 2; width = COLS - width; height = LINES; } else if (params.cluster_dims == 3) { startx = width; COLS -= 2; width = COLS - width; height = LINES; } else { startx = 0; starty = height; height = LINES - height; } text_win = newwin(height, width, starty, startx); } while (!end) { if (!params.commandline) { _get_option(); redraw: clear_window(text_win); clear_window(grid_win); move(0, 0); main_xcord = 1; main_ycord = 1; } if (!params.no_header) print_date(); clear_grid(); switch (params.display) { case JOBS: get_job(); break; case RESERVATIONS: get_reservation(); break; case SLURMPART: get_slurm_part(); break; case COMMANDS: if (params.cluster_flags & CLUSTER_FLAG_BG) { if (!mapset) { mapset = 1; wclear(text_win); } get_command(); } else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; case BGPART: if (params.cluster_flags & CLUSTER_FLAG_BG) get_bg_part(); else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; } if (!params.commandline) { box(text_win, 0, 0); wnoutrefresh(text_win); print_grid(); box(grid_win, 0, 0); wnoutrefresh(grid_win); doupdate(); node_info_ptr = new_node_ptr; if (node_info_ptr) { error_code = slurm_load_node( node_info_ptr->last_update, &new_node_ptr, SHOW_ALL); if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg( node_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = node_info_ptr; } } else { error_code = slurm_load_node( (time_t) NULL, &new_node_ptr, SHOW_ALL); } if (error_code && (quiet_flag != 1)) { if (!params.commandline) { mvwprintw( text_win, main_ycord, 1, "slurm_load_node: %s", slurm_strerror( slurm_get_errno())); main_ycord++; } else { printf("slurm_load_node: %s", slurm_strerror( slurm_get_errno())); } } } if (params.iterate) { for (i = 0; i < params.iterate; i++) { sleep(1); if (!params.commandline) { if ((rc = _get_option()) == 1) goto redraw; else if (resize_screen) { resize_screen = 0; goto redraw; } } } } else break; } if (!params.commandline) { nodelay(stdscr, FALSE); getch(); endwin(); } _smap_exit(0); /* Calls exit(), no return */ exit(0); /* Redundant, but eliminates compiler warning */ }
int main (int argc, char **argv) { int opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"helpformat",0,0, 'e'}, {"long", 0, 0, 'l'}, {"partition",0, 0, 'm'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'n'}, {"format", 1, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"Users", 0, 0, 'U'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); slurm_conf_init(NULL); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while ((opt_char = getopt_long(argc, argv, "aA:ehlM:no:pPqUu:t:vVm", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if (!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'e': _help_format_msg(); exit(0); break; case 'h': print_fields_have_header = 0; break; case 'l': long_flag = 1; break; case 'M': FREE_NULL_LIST(clusters); if (!(clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'm': options |= PRINT_PARTITIONS; break; case 'n': print_fields_have_header = 0; break; case 'o': xstrfmtcat(opt_field_list, "%s,", optarg); break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if (!xstrcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'U': options |= PRINT_USERS_ONLY; break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if (all_users) { if (req_msg.user_list && list_count(req_msg.user_list)) { FREE_NULL_LIST(req_msg.user_list); } if (verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while ((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if (!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd; if ((pwd = getpwuid(getuid()))) { if (!req_msg.user_list) { req_msg.user_list = list_create(slurm_destroy_char); } temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if (verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } } if (req_msg.acct_list && list_count(req_msg.acct_list)) { if (verbosity) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while ((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } } else { if (req_msg.acct_list && list_count(req_msg.acct_list)) { FREE_NULL_LIST(req_msg.acct_list); } if (verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } if (clusters) exit_code = _multi_cluster(&req_msg); else exit_code = _single_cluster(&req_msg); exit(exit_code); }
/* * This function handles the initialization information from slurmd * sent by _send_slurmstepd_init() in src/slurmd/slurmd/req.c. */ static int _init_from_slurmd(int sock, char **argv, slurm_addr_t **_cli, slurm_addr_t **_self, slurm_msg_t **_msg, int *_ngids, gid_t **_gids) { char *incoming_buffer = NULL; Buf buffer; int step_type; int len; slurm_addr_t *cli = NULL; slurm_addr_t *self = NULL; slurm_msg_t *msg = NULL; int ngids = 0; gid_t *gids = NULL; uint16_t port; char buf[16]; log_options_t lopts = LOG_OPTS_INITIALIZER; log_init(argv[0], lopts, LOG_DAEMON, NULL); /* receive job type from slurmd */ safe_read(sock, &step_type, sizeof(int)); debug3("step_type = %d", step_type); /* receive reverse-tree info from slurmd */ pthread_mutex_lock(&step_complete.lock); safe_read(sock, &step_complete.rank, sizeof(int)); safe_read(sock, &step_complete.parent_rank, sizeof(int)); safe_read(sock, &step_complete.children, sizeof(int)); safe_read(sock, &step_complete.depth, sizeof(int)); safe_read(sock, &step_complete.max_depth, sizeof(int)); safe_read(sock, &step_complete.parent_addr, sizeof(slurm_addr_t)); step_complete.bits = bit_alloc(step_complete.children); step_complete.jobacct = jobacct_gather_g_create(NULL); pthread_mutex_unlock(&step_complete.lock); /* receive conf from slurmd */ if ((conf = read_slurmd_conf_lite (sock)) == NULL) fatal("Failed to read conf from slurmd"); log_alter(conf->log_opts, 0, conf->logfile); debug2("debug level is %d.", conf->debug_level); /* acct info */ jobacct_gather_g_startpoll(conf->job_acct_gather_freq); switch_g_slurmd_step_init(); slurm_get_ip_str(&step_complete.parent_addr, &port, buf, 16); debug3("slurmstepd rank %d, parent address = %s, port = %u", step_complete.rank, buf, port); /* receive cli from slurmd */ safe_read(sock, &len, sizeof(int)); incoming_buffer = xmalloc(sizeof(char) * len); safe_read(sock, incoming_buffer, len); buffer = create_buf(incoming_buffer,len); cli = xmalloc(sizeof(slurm_addr_t)); if(slurm_unpack_slurm_addr_no_alloc(cli, buffer) == SLURM_ERROR) fatal("slurmstepd: problem with unpack of slurmd_conf"); free_buf(buffer); /* receive self from slurmd */ safe_read(sock, &len, sizeof(int)); if (len > 0) { /* receive packed self from main slurmd */ incoming_buffer = xmalloc(sizeof(char) * len); safe_read(sock, incoming_buffer, len); buffer = create_buf(incoming_buffer,len); self = xmalloc(sizeof(slurm_addr_t)); if (slurm_unpack_slurm_addr_no_alloc(self, buffer) == SLURM_ERROR) { fatal("slurmstepd: problem with unpack of " "slurmd_conf"); } free_buf(buffer); } /* Receive GRES information from slurmd */ gres_plugin_recv_stepd(sock); /* receive req from slurmd */ safe_read(sock, &len, sizeof(int)); incoming_buffer = xmalloc(sizeof(char) * len); safe_read(sock, incoming_buffer, len); buffer = create_buf(incoming_buffer,len); msg = xmalloc(sizeof(slurm_msg_t)); slurm_msg_t_init(msg); switch(step_type) { case LAUNCH_BATCH_JOB: msg->msg_type = REQUEST_BATCH_JOB_LAUNCH; break; case LAUNCH_TASKS: msg->msg_type = REQUEST_LAUNCH_TASKS; break; default: fatal("Unrecognized launch RPC"); break; } if(unpack_msg(msg, buffer) == SLURM_ERROR) fatal("slurmstepd: we didn't unpack the request correctly"); free_buf(buffer); /* receive cached group ids array for the relevant uid */ safe_read(sock, &ngids, sizeof(int)); if (ngids > 0) { int i; uint32_t tmp32; gids = (gid_t *)xmalloc(sizeof(gid_t) * ngids); for (i = 0; i < ngids; i++) { safe_read(sock, &tmp32, sizeof(uint32_t)); gids[i] = (gid_t)tmp32; debug2("got gid %d", gids[i]); } } *_cli = cli; *_self = self; *_msg = msg; *_ngids = ngids; *_gids = gids; return 1; rwfail: fatal("Error reading initialization data from slurmd"); exit(1); }
int main(int argc, char *argv[]) { log_options_t logopt = LOG_OPTS_STDERR_ONLY; job_desc_msg_t desc; resource_allocation_response_msg_t *alloc; time_t before, after; allocation_msg_thread_t *msg_thr; char **env = NULL; int status = 0; int retries = 0; pid_t pid = getpid(); pid_t tpgid = 0; pid_t rc_pid = 0; int i, rc = 0; static char *msg = "Slurm job queue full, sleeping and retrying."; slurm_allocation_callbacks_t callbacks; log_init(xbasename(argv[0]), logopt, 0, NULL); _set_exit_code(); if (spank_init_allocator() < 0) { error("Failed to initialize plugin stack"); exit(error_exit); } /* Be sure to call spank_fini when salloc exits */ if (atexit((void (*) (void)) spank_fini) < 0) error("Failed to register atexit handler for plugins: %m"); if (initialize_and_process_args(argc, argv) < 0) { error("salloc parameter parsing"); exit(error_exit); } /* reinit log with new verbosity (if changed by command line) */ if (opt.verbose || opt.quiet) { logopt.stderr_level += opt.verbose; logopt.stderr_level -= opt.quiet; logopt.prefix_level = 1; log_alter(logopt, 0, NULL); } if (spank_init_post_opt() < 0) { error("Plugin stack post-option processing failed"); exit(error_exit); } _set_spank_env(); _set_submit_dir_env(); if (opt.cwd && chdir(opt.cwd)) { error("chdir(%s): %m", opt.cwd); exit(error_exit); } if (opt.get_user_env_time >= 0) { char *user = uid_to_string(opt.uid); if (strcmp(user, "nobody") == 0) { error("Invalid user id %u: %m", (uint32_t)opt.uid); exit(error_exit); } env = env_array_user_default(user, opt.get_user_env_time, opt.get_user_env_mode); xfree(user); if (env == NULL) exit(error_exit); /* error already logged */ _set_rlimits(env); } /* * Job control for interactive salloc sessions: only if ... * * a) input is from a terminal (stdin has valid termios attributes), * b) controlling terminal exists (non-negative tpgid), * c) salloc is not run in allocation-only (--no-shell) mode, * d) salloc runs in its own process group (true in interactive * shells that support job control), * e) salloc has been configured at compile-time to support background * execution and is not currently in the background process group. */ if (tcgetattr(STDIN_FILENO, &saved_tty_attributes) < 0) { /* * Test existence of controlling terminal (tpgid > 0) * after first making sure stdin is not redirected. */ } else if ((tpgid = tcgetpgrp(STDIN_FILENO)) < 0) { if (!opt.no_shell) { error("no controlling terminal: please set --no-shell"); exit(error_exit); } } else if ((!opt.no_shell) && (pid == getpgrp())) { if (tpgid == pid) is_interactive = true; #ifdef SALLOC_RUN_FOREGROUND while (tcgetpgrp(STDIN_FILENO) != pid) { if (!is_interactive) { error("Waiting for program to be placed in " "the foreground"); is_interactive = true; } killpg(pid, SIGTTIN); } #endif } /* * Reset saved tty attributes at exit, in case a child * process died before properly resetting terminal. */ if (is_interactive) atexit (_reset_input_mode); /* * Request a job allocation */ slurm_init_job_desc_msg(&desc); if (_fill_job_desc_from_opts(&desc) == -1) { exit(error_exit); } if (opt.gid != (gid_t) -1) { if (setgid(opt.gid) < 0) { error("setgid: %m"); exit(error_exit); } } callbacks.ping = _ping_handler; callbacks.timeout = _timeout_handler; callbacks.job_complete = _job_complete_handler; callbacks.user_msg = _user_msg_handler; callbacks.node_fail = _node_fail_handler; /* create message thread to handle pings and such from slurmctld */ msg_thr = slurm_allocation_msg_thr_create(&desc.other_port, &callbacks); /* NOTE: Do not process signals in separate pthread. The signal will * cause slurm_allocate_resources_blocking() to exit immediately. */ for (i = 0; sig_array[i]; i++) xsignal(sig_array[i], _signal_while_allocating); before = time(NULL); while ((alloc = slurm_allocate_resources_blocking(&desc, opt.immediate, _pending_callback)) == NULL) { if ((errno != ESLURM_ERROR_ON_DESC_TO_RECORD_COPY) || (retries >= MAX_RETRIES)) break; if (retries == 0) error("%s", msg); else debug("%s", msg); sleep (++retries); } /* become the user after the allocation has been requested. */ if (opt.uid != (uid_t) -1) { if (setuid(opt.uid) < 0) { error("setuid: %m"); exit(error_exit); } } if (alloc == NULL) { if (allocation_interrupted) { /* cancelled by signal */ info("Job aborted due to signal"); } else if (errno == EINTR) { error("Interrupted by signal." " Allocation request rescinded."); } else if (opt.immediate && ((errno == ETIMEDOUT) || (errno == ESLURM_NOT_TOP_PRIORITY) || (errno == ESLURM_NODES_BUSY))) { error("Unable to allocate resources: %m"); error_exit = immediate_exit; } else { error("Failed to allocate resources: %m"); } slurm_allocation_msg_thr_destroy(msg_thr); exit(error_exit); } else if (!allocation_interrupted) { /* * Allocation granted! */ info("Granted job allocation %u", alloc->job_id); pending_job_id = alloc->job_id; #ifdef HAVE_BG if (!_wait_bluegene_block_ready(alloc)) { if(!allocation_interrupted) error("Something is wrong with the " "boot of the block."); goto relinquish; } #else if (!_wait_nodes_ready(alloc)) { if(!allocation_interrupted) error("Something is wrong with the " "boot of the nodes."); goto relinquish; } #endif } after = time(NULL); if (opt.bell == BELL_ALWAYS || (opt.bell == BELL_AFTER_DELAY && ((after - before) > DEFAULT_BELL_DELAY))) { _ring_terminal_bell(); } if (opt.no_shell) exit(0); if (allocation_interrupted) { /* salloc process received a signal after * slurm_allocate_resources_blocking returned with the * allocation, but before the new signal handlers were * registered. */ goto relinquish; } /* * Run the user's command. */ if (env_array_for_job(&env, alloc, &desc) != SLURM_SUCCESS) goto relinquish; /* Add default task count for srun, if not already set */ if (opt.ntasks_set) { env_array_append_fmt(&env, "SLURM_NTASKS", "%d", opt.ntasks); /* keep around for old scripts */ env_array_append_fmt(&env, "SLURM_NPROCS", "%d", opt.ntasks); } if (opt.cpus_per_task > 1) { env_array_append_fmt(&env, "SLURM_CPUS_PER_TASK", "%d", opt.cpus_per_task); } if (opt.overcommit) { env_array_append_fmt(&env, "SLURM_OVERCOMMIT", "%d", opt.overcommit); } if (opt.acctg_freq >= 0) { env_array_append_fmt(&env, "SLURM_ACCTG_FREQ", "%d", opt.acctg_freq); } if (opt.network) env_array_append_fmt(&env, "SLURM_NETWORK", "%s", opt.network); env_array_set_environment(env); env_array_free(env); pthread_mutex_lock(&allocation_state_lock); if (allocation_state == REVOKED) { error("Allocation was revoked for job %u before command could " "be run", alloc->job_id); pthread_mutex_unlock(&allocation_state_lock); if (slurm_complete_job(alloc->job_id, status) != 0) { error("Unable to clean up allocation for job %u: %m", alloc->job_id); } return 1; } allocation_state = GRANTED; pthread_mutex_unlock(&allocation_state_lock); /* Ensure that salloc has initial terminal foreground control. */ if (is_interactive) { /* * Ignore remaining job-control signals (other than those in * sig_array, which at this state act like SIG_IGN). */ xsignal(SIGTSTP, SIG_IGN); xsignal(SIGTTIN, SIG_IGN); xsignal(SIGTTOU, SIG_IGN); pid = getpid(); setpgid(pid, pid); tcsetpgrp(STDIN_FILENO, pid); } command_pid = _fork_command(command_argv); /* * Wait for command to exit, OR for waitpid to be interrupted by a * signal. Either way, we are going to release the allocation next. */ if (command_pid > 0) { setpgid(command_pid, command_pid); if (is_interactive) tcsetpgrp(STDIN_FILENO, command_pid); /* NOTE: Do not process signals in separate pthread. * The signal will cause waitpid() to exit immediately. */ xsignal(SIGHUP, _exit_on_signal); /* Use WUNTRACED to treat stopped children like terminated ones */ do { rc_pid = waitpid(command_pid, &status, WUNTRACED); } while ((rc_pid == -1) && (!exit_flag)); if ((rc_pid == -1) && (errno != EINTR)) error("waitpid for %s failed: %m", command_argv[0]); } if (is_interactive) tcsetpgrp(STDIN_FILENO, pid); /* * Relinquish the job allocation (if not already revoked). */ relinquish: pthread_mutex_lock(&allocation_state_lock); if (allocation_state != REVOKED) { pthread_mutex_unlock(&allocation_state_lock); info("Relinquishing job allocation %d", alloc->job_id); if ((slurm_complete_job(alloc->job_id, status) != 0) && (slurm_get_errno() != ESLURM_ALREADY_DONE)) error("Unable to clean up job allocation %d: %m", alloc->job_id); pthread_mutex_lock(&allocation_state_lock); allocation_state = REVOKED; } pthread_mutex_unlock(&allocation_state_lock); slurm_free_resource_allocation_response_msg(alloc); slurm_allocation_msg_thr_destroy(msg_thr); /* * Figure out what return code we should use. If the user's command * exited normally, return the user's return code. */ rc = 1; if (rc_pid != -1) { if (WIFEXITED(status)) { rc = WEXITSTATUS(status); } else if (WIFSIGNALED(status)) { verbose("Command \"%s\" was terminated by signal %d", command_argv[0], WTERMSIG(status)); /* if we get these signals we return a normal * exit since this was most likely sent from the * user */ switch(WTERMSIG(status)) { case SIGHUP: case SIGINT: case SIGQUIT: case SIGKILL: rc = 0; break; default: break; } } } return rc; }
void parse_command_line(int argc, char **argv) { extern int optind; int c, i, optionIndex = 0; char *end = NULL, *start = NULL, *acct_type = NULL; slurmdb_selected_step_t *selected_step = NULL; ListIterator itr = NULL; struct stat stat_buf; char *dot = NULL; bool brief_output = FALSE, long_output = FALSE; bool all_users = 0; bool all_clusters = 0; slurmdb_job_cond_t *job_cond = params.job_cond; log_options_t opts = LOG_OPTS_STDERR_ONLY ; int verbosity; /* count of -v options */ bool set; static struct option long_options[] = { {"allusers", no_argument, 0, 'a'}, {"accounts", required_argument, 0, 'A'}, {"allocations", no_argument, ¶ms.opt_allocs, OPT_LONG_ALLOCS}, {"brief", no_argument, 0, 'b'}, {"completion", no_argument, ¶ms.opt_completion, 'c'}, {"duplicates", no_argument, ¶ms.opt_dup, OPT_LONG_DUP}, {"helpformat", no_argument, 0, 'e'}, {"help-fields", no_argument, 0, 'e'}, {"endtime", required_argument, 0, 'E'}, {"file", required_argument, 0, 'f'}, {"gid", required_argument, 0, 'g'}, {"group", required_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, {"helpformat", no_argument, ¶ms.opt_help, OPT_LONG_HELP}, {"name", required_argument, 0, OPT_LONG_NAME}, {"nnodes", required_argument, 0, 'i'}, {"ncpus", required_argument, 0, 'I'}, {"jobs", required_argument, 0, 'j'}, {"timelimit-min", required_argument, 0, 'k'}, {"timelimit-max", required_argument, 0, 'K'}, {"long", no_argument, 0, 'l'}, {"allclusters", no_argument, 0, 'L'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodelist", required_argument, 0, 'N'}, {"noheader", no_argument, 0, 'n'}, {"fields", required_argument, 0, 'o'}, {"format", required_argument, 0, 'o'}, {"parsable", no_argument, 0, 'p'}, {"parsable2", no_argument, 0, 'P'}, {"qos", required_argument, 0, 'q'}, {"partition", required_argument, 0, 'r'}, {"state", required_argument, 0, 's'}, {"starttime", required_argument, 0, 'S'}, {"truncate", no_argument, 0, 'T'}, {"uid", required_argument, 0, 'u'}, {"usage", no_argument, ¶ms.opt_help, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckeys", required_argument, 0, 'W'}, {"associations", required_argument, 0, 'x'}, {0, 0, 0, 0}}; params.opt_uid = getuid(); params.opt_gid = getgid(); verbosity = 0; log_init("sacct", opts, SYSLOG_FACILITY_DAEMON, NULL); opterr = 1; /* Let getopt report problems to the user */ while (1) { /* now cycle through the command line */ c = getopt_long(argc, argv, "aA:bcC:dDeE:f:g:hi:I:j:k:K:lLM:nN:o:OpPq:r:s:S:Ttu:vVW:x:X", long_options, &optionIndex); if (c == -1) break; switch (c) { case 'a': all_users = 1; break; case 'A': if(!job_cond->acct_list) job_cond->acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->acct_list, optarg); break; case 'b': brief_output = true; break; case 'c': params.opt_completion = 1; break; case 'C': /* 'C' is deprecated since 'M' is cluster on everything else. */ case 'M': if(!strcasecmp(optarg, "-1")) { all_clusters = 1; break; } all_clusters=0; if(!job_cond->cluster_list) job_cond->cluster_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->cluster_list, optarg); break; case 'D': params.opt_dup = 1; break; case 'e': params.opt_help = 2; break; case 'E': job_cond->usage_end = parse_time(optarg, 1); if (errno == ESLURM_INVALID_TIME_VALUE) exit(1); break; case 'f': xfree(params.opt_filein); params.opt_filein = xstrdup(optarg); break; case 'g': if(!job_cond->groupid_list) job_cond->groupid_list = list_create(slurm_destroy_char); _addto_id_char_list(job_cond->groupid_list, optarg, 1); break; case 'h': params.opt_help = 1; break; case 'i': set = get_resource_arg_range( optarg, "requested node range", (int *)&job_cond->nodes_min, (int *)&job_cond->nodes_max, true); if (set == false) { error("invalid node range -i '%s'", optarg); exit(1); } break; case 'I': set = get_resource_arg_range( optarg, "requested cpu range", (int *)&job_cond->cpus_min, (int *)&job_cond->cpus_max, true); if (set == false) { error("invalid cpu range -i '%s'", optarg); exit(1); } break; case 'j': if ((strspn(optarg, "0123456789, ") < strlen(optarg)) && (strspn(optarg, ".batch0123456789, ") < strlen(optarg))) { fprintf(stderr, "Invalid jobs list: %s\n", optarg); exit(1); } if(!job_cond->step_list) job_cond->step_list = list_create( slurmdb_destroy_selected_step); _addto_step_list(job_cond->step_list, optarg); break; case 'k': job_cond->timelimit_min = time_str2mins(optarg); if (((int32_t)job_cond->timelimit_min <= 0) && (job_cond->timelimit_min != INFINITE)) fatal("Invalid time limit specification"); break; case 'K': job_cond->timelimit_max = time_str2mins(optarg); if (((int32_t)job_cond->timelimit_max <= 0) && (job_cond->timelimit_max != INFINITE)) fatal("Invalid time limit specification"); break; case 'L': all_clusters = 1; break; case 'l': long_output = true; break; case 'n': print_fields_have_header = 0; break; case 'N': if(job_cond->used_nodes) { error("Aleady asked for nodes '%s'", job_cond->used_nodes); break; } job_cond->used_nodes = xstrdup(optarg); break; case OPT_LONG_NAME: if(!job_cond->jobname_list) job_cond->jobname_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->jobname_list, optarg); break; case 'o': xstrfmtcat(params.opt_field_list, "%s,", optarg); break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'q': if (!g_qos_list) { slurmdb_qos_cond_t qos_cond; memset(&qos_cond, 0, sizeof(slurmdb_qos_cond_t)); qos_cond.with_deleted = 1; g_qos_list = slurmdb_qos_get( acct_db_conn, &qos_cond); } if(!job_cond->qos_list) job_cond->qos_list = list_create(slurm_destroy_char); if(!slurmdb_addto_qos_char_list(job_cond->qos_list, g_qos_list, optarg, 0)) fatal("problem processing qos list"); break; case 'r': if(!job_cond->partition_list) job_cond->partition_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->partition_list, optarg); break; case 's': if(!job_cond->state_list) job_cond->state_list = list_create(slurm_destroy_char); _addto_state_char_list(job_cond->state_list, optarg); break; case 'S': job_cond->usage_start = parse_time(optarg, 1); if (errno == ESLURM_INVALID_TIME_VALUE) exit(1); break; case 'T': job_cond->without_usage_truncation = 0; break; case 'U': params.opt_help = 3; break; case 'u': if(!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if(!job_cond->userid_list) job_cond->userid_list = list_create(slurm_destroy_char); _addto_id_char_list(job_cond->userid_list, optarg, 0); break; case 'v': /* Handle -vvv thusly... */ verbosity++; break; case 'W': if(!job_cond->wckey_list) job_cond->wckey_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->wckey_list, optarg); break; case 'V': print_slurm_version(); exit(0); case 'x': if(!job_cond->associd_list) job_cond->associd_list = list_create(slurm_destroy_char); slurm_addto_char_list(job_cond->associd_list, optarg); break; case 't': case 'X': params.opt_allocs = 1; break; case ':': case '?': /* getopt() has explained it */ exit(1); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } /* Now set params.opt_dup, unless they've already done so */ if (params.opt_dup < 0) /* not already set explicitly */ params.opt_dup = 0; job_cond->duplicates = params.opt_dup; job_cond->without_steps = params.opt_allocs; if(!job_cond->usage_start && !job_cond->step_list) { struct tm start_tm; job_cond->usage_start = time(NULL); if (!localtime_r(&job_cond->usage_start, &start_tm)) { error("Couldn't get localtime from %ld", (long)job_cond->usage_start); return; } start_tm.tm_sec = 0; start_tm.tm_min = 0; start_tm.tm_hour = 0; start_tm.tm_isdst = -1; job_cond->usage_start = mktime(&start_tm); } if(verbosity > 0) { char *start_char =NULL, *end_char = NULL; start_char = xstrdup(ctime(&job_cond->usage_start)); /* remove the new line */ start_char[strlen(start_char)-1] = '\0'; if(job_cond->usage_end) { end_char = xstrdup(ctime(&job_cond->usage_end)); /* remove the new line */ end_char[strlen(end_char)-1] = '\0'; } else end_char = xstrdup("Now"); info("Jobs eligible from %s - %s", start_char, end_char); xfree(start_char); xfree(end_char); } debug("Options selected:\n" "\topt_completion=%d\n" "\topt_dup=%d\n" "\topt_field_list=%s\n" "\topt_help=%d\n" "\topt_allocs=%d", params.opt_completion, params.opt_dup, params.opt_field_list, params.opt_help, params.opt_allocs); if(params.opt_completion) { g_slurm_jobcomp_init(params.opt_filein); acct_type = slurm_get_jobcomp_type(); if ((strcmp(acct_type, "jobcomp/none") == 0) && (stat(params.opt_filein, &stat_buf) != 0)) { fprintf(stderr, "SLURM job completion is disabled\n"); exit(1); } xfree(acct_type); } else { slurm_acct_storage_init(params.opt_filein); acct_type = slurm_get_accounting_storage_type(); if ((strcmp(acct_type, "accounting_storage/none") == 0) && (stat(params.opt_filein, &stat_buf) != 0)) { fprintf(stderr, "SLURM accounting storage is disabled\n"); exit(1); } xfree(acct_type); acct_db_conn = slurmdb_connection_get(); if(errno != SLURM_SUCCESS) { error("Problem talking to the database: %m"); exit(1); } } /* specific clusters requested? */ if(all_clusters) { if(job_cond->cluster_list && list_count(job_cond->cluster_list)) { list_destroy(job_cond->cluster_list); job_cond->cluster_list = NULL; } debug2("Clusters requested:\tall"); } else if (job_cond->cluster_list && list_count(job_cond->cluster_list)) { debug2( "Clusters requested:"); itr = list_iterator_create(job_cond->cluster_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } else if(!job_cond->cluster_list || !list_count(job_cond->cluster_list)) { if(!job_cond->cluster_list) job_cond->cluster_list = list_create(slurm_destroy_char); if((start = slurm_get_cluster_name())) { list_append(job_cond->cluster_list, start); debug2("Clusters requested:\t%s", start); } } /* if any jobs or nodes are specified set to look for all users if none are set */ if(!job_cond->userid_list || !list_count(job_cond->userid_list)) if((job_cond->step_list && list_count(job_cond->step_list)) || job_cond->used_nodes) all_users=1; /* set all_users for user root if not requesting any */ if(!job_cond->userid_list && !params.opt_uid) all_users = 1; if(all_users) { if(job_cond->userid_list && list_count(job_cond->userid_list)) { list_destroy(job_cond->userid_list); job_cond->userid_list = NULL; } debug2("Userids requested:\tall"); } else if (job_cond->userid_list && list_count(job_cond->userid_list)) { debug2("Userids requested:"); itr = list_iterator_create(job_cond->userid_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } else if(!job_cond->userid_list || !list_count(job_cond->userid_list)) { if(!job_cond->userid_list) job_cond->userid_list = list_create(slurm_destroy_char); start = xstrdup_printf("%u", params.opt_uid); list_append(job_cond->userid_list, start); debug2("Userid requested\t: %s", start); } if (job_cond->groupid_list && list_count(job_cond->groupid_list)) { debug2("Groupids requested:"); itr = list_iterator_create(job_cond->groupid_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } /* specific partitions requested? */ if (job_cond->partition_list && list_count(job_cond->partition_list)) { debug2("Partitions requested:"); itr = list_iterator_create(job_cond->partition_list); while((start = list_next(itr))) debug2("\t: %s", start); list_iterator_destroy(itr); } /* specific qos' requested? */ if (job_cond->qos_list && list_count(job_cond->qos_list)) { start = get_qos_complete_str(g_qos_list, job_cond->qos_list); debug2("QOS requested\t: %s\n", start); xfree(start); } /* specific jobs requested? */ if (job_cond->step_list && list_count(job_cond->step_list)) { debug2("Jobs requested:"); itr = list_iterator_create(job_cond->step_list); while((selected_step = list_next(itr))) { if(selected_step->stepid != NO_VAL) debug2("\t: %d.%d", selected_step->jobid, selected_step->stepid); else debug2("\t: %d", selected_step->jobid); } list_iterator_destroy(itr); } /* specific states (completion state) requested? */ if (job_cond->state_list && list_count(job_cond->state_list)) { debug2("States requested:"); itr = list_iterator_create(job_cond->state_list); while((start = list_next(itr))) { debug2("\t: %s", job_state_string(atoi(start))); } list_iterator_destroy(itr); } if (job_cond->wckey_list && list_count(job_cond->wckey_list)) { debug2("Wckeys requested:"); itr = list_iterator_create(job_cond->wckey_list); while((start = list_next(itr))) debug2("\t: %s\n", start); list_iterator_destroy(itr); } if (job_cond->timelimit_min) { char time_str[128], tmp1[32], tmp2[32]; mins2time_str(job_cond->timelimit_min, tmp1, sizeof(tmp1)); sprintf(time_str, "%s", tmp1); if(job_cond->timelimit_max) { int len = strlen(tmp1); mins2time_str(job_cond->timelimit_max, tmp2, sizeof(tmp2)); sprintf(time_str+len, " - %s", tmp2); } debug2("Timelimit requested\t: %s", time_str); } /* specific jobnames requested? */ if (job_cond->jobname_list && list_count(job_cond->jobname_list)) { debug2("Jobnames requested:"); itr = list_iterator_create(job_cond->jobname_list); while((start = list_next(itr))) { debug2("\t: %s", start); } list_iterator_destroy(itr); } /* select the output fields */ if(brief_output) { if(params.opt_completion) dot = BRIEF_COMP_FIELDS; else dot = BRIEF_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } if(long_output) { if(params.opt_completion) dot = LONG_COMP_FIELDS; else dot = LONG_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } if (params.opt_field_list==NULL) { if(params.opt_completion) dot = DEFAULT_COMP_FIELDS; else dot = DEFAULT_FIELDS; xstrfmtcat(params.opt_field_list, "%s,", dot); } start = params.opt_field_list; while ((end = strstr(start, ","))) { char *tmp_char = NULL; int command_len = 0; int newlen = 0; *end = 0; while (isspace(*start)) start++; /* discard whitespace */ if(!(int)*start) continue; if((tmp_char = strstr(start, "\%"))) { newlen = atoi(tmp_char+1); tmp_char[0] = '\0'; } command_len = strlen(start); for (i = 0; fields[i].name; i++) { if (!strncasecmp(fields[i].name, start, command_len)) goto foundfield; } error("Invalid field requested: \"%s\"", start); exit(1); foundfield: if(newlen) fields[i].len = newlen; list_append(print_fields_list, &fields[i]); start = end + 1; }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; shares_response_msg_t *resp_msg = NULL; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"long", 0, 0, 'l'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'h'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "aA:hlM:npPqu:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if(!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'h': print_fields_have_header = 0; break; exit(exit_code); break; case 'l': long_flag = 1; break; case 'M': if(clusters) list_destroy(clusters); if(!(clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see available clusters.", optarg); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'n': print_fields_have_header = 0; break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if(!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if(!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if(all_users) { if(req_msg.user_list && list_count(req_msg.user_list)) { list_destroy(req_msg.user_list); req_msg.user_list = NULL; } if(verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if(!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd = getpwuid(getuid()); if(!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if(verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } if(req_msg.acct_list && list_count(req_msg.acct_list)) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else { if(req_msg.acct_list && list_count(req_msg.acct_list)) { list_destroy(req_msg.acct_list); req_msg.acct_list = NULL; } if(verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } error_code = _get_info(&req_msg, &resp_msg); if(req_msg.acct_list) list_destroy(req_msg.acct_list); if(req_msg.user_list) list_destroy(req_msg.user_list); if (error_code) { slurm_perror("Couldn't get shares from controller"); exit(error_code); } /* do stuff with it */ process(resp_msg); slurm_free_shares_response_msg(resp_msg); exit(exit_code); }