mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-11 13:01:28 +02:00
users/19850: add pattern support to watch variable
This commit is contained in:
parent
0209635832
commit
638bccb1c5
3 changed files with 42 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2015-02-11 Peter Stephenson <p.stephenson@samsung.com>
|
||||||
|
|
||||||
|
* users/19850: Doc/Zsh/params.yo, Src/watch.c: watch variable
|
||||||
|
supports patterns for user, tty and host names.
|
||||||
|
|
||||||
2015-02-10 Mikael Magnusson <mikachu@gmail.com>
|
2015-02-10 Mikael Magnusson <mikachu@gmail.com>
|
||||||
|
|
||||||
* 34488: Src/builtin.c: Fix use-after-free for print -zf and
|
* 34488: Src/builtin.c: Fix use-after-free for print -zf and
|
||||||
|
|
|
@ -1472,15 +1472,27 @@ vindex(watch)
|
||||||
vindex(WATCH)
|
vindex(WATCH)
|
||||||
item(tt(watch) <S> <Z> (tt(WATCH) <S>))(
|
item(tt(watch) <S> <Z> (tt(WATCH) <S>))(
|
||||||
An array (colon-separated list) of login/logout events to report.
|
An array (colon-separated list) of login/logout events to report.
|
||||||
|
|
||||||
If it contains the single word `tt(all)', then all login/logout events
|
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
|
are reported. If it contains the single word `tt(notme)', then all
|
||||||
events are reported as with `tt(all)' except tt($USERNAME).
|
events are reported as with `tt(all)' except tt($USERNAME).
|
||||||
|
|
||||||
An entry in this list may consist of a username,
|
An entry in this list may consist of a username,
|
||||||
an `tt(@)' followed by a remote hostname,
|
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;
|
Any or all of these components may be present in an entry;
|
||||||
if a login/logout event matches all of them,
|
if a login/logout event matches all of them,
|
||||||
it is reported.
|
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)
|
vindex(WATCHFMT)
|
||||||
item(tt(WATCHFMT))(
|
item(tt(WATCHFMT))(
|
||||||
|
|
27
Src/watch.c
27
Src/watch.c
|
@ -372,6 +372,27 @@ watchlog2(int inout, WATCH_STRUCT_UTMP *u, char *fmt, int prnt, int fini)
|
||||||
return fmt;
|
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 */
|
/* 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++);
|
for (vv = v; *vv && *vv != '@' && *vv != '%'; vv++);
|
||||||
sav = *vv;
|
sav = *vv;
|
||||||
*vv = '\0';
|
*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;
|
bad = 1;
|
||||||
*vv = sav;
|
*vv = sav;
|
||||||
v = vv;
|
v = vv;
|
||||||
|
@ -410,7 +431,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
|
||||||
for (vv = ++v; *vv && *vv != '@'; vv++);
|
for (vv = ++v; *vv && *vv != '@'; vv++);
|
||||||
sav = *vv;
|
sav = *vv;
|
||||||
*vv = '\0';
|
*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;
|
bad = 1;
|
||||||
*vv = sav;
|
*vv = sav;
|
||||||
v = vv;
|
v = vv;
|
||||||
|
@ -420,7 +441,7 @@ watchlog(int inout, WATCH_STRUCT_UTMP *u, char **w, char *fmt)
|
||||||
for (vv = ++v; *vv && *vv != '%'; vv++);
|
for (vv = ++v; *vv && *vv != '%'; vv++);
|
||||||
sav = *vv;
|
sav = *vv;
|
||||||
*vv = '\0';
|
*vv = '\0';
|
||||||
if (strncmp(u->ut_host, v, strlen(v)))
|
if (!watchlog_match(v, u->ut_host, strlen(v)))
|
||||||
bad = 1;
|
bad = 1;
|
||||||
*vv = sav;
|
*vv = sav;
|
||||||
v = vv;
|
v = vv;
|
||||||
|
|
Loading…
Reference in a new issue