I've committed my cmdq changes after all so you will need to do it that
way at some point, the differences aren't substantial - basically what I
outlined below, save and reference the cmdq rather than the client and
wake it up with cmdq_free/cmdq_continue. If you look at run-shell it
should be clear enough.


On Sat, Feb 23, 2013 at 09:55:43PM +0000, Nicholas Marriott wrote:
> On Sat, Feb 23, 2013 at 06:24:56PM -0300, Thiago Padilha wrote:
> >    I have started to read the source code and began to wonder if those
> >    features are possible to implement.
> >    I'm assuming that a overview(very high level) of what happens when a tmux
> >    command is executed is:
> 
> Yes this is correct, except for attach-client or new-session.
> 
> >    1- user types 'tmux somecmd' in a shell running inside a tmux session,
> >    which opens 'tmux program'
> >    2- tmux program opens a connection with the server
> >    3- tmux program sends 'somecmd' through the connection fd and wait for a
> >    response
> >    4- tmux server processes the command, sending every output to the
> >    connection fd, which tmux program forwards to stdout(which I assume is 
> > the
> >    tmux client)
> >    5- tmux server closes the connection fd**
> 
> Not quite, there is a client exit protocol, it is not just a close. But
> that isn't important.
> 
> >    6- tmux program detects EOF and returns.
> >    Since tmux is libevent based, to implement the semaphore/lock mechanisms
> >    described, I would need to block the tmux program from returning, which
> >    would require me to push the connection fd to some list or queue and only
> >    close it at a later time.
> 
> The client will not exit until it is told to, it will just sit on the
> tty. What you do currently for a command-line client is return
> CMD_RETURN_YIELD from your command exec function and then set the
> CLIENT_EXIT bit in the flags when you are done. Take a look at
> cmd-run-shell.c.
> 
> This will change shortly when I commit my command queue changes but I
> suggest you not worry about that for now - just work on the current
> system, it won't be hard to convert later.
> 
> >    Is something like this possible to do inside a normal tmux command? If so
> >    can you give me some hints?
> 
> I would say you need to do this for waiting:
> 
> - Define a global tree of wait ids keyed by string, each one will need a
>   queue of clients. Use the tree.h RB tree and queue.h TAILQ (so eg add
>   a TAILQ_ENTRY waitqentry to struct client).
> 
> - In your new command's exec function make sure cmdclient is non-NULL,
>   if not you are inside tmux or in the config file and you can't do this
>   at the moment so make it an error.
> 
> - Add your client to the queue for the wait id and return
>   CMD_RETURN_YIELD. Don't forget to increase the client reference count
>   (c->references).
> 
> Then for the wakeup:
> 
> - Lookup the wait id in the tree.
> 
> - Walk the list of waiters, set their CLIENT_EXIT flag and reduce the
>   reference count.
> 
> - Free all the bits that aren't needed now and return CMD_RETURN_NORMAL.
> 
> With the current code this will NOT block execution of further commands
> in a command sequence - this is impossible until I commit my changes. So
> don't expect this to work:
> 
> tmux wait foo\; lsk
> 
> But this will:
> 
> tmux wait foo
> tmux lsk
> 
> I'm not sure if I will commit my new code before I go but if I do the
> idea will be very similar except instead of putting the client on the
> list you will put the struct cmdq on there (and increase it's reference
> but not the client's), instead of YIELD you will return WAIT and instead
> of doing references-- and setting CLIENT_EXIT flag you will do
> if(!cmdq_free(cmdq)) cmdq_continue(cmdq).
> 
> If you have any questions make them before about 0900 GMT tomorrow or I
> will be gone until next Sunday :-).
> 
> >    Thanks
> >    On Fri, Feb 22, 2013 at 8:16 PM, Nicholas Marriott
> >    <[1]nicholas.marri...@gmail.com> wrote:
> > 
> >      No don't need any other changes thanks
> > 
> >      On Fri, Feb 22, 2013 at 07:14:30PM -0300, Thiago Padilha wrote:
> >      > Ok by me, I was just **following the existing code :)
> >      >
> >      > So the patch is good to merge? Need me to do any other modifications?
> >      >
> >      > On Fri, Feb 22, 2013 at 6:50 PM, Nicholas Marriott
> >      > <[2]nicholas.marri...@gmail.com> wrote:
> >      > > On Fri, Feb 22, 2013 at 06:34:14PM -0300, Thiago Padilha wrote:
> >      > >> I had forgotten to update the man pages to reflect the nem flag,
> >      this
> >      > >> patch contains the complete thing.
> >      > >
> >      > > I think this is a bit more pithy, don't see a need to info() the 
> > old
> >      > > value.
> >      > >
> >      > >
> >      > > diff --git a/cmd-set-option.c b/cmd-set-option.c
> >      > > index a09e6db..94b44c7 100644
> >      > > --- a/cmd-set-option.c
> >      > > +++ b/cmd-set-option.c
> >      > > @@ -63,8 +63,8 @@ struct options_entry 
> > *cmd_set_option_choice(struct
> >      cmd *, struct cmd_ctx *,
> >      > >
> >      > > **const struct cmd_entry cmd_set_option_entry = {
> >      > > ** ** ** ** "set-option", "set",
> >      > > - ** ** ** "agqst:uw", 1, 2,
> >      > > - ** ** ** "[-agsquw] [-t target-session|target-window] option
> >      [value]",
> >      > > + ** ** ** "agoqst:uw", 1, 2,
> >      > > + ** ** ** "[-agosquw] [-t target-session|target-window] option
> >      [value]",
> >      > > ** ** ** ** 0,
> >      > > ** ** ** ** NULL,
> >      > > ** ** ** ** NULL,
> >      > > @@ -73,8 +73,8 @@ const struct cmd_entry cmd_set_option_entry = {
> >      > >
> >      > > **const struct cmd_entry cmd_set_window_option_entry = {
> >      > > ** ** ** ** "set-window-option", "setw",
> >      > > - ** ** ** "agqt:u", 1, 2,
> >      > > - ** ** ** "[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
> >      > > + ** ** ** "agoqt:u", 1, 2,
> >      > > + ** ** ** "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
> >      > > ** ** ** ** 0,
> >      > > ** ** ** ** NULL,
> >      > > ** ** ** ** NULL,
> >      > > @@ -151,6 +151,11 @@ cmd_set_option_exec(struct cmd *self, struct
> >      cmd_ctx *ctx)
> >      > > ** ** ** ** ** ** ** ** if (cmd_set_option_unset(self, ctx, oe, oo,
> >      valstr) != 0)
> >      > > ** ** ** ** ** ** ** ** ** ** ** ** return (CMD_RETURN_ERROR);
> >      > > ** ** ** ** } else {
> >      > > + ** ** ** ** ** ** ** if (args_has(args, 'o') && options_find1(oo,
> >      optstr) != NULL) {
> >      > > + ** ** ** ** ** ** ** ** ** ** ** if (!args_has(args, 'q'))
> >      > > + ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ctx->print(ctx,
> >      "already set: %s", optstr);
> >      > > + ** ** ** ** ** ** ** ** ** ** ** return (CMD_RETURN_NORMAL);
> >      > > + ** ** ** ** ** ** ** }
> >      > > ** ** ** ** ** ** ** ** if (cmd_set_option_set(self, ctx, oe, oo,
> >      valstr) != 0)
> >      > > ** ** ** ** ** ** ** ** ** ** ** ** return (CMD_RETURN_ERROR);
> >      > > ** ** ** ** }
> >      > > @@ -227,6 +232,11 @@ cmd_set_option_user(struct cmd *self, struct
> >      cmd_ctx *ctx, const char* optstr,
> >      > > ** ** ** ** ** ** ** ** ** ** ** ** ctx->error(ctx, "empty value");
> >      > > ** ** ** ** ** ** ** ** ** ** ** ** return (CMD_RETURN_ERROR);
> >      > > ** ** ** ** ** ** ** ** }
> >      > > + ** ** ** ** ** ** ** if (args_has(args, 'o') && options_find1(oo,
> >      optstr) != NULL) {
> >      > > + ** ** ** ** ** ** ** ** ** ** ** if (!args_has(args, 'q'))
> >      > > + ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ctx->print(ctx,
> >      "already set: %s", optstr);
> >      > > + ** ** ** ** ** ** ** ** ** ** ** return (CMD_RETURN_NORMAL);
> >      > > + ** ** ** ** ** ** ** }
> >      > > ** ** ** ** ** ** ** ** options_set_string(oo, optstr, "%s",
> >      valstr);
> >      > > ** ** ** ** ** ** ** ** if (!args_has(args, 'q'))
> >      > > ** ** ** ** ** ** ** ** ** ** ** ** ctx->info(ctx, "set option: %s
> >      -> %s", optstr, valstr);
> >      > > diff --git a/tmux.1 b/tmux.1
> >      > > index 475bac0..0b2892a 100644
> >      > > --- a/tmux.1
> >      > > +++ b/tmux.1
> >      > > @@ -1996,7 +1996,7 @@ abc123
> >      > > **Commands which set options are as follows:
> >      > > **.Bl -tag -width Ds
> >      > > **.It Xo Ic set-option
> >      > > -.Op Fl agqsuw
> >      > > +.Op Fl agoqsuw
> >      > > **.Op Fl t Ar target-session | Ar target-window
> >      > > **.Ar option Ar value
> >      > > **.Xc
> >      > > @@ -2025,6 +2025,10 @@ options.
> >      > > **It is not possible to unset a global option.
> >      > > **.Pp
> >      > > **The
> >      > > +.Fl o
> >      > > +flag prevents setting an option that is already set.
> >      > > +.Pp
> >      > > +The
> >      > > **.Fl q
> >      > > **flag suppresses the informational message (as if the
> >      > > **.Ic quiet
> >      > >
> >      > >
> > 
> > References
> > 
> >    Visible links
> >    1. mailto:nicholas.marri...@gmail.com
> >    2. mailto:nicholas.marri...@gmail.com

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to