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

Diff for /src/usr.bin/tmux/cmd-if-shell.c between version 1.82 and 1.83

version 1.82, 2021/09/09 13:38:32 version 1.83, 2021/09/15 07:38:30
Line 20 
Line 20 
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/wait.h>  #include <sys/wait.h>
   
   #include <ctype.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   
Line 52 
Line 53 
 };  };
   
 struct cmd_if_shell_data {  struct cmd_if_shell_data {
         struct cmd_list         *cmd_if;          struct args_command_state       *cmd_if;
         struct cmd_list         *cmd_else;          struct args_command_state       *cmd_else;
   
         struct client           *client;          struct client                   *client;
         struct cmdq_item        *item;          struct cmdq_item                *item;
 };  };
   
 static enum args_parse_type  static enum args_parse_type
Line 78 
Line 79 
         char                            *shellcmd;          char                            *shellcmd;
         struct client                   *tc = cmdq_get_target_client(item);          struct client                   *tc = cmdq_get_target_client(item);
         struct session                  *s = target->s;          struct session                  *s = target->s;
         struct cmd_list                 *cmdlist = NULL;          struct cmd_list                 *cmdlist;
         u_int                            count = args_count(args);          u_int                            count = args_count(args);
           int                              wait = !args_has(args, 'b');
   
         shellcmd = format_single_from_target(item, args_string(args, 0));          shellcmd = format_single_from_target(item, args_string(args, 0));
         if (args_has(args, 'F')) {          if (args_has(args, 'F')) {
Line 101 
Line 103 
   
         cdata = xcalloc(1, sizeof *cdata);          cdata = xcalloc(1, sizeof *cdata);
   
         cdata->cmd_if = args_make_commands_now(self, item, 1, 0);          cdata->cmd_if = args_make_commands_prepare(self, item, 1, NULL, wait,
         if (cdata->cmd_if == NULL)              0);
             return (CMD_RETURN_ERROR);  
         if (count == 3) {          if (count == 3) {
                 cdata->cmd_else = args_make_commands_now(self, item, 2, 0);                  cdata->cmd_else = args_make_commands_prepare(self, item, 2,
                 if (cdata->cmd_else == NULL)                      NULL, wait, 0);
                     return (CMD_RETURN_ERROR);  
         }          }
   
         if (!args_has(args, 'b'))          if (wait) {
                 cdata->client = cmdq_get_client(item);                  cdata->client = cmdq_get_client(item);
         else                  cdata->item = item;
           } else
                 cdata->client = tc;                  cdata->client = tc;
         if (cdata->client != NULL)          if (cdata->client != NULL)
                 cdata->client->references++;                  cdata->client->references++;
   
         if (!args_has(args, 'b'))  
                 cdata->item = item;  
   
         if (job_run(shellcmd, 0, NULL, s,          if (job_run(shellcmd, 0, NULL, s,
             server_client_get_cwd(cmdq_get_client(item), s), NULL,              server_client_get_cwd(cmdq_get_client(item), s), NULL,
             cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,              cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,
Line 131 
Line 129 
         }          }
         free(shellcmd);          free(shellcmd);
   
         if (args_has(args, 'b'))          if (!wait)
                 return (CMD_RETURN_NORMAL);                  return (CMD_RETURN_NORMAL);
         return (CMD_RETURN_WAIT);          return (CMD_RETURN_WAIT);
 }  }
Line 142 
Line 140 
         struct cmd_if_shell_data        *cdata = job_get_data(job);          struct cmd_if_shell_data        *cdata = job_get_data(job);
         struct client                   *c = cdata->client;          struct client                   *c = cdata->client;
         struct cmdq_item                *item = cdata->item, *new_item;          struct cmdq_item                *item = cdata->item, *new_item;
           struct args_command_state       *state;
         struct cmd_list                 *cmdlist;          struct cmd_list                 *cmdlist;
           char                            *error;
         int                              status;          int                              status;
   
         status = job_get_status(job);          status = job_get_status(job);
         if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)          if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
                 cmdlist = cdata->cmd_else;                  state = cdata->cmd_else;
         else          else
                 cmdlist = cdata->cmd_if;                  state = cdata->cmd_if;
         if (cmdlist == NULL)          if (state == NULL)
                 goto out;                  goto out;
   
         if (item == NULL) {          cmdlist = args_make_commands(state, 0, NULL, &error);
           if (cmdlist == NULL) {
                   if (cdata->item == NULL) {
                           *error = toupper((u_char)*error);
                           status_message_set(c, -1, 1, 0, "%s", error);
                   } else
                           cmdq_error(cdata->item, "%s", error);
                   free(error);
           } else if (item == NULL) {
                 new_item = cmdq_get_command(cmdlist, NULL);                  new_item = cmdq_get_command(cmdlist, NULL);
                 cmdq_append(c, new_item);                  cmdq_append(c, new_item);
         } else {          } else {
Line 175 
Line 183 
                 server_client_unref(cdata->client);                  server_client_unref(cdata->client);
   
         if (cdata->cmd_else != NULL)          if (cdata->cmd_else != NULL)
                 cmd_list_free(cdata->cmd_else);                  args_make_commands_free(cdata->cmd_else);
         cmd_list_free(cdata->cmd_if);          args_make_commands_free(cdata->cmd_if);
   
         free(cdata);          free(cdata);
 }  }

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.83