[BACK]Return to cmd-run-shell.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-run-shell.c between version 1.17 and 1.18

version 1.17, 2013/03/24 09:33:35 version 1.18, 2013/03/24 09:54:10
Line 29 
Line 29 
  * Runs a command without a window.   * Runs a command without a window.
  */   */
   
 enum cmd_retval  cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);  enum cmd_retval  cmd_run_shell_exec(struct cmd *, struct cmd_q *);
   
 void    cmd_run_shell_callback(struct job *);  void    cmd_run_shell_callback(struct job *);
 void    cmd_run_shell_free(void *);  void    cmd_run_shell_free(void *);
Line 37 
Line 37 
   
 const struct cmd_entry cmd_run_shell_entry = {  const struct cmd_entry cmd_run_shell_entry = {
         "run-shell", "run",          "run-shell", "run",
         "t:", 1, 1,          "bt:", 1, 1,
         CMD_TARGET_PANE_USAGE " command",          "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
         0,          0,
         NULL,          NULL,
         NULL,          NULL,
Line 47 
Line 47 
   
 struct cmd_run_shell_data {  struct cmd_run_shell_data {
         char            *cmd;          char            *cmd;
         struct cmd_ctx  *ctx;          struct cmd_q    *cmdq;
           int              bflag;
         u_int            wp_id;          u_int            wp_id;
 };  };
   
Line 55 
Line 56 
 cmd_run_shell_print(struct job *job, const char *msg)  cmd_run_shell_print(struct job *job, const char *msg)
 {  {
         struct cmd_run_shell_data       *cdata = job->data;          struct cmd_run_shell_data       *cdata = job->data;
         struct cmd_ctx                  *ctx = cdata->ctx;  
         struct window_pane              *wp;          struct window_pane              *wp;
   
         wp = window_pane_find_by_id(cdata->wp_id);          wp = window_pane_find_by_id(cdata->wp_id);
         if (wp == NULL) {          if (wp == NULL) {
                 ctx->print(ctx, "%s", msg);                  cmdq_print(cdata->cmdq, "%s", msg);
                 return;                  return;
         }          }
   
Line 71 
Line 71 
 }  }
   
 enum cmd_retval  enum cmd_retval
 cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)  cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
 {  {
         struct args                     *args = self->args;          struct args                     *args = self->args;
         struct cmd_run_shell_data       *cdata;          struct cmd_run_shell_data       *cdata;
Line 81 
Line 81 
         struct window_pane              *wp;          struct window_pane              *wp;
         struct format_tree              *ft;          struct format_tree              *ft;
   
         wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);          wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
         if (wl == NULL)          if (wl == NULL)
                 return (CMD_RETURN_ERROR);                  return (CMD_RETURN_ERROR);
   
Line 94 
Line 94 
   
         cdata = xmalloc(sizeof *cdata);          cdata = xmalloc(sizeof *cdata);
         cdata->cmd = shellcmd;          cdata->cmd = shellcmd;
           cdata->bflag = args_has(args, 'b');
         cdata->wp_id = wp->id;          cdata->wp_id = wp->id;
   
         cdata->ctx = ctx;          cdata->cmdq = cmdq;
         cmd_ref_ctx(ctx);          cmdq->references++;
   
         job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);          job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
   
         return (CMD_RETURN_YIELD);      /* don't let client exit */          if (cdata->bflag)
                   return (CMD_RETURN_NORMAL);
           return (CMD_RETURN_WAIT);
 }  }
   
 void  void
 cmd_run_shell_callback(struct job *job)  cmd_run_shell_callback(struct job *job)
 {  {
         struct cmd_run_shell_data       *cdata = job->data;          struct cmd_run_shell_data       *cdata = job->data;
         struct cmd_ctx                  *ctx = cdata->ctx;          struct cmd_q                    *cmdq = cdata->cmdq;
         char                            *cmd, *msg, *line;          char                            *cmd, *msg, *line;
         size_t                           size;          size_t                           size;
         int                              retcode;          int                              retcode;
         u_int                            lines;          u_int                            lines;
   
         if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)          if (cmdq->dead)
                 return;                  return;
         if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)          cmd = cdata->cmd;
                 return;  
   
         lines = 0;          lines = 0;
         do {          do {
                 if ((line = evbuffer_readline(job->event->input)) != NULL) {                  if ((line = evbuffer_readline(job->event->input)) != NULL) {
                         cmd_run_shell_print (job, line);                          cmd_run_shell_print(job, line);
                         free(line);                          free(line);
                         lines++;                          lines++;
                 }                  }
Line 140 
Line 142 
                 free(line);                  free(line);
         }          }
   
         cmd = cdata->cmd;  
   
         msg = NULL;          msg = NULL;
         if (WIFEXITED(job->status)) {          if (WIFEXITED(job->status)) {
                 if ((retcode = WEXITSTATUS(job->status)) != 0)                  if ((retcode = WEXITSTATUS(job->status)) != 0)
Line 152 
Line 152 
         }          }
         if (msg != NULL) {          if (msg != NULL) {
                 if (lines == 0)                  if (lines == 0)
                         ctx->info(ctx, "%s", msg);                          cmdq_info(cmdq, "%s", msg);
                 else                  else
                         cmd_run_shell_print(job, msg);                          cmd_run_shell_print(job, msg);
                 free(msg);                  free(msg);
Line 163 
Line 163 
 cmd_run_shell_free(void *data)  cmd_run_shell_free(void *data)
 {  {
         struct cmd_run_shell_data       *cdata = data;          struct cmd_run_shell_data       *cdata = data;
         struct cmd_ctx                  *ctx = cdata->ctx;          struct cmd_q                    *cmdq = cdata->cmdq;
   
         if (ctx->cmdclient != NULL)          if (!cmdq_free(cmdq) && !cdata->bflag)
                 ctx->cmdclient->flags |= CLIENT_EXIT;                  cmdq_continue(cmdq);
         cmd_free_ctx(ctx);  
   
         free(cdata->cmd);          free(cdata->cmd);
         free(cdata);          free(cdata);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18