staticbool match_pat(char *file, constchar **pat)
{ int i = 0;
if (!pat) returntrue;
while (pat[i]) { if (strglobmatch(file, pat[i])) returntrue;
i++;
}
returnfalse;
}
/* * The depth specify how deep the removal will go. * 0 - will remove only files under the 'path' directory * 1 .. x - will dive in x-level deep under the 'path' directory * * If specified the pat is array of string patterns ended with NULL, * which are checked upon every file/directory found. Only matching * ones are removed. * * The function returns: * 0 on success * -1 on removal failure with errno set * -2 on pattern failure
*/ staticint rm_rf_depth_pat(constchar *path, int depth, constchar **pat)
{
DIR *dir; int ret; struct dirent *d; char namebuf[PATH_MAX]; struct stat statbuf;
/* Do not fail if there's no file. */
ret = lstat(path, &statbuf); if (ret) return 0;
/* Try to remove any file we get. */ if (!(statbuf.st_mode & S_IFDIR)) return unlink(path);
/* We have directory in path. */
dir = opendir(path); if (dir == NULL) return -1;
while ((d = readdir(dir)) != NULL && !ret) {
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue;
if (!match_pat(d->d_name, pat)) {
ret = -2; break;
}
node = strlist__entry(tips, random() % strlist__nr_entries(tips)); if (asprintf(strp, "Tip: %s", node->s) < 0)
ret = -ENOMEM;
out:
strlist__delete(tips);
return ret;
}
char *perf_exe(char *buf, int len)
{ int n = readlink("/proc/self/exe", buf, len); if (n > 0) {
buf[n] = 0; return buf;
} return strcpy(buf, "perf");
}
void perf_debuginfod_setup(struct perf_debuginfod *di)
{ /* * By default '!di->set' we clear DEBUGINFOD_URLS, so debuginfod * processing is not triggered, otherwise we set it to 'di->urls' * value. If 'di->urls' is "system" we keep DEBUGINFOD_URLS value.
*/ if (!di->set)
setenv("DEBUGINFOD_URLS", "", 1); elseif (di->urls && strcmp(di->urls, "system"))
setenv("DEBUGINFOD_URLS", di->urls, 1);
#ifndef HAVE_DEBUGINFOD_SUPPORT if (di->set)
pr_warning("WARNING: debuginfod support requested, but perf is not built with it\n"); #endif
}
/* * Return a new filename prepended with task's root directory if it's in * a chroot. Callers should free the returned string.
*/ char *filename_with_chroot(int pid, constchar *filename)
{ char buf[PATH_MAX]; char proc_root[32]; char *new_name = NULL; int ret;
scnprintf(proc_root, sizeof(proc_root), "/proc/%d/root", pid);
ret = readlink(proc_root, buf, sizeof(buf) - 1); if (ret <= 0) return NULL;
/* readlink(2) does not append a null byte to buf */
buf[ret] = '\0';
if (!strcmp(buf, "/")) return NULL;
if (strstr(buf, "(deleted)")) return NULL;
if (asprintf(&new_name, "%s/%s", buf, filename) < 0) return NULL;
return new_name;
}
/* * Reallocate an array *arr of size *arr_sz so that it is big enough to contain * x elements of size msz, initializing new entries to *init_val or zero if * init_val is NULL
*/ int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, size_t msz, constvoid *init_val)
{
size_t new_sz = *arr_sz; void *new_arr;
size_t i;
if (!new_sz)
new_sz = msz >= 64 ? 1 : roundup(64, msz); /* Start with at least 64 bytes */ while (x >= new_sz) { if (check_mul_overflow(new_sz, (size_t)2, &new_sz)) return -ENOMEM;
} if (new_sz == *arr_sz) return 0;
new_arr = calloc(new_sz, msz); if (!new_arr) return -ENOMEM; if (*arr_sz)
memcpy(new_arr, *arr, *arr_sz * msz); if (init_val) { for (i = *arr_sz; i < new_sz; i++)
memcpy(new_arr + (i * msz), init_val, msz);
}
*arr = new_arr;
*arr_sz = new_sz; return 0;
}
#ifndef HAVE_SCHED_GETCPU_SUPPORT int sched_getcpu(void)
{ #ifdef __NR_getcpu unsignedint cpu; int err = syscall(__NR_getcpu, &cpu, NULL, NULL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.