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

Diff for /src/usr.bin/tmux/cmd-new-session.c between version 1.115 and 1.116

version 1.115, 2019/03/12 13:56:30 version 1.116, 2019/04/17 14:37:48
Line 69 
Line 69 
         struct args             *args = self->args;          struct args             *args = self->args;
         struct client           *c = item->client;          struct client           *c = item->client;
         struct session          *s, *as, *groupwith;          struct session          *s, *as, *groupwith;
         struct window           *w;  
         struct environ          *env;          struct environ          *env;
         struct options          *oo;          struct options          *oo;
         struct termios           tio, *tiop;          struct termios           tio, *tiop;
         struct session_group    *sg;          struct session_group    *sg;
         const char              *errstr, *template, *group, *prefix;          const char              *errstr, *template, *group, *prefix, *tmp;
         const char              *path, *cmd, *tmp, *value;          char                    *cause, *cwd = NULL, *cp, *newname = NULL;
         char                   **argv, *cause, *cp, *newname, *cwd = NULL;          int                      detached, already_attached, is_control = 0;
         int                      detached, already_attached, idx, argc;          u_int                    sx, sy, dsx, dsy;
         int                      is_control = 0;          struct spawn_context     sc;
         u_int                    sx, sy, dsx = 80, dsy = 24;  
         struct environ_entry    *envent;  
         struct cmd_find_state    fs;  
         enum cmd_retval          retval;          enum cmd_retval          retval;
           struct cmd_find_state    fs;
   
         if (self->entry == &cmd_has_session_entry) {          if (self->entry == &cmd_has_session_entry) {
                 /*                  /*
Line 97 
Line 94 
                 return (CMD_RETURN_ERROR);                  return (CMD_RETURN_ERROR);
         }          }
   
         newname = NULL;  
         if (args_has(args, 's')) {          if (args_has(args, 's')) {
                 newname = format_single(item, args_get(args, 's'), c, NULL,                  newname = format_single(item, args_get(args, 's'), c, NULL,
                     NULL, NULL);                      NULL, NULL);
                 if (!session_check_name(newname)) {                  if (!session_check_name(newname)) {
                         cmdq_error(item, "bad session name: %s", newname);                          cmdq_error(item, "bad session name: %s", newname);
                         goto error;                          goto fail;
                 }                  }
                 if ((as = session_find(newname)) != NULL) {                  if ((as = session_find(newname)) != NULL) {
                         if (args_has(args, 'A')) {                          if (args_has(args, 'A')) {
Line 114 
Line 110 
                                 return (retval);                                  return (retval);
                         }                          }
                         cmdq_error(item, "duplicate session: %s", newname);                          cmdq_error(item, "duplicate session: %s", newname);
                         goto error;                          goto fail;
                 }                  }
         }          }
   
Line 125 
Line 121 
                 if (groupwith == NULL) {                  if (groupwith == NULL) {
                         if (!session_check_name(group)) {                          if (!session_check_name(group)) {
                                 cmdq_error(item, "bad group name: %s", group);                                  cmdq_error(item, "bad group name: %s", group);
                                 goto error;                                  goto fail;
                         }                          }
                         sg = session_group_find(group);                          sg = session_group_find(group);
                 } else                  } else
Line 173 
Line 169 
                 if (server_client_check_nested(item->client)) {                  if (server_client_check_nested(item->client)) {
                         cmdq_error(item, "sessions should be nested with care, "                          cmdq_error(item, "sessions should be nested with care, "
                             "unset $TMUX to force");                              "unset $TMUX to force");
                         return (CMD_RETURN_ERROR);                          goto fail;
                 }                  }
                 if (tcgetattr(c->tty.fd, &tio) != 0)                  if (tcgetattr(c->tty.fd, &tio) != 0)
                         fatal("tcgetattr failed");                          fatal("tcgetattr failed");
Line 186 
Line 182 
                 if (server_client_open(c, &cause) != 0) {                  if (server_client_open(c, &cause) != 0) {
                         cmdq_error(item, "open terminal failed: %s", cause);                          cmdq_error(item, "open terminal failed: %s", cause);
                         free(cause);                          free(cause);
                         goto error;                          goto fail;
                 }                  }
         }          }
   
Line 200 
Line 196 
                         dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);                          dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);
                         if (errstr != NULL) {                          if (errstr != NULL) {
                                 cmdq_error(item, "width %s", errstr);                                  cmdq_error(item, "width %s", errstr);
                                 goto error;                                  goto fail;
                         }                          }
                 }                  }
         }          }
Line 213 
Line 209 
                         dsy = strtonum(tmp, 1, USHRT_MAX, &errstr);                          dsy = strtonum(tmp, 1, USHRT_MAX, &errstr);
                         if (errstr != NULL) {                          if (errstr != NULL) {
                                 cmdq_error(item, "height %s", errstr);                                  cmdq_error(item, "height %s", errstr);
                                 goto error;                                  goto fail;
                         }                          }
                 }                  }
         }          }
Line 225 
Line 221 
                 if (sy > 0 && options_get_number(global_s_options, "status"))                  if (sy > 0 && options_get_number(global_s_options, "status"))
                         sy--;                          sy--;
         } else {          } else {
                 value = options_get_string(global_s_options, "default-size");                  tmp = options_get_string(global_s_options, "default-size");
                 if (sscanf(value, "%ux%u", &sx, &sy) != 2) {                  if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) {
                         sx = 80;                          sx = 80;
                         sy = 24;                          sy = 24;
                 }                  }
Line 240 
Line 236 
         if (sy == 0)          if (sy == 0)
                 sy = 1;                  sy = 1;
   
         /* Figure out the command for the new window. */          /* Create the new session. */
         argc = -1;          oo = options_create(global_s_options);
         argv = NULL;          if (args_has(args, 'x') || args_has(args, 'y'))
         if (!args_has(args, 't') && args->argc != 0) {                  options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);
                 argc = args->argc;  
                 argv = args->argv;  
         } else if (sg == NULL && groupwith == NULL) {  
                 cmd = options_get_string(global_s_options, "default-command");  
                 if (cmd != NULL && *cmd != '\0') {  
                         argc = 1;  
                         argv = (char **)&cmd;  
                 } else {  
                         argc = 0;  
                         argv = NULL;  
                 }  
         }  
   
         path = NULL;  
         if (c != NULL && c->session == NULL)  
                 envent = environ_find(c->environ, "PATH");  
         else  
                 envent = environ_find(global_environ, "PATH");  
         if (envent != NULL)  
                 path = envent->value;  
   
         /* Construct the environment. */  
         env = environ_create();          env = environ_create();
         if (c != NULL && !args_has(args, 'E'))          if (c != NULL && !args_has(args, 'E'))
                 environ_update(global_s_options, c->environ, env);                  environ_update(global_s_options, c->environ, env);
           s = session_create(prefix, newname, cwd, env, oo, tiop);
   
         /* Set up the options. */          /* Spawn the initial window. */
         oo = options_create(global_s_options);          memset(&sc, 0, sizeof sc);
         if (args_has(args, 'x') || args_has(args, 'y'))          sc.item = item;
                 options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);          sc.s = s;
   
         /* Create the new session. */          sc.name = args_get(args, 'n');
         idx = -1 - options_get_number(global_s_options, "base-index");          sc.argc = args->argc;
         s = session_create(prefix, newname, argc, argv, path, cwd, env, oo,          sc.argv = args->argv;
             tiop, idx, &cause);  
         environ_free(env);          sc.idx = -1;
         if (s == NULL) {          sc.cwd = args_get(args, 'c');
                 cmdq_error(item, "create session failed: %s", cause);  
           sc.flags = 0;
   
           if (spawn_window(&sc, &cause) == NULL) {
                   session_destroy(s, 0, __func__);
                   cmdq_error(item, "create window failed: %s", cause);
                 free(cause);                  free(cause);
                 goto error;                  goto fail;
         }          }
   
         /* Set the initial window name if one given. */  
         if (argc >= 0 && (tmp = args_get(args, 'n')) != NULL) {  
                 cp = format_single(item, tmp, c, s, NULL, NULL);  
                 w = s->curw->window;  
                 window_set_name(w, cp);  
                 options_set_number(w->options, "automatic-rename", 0);  
                 free(cp);  
         }  
   
         /*          /*
          * If a target session is given, this is to be part of a session group,           * If a target session is given, this is to be part of a session group,
          * so add it to the group and synchronize.           * so add it to the group and synchronize.
Line 364 
Line 335 
         free(newname);          free(newname);
         return (CMD_RETURN_NORMAL);          return (CMD_RETURN_NORMAL);
   
 error:  fail:
         free(cwd);          free(cwd);
         free(newname);          free(newname);
         return (CMD_RETURN_ERROR);          return (CMD_RETURN_ERROR);

Legend:
Removed from v.1.115  
changed lines
  Added in v.1.116