Use ^ for negation, not !
cover Use ^ for negation, not !
People keep having trouble with the ! syntax for negation, because of the !-history feature in some shells (notably, enabled by default in bash in all distros).
The result is that attempts to deallocate hosts, or do some other things, produces an incomprensible "event not found" message.
I don't suffer from this because I have it turned off, with set -H. IMO it should be off by default. (This is Debian #897422.)
Avoid this whole problem by using ^ everywhere we previously used ! for negation. (We continue to honour !.)
Places where ! is still the necessary syntactic character to do something in osstest are:
* In the ms-queuedaemon protocol, ! is used to indicate an unsolicited response.
* In sg-run-job, ! in an IFFAIL means to run a step even if the job has failed or is being truncated.
These go nowhere near a shell and are not, conceptually, negation.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 mg-allocate: Use ^ for deallocation, not !
! is annoying because some shells enable !-history expantion by default even though few users have any idea about it. In general users are confused by the error message and do not know what to do next.
We still honour ! for the benefit of old wrapper scripts, finger macros, etc.
--- README.dev | 4 ++-- mg-allocate | 8 ++++---- mg-schema-test-database | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
README.dev +2 -2
@@ -13,10 +13,10 @@ e.g. $ ./mg-hosts manual-task-create ianc@kazak Borrow, estimating 1 day duration (for the planner): -$ ./mg-allocate -U 1d marilith-n5 +$ ./mg-allocate -U 1d marilith-n5 Return (not automatic, even with an estimate given): -$ ./mg-allocate \!marilith-n5 +$ ./mg-allocate ^marilith-n5 Removing machines for servicing/outage ======================================
mg-allocate +4 -4
@@ -5,11 +5,11 @@ # ./mg-allocate [-l] [-l] [-l] # # <resource-spec> syntax: -# [!][<type>/]<name>[/<share>] type defaults to 'host' +# [^][<type>/]<name>[/<share>] type defaults to 'host' # type=='S' means 'shared-host' # type=='F' means 'shared-flight' # share defaults to * -# "!" prefix means deallocate +# "^" prefix (or "!") means deallocate # name=option|option|... means # any one of those options # option={flag,flag...} means anything
@@ -38,7 +38,7 @@ # be owned by the current task (or perhaps by a task # named in --steal). # -# Not compatible with the !<resource> deallocation +# Not compatible with the ^<resource> deallocation # syntax: donation implies deallocation, in a sense. # # --steal <task-spec>
@@ -125,7 +125,7 @@ END sub parse_1res ($) { my ($res) = @_; - $res =~ m,^(\!?) (?: ([^/]+)/ )? ([^/]+) (?: /(\d+|\*) )?$,x + $res =~ m,^([!^]?) (?: ([^/]+)/ )? ([^/]+) (?: /(\d+|\*) )?$,x or die "bad resource $res ?"; my $allocate= !$1; my $restype= defined($2) ? $2 : 'host';
mg-schema-test-database +1 -1
@@ -71,7 +71,7 @@ # ./mg-schema-test-database drop [_SUFFIX] # This will throw away all of the information in the test DB. # -# 5. OSSTEST_TASK=iwj@testing ./mg-allocate !a-host +# 5. OSSTEST_TASK=iwj@testing ./mg-allocate ^a-host # Hosts that were marked in the main DB as borrowed, are returned by # mg-schema-test-database to the main DB task that previously owned # them, but not freed. So you need to explicitly free them.
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 mg-hosts: Use ^ for flag negation, not !
In reply to Ian JacksonWe still honour (and document) !
--- README.dev | 2 +- mg-hosts | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-)
README.dev +1 -1
@@ -145,7 +145,7 @@ Bless Once machines are ready for production use remove the commission blessing and add the production ones, e.g. - $ ./mg-hosts setflags mudcake{0,1} -- \!blessed-commission blessed-{real,play,adhoc} + $ ./mg-hosts setflags mudcake{0,1} -- ^blessed-commission blessed-{real,play,adhoc} Shutting down the whole system
mg-hosts +10 -9
@@ -70,9 +70,9 @@ # ./mg-hosts showflags # Print a table showing the flags of all hosts. # -# ./mg-hosts setflags HOSTGLOB... -|-- !FLAG|-FLAG|FLAG... -# Updates some flags of the specified hosts. !FLAG and -# -FLAG both clear the flag; FLAG sets it. +# ./mg-hosts setflags HOSTGLOB... -|-- ^FLAG|FLAG... +# Updates some flags of the specified hosts. ^FLAG +# (or -FLAG or !FLAG) clears the flag; FLAG sets it. # # ./mg-hosts setflagexpr HOSTGLOB... - FLAG EXPR [-|-- FLAG EXPR...] # Sets or clears some flags of the specified hosts,
@@ -84,8 +84,9 @@ # decreasing order of precedence): # FLAG true iff FLAG is set for the host # (EXPR) override precedence -# !EXPR boolean negation } alternative -# ~EXPR boolean negation } equivalent syntax +# ^EXPR boolean negation } alternative +# ~EXPR boolean negation } equivalent +# !EXPR boolean negation } syntax # EXPR&EXPR boolean "and" # EXPR|EXPR boolean inclusive-or # Spaces and tabs are disregarded (outside FLAG names).
@@ -428,8 +429,8 @@ sub cmd_setflags () { die unless @$section; foreach my $flagorig (@$section) { my $flag = $flagorig; - # each flag may start with - or ! to remove - my $remove= $flag =~ s/^[-!]//; + # each flag may start with ^ (or - or !) to remove + my $remove= $flag =~ s/^[-!^]//; setflagval($dst,$flag,!$remove); } });
@@ -443,14 +444,14 @@ END my ($dst,$section) = @_; die unless @$section == 2; my ($dstflag, $expr) = @$section; - die "$expr $& ?" if $expr =~ m/[^-0-9a-z_&|()!~ \t]/; + die "$expr $& ?" if $expr =~ m/[^-0-9a-z_&|()!~ \t^]/; my %inputs; $expr =~ s{[-0-9a-z_]+}{ $inputs{$&} = undef; " \$inputs{'$&'} "; }ge; - $expr =~ s/\~/!/g; + $expr =~ s/[~^]/!/g; $expr =~ s/[&|]/$&$&/g; foreach my $flagorig (sort keys %inputs) {
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 mg-adjust-flight-makexrefs: Use ^ for excluding jobs, not !
In reply to Ian JacksonThe ! here doesn't cause shell rune trouble in practice very much, but we want to move to using ^ everywhere for consistency.
We still honour !.
--- cr-daily-branch | 2 +- mg-adjust-flight-makexrefs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-)
cr-daily-branch +1 -1
@@ -343,7 +343,7 @@ xen-unstable-smoke) : ${SMOKE_HARNESS_REV:=$harness_rev} ./mg-adjust-flight-makexrefs -v $flight \ - '!build-*-xsm !build-*-libvirt build-*-*' \ + '^build-*-xsm ^build-*-libvirt build-*-*' \ --debug --blessings=real \ --branch=xen-unstable,xen-unstable-smoke,osstest \ --revision-osstest=$SMOKE_HARNESS_REV
mg-adjust-flight-makexrefs +4 -3
@@ -1,15 +1,16 @@ #!/bin/bash # # usage: ./mg-adjust-flight-makexrefs [OPTIONS..] FLIGHT \ -# '[!]JOB-GLOB ...' \ +# '[^]JOB-GLOB ...' \ # REF-CONDS... # # JOB-GLOB is as for shell `case'. Sense of first match is used. # If no match for a job, uses reverse of sense of last glob. # -# ! means keep such jobs in FLIGHT. Without ! means delete each such +# ^ means keep such jobs in FLIGHT. Without ^ means delete each such # job from FLIGHT and replace intra-flight references to it with # references to the same job in a suitable other flight. +# (! may be used instead of ^.) # # `Suitable' means one in which the required job passed, subject to # REF-CONDS (which are passed to sg-check-tested). REF-CONDS really
@@ -59,7 +60,7 @@ for j in `./cs-adjust-flight $flight jobs-list '^build-'`; do for glob in $keepjobs; do case "$glob" in - !*) ifmatch=$tokeep; action=$todelete ; glob="${glob#!}" ;; + [!^]*) ifmatch=$tokeep; action=$todelete ; glob="${glob#?}" ;; *) ifmatch=$todelete; action=$tokeep ;; esac
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 Standalone HostFlags: Use ^ for negation, not !
In reply to Ian JacksonThe ! here doesn't cause any shell rune trouble in, but we want to move to using ^ everywhere for consistency.
We still honour ! to support old configs.
--- Osstest/HostDB/Static.pm | 2 +- README | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
Osstest/HostDB/Static.pm +1 -1
@@ -56,7 +56,7 @@ sub get_flags ($$) { #method return unless defined $str; foreach my $fl (split /[ \t,;]+/, $str) { next unless length $fl; - if ($fl =~ s/^\!//) { + if ($fl =~ s/^[!^]//) { delete $flags->{$fl}; } else { $flags->{$fl} = 1;
README +2 -2
@@ -447,7 +447,7 @@ HostProp_<testbox>_NtpServer HostFlags_<testbox> Defines a set of flags for the host. Flags is a list separated by whitespace, comma or semi-colon. A flag can be unset by prepending - a !. Only used in standalone mode. + a ^ (or !). Only used in standalone mode. HostGroup_<testbox> <group> Defines a group of similar hosts of which <testbox> is a
@@ -488,7 +488,7 @@ TestHost HostProp_<property> HostProp_<host>_<property> HostFlags flag,flag,flag,... -HostFlags_<host> flag,!flag,!flag,flag... +HostFlags_<host> flag,^flag,^flag,flag... HostProp_DhcpWatchMethod leases <format> <source>
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel