From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21535 invoked by alias); 11 Feb 2015 12:37:06 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19850 Received: (qmail 24008 invoked from network); 11 Feb 2015 12:37:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f4-b7f126d000001e9a-e4-54db49fff552 Date: Wed, 11 Feb 2015 12:26:30 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: exclude users in watch variable? Message-id: <20150211122630.619e332c@pwslap01u.europe.root.pri> In-reply-to: <20150204174605.GA14529@spiegl.de> References: <20150204174605.GA14529@spiegl.de> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKLMWRmVeSWpSXmKPExsVy+t/xq7r/PW+HGHy9pW2x4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZby5t4Wp4K5sxc77F5gbGPvFuxg5OSQETCQW77rPBmGLSVy4 tx7I5uIQEljKKPHv9npWCGcRk8T1kxPYQaqEBLYxSnw/xgRiswioSrx89h6sm03AUGLqptmM ILaIgKjE8hWbweqFBXQlVhx+A1bPK2AvcfD9YrAaTgF9iabN6xghZupJTF/xmgXE5geKX/37 iQniInuJmVfOMEL0Ckr8mHwPrIZZQEti87YmVghbXmLzmrfMEHPUJW7c3c0+gVFoFpKWWUha ZiFpWcDIvIpRNLU0uaA4KT3XUK84Mbe4NC9dLzk/dxMjJGi/7GBcfMzqEKMAB6MSD2/AhJsh QqyJZcWVuYcYJTiYlUR4r7neDhHiTUmsrEotyo8vKs1JLT7EyMTBKdXAuDhfPmT1Iju9s1lf ex9eO9KfIvPuzNlnX6vULBoE30XumHqrMZgp1VPRtSineVtOygXLif5b1mTreYj1iZ3Nv7m1 njOF6YO5+vwZHIXS8VOZL5QZrDCoyc1U9lde9P2kjK7xq637uYQYI/UX/Lw8VaBn5UU7xd8W 7G1hxf7H4wz/1Jode/hSiaU4I9FQi7moOBEAvTDavTgCAAA= On Wed, 4 Feb 2015 18:46:06 +0100 Andy Spiegl wrote: > "watch=( notme )" excludes myself but is there a way to exclude other > usernames? > > I was trying "watch=( notme ^user1 ^user2 )" but I am expecting too > much, right? Patterns are easy to add, we might as well do it. I can't see how this could be problematic since user names tty names and host names can't contain pattern characters. Note you'll need to do it the way suggested in the example: the list you've got won't work because you're looking for an "or" of 'anyone apart from me', 'anyone apart from user1', 'anyone apart from user2'. In fact, you can basically only use one negative in the list since "or"ing negatives isn't useful. I'm not proposing to change this since there isn't a convenient alternative behaviour. pws diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index ee7c054..273be21 100644 --- a/Doc/Zsh/params.yo +++ b/Doc/Zsh/params.yo @@ -1472,15 +1472,27 @@ vindex(watch) vindex(WATCH) item(tt(watch) (tt(WATCH) ))( An array (colon-separated list) of login/logout events to report. + If it contains the single word `tt(all)', then all login/logout events are reported. If it contains the single word `tt(notme)', then all events are reported as with `tt(all)' except tt($USERNAME). + An entry in this list may consist of a username, an `tt(@)' followed by a remote hostname, -and a `tt(%)' followed by a line (tty). +and a `tt(%)' followed by a line (tty). Any of these may +be a pattern (be sure to quote this during the assignment to +tt(watch) so that it does not immediately perform file generation); +the setting of the tt(EXTENDED_GLOB) option is respected. Any or all of these components may be present in an entry; if a login/logout event matches all of them, it is reported. + +For example, with the tt(EXTENDED_GLOB) option set, the following: + +example(watch=('^(pws|barts)')) + +causes reports for activity assoicated with any user other than tt(pws) +or tt(barts). ) vindex(WATCHFMT) item(tt(WATCHFMT))( diff --git a/Src/watch.c b/Src/watch.c index 8dea0b4..fe409f9 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -372,6 +372,27 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini) return fmt; } +/* See if the watch entry matches */ + +static int +watchlog_match(char *teststr, char *actual, int len) +{ + int ret = 0; + Patprog pprog; + char *str = dupstring(teststr); + + tokenize(str); + + if ((pprog = patcompile(str, PAT_STATIC, 0))) { + queue_signals(); + if (pattry(pprog, actual)) + ret = 1; + unqueue_signals(); + } else if (!strncmp(actual, teststr, len)) + ret = 1; + return ret; +} + /* check the List for login/logouts */ /**/ @@ -400,7 +421,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = v; *vv && *vv != '@' && *vv != '%'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_name, v, sizeof(u->ut_name))) + if (!watchlog_match(v, u->ut_name, sizeof(u->ut_name))) bad = 1; *vv = sav; v = vv; @@ -410,7 +431,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = ++v; *vv && *vv != '@'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_line, v, sizeof(u->ut_line))) + if (!watchlog_match(v, u->ut_line, sizeof(u->ut_line))) bad = 1; *vv = sav; v = vv; @@ -420,7 +441,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt) for (vv = ++v; *vv && *vv != '%'; vv++); sav = *vv; *vv = '\0'; - if (strncmp(u->ut_host, v, strlen(v))) + if (!watchlog_match(v, u->ut_host, strlen(v))) bad = 1; *vv = sav; v = vv;