License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-18 03:51:59 +08:00
|
|
|
#include "string2.h"
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <stdlib.h>
|
2009-06-02 09:31:03 +08:00
|
|
|
|
tools perf: Move from sane_ctype.h obtained from git to the Linux's original
We got the sane_ctype.h headers from git and kept using it so far, but
since that code originally came from the kernel sources to the git
sources, perhaps its better to just use the one in the kernel, so that
we can leverage tools/perf/check_headers.sh to be notified when our copy
gets out of sync, i.e. when fixes or goodies are added to the code we've
copied.
This will help with things like tools/lib/string.c where we want to have
more things in common with the kernel, such as strim(), skip_spaces(),
etc so as to go on removing the things that we have in tools/perf/util/
and instead using the code in the kernel, indirectly and removing things
like EXPORT_SYMBOL(), etc, getting notified when fixes and improvements
are made to the original code.
Hopefully this also should help with reducing the difference of code
hosted in tools/ to the one in the kernel proper.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-7k9868l713wqtgo01xxygn12@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-06-26 04:27:31 +08:00
|
|
|
#include <linux/ctype.h>
|
2017-04-18 03:10:49 +08:00
|
|
|
|
2019-06-26 04:31:26 +08:00
|
|
|
const char *graph_dotted_line =
|
|
|
|
"---------------------------------------------------------------------"
|
|
|
|
"---------------------------------------------------------------------"
|
|
|
|
"---------------------------------------------------------------------";
|
|
|
|
const char *dots =
|
|
|
|
"....................................................................."
|
|
|
|
"....................................................................."
|
|
|
|
".....................................................................";
|
|
|
|
|
2009-11-15 19:36:53 +08:00
|
|
|
#define K 1024LL
|
|
|
|
/*
|
|
|
|
* perf_atoll()
|
|
|
|
* Parse (\d+)(b|B|kb|KB|mb|MB|gb|GB|tb|TB) (e.g. "256MB")
|
|
|
|
* and return its numeric value
|
|
|
|
*/
|
|
|
|
s64 perf_atoll(const char *str)
|
|
|
|
{
|
2014-08-30 00:37:29 +08:00
|
|
|
s64 length;
|
|
|
|
char *p;
|
|
|
|
char c;
|
2009-11-15 19:36:53 +08:00
|
|
|
|
|
|
|
if (!isdigit(str[0]))
|
|
|
|
goto out_err;
|
|
|
|
|
2014-08-30 00:37:29 +08:00
|
|
|
length = strtoll(str, &p, 10);
|
|
|
|
switch (c = *p++) {
|
|
|
|
case 'b': case 'B':
|
|
|
|
if (*p)
|
2009-11-15 19:36:53 +08:00
|
|
|
goto out_err;
|
2017-02-09 04:01:46 +08:00
|
|
|
|
|
|
|
__fallthrough;
|
2014-08-30 00:37:29 +08:00
|
|
|
case '\0':
|
|
|
|
return length;
|
|
|
|
default:
|
|
|
|
goto out_err;
|
|
|
|
/* two-letter suffices */
|
|
|
|
case 'k': case 'K':
|
|
|
|
length <<= 10;
|
2009-11-15 19:36:53 +08:00
|
|
|
break;
|
2014-08-30 00:37:29 +08:00
|
|
|
case 'm': case 'M':
|
|
|
|
length <<= 20;
|
2009-11-15 19:36:53 +08:00
|
|
|
break;
|
2014-08-30 00:37:29 +08:00
|
|
|
case 'g': case 'G':
|
|
|
|
length <<= 30;
|
2009-11-15 19:36:53 +08:00
|
|
|
break;
|
2014-08-30 00:37:29 +08:00
|
|
|
case 't': case 'T':
|
|
|
|
length <<= 40;
|
2009-11-15 19:36:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-08-30 00:37:29 +08:00
|
|
|
/* we want the cases to match */
|
|
|
|
if (islower(c)) {
|
|
|
|
if (strcmp(p, "b") != 0)
|
|
|
|
goto out_err;
|
|
|
|
} else {
|
|
|
|
if (strcmp(p, "B") != 0)
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
return length;
|
2009-11-15 19:36:53 +08:00
|
|
|
|
|
|
|
out_err:
|
2014-08-30 00:37:29 +08:00
|
|
|
return -1;
|
2009-11-15 19:36:53 +08:00
|
|
|
}
|
2009-12-01 08:20:05 +08:00
|
|
|
|
|
|
|
static const char *skip_arg(const char *cp)
|
|
|
|
{
|
|
|
|
while (*cp && !isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int count_argc(const char *str)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (*str) {
|
2019-06-26 08:46:39 +08:00
|
|
|
str = skip_spaces(str);
|
2009-12-01 08:20:05 +08:00
|
|
|
if (*str) {
|
|
|
|
count++;
|
|
|
|
str = skip_arg(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* argv_free - free an argv
|
|
|
|
* @argv - the argument vector to be freed
|
|
|
|
*
|
|
|
|
* Frees an argv and the strings it points to.
|
|
|
|
*/
|
|
|
|
void argv_free(char **argv)
|
|
|
|
{
|
|
|
|
char **p;
|
2017-04-18 03:51:59 +08:00
|
|
|
for (p = argv; *p; p++) {
|
|
|
|
free(*p);
|
|
|
|
*p = NULL;
|
|
|
|
}
|
2009-12-01 08:20:05 +08:00
|
|
|
|
|
|
|
free(argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* argv_split - split a string at whitespace, returning an argv
|
|
|
|
* @str: the string to be split
|
|
|
|
* @argcp: returned argument count
|
|
|
|
*
|
|
|
|
* Returns an array of pointers to strings which are split out from
|
|
|
|
* @str. This is performed by strictly splitting on white-space; no
|
|
|
|
* quote processing is performed. Multiple whitespace characters are
|
|
|
|
* considered to be a single argument separator. The returned array
|
|
|
|
* is always NULL-terminated. Returns NULL on memory allocation
|
|
|
|
* failure.
|
|
|
|
*/
|
|
|
|
char **argv_split(const char *str, int *argcp)
|
|
|
|
{
|
|
|
|
int argc = count_argc(str);
|
2017-04-18 03:51:59 +08:00
|
|
|
char **argv = calloc(argc + 1, sizeof(*argv));
|
2009-12-01 08:20:05 +08:00
|
|
|
char **argvp;
|
|
|
|
|
|
|
|
if (argv == NULL)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (argcp)
|
|
|
|
*argcp = argc;
|
|
|
|
|
|
|
|
argvp = argv;
|
|
|
|
|
|
|
|
while (*str) {
|
2019-06-26 08:46:39 +08:00
|
|
|
str = skip_spaces(str);
|
2009-12-01 08:20:05 +08:00
|
|
|
|
|
|
|
if (*str) {
|
|
|
|
const char *p = str;
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
str = skip_arg(str);
|
|
|
|
|
|
|
|
t = strndup(p, str-p);
|
|
|
|
if (t == NULL)
|
|
|
|
goto fail;
|
|
|
|
*argvp++ = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*argvp = NULL;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return argv;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
argv_free(argv);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-12-15 23:32:10 +08:00
|
|
|
|
2010-01-06 06:47:24 +08:00
|
|
|
/* Character class matching */
|
|
|
|
static bool __match_charclass(const char *pat, char c, const char **npat)
|
|
|
|
{
|
|
|
|
bool complement = false, ret = true;
|
|
|
|
|
|
|
|
if (*pat == '!') {
|
|
|
|
complement = true;
|
|
|
|
pat++;
|
|
|
|
}
|
|
|
|
if (*pat++ == c) /* First character is special */
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
while (*pat && *pat != ']') { /* Matching */
|
|
|
|
if (*pat == '-' && *(pat + 1) != ']') { /* Range */
|
|
|
|
if (*(pat - 1) <= c && c <= *(pat + 1))
|
|
|
|
goto end;
|
|
|
|
if (*(pat - 1) > *(pat + 1))
|
|
|
|
goto error;
|
|
|
|
pat += 2;
|
|
|
|
} else if (*pat++ == c)
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (!*pat)
|
|
|
|
goto error;
|
|
|
|
ret = false;
|
|
|
|
|
|
|
|
end:
|
|
|
|
while (*pat && *pat != ']') /* Searching closing */
|
|
|
|
pat++;
|
|
|
|
if (!*pat)
|
|
|
|
goto error;
|
|
|
|
*npat = pat + 1;
|
|
|
|
return complement ? !ret : ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-25 21:36:12 +08:00
|
|
|
/* Glob/lazy pattern matching */
|
2016-10-20 01:50:01 +08:00
|
|
|
static bool __match_glob(const char *str, const char *pat, bool ignore_space,
|
|
|
|
bool case_ins)
|
2009-12-15 23:32:10 +08:00
|
|
|
{
|
|
|
|
while (*str && *pat && *pat != '*') {
|
2010-02-25 21:36:12 +08:00
|
|
|
if (ignore_space) {
|
|
|
|
/* Ignore spaces for lazy matching */
|
|
|
|
if (isspace(*str)) {
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isspace(*pat)) {
|
|
|
|
pat++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-01-06 06:47:24 +08:00
|
|
|
if (*pat == '?') { /* Matches any single character */
|
2009-12-15 23:32:10 +08:00
|
|
|
str++;
|
|
|
|
pat++;
|
2010-01-06 06:47:24 +08:00
|
|
|
continue;
|
|
|
|
} else if (*pat == '[') /* Character classes/Ranges */
|
|
|
|
if (__match_charclass(pat + 1, *str, &pat)) {
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
} else
|
2009-12-15 23:32:10 +08:00
|
|
|
return false;
|
2010-01-06 06:47:24 +08:00
|
|
|
else if (*pat == '\\') /* Escaped char match as normal char */
|
|
|
|
pat++;
|
2016-10-20 01:50:01 +08:00
|
|
|
if (case_ins) {
|
|
|
|
if (tolower(*str) != tolower(*pat))
|
|
|
|
return false;
|
|
|
|
} else if (*str != *pat)
|
2010-01-06 06:47:24 +08:00
|
|
|
return false;
|
2016-10-20 01:50:01 +08:00
|
|
|
str++;
|
|
|
|
pat++;
|
2009-12-15 23:32:10 +08:00
|
|
|
}
|
|
|
|
/* Check wild card */
|
|
|
|
if (*pat == '*') {
|
|
|
|
while (*pat == '*')
|
|
|
|
pat++;
|
|
|
|
if (!*pat) /* Tail wild card matches all */
|
|
|
|
return true;
|
|
|
|
while (*str)
|
2016-10-20 01:50:01 +08:00
|
|
|
if (__match_glob(str++, pat, ignore_space, case_ins))
|
2009-12-15 23:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return !*str && !*pat;
|
|
|
|
}
|
|
|
|
|
2010-02-25 21:36:12 +08:00
|
|
|
/**
|
|
|
|
* strglobmatch - glob expression pattern matching
|
|
|
|
* @str: the target string to match
|
|
|
|
* @pat: the pattern string to match
|
|
|
|
*
|
|
|
|
* This returns true if the @str matches @pat. @pat can includes wildcards
|
|
|
|
* ('*','?') and character classes ([CHARS], complementation and ranges are
|
|
|
|
* also supported). Also, this supports escape character ('\') to use special
|
|
|
|
* characters as normal character.
|
|
|
|
*
|
|
|
|
* Note: if @pat syntax is broken, this always returns false.
|
|
|
|
*/
|
|
|
|
bool strglobmatch(const char *str, const char *pat)
|
|
|
|
{
|
2016-10-20 01:50:01 +08:00
|
|
|
return __match_glob(str, pat, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool strglobmatch_nocase(const char *str, const char *pat)
|
|
|
|
{
|
|
|
|
return __match_glob(str, pat, false, true);
|
2010-02-25 21:36:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* strlazymatch - matching pattern strings lazily with glob pattern
|
|
|
|
* @str: the target string to match
|
|
|
|
* @pat: the pattern string to match
|
|
|
|
*
|
|
|
|
* This is similar to strglobmatch, except this ignores spaces in
|
|
|
|
* the target string.
|
|
|
|
*/
|
|
|
|
bool strlazymatch(const char *str, const char *pat)
|
|
|
|
{
|
2016-10-20 01:50:01 +08:00
|
|
|
return __match_glob(str, pat, true, false);
|
2010-02-25 21:36:12 +08:00
|
|
|
}
|
2011-06-27 15:27:15 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* strtailcmp - Compare the tail of two strings
|
|
|
|
* @s1: 1st string to be compared
|
|
|
|
* @s2: 2nd string to be compared
|
|
|
|
*
|
|
|
|
* Return 0 if whole of either string is same as another's tail part.
|
|
|
|
*/
|
|
|
|
int strtailcmp(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
int i1 = strlen(s1);
|
|
|
|
int i2 = strlen(s2);
|
|
|
|
while (--i1 >= 0 && --i2 >= 0) {
|
|
|
|
if (s1[i1] != s2[i2])
|
|
|
|
return s1[i1] - s2[i2];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-28 05:18:31 +08:00
|
|
|
/**
|
|
|
|
* strxfrchar - Locate and replace character in @s
|
|
|
|
* @s: The string to be searched/changed.
|
|
|
|
* @from: Source character to be replaced.
|
|
|
|
* @to: Destination character.
|
|
|
|
*
|
|
|
|
* Return pointer to the changed string.
|
|
|
|
*/
|
|
|
|
char *strxfrchar(char *s, char from, char to)
|
|
|
|
{
|
|
|
|
char *p = s;
|
|
|
|
|
|
|
|
while ((p = strchr(p, from)) != NULL)
|
|
|
|
*p++ = to;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2013-01-22 17:09:41 +08:00
|
|
|
|
2012-06-08 05:23:31 +08:00
|
|
|
/**
|
|
|
|
* rtrim - Removes trailing whitespace from @s.
|
|
|
|
* @s: The string to be stripped.
|
|
|
|
*
|
|
|
|
* Note that the first trailing whitespace is replaced with a %NUL-terminator
|
|
|
|
* in the given string @s. Returns @s.
|
|
|
|
*/
|
|
|
|
char *rtrim(char *s)
|
|
|
|
{
|
|
|
|
size_t size = strlen(s);
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return s;
|
|
|
|
|
|
|
|
end = s + size - 1;
|
|
|
|
while (end >= s && isspace(*end))
|
|
|
|
end--;
|
|
|
|
*(end + 1) = '\0';
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2012-09-11 00:50:17 +08:00
|
|
|
|
perf tools: Asprintf like functions to format integer filter expression
char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints);
char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints);
Example of output formatted with those functions:
# ./tp_filter 6 12 2015
asprintf_expr_in_ints: id == 6 || id == 12 || id == 2015
asprintf_expr_not_in_ints: id != 6 && id != 12 && id != 2015
#
It'll be used with, for instance, perf_evsel__set_filter_in_ints(), that
will be used in turn to ask the kernel to filter out all raw_syscalls:*
except for the ones specified by the user via:
$ perf trace -e some,list,of,syscalls
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-jt07vfp6bd8y50c05j1t7hrn@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-07-03 04:48:23 +08:00
|
|
|
char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FIXME: replace this with an expression using log10() when we
|
|
|
|
* find a suitable implementation, maybe the one in the dvb drivers...
|
|
|
|
*
|
|
|
|
* "%s == %d || " = log10(MAXINT) * 2 + 8 chars for the operators
|
|
|
|
*/
|
|
|
|
size_t size = nints * 28 + 1; /* \0 */
|
|
|
|
size_t i, printed = 0;
|
|
|
|
char *expr = malloc(size);
|
|
|
|
|
|
|
|
if (expr) {
|
|
|
|
const char *or_and = "||", *eq_neq = "==";
|
|
|
|
char *e = expr;
|
|
|
|
|
|
|
|
if (!in) {
|
|
|
|
or_and = "&&";
|
|
|
|
eq_neq = "!=";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nints; ++i) {
|
|
|
|
if (printed == size)
|
|
|
|
goto out_err_overflow;
|
|
|
|
|
|
|
|
if (i > 0)
|
2017-04-18 03:51:59 +08:00
|
|
|
printed += scnprintf(e + printed, size - printed, " %s ", or_and);
|
perf tools: Asprintf like functions to format integer filter expression
char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints);
char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints);
Example of output formatted with those functions:
# ./tp_filter 6 12 2015
asprintf_expr_in_ints: id == 6 || id == 12 || id == 2015
asprintf_expr_not_in_ints: id != 6 && id != 12 && id != 2015
#
It'll be used with, for instance, perf_evsel__set_filter_in_ints(), that
will be used in turn to ask the kernel to filter out all raw_syscalls:*
except for the ones specified by the user via:
$ perf trace -e some,list,of,syscalls
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-jt07vfp6bd8y50c05j1t7hrn@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-07-03 04:48:23 +08:00
|
|
|
printed += scnprintf(e + printed, size - printed,
|
|
|
|
"%s %s %d", var, eq_neq, ints[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return expr;
|
|
|
|
|
|
|
|
out_err_overflow:
|
|
|
|
free(expr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-09 00:28:41 +08:00
|
|
|
|
|
|
|
/* Like strpbrk(), but not break if it is right after a backslash (escaped) */
|
|
|
|
char *strpbrk_esc(char *str, const char *stopset)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ptr = strpbrk(str, stopset);
|
|
|
|
if (ptr == str ||
|
|
|
|
(ptr == str + 1 && *(ptr - 1) != '\\'))
|
|
|
|
break;
|
|
|
|
str = ptr + 1;
|
|
|
|
} while (ptr && *(ptr - 1) == '\\' && *(ptr - 2) != '\\');
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Like strdup, but do not copy a single backslash */
|
|
|
|
char *strdup_esc(const char *str)
|
|
|
|
{
|
|
|
|
char *s, *d, *p, *ret = strdup(str);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
d = strchr(ret, '\\');
|
|
|
|
if (!d)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
s = d + 1;
|
|
|
|
do {
|
|
|
|
if (*s == '\0') {
|
|
|
|
*d = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p = strchr(s + 1, '\\');
|
|
|
|
if (p) {
|
|
|
|
memmove(d, s, p - s);
|
|
|
|
d += p - s;
|
|
|
|
s = p + 1;
|
|
|
|
} else
|
|
|
|
memmove(d, s, strlen(s) + 1);
|
|
|
|
} while (p);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|