
On 09/15/2011 08:17 AM, Serge E. Hallyn wrote:
If the regexes supported (?:pvs)?, then we could handle this by optionally matching but not returning the initial command name. But it doesn't. So add a new char* argument to virStorageBackendRunProgRegex(). If that argument is NULL then we act as usual. Otherwise, if the string at that argument is found at the start of a returned line, we drop that before running the regex.
Yeah, ignoring a prefix seems like the right approach, since we can't rely on non-capturing regex extensions.
+ p = line; + /* if cmd_to_ignore is specified, then ignore it */ + if (strncmp(line, cmd_to_ignore, strlen(cmd_to_ignore)) == 0)
'make syntax-check' should have called you on this; you should be using STRPREFIX here. Something like (untested): diff --git i/src/storage/storage_backend.c w/src/storage/storage_backend.c index 7a352da..3415918 100644 --- i/src/storage/storage_backend.c +++ w/src/storage/storage_backend.c @@ -1460,16 +1460,17 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, } while (fgets(line, sizeof(line), list) != NULL) { - char *p; + char *p = NULL; /* Strip trailing newline */ int len = strlen(line); if (len && line[len-1] == '\n') line[len-1] = '\0'; - p = line; /* if cmd_to_ignore is specified, then ignore it */ - if (strncmp(line, cmd_to_ignore, strlen(cmd_to_ignore)) == 0) - p += strlen(cmd_to_ignore); + if (cmd_to_ignore) + p = STRSKIP(line, cmd_to_ignore); + if (!p) + p = line; for (i = 0 ; i <= maxReg && i < nregex ; i++) { if (regexec(®[i], p, nvars[i]+1, vars, 0) == 0) { -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org