代码拉取完成,页面将自动刷新
同步操作将从 openEuler/A-Tune-BPF-Collection 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "common_helper.h"
static void free_opt(struct opt *opt)
{
if (!opt) {
return;
}
free(opt->name);
free(opt->val);
free(opt);
}
static struct opt *new_opt(char *name, char *val)
{
struct opt *opt = (struct opt*)malloc(sizeof(struct opt));
if (opt) {
opt->name = strdup(name);
opt->val = strdup(val);
opt->next = NULL;
if (!opt->name || !opt->val) {
free_opt(opt);
opt = NULL;
}
}
return opt;
}
struct opt **parse_init(unsigned int size)
{
struct opt **opts = (struct opt **)malloc(size * sizeof(struct opt *));
if (opts)
memset(opts, 0, size * sizeof(struct opt*));
return opts;
}
void parse_fini(struct opt **opts, unsigned int size)
{
if (!opts) {
return;
}
for (unsigned int i = 0; i < size; i++) {
if (opts[i] != NULL) {
free_opt(opts[i]);
}
}
}
static int empty(char *s)
{
while (isspace(*s)) {
++s;
}
return *s == 0;
}
static char *strstrip(char *s)
{
while (isspace(*s)) {
s++;
}
char *p = s + strlen(s) - 1;
if (p <= s) {
return s;
}
while (isspace(*p) && p >= s) {
*p-- = 0;
}
return s;
}
/* djb hash */
static unsigned hash(const char *str, unsigned int size)
{
unsigned hash = 5381;
for (const unsigned char *s = (const unsigned char *)str; *s; s++) {
hash = (hash * 32) + hash + *s;
}
return hash % size;
}
int parse_config_file(unsigned int where, const char *conf_fn, struct opt **opts, unsigned int size)
{
char *line = NULL;
size_t linelen = 0;
char *val = NULL;
unsigned int lineno = 1;
int ret = 0;
FILE *f = fopen(conf_fn, "r");
if (!f) {
log(where, LOG_ERR, "fopen config file(%s) failed\n", conf_fn);
return -1;
}
while (getline(&line, &linelen, f) > 0) {
char *s = strchr(line, '#');
if (s) {
*s = 0;
}
s = strstrip(line);
if ((val = strchr(line, '=')) != NULL) {
*val++ = 0;
char *name = strstrip(s);
val = strstrip(val);
struct opt * opt = new_opt(name, val);
if (!opt) {
ret = -1;
log(where, LOG_ERR, "failed to alloc opt struct\n");
goto cleanup;
}
unsigned int h = hash(name, size);
if (opts[h]) {
struct opt *next = opts[h]->next;
opts[h]->next = opt;
opt->next = next;
} else {
opts[h] = opt;
}
} else if (!empty(s)) {
ret = -1;
log(where, LOG_ERR, "config file(%s) line(%u) is not field\n", conf_fn, lineno);
goto cleanup;
}
lineno++;
}
goto ret;
cleanup:
parse_fini(opts, size);
ret:
fclose(f);
free(line);
return ret;
}
char* config_opt(struct opt **opts, unsigned int size, const char *name)
{
unsigned int h = hash(name, size);
struct opt *header = opts[h];
while (header) {
if (strcmp(header->name, name)) {
header = header->next;
} else {
break;
}
}
return header ? header->val : NULL;
}
void bump_memlock_rlimit(unsigned int where)
{
struct rlimit rlim_new = {
.rlim_cur = RLIM_INFINITY,
.rlim_max = RLIM_INFINITY,
};
if (setrlimit(RLIMIT_MEMLOCK, &rlim_new)) {
log(where, LOG_ERR, "Failed to increase RLIMIT_MEMLOCK limit!\n");
exit(1);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。