static enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_run_shell_data *cdata; struct client *c = cmd_find_client(item, NULL, 1); struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct window_pane *wp = item->target.wp; cdata = xcalloc(1, sizeof *cdata); cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp); if (args_has(args, 't') && wp != NULL) cdata->wp_id = wp->id; else cdata->wp_id = -1; if (!args_has(args, 'b')) cdata->item = item; job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL, cmd_run_shell_callback, cmd_run_shell_free, cdata, 0); if (args_has(args, 'b')) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); }
enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct cmd_run_shell_data *cdata; const char *shellcmd = args->argv[0]; struct window_pane *wp; if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) return (CMD_RETURN_ERROR); cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[0]); cdata->wp_id = wp->id; memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); if (ctx->cmdclient != NULL) ctx->cmdclient->references++; if (ctx->curclient != NULL) ctx->curclient->references++; job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata); return (CMD_RETURN_YIELD); /* don't let client exit */ }
void job_run_command(const char *command, char *envp[]) { job_t *job = job_from_command_line(command, envp); if (job) { job_run(job); /* printf("running on %d\n", job->bg); */ } }
enum cmd_retval cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_run_shell_data *cdata; char *shellcmd; struct client *c; struct session *s = NULL; struct winlink *wl = NULL; struct window_pane *wp = NULL; struct format_tree *ft; if (args_has(args, 't')) wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); else { c = cmd_find_client(cmdq, NULL, 1); if (c != NULL && c->session != NULL) { s = c->session; wl = s->curw; wp = wl->window->active; } } ft = format_create(); if (s != NULL) format_session(ft, s); if (s != NULL && wl != NULL) format_winlink(ft, s, wl); if (wp != NULL) format_window_pane(ft, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); cdata = xmalloc(sizeof *cdata); cdata->cmd = shellcmd; cdata->bflag = args_has(args, 'b'); cdata->wp_id = wp != NULL ? (int) wp->id : -1; cdata->cmdq = cmdq; cmdq->references++; job_run(shellcmd, s, cmd_run_shell_callback, cmd_run_shell_free, cdata); if (cdata->bflag) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); }
static void dispatch(const struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; if (devc->job_again) { job_run_again(sdi); return; } if (!job_is_running(devc)) job_next(devc); else if (job_has_timeout(devc)) job_done(devc); if (!job_is_running(devc) && !job_in_interval(devc)) job_run(sdi); }
int cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct cmd_if_shell_data *cdata; const char *shellcmd = args->argv[0]; cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(args->argv[1]); memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); if (ctx->cmdclient != NULL) ctx->cmdclient->references++; if (ctx->curclient != NULL) ctx->curclient->references++; job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); return (1); /* don't let client exit */ }
enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct cmd_if_shell_data *cdata; const char *shellcmd = args->argv[0]; cdata = xmalloc(sizeof *cdata); cdata->cmd_if = xstrdup(args->argv[1]); if (args->argc == 3) cdata->cmd_else = xstrdup(args->argv[2]); else cdata->cmd_else = NULL; cdata->ctx = ctx; cmd_ref_ctx(ctx); job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); return (CMD_RETURN_YIELD); /* don't let client exit */ }
int cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_target_data *data = self->data; struct cmd_if_shell_data *cdata; struct job *job; cdata = xmalloc(sizeof *cdata); cdata->cmd = xstrdup(data->arg2); memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); if (ctx->cmdclient != NULL) ctx->cmdclient->references++; if (ctx->curclient != NULL) ctx->curclient->references++; job = job_add(NULL, 0, NULL, data->arg, cmd_if_shell_callback, cmd_if_shell_free, cdata); job_run(job); return (1); /* don't let client exit */ }
enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct cmd_if_shell_data *cdata; char *shellcmd, *cmd, *cause; struct cmd_list *cmdlist; struct client *c; struct session *s = NULL; struct winlink *wl = NULL; struct window_pane *wp = NULL; struct format_tree *ft; int cwd; if (args_has(args, 't')) { wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); cwd = wp->cwd; } else { c = cmd_find_client(cmdq, NULL, 1); if (c != NULL && c->session != NULL) { s = c->session; wl = s->curw; wp = wl->window->active; } if (cmdq->client != NULL && cmdq->client->session == NULL) cwd = cmdq->client->cwd; else if (s != NULL) cwd = s->cwd; else cwd = -1; } ft = format_create(); format_defaults(ft, NULL, s, wl, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); if (args_has(args, 'F')) { cmd = NULL; if (*shellcmd != '0' && *shellcmd != '\0') cmd = args->argv[1]; else if (args->argc == 3) cmd = args->argv[2]; if (cmd == NULL) return (CMD_RETURN_NORMAL); if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) { if (cause != NULL) { cmdq_error(cmdq, "%s", cause); free(cause); } return (CMD_RETURN_ERROR); } cmdq_run(cmdq, cmdlist, &cmdq->item->mouse); cmd_list_free(cmdlist); return (CMD_RETURN_NORMAL); } cdata = xmalloc(sizeof *cdata); cdata->cmd_if = xstrdup(args->argv[1]); if (args->argc == 3) cdata->cmd_else = xstrdup(args->argv[2]); else cdata->cmd_else = NULL; cdata->bflag = args_has(args, 'b'); cdata->cmdq = cmdq; memcpy(&cdata->mouse, &cmdq->item->mouse, sizeof cdata->mouse); cmdq->references++; cdata->references = 1; job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free, cdata); free(shellcmd); if (cdata->bflag) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); }
static enum cmd_retval cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; struct cmd_if_shell_data *cdata; char *shellcmd, *cmd, *cause; struct cmd_list *cmdlist; struct cmdq_item *new_item; struct client *c = item->state.c; struct session *s = item->state.tflag.s; struct winlink *wl = item->state.tflag.wl; struct window_pane *wp = item->state.tflag.wp; const char *cwd; if (item->client != NULL && item->client->session == NULL) cwd = item->client->cwd; else if (s != NULL) cwd = s->cwd; else cwd = NULL; shellcmd = format_single(item, args->argv[0], c, s, wl, wp); if (args_has(args, 'F')) { cmd = NULL; if (*shellcmd != '0' && *shellcmd != '\0') cmd = args->argv[1]; else if (args->argc == 3) cmd = args->argv[2]; free(shellcmd); if (cmd == NULL) return (CMD_RETURN_NORMAL); cmdlist = cmd_string_parse(cmd, NULL, 0, &cause); if (cmdlist == NULL) { if (cause != NULL) { cmdq_error(item, "%s", cause); free(cause); } return (CMD_RETURN_ERROR); } new_item = cmdq_get_command(cmdlist, NULL, &item->mouse, 0); cmdq_insert_after(item, new_item); cmd_list_free(cmdlist); return (CMD_RETURN_NORMAL); } cdata = xcalloc(1, sizeof *cdata); if (self->file != NULL) { cdata->file = xstrdup(self->file); cdata->line = self->line; } cdata->cmd_if = xstrdup(args->argv[1]); if (args->argc == 3) cdata->cmd_else = xstrdup(args->argv[2]); else cdata->cmd_else = NULL; cdata->client = item->client; cdata->client->references++; if (!args_has(args, 'b')) cdata->item = item; else cdata->item = NULL; memcpy(&cdata->mouse, &item->mouse, sizeof cdata->mouse); job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free, cdata); free(shellcmd); if (args_has(args, 'b')) return (CMD_RETURN_NORMAL); return (CMD_RETURN_WAIT); }
void joblist_check_run(joblist *jl, suq_serv *srv) { /* first check how many jobs are running */ int n_running=0; job *j; if (debug>1) printf("SERVER: joblist_check_run\n"); /* first count the running jobs and handle old status updates */ j=joblist_first(jl); while(j) { char timestr[26]; job *next=joblist_next(jl, j); char *loc; if (j->state == running || j->state == started) { n_running += j->ntask; } if (j->state == started) { ctime_r(&(j->start_time), timestr); loc=strchr(timestr, '\n'); /* remove newline */ if (loc) *loc=0; printf("%s: job %d (%s) started with pid %d\n", timestr, j->id, j->name, j->pid); /* it can only gain in priority, so we won't see it again later in the list. */ j->state = running; joblist_re_place(jl, j); } else if (j->state == done) { ctime_r(&(j->end_time), timestr); loc=strchr(timestr, '\n'); /* remove newline */ if (loc) *loc=0; printf("%s: job %d (%s) finished\n", timestr, j->id, j->name); joblist_remove(jl, j); } j=next; } if (debug>1) printf("SERVER: n_running=%d\n", n_running); /* then run new jobs if there's place for them */ j=joblist_first(jl); while ( j && (n_running <= srv->st->ntask) ) { job *next=joblist_next(jl, j); int jntask=j->ntask; if (jntask <= 0) jntask = srv->st->ntask; if ( j->state==waiting ) { if (n_running + jntask <= srv->st->ntask) { job_run(j, (jl->run_id)++); /* it can only gain in priority, so we won't see it again */ joblist_re_place(jl, j); j->state = running; } /* this makes the queue non-backfilling */ n_running += jntask; } if (j->state==waiting && (j->ntask > srv->st->ntask) ) { j->state = resource_error; j->error_string = job_resource_error_string; /* it doesn't matter if we look at it again */ joblist_re_place(jl, j); } j=next; } }