/* add `mode' to `old' - return newly allocated mode. `channel' specifies if we're parsing channel mode and we should try to join mode arguments too. */ char *modes_join(const char *old, const char *mode, int channel) { GString *newmode; char *dup, *modestr, *curmode, type; g_return_val_if_fail(mode != NULL, NULL); type = '+'; newmode = g_string_new(old); dup = modestr = g_strdup(mode); curmode = cmd_get_param(&modestr); while (*curmode != '\0' && *curmode != ' ') { if (*curmode == '+' || *curmode == '-') { type = *curmode; curmode++; continue; } if (!channel || !HAS_MODE_ARG(type, *curmode)) mode_set(newmode, type, *curmode); else { mode_set_arg(newmode, type, *curmode, cmd_get_param(&modestr)); } curmode++; } g_free(dup); modestr = newmode->str; g_string_free(newmode, FALSE); return modestr; }
// This function will set all the pwms that will be used on the Beaglebone void set_pwms(){ mode_set("mcasp0_fsx", "1"); // Pin9 29 , 0B mode_set("mcasp0_aclkx","1"); // Pin9 31, 0A mode_set("gpmc_a2", "6"); // Pin9 14, 1A mode_set("gpmc_a3","6"); // Pin9 16, 1B mode_set("gpmc_ad8","4"); // Pin8 19, 2A mode_set("gpmc_ad9","4"); // Pin8 13, 2B }
static void cmd_index_dec (void) { if (cmd_mode == MODE_CMD) { if (cmd_index > 0) cmd_index--; } else if (cmd_mode == MODE_VALUE) { if (cmd_value > 0) cmd_value--; } mode_set (); }
static void cmd_index_inc (void) { if (cmd_mode == MODE_CMD) { if (cmd_index < NUM_CMDS - 1) cmd_index++; } else if (cmd_mode == MODE_VALUE) { if (cmd_value < 255) cmd_value++; } mode_set (); }
void mode_change(uint8_t mode_num) { uint16_t mode_setting; if(mode_num == 1){ mode_setting = CUSTOM_MODE; } else if(mode_num == 2){ mode_setting = HIGHWAY_MODE; } else if(mode_num == 3){ mode_setting = MOUNTAIN_MODE; } else if(mode_num == 4){ mode_setting = CITY_MODE; } mode_set(mode_setting); }
/* set [inode] attributes based on [info], uid/gid based on [sf_g] */ void sf_init_inode(struct sf_glob_info *sf_g, struct inode *inode, PSHFLFSOBJINFO info) { PSHFLFSOBJATTR attr; int mode; TRACE(); attr = &info->Attr; #define mode_set(r) attr->fMode & (RTFS_UNIX_##r) ? (S_##r) : 0; mode = mode_set(ISUID); mode |= mode_set(ISGID); mode |= mode_set(IRUSR); mode |= mode_set(IWUSR); mode |= mode_set(IXUSR); mode |= mode_set(IRGRP); mode |= mode_set(IWGRP); mode |= mode_set(IXGRP); mode |= mode_set(IROTH); mode |= mode_set(IWOTH); mode |= mode_set(IXOTH); #undef mode_set #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) inode->i_mapping->a_ops = &sf_reg_aops; # if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 19, 0) /* XXX Was this ever necessary? */ inode->i_mapping->backing_dev_info = &sf_g->bdi; # endif #endif if (RTFS_IS_DIRECTORY(attr->fMode)) { inode->i_mode = sf_g->dmode != ~0 ? (sf_g->dmode & 0777) : mode; inode->i_mode &= ~sf_g->dmask; inode->i_mode |= S_IFDIR; inode->i_op = &sf_dir_iops; inode->i_fop = &sf_dir_fops; /* XXX: this probably should be set to the number of entries in the directory plus two (. ..) */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) set_nlink(inode, 1); #else inode->i_nlink = 1; #endif } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) else if (RTFS_IS_SYMLINK(attr->fMode)) { inode->i_mode = sf_g->fmode != ~0 ? (sf_g->fmode & 0777): mode; inode->i_mode &= ~sf_g->fmask; inode->i_mode |= S_IFLNK; inode->i_op = &sf_lnk_iops; # if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) set_nlink(inode, 1); # else inode->i_nlink = 1; # endif } #endif else { inode->i_mode = sf_g->fmode != ~0 ? (sf_g->fmode & 0777): mode; inode->i_mode &= ~sf_g->fmask; inode->i_mode |= S_IFREG; inode->i_op = &sf_reg_iops; inode->i_fop = &sf_reg_fops; #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0) set_nlink(inode, 1); #else inode->i_nlink = 1; #endif } #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) inode->i_uid = make_kuid(current_user_ns(), sf_g->uid); inode->i_gid = make_kgid(current_user_ns(), sf_g->gid); #else inode->i_uid = sf_g->uid; inode->i_gid = sf_g->gid; #endif inode->i_size = info->cbObject; #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) && !defined(KERNEL_FC6) inode->i_blksize = 4096; #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 11) inode->i_blkbits = 12; #endif /* i_blocks always in units of 512 bytes! */ inode->i_blocks = (info->cbAllocated + 511) / 512; sf_ftime_from_timespec(&inode->i_atime, &info->AccessTime); sf_ftime_from_timespec(&inode->i_ctime, &info->ChangeTime); sf_ftime_from_timespec(&inode->i_mtime, &info->ModificationTime); }
int sf_setattr(struct dentry *dentry, struct iattr *iattr) { struct sf_glob_info *sf_g; struct sf_inode_info *sf_i; SHFLCREATEPARMS params; SHFLFSOBJINFO info; uint32_t cbBuffer; int rc, err; TRACE(); sf_g = GET_GLOB_INFO(dentry->d_inode->i_sb); sf_i = GET_INODE_INFO(dentry->d_inode); err = 0; RT_ZERO(params); params.Handle = SHFL_HANDLE_NIL; params.CreateFlags = SHFL_CF_ACT_OPEN_IF_EXISTS | SHFL_CF_ACT_FAIL_IF_NEW | SHFL_CF_ACCESS_ATTR_WRITE; /* this is at least required for Posix hosts */ if (iattr->ia_valid & ATTR_SIZE) params.CreateFlags |= SHFL_CF_ACCESS_WRITE; rc = VbglR0SfCreate(&client_handle, &sf_g->map, sf_i->path, ¶ms); if (RT_FAILURE(rc)) { LogFunc(("VbglR0SfCreate(%s) failed rc=%Rrc\n", sf_i->path->String.utf8, rc)); err = -RTErrConvertToErrno(rc); goto fail2; } if (params.Result != SHFL_FILE_EXISTS) { LogFunc(("file %s does not exist\n", sf_i->path->String.utf8)); err = -ENOENT; goto fail1; } /* Setting the file size and setting the other attributes has to be * handled separately, see implementation of vbsfSetFSInfo() in * vbsf.cpp */ if (iattr->ia_valid & (ATTR_MODE | ATTR_ATIME | ATTR_MTIME)) { #define mode_set(r) ((iattr->ia_mode & (S_##r)) ? RTFS_UNIX_##r : 0) RT_ZERO(info); if (iattr->ia_valid & ATTR_MODE) { info.Attr.fMode = mode_set(ISUID); info.Attr.fMode |= mode_set(ISGID); info.Attr.fMode |= mode_set(IRUSR); info.Attr.fMode |= mode_set(IWUSR); info.Attr.fMode |= mode_set(IXUSR); info.Attr.fMode |= mode_set(IRGRP); info.Attr.fMode |= mode_set(IWGRP); info.Attr.fMode |= mode_set(IXGRP); info.Attr.fMode |= mode_set(IROTH); info.Attr.fMode |= mode_set(IWOTH); info.Attr.fMode |= mode_set(IXOTH); if (iattr->ia_mode & S_IFDIR) info.Attr.fMode |= RTFS_TYPE_DIRECTORY; else info.Attr.fMode |= RTFS_TYPE_FILE; } if (iattr->ia_valid & ATTR_ATIME) sf_timespec_from_ftime(&info.AccessTime, &iattr->ia_atime); if (iattr->ia_valid & ATTR_MTIME) sf_timespec_from_ftime(&info.ModificationTime, &iattr->ia_mtime); /* ignore ctime (inode change time) as it can't be set from userland anyway */ cbBuffer = sizeof(info); rc = VbglR0SfFsInfo(&client_handle, &sf_g->map, params.Handle, SHFL_INFO_SET | SHFL_INFO_FILE, &cbBuffer, (PSHFLDIRINFO)&info); if (RT_FAILURE(rc)) { LogFunc(("VbglR0SfFsInfo(%s, FILE) failed rc=%Rrc\n", sf_i->path->String.utf8, rc)); err = -RTErrConvertToErrno(rc); goto fail1; } } if (iattr->ia_valid & ATTR_SIZE) { RT_ZERO(info); info.cbObject = iattr->ia_size; cbBuffer = sizeof(info); rc = VbglR0SfFsInfo(&client_handle, &sf_g->map, params.Handle, SHFL_INFO_SET | SHFL_INFO_SIZE, &cbBuffer, (PSHFLDIRINFO)&info); if (RT_FAILURE(rc)) { LogFunc(("VbglR0SfFsInfo(%s, SIZE) failed rc=%Rrc\n", sf_i->path->String.utf8, rc)); err = -RTErrConvertToErrno(rc); goto fail1; } } rc = VbglR0SfClose(&client_handle, &sf_g->map, params.Handle); if (RT_FAILURE(rc)) LogFunc(("VbglR0SfClose(%s) failed rc=%Rrc\n", sf_i->path->String.utf8, rc)); return sf_inode_revalidate(dentry); fail1: rc = VbglR0SfClose(&client_handle, &sf_g->map, params.Handle); if (RT_FAILURE(rc)) LogFunc(("VbglR0SfClose(%s) failed rc=%Rrc\n", sf_i->path->String.utf8, rc)); fail2: return err; }
/* Parse channel mode string */ void parse_channel_modes(IRC_CHANNEL_REC *channel, const char *setby, const char *mode) { GString *newmode; char *dup, *modestr, *arg, *curmode, type; g_return_if_fail(IS_IRC_CHANNEL(channel)); g_return_if_fail(mode != NULL); type = '+'; newmode = g_string_new(channel->mode); dup = modestr = g_strdup(mode); curmode = cmd_get_param(&modestr); while (*curmode != '\0') { if (HAS_MODE_ARG(type, *curmode)) { /* get the argument for the mode. since we're expecting argument, ignore the mode if there's no argument (shouldn't happen). */ arg = cmd_get_param(&modestr); if (*arg == '\0') { curmode++; continue; } } else { arg = NULL; } switch (*curmode) { case '+': case '-': type = *curmode; break; case 'b': if (type == '+') banlist_add(channel, arg, setby, time(NULL)); else banlist_remove(channel, arg); break; case 'e': if (type == '+') banlist_exception_add(channel, arg, setby, time(NULL)); else banlist_exception_remove(channel, arg); break; case 'I': if (type == '+') invitelist_add(channel, arg); else invitelist_remove(channel, arg); break; case 'o': if (g_strcasecmp(channel->server->nick, arg) == 0) channel->chanop = type == '+'; nick_mode_change(channel, arg, '@', type); break; case 'h': nick_mode_change(channel, arg, '%', type); break; case 'v': nick_mode_change(channel, arg, '+', type); break; case 'l': mode_set_arg(newmode, type, 'l', arg); channel->limit = type == '-' ? 0 : atoi(arg); break; case 'k': mode_set_arg(newmode, type, 'k', arg); g_free_and_null(channel->key); if (type == '+') channel->key = g_strdup(arg); break; default: mode_set(newmode, type, *curmode); break; } curmode++; } g_free(dup); if (strchr(channel->mode, 'k') == NULL && channel->key != NULL) { /* join was used with key but there's no key set in channel modes.. */ g_free(channel->key); channel->key = NULL; } if (strcmp(newmode->str, channel->mode) != 0) { g_free(channel->mode); channel->mode = g_strdup(newmode->str); signal_emit("channel mode changed", 1, channel); } g_string_free(newmode, TRUE); }
/* Mode that takes no parameter */ void modes_type_d(IRC_CHANNEL_REC *channel, const char *setby, char type, char mode, char *arg, GString *newmode) { mode_set(channel->server, newmode, type, mode, FALSE); }
void action_do(Vis *vis, Action *a) { Win *win = vis->win; Text *txt = win->file->text; View *view = win->view; if (a->op == &vis_operators[VIS_OP_FILTER] && !vis->mode->visual) vis_mode_switch(vis, VIS_MODE_VISUAL_LINE); int count = MAX(a->count, 1); bool repeatable = a->op && !vis->macro_operator; bool multiple_cursors = view_cursors_multiple(view); bool linewise = !(a->type & CHARWISE) && ( a->type & LINEWISE || (a->movement && a->movement->type & LINEWISE) || vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE]); for (Cursor *cursor = view_cursors(view), *next; cursor; cursor = next) { next = view_cursors_next(cursor); size_t pos = view_cursors_pos(cursor); Register *reg = multiple_cursors ? view_cursors_register(cursor) : a->reg; if (!reg) reg = &vis->registers[win->file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT]; OperatorContext c = { .count = count, .pos = pos, .newpos = EPOS, .range = text_range_empty(), .reg = reg, .linewise = linewise, .arg = &a->arg, }; if (a->movement) { size_t start = pos; for (int i = 0; i < count; i++) { size_t pos_prev = pos; if (a->movement->txt) pos = a->movement->txt(txt, pos); else if (a->movement->cur) pos = a->movement->cur(cursor); else if (a->movement->file) pos = a->movement->file(vis, vis->win->file, pos); else if (a->movement->vis) pos = a->movement->vis(vis, txt, pos); else if (a->movement->view) pos = a->movement->view(vis, view); else if (a->movement->win) pos = a->movement->win(vis, win, pos); else if (a->movement->user) pos = a->movement->user(vis, win, a->movement->data, pos); if (pos == EPOS || a->movement->type & IDEMPOTENT || pos == pos_prev) break; } if (pos == EPOS) { c.range.start = start; c.range.end = start; pos = start; } else { c.range = text_range_new(start, pos); c.newpos = pos; } if (!a->op) { if (a->movement->type & CHARWISE) view_cursors_scroll_to(cursor, pos); else view_cursors_to(cursor, pos); if (vis->mode->visual) c.range = view_cursors_selection_get(cursor); if (a->movement->type & JUMP) window_jumplist_add(win, pos); else window_jumplist_invalidate(win); } else if (a->movement->type & INCLUSIVE || (linewise && a->movement->type & LINEWISE_INCLUSIVE)) { c.range.end = text_char_next(txt, c.range.end); } } else if (a->textobj) { if (vis->mode->visual) c.range = view_cursors_selection_get(cursor); else c.range.start = c.range.end = pos; for (int i = 0; i < count; i++) { Filerange r = text_range_empty(); if (a->textobj->txt) r = a->textobj->txt(txt, pos); else if (a->textobj->vis) r = a->textobj->vis(vis, txt, pos); else if (a->textobj->user) r = a->textobj->user(vis, win, a->textobj->data, pos); if (!text_range_valid(&r)) break; if (a->textobj->type & OUTER) { r.start--; r.end++; } if (a->textobj->type & SPLIT) c.range = r; else c.range = text_range_union(&c.range, &r); if (i < count - 1) pos = c.range.end + 1; } } else if (vis->mode->visual) { c.range = view_cursors_selection_get(cursor); if (!text_range_valid(&c.range)) c.range.start = c.range.end = pos; } if (linewise && vis->mode != &vis_modes[VIS_MODE_VISUAL]) c.range = text_range_linewise(txt, &c.range); if (vis->mode->visual) { view_cursors_selection_set(cursor, &c.range); if (vis->mode == &vis_modes[VIS_MODE_VISUAL] || a->textobj) view_cursors_selection_sync(cursor); } if (a->op) { size_t pos = a->op->func(vis, txt, &c); if (pos == EPOS) { view_cursors_dispose(cursor); } else if (pos <= text_size(txt)) { /* moving the cursor will affect the selection. * because we want to be able to later restore * the old selection we update it again before * leaving visual mode. */ Filerange sel = view_cursors_selection_get(cursor); view_cursors_to(cursor, pos); if (vis->mode->visual) { if (sel.start == EPOS && sel.end == EPOS) sel = c.range; else if (sel.start == EPOS) sel = text_range_new(c.range.start, sel.end); else if (sel.end == EPOS) sel = text_range_new(c.range.start, sel.start); if (vis->mode == &vis_modes[VIS_MODE_VISUAL_LINE]) sel = text_range_linewise(txt, &sel); view_cursors_selection_set(cursor, &sel); } } } } if (a->op) { /* we do not support visual repeat, still do something resonable */ if (vis->mode->visual && !a->movement && !a->textobj) a->movement = &vis_motions[VIS_MOVE_NOP]; /* operator implementations must not change the mode, * they might get called multiple times (once for every cursor) */ if (a->op == &vis_operators[VIS_OP_INSERT] || a->op == &vis_operators[VIS_OP_CHANGE]) { vis_mode_switch(vis, VIS_MODE_INSERT); } else if (a->op == &vis_operators[VIS_OP_REPLACE]) { vis_mode_switch(vis, VIS_MODE_REPLACE); } else if (a->op == &vis_operators[VIS_OP_FILTER]) { if (a->arg.s) vis_cmd(vis, a->arg.s); else vis_prompt_show(vis, ":|"); } else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR_PENDING]) { mode_set(vis, vis->mode_prev); } else if (vis->mode->visual) { vis_mode_switch(vis, VIS_MODE_NORMAL); } text_snapshot(txt); vis_draw(vis); } if (a != &vis->action_prev) { if (repeatable) { if (!a->macro) a->macro = vis->macro_operator; vis->action_prev = *a; } action_reset(a); } } void action_reset(Action *a) { memset(a, 0, sizeof(*a)); a->count = VIS_COUNT_UNKNOWN; }
// Handle the connection to the console service. static void handle_connection(ipc_structure_type *ipc_structure) { bool done = FALSE; uint32_t *data; unsigned int data_size = 8192; memory_allocate((void **) &data, data_size); // Accept the connection. message_parameter_type message_parameter; message_parameter.data = data; message_parameter.block = TRUE; message_parameter.protocol = IPC_PROTOCOL_VIDEO; while (!done) { message_parameter.message_class = IPC_CLASS_NONE; message_parameter.length = data_size; if (ipc_receive(ipc_structure->input_mailbox_id, &message_parameter, &data_size) != STORM_RETURN_SUCCESS) { continue; } switch (message_parameter.message_class) { // Place the text mode cursor. case IPC_VIDEO_CURSOR_PLACE: { video_cursor_type *cursor = (video_cursor_type *) message_parameter.data; vga_cursor_place(cursor->x, cursor->y); break; } // Set the font. case IPC_VIDEO_FONT_SET: { // FIXME: Do security checks here. vga_font_set((uint8_t *) data, message_parameter.length); break; } // Set a video mode. case IPC_VIDEO_MODE_SET: { video_mode_type *video_mode = (video_mode_type *) message_parameter.data; return_type *return_value = (return_type *) message_parameter.data; if (video_mode != NULL) { message_parameter.length = sizeof (return_type); if (mode_set(video_mode->width, video_mode->height, video_mode->depth, video_mode->mode_type)) { if (video_mode->mode_type == VIDEO_MODE_TYPE_TEXT) { for (int index = 0; index < 16; index++) { vga_palette_set_entry(index, &text_palette[index]); } vga_font_set(font_8x8, sizeof(font_8x8)); } else if (video_mode->mode_type == VIDEO_MODE_TYPE_GRAPHIC && video_mode->depth == 8) { for (int index = 0; index < 256; index++) { vga_palette_entry_type entry; entry.red = ((index & 0xE0) >> 5) << 3; entry.green = ((index & 0x1C) >> 2) << 3; entry.blue = ((index & 0x03) >> 0) << 4; vga_palette_set_entry(index, &entry); } } *return_value = IPC_VIDEO_RETURN_SUCCESS; } else { *return_value = IPC_VIDEO_RETURN_MODE_UNAVAILABLE; } } else { *return_value = IPC_VIDEO_RETURN_MODE_UNAVAILABLE; } ipc_send(ipc_structure->output_mailbox_id, &message_parameter); break; }
int engine(struct engine_s *e) { int ret=0; int i; #ifdef DEBUG do { CPUSET_HEXSTRING(tmpaff); printf("Dumping mode: 0x%x\n", e->mode); printf("Dumping affinity: 0x%s\n", cpuset_to_str(&(e->aff_mask), tmpaff)); printf("We have %d args to do\n", e->n); for(i=0;i < e->n; i++) { printf("Dump arg %d: %s\n", i, e->args[i]); } } while(0); #endif /* handle normal query/set operation: set/query all given PIDs */ for(i=0; i < e->n; i++) { int pid, tmpret=0; cpu_set_t affi; CPU_ZERO(&affi); CPU_SET(0, &affi); /* if in MODE_EXEC skip check for PIDs */ if(mode_set(e->mode, MODE_EXEC)) { pid=getpid(); goto exec_mode_special; } if(! (isdigit( *(e->args[i])) ) ) { decode_error("Ignoring arg %s: is not a PID", e->args[i]); continue; } pid=atoi(e->args[i]); exec_mode_special: if(mode_set(e->mode, MODE_SETPOLICY)) { struct sched_param_ex p; p.sched_priority= e->prio; p.sched_runtime=us_to_tspec(e->rtime); p.sched_deadline=us_to_tspec(e->dline); p.sched_period=us_to_tspec(e->priod); p.sched_flags=e->flags; /* accumulate possible errors the return value of main will indicate how much set-calls went wrong set_process returns -1 upon failure */ tmpret=set_process(pid,e->policy,&p); ret += tmpret; /* don't proceed as something went wrong already */ if(tmpret) { continue; } } if(mode_set(e->mode, MODE_NICE)) { tmpret=set_niceness(pid, e->nice); ret += tmpret; if(tmpret) { continue; } } if(mode_set(e->mode, MODE_AFFINITY)) { tmpret=set_affinity(pid, &(e->aff_mask)); ret += tmpret; if(tmpret) { continue; } } /* and print process info when set, too */ if(mode_set(e->mode, MODE_PRINT)) { print_process(pid); } /* EXECUTE: at the end */ if(mode_set(e->mode, MODE_EXEC)) { char **new_argv=e->args; ret=execvp(*new_argv, new_argv); /* only reached on error */ decode_error("schedtool: Could not exec %s", *new_argv); return(ret); } } /* indicate how many errors we got; as ret is accumulated negative, convert to positive */ return(abs(ret)); }
int main(int ac, char **dc) { /* policy: -1, to indicate it was not set; nice: 10, as nice/renice have as default; prio: 0 per default mode: MODE_NOTHING, no options set */ int policy=-1, nice=10, prio=0, mode=MODE_NOTHING; long rtime=0, dline=0, priod=0; unsigned flags = 0; /* aff_mask: zero it out */ cpu_set_t aff_mask; CPU_ZERO(&aff_mask); /* for getopt() */ int c; if (ac < 2) { usage(); return(0); } while((c=getopt(ac, dc, "+NFRBIDE012345M:a:p:t:f:n:ervh")) != -1) { switch(c) { case '0': case 'N': policy=SCHED_NORMAL; mode |= MODE_SETPOLICY; break; case '1': case 'F': policy=SCHED_FIFO; mode |= MODE_SETPOLICY; break; case '2': case 'R': policy=SCHED_RR; mode |= MODE_SETPOLICY; break; case '3': case 'B': policy=SCHED_BATCH; mode |= MODE_SETPOLICY; break; case '4': case 'I': policy=SCHED_ISO; mode |= MODE_SETPOLICY; break; case '5': case 'D': policy=SCHED_IDLEPRIO; mode |= MODE_SETPOLICY; break; case '6': case 'E': policy=SCHED_DEADLINE; mode |= MODE_SETPOLICY; break; case 'M': /* manual setting */ policy=atoi(optarg); mode |= MODE_SETPOLICY; break; case 'a': mode |= MODE_AFFINITY; parse_affinity(&aff_mask, optarg); break; case 'n': mode |= MODE_NICE; nice=atoi(optarg); break; case 'e': mode |= MODE_EXEC; break; case 'p': prio=atoi(optarg); break; case 't': parse_time(&rtime, &dline, &priod, optarg); break; case 'f': parse_flags(&flags, optarg); break; case 'r': probe_sched_features(); break; case 'v': /* the user wants feedback for each process */ mode |= MODE_PRINT; break; case 'V': case 'h': usage(); return(0); default: //printf("ERROR: unknown switch\n"); usage(); return(1); } } /* DAMN F*****G parameter checking ARGH! */ /* for _BATCH and _NORMAL, prio is ignored and must be 0*/ if((policy==SCHED_NORMAL || policy==SCHED_BATCH) && prio) { decode_error("%s call may fail as static PRIO must be 0 or omitted", TAB[policy] ); /* _FIFO and _RR MUST have prio set */ } else if((policy==SCHED_FIFO || policy==SCHED_RR || policy==SCHED_ISO)) { #define CHECK_RANGE_PRIO(p, p_low, p_high) (p <= (p_high) && p >= (p_low)) /* FIFO and RR - check min/max priority */ int prio_min, prio_max; get_prio_min_max(policy, &prio_min, &prio_max); //int prio_max=sched_get_priority_max(policy); //int prio_min=sched_get_priority_min(policy); if(! CHECK_RANGE_PRIO(prio, prio_min, prio_max)) { // this could be problematic on very special custom kernels if(prio == 0) { decode_error("missing priority; specify static priority via -p"); } else { decode_error("PRIO %d is out of range %d-%d for %s", prio, prio_min, prio_max, TAB[policy] ); } /* treat as all calls have failed */ return(ac-optind); } #undef CHECK_RANGE_PRIO } else if (policy == SCHED_DEADLINE) { if (!dline || !rtime) { decode_error("timing parameters are required for policy %s", TAB[policy]); return(ac-optind); } } /* no mode -> do querying */ if(! mode) { mode |= MODE_PRINT; } if( mode_set(mode, MODE_EXEC) && ! ( mode_set(mode, MODE_SETPOLICY) || mode_set(mode, MODE_AFFINITY) || mode_set(mode, MODE_NICE) ) ) { /* we have nothing to do */ decode_error("Option -e needs scheduling-parameters, not given - exiting"); return(-1); } if(! CHECK_RANGE_NICE(nice)) { decode_error("NICE %d is out of range -20 to 20", nice); return(-1); } #undef CHECK_RANGE_NICE /* and: ignition */ { struct engine_s stuff; /* now fill struct */ stuff.mode=mode; stuff.policy=policy; stuff.prio=prio; stuff.nice=nice; stuff.rtime=rtime; stuff.dline=dline; stuff.priod=priod; stuff.flags=flags; stuff.aff_mask=aff_mask; /* we have this much real args/PIDs to process */ stuff.n=ac-optind; /* this is the first real arg */ stuff.args=dc+optind; /* now go on and do what we were told */ return(engine(&stuff)); } }
static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) { /* invalid operator */ vis_cancel(vis); mode_set(vis, vis->mode_prev); }
void vis_mode_switch(Vis *vis, enum VisMode mode) { mode_set(vis, &vis_modes[mode]); }