From 8fe3ede0cf74fd33010e0b120c12c592daf0e711 Mon Sep 17 00:00:00 2001 From: Grooooot Date: Mon, 20 Jan 2020 10:45:57 +0800 Subject: [PATCH] sync openeuler Signed-off-by: Grooooot --- CMakeLists.txt | 1 + clibcni.spec | 2 +- src/json/schema/src/common_c.py | 31 +++++++++++-------- src/json/schema/src/common_h.py | 31 +++++++++++-------- src/json/schema/src/generate.py | 31 +++++++++++-------- src/json/schema/src/headers.py | 31 +++++++++++-------- src/json/schema/src/helpers.py | 31 +++++++++++-------- src/json/schema/src/read_file.c | 28 ++++++++--------- src/json/schema/src/read_file.h | 28 ++++++++--------- src/json/schema/src/sources.py | 35 +++++++++++---------- src/log.c | 54 ++++++++++++++------------------- src/log.h | 32 ++++++------------- 12 files changed, 174 insertions(+), 161 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9154c6b..ea798af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ endif() set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler") set(CMAKE_C_FLAGS "-fPIC -fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -Wall -Werror") set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wtrampolines -fPIE -pie -shared -pthread") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" diff --git a/clibcni.spec b/clibcni.spec index a7af0a7..3a36215 100644 --- a/clibcni.spec +++ b/clibcni.spec @@ -1,5 +1,5 @@ %global _version 1.0.8 -%global _release 20191225.122403.git49093ba7 +%global _release 20200120.104549.gitefa9896c Name: clibcni Version: %{_version} Release: %{_release} diff --git a/src/json/schema/src/common_c.py b/src/json/schema/src/common_c.py index a3e8b1b..4ccf16b 100644 --- a/src/json/schema/src/common_c.py +++ b/src/json/schema/src/common_c.py @@ -4,19 +4,24 @@ Description: commom source file Interface: None History: 2019-06-17 ''' -# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -# - Description: generate json -# - Author: tanyifeng -# - Create: 2018-04-25 -#!/usr/bin/python -Es +# +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . CODE = '''// Auto generated file. Do not edit! # define _GNU_SOURCE diff --git a/src/json/schema/src/common_h.py b/src/json/schema/src/common_h.py index 708e459..c1a8a8b 100644 --- a/src/json/schema/src/common_h.py +++ b/src/json/schema/src/common_h.py @@ -4,18 +4,25 @@ Description: commom header file Interface: None History: 2019-06-17 ''' -# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -# - Description: generate json -# - Author: tanyifeng -# - Create: 2018-04-25 +# +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . +# #!/usr/bin/python -Es """ diff --git a/src/json/schema/src/generate.py b/src/json/schema/src/generate.py index fc5e84a..534e07e 100644 --- a/src/json/schema/src/generate.py +++ b/src/json/schema/src/generate.py @@ -4,19 +4,24 @@ Description: header class and functions Interface: None History: 2019-06-17 ''' -# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -# - Description: generate json -# - Author: tanyifeng -# - Create: 2018-04-25 -#!/usr/bin/python -Es + +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . import traceback import os diff --git a/src/json/schema/src/headers.py b/src/json/schema/src/headers.py index 89d2b7d..98116a6 100644 --- a/src/json/schema/src/headers.py +++ b/src/json/schema/src/headers.py @@ -4,18 +4,25 @@ Description: header class and functions Interface: None History: 2019-06-17 ''' -# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -# - Description: generate json -# - Author: tanyifeng -# - Create: 2018-04-25 +# +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . +# #!/usr/bin/python -Es import helpers diff --git a/src/json/schema/src/helpers.py b/src/json/schema/src/helpers.py index a08789b..92a96c9 100644 --- a/src/json/schema/src/helpers.py +++ b/src/json/schema/src/helpers.py @@ -4,18 +4,25 @@ Description: helper class and functions Interface: None History: 2019-06-17 ''' -# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -# - Description: generate json -# - Author: tanyifeng -# - Create: 2018-04-25 +# +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . +# #!/usr/bin/python -Es import os import sys diff --git a/src/json/schema/src/read_file.c b/src/json/schema/src/read_file.c index 9732b89..bbfff73 100644 --- a/src/json/schema/src/read_file.c +++ b/src/json/schema/src/read_file.c @@ -1,17 +1,17 @@ -/****************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved. - * clibcni licensed under the Mulan PSL v1. - * You can use this software according to the terms and conditions of the Mulan PSL v1. - * You may obtain a copy of Mulan PSL v1 at: - * http://license.coscl.org.cn/MulanPSL - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v1 for more details. - * Author: tanyifeng - * Create: 2018-11-1 - * Description: provide file read functions - ********************************************************************************/ +/* + Copyright 2017 Giuseppe Scrivano + Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ #include #include #include diff --git a/src/json/schema/src/read_file.h b/src/json/schema/src/read_file.h index 0cb063b..0bf6a25 100644 --- a/src/json/schema/src/read_file.h +++ b/src/json/schema/src/read_file.h @@ -1,17 +1,17 @@ -/***************************************************************************** - * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved. - * clibcni licensed under the Mulan PSL v1. - * You can use this software according to the terms and conditions of the Mulan PSL v1. - * You may obtain a copy of Mulan PSL v1 at: - * http://license.coscl.org.cn/MulanPSL - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v1 for more details. - * Author: tanyifeng - * Create: 2018-11-08 - * Description: provide container read file definition - ****************************************************************************/ +/* + Copyright 2017 Giuseppe Scrivano + Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ #ifndef __JSON_READ_FILE_H_ #define __JSON_READ_FILE_H_ diff --git a/src/json/schema/src/sources.py b/src/json/schema/src/sources.py index aecdbae..d4b5393 100644 --- a/src/json/schema/src/sources.py +++ b/src/json/schema/src/sources.py @@ -1,21 +1,24 @@ # -*- coding: utf-8 -*- -""" -Copyright (C) Huawei Technologies., Ltd. 2017-2019. All rights reserved. -# - clibcni licensed under the Mulan PSL v1. -# - You can use this software according to the terms and conditions of the Mulan PSL v1. -# - You may obtain a copy of Mulan PSL v1 at: -# - http://license.coscl.org.cn/MulanPSL -# - THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR -# - IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR -# - PURPOSE. -# - See the Mulan PSL v1 for more details. -Description: generate json -Author: tanyifeng -Interface: None -History: 2018-04-25 created -2019-06-17 Code specification -""" #!/usr/bin/python -Es +# +# libocispec - a C library for parsing OCI spec files. +# +# Copyright (C) 2017, 2019 Giuseppe Scrivano +# Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. +# +# libocispec is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# libocispec is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with libocispec. If not, see . +# import helpers diff --git a/src/log.c b/src/log.c index fc9df2a..262235a 100644 --- a/src/log.c +++ b/src/log.c @@ -39,8 +39,7 @@ const char * const g_clibcni_log_prio_name[] = { static __thread char *g_clibcni_log_prefix = NULL; -static char *g_clibcni_log_vmname = NULL; -static bool g_clibcni_log_quiet = false; +static char *g_clibcni_log_module = NULL; static int g_clibcni_log_level = CLIBCNI_LOG_DEBUG; static int g_clibcni_log_driver = LOG_DRIVER_STDOUT; int g_clibcni_log_fd = -1; @@ -65,10 +64,10 @@ void clibcni_free_log_prefix(void) static ssize_t write_nointr(int fd, const void *buf, size_t count); -static void log_append_logfile(const struct clibcni_log_object_metadata *metadata, const char *timestamp, +static void do_fifo_log(const struct clibcni_log_object_metadata *metadata, const char *timestamp, const char *msg); -static void log_append_stderr(const struct clibcni_log_object_metadata *metadata, const char *timestamp, +static void do_stderr_log(const struct clibcni_log_object_metadata *metadata, const char *timestamp, const char *msg); /* engine change str logdriver to enum */ @@ -156,7 +155,7 @@ static int do_check_log_configs(const struct clibcni_log_config *log) return -1; } - invalid_arg = ((log->file == NULL || strcmp(log->file, "none") == 0) && (g_clibcni_log_driver == LOG_DRIVER_FIFO)); + invalid_arg = ((log->file == NULL) && (g_clibcni_log_driver == LOG_DRIVER_FIFO)); if (invalid_arg) { COMMAND_ERROR("Must set log file for driver %s", log->driver); return -1; @@ -185,10 +184,9 @@ int clibcni_log_enable(const struct clibcni_log_config *log) return -1; } - free(g_clibcni_log_vmname); - g_clibcni_log_vmname = util_strdup_s(log->name); + free(g_clibcni_log_module); + g_clibcni_log_module = util_strdup_s(log->name); - g_clibcni_log_quiet = log->quiet; full_path = util_strdup_s(log->file); nret = util_build_dir(full_path); @@ -213,22 +211,19 @@ out: return nret; } -static int do_log_append_by_driver(const struct clibcni_log_object_metadata *metadata, const char *msg, +static int do_log_by_driver(const struct clibcni_log_object_metadata *metadata, const char *msg, const char *date_time) { switch (g_clibcni_log_driver) { case LOG_DRIVER_STDOUT: - if (g_clibcni_log_quiet) { - break; - } - log_append_stderr(metadata, date_time, msg); + do_stderr_log(metadata, date_time, msg); break; case LOG_DRIVER_FIFO: if (g_clibcni_log_fd == -1) { COMMAND_ERROR("Do not set log file\n"); return -1; } - log_append_logfile(metadata, date_time, msg); + do_fifo_log(metadata, date_time, msg); break; case LOG_DRIVER_NOSET: break; @@ -243,7 +238,7 @@ static char *parse_timespec_to_human() { struct timespec timestamp; struct tm ptm = {0}; - char date_time[CLIBCNI_LOG_TIME_SIZE] = { 0 }; + char date_time[CLIBCNI_LOG_TIME_STR_MAX_LEN] = { 0 }; int nret; #define SEC_TO_NSEC 1000000 #define FIRST_YEAR_OF_GMT 1900 @@ -258,11 +253,11 @@ static char *parse_timespec_to_human() return NULL; } - nret = snprintf(date_time, CLIBCNI_LOG_TIME_SIZE, "%04d%02d%02d%02d%02d%02d.%03ld", + nret = snprintf(date_time, CLIBCNI_LOG_TIME_STR_MAX_LEN, "%04d%02d%02d%02d%02d%02d.%03ld", ptm.tm_year + FIRST_YEAR_OF_GMT, ptm.tm_mon + 1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, ptm.tm_sec, timestamp.tv_nsec / SEC_TO_NSEC); - if (nret < 0 || nret >= CLIBCNI_LOG_TIME_SIZE) { + if (nret < 0 || nret >= CLIBCNI_LOG_TIME_STR_MAX_LEN) { COMMAND_ERROR("Sprintf failed"); return NULL; } @@ -270,8 +265,8 @@ static char *parse_timespec_to_human() return util_strdup_s(date_time); } -/* use to append log to driver */ -int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const char *format, ...) +/* use to add log to driver */ +int clibcni_log(const struct clibcni_log_object_metadata *metadata, const char *format, ...) { int rc; char msg[MAX_MSG_LENGTH] = { 0 }; @@ -294,7 +289,7 @@ int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const goto out; } - ret = do_log_append_by_driver(metadata, msg, date_time); + ret = do_log_by_driver(metadata, msg, date_time); out: free(date_time); @@ -318,7 +313,7 @@ static void do_write_log_into_file(int log_fd, char *log_msg, size_t max_len, si } /* log append logfile */ -static void log_append_logfile(const struct clibcni_log_object_metadata *metadata, const char *timestamp, +static void do_fifo_log(const struct clibcni_log_object_metadata *metadata, const char *timestamp, const char *msg) { char log_buffer[CLIBCNI_LOG_BUFFER_SIZE] = { 0 }; @@ -335,20 +330,18 @@ static void log_append_logfile(const struct clibcni_log_object_metadata *metadat return; } - tmp_prefix = g_clibcni_log_prefix ? g_clibcni_log_prefix : g_clibcni_log_vmname; + tmp_prefix = g_clibcni_log_prefix ? g_clibcni_log_prefix : g_clibcni_log_module; if (tmp_prefix != NULL && strlen(tmp_prefix) > MAX_LOG_PREFIX_LENGTH) { tmp_prefix = tmp_prefix + (strlen(tmp_prefix) - MAX_LOG_PREFIX_LENGTH); } - nret = snprintf(log_buffer, sizeof(log_buffer), "%15s %s %-8s %s - %s:%s:%d - %s", tmp_prefix ? tmp_prefix : "", - timestamp, g_clibcni_log_prio_name[metadata->level], - g_clibcni_log_vmname ? g_clibcni_log_vmname : "clibcni", metadata->file, + nret = snprintf(log_buffer, sizeof(log_buffer), "%15s %s %-8s %s:%s:%d - %s", tmp_prefix ? tmp_prefix : "", + timestamp, g_clibcni_log_prio_name[metadata->level], metadata->file, metadata->func, metadata->line, msg); if (nret < 0) { - nret = snprintf(log_buffer, sizeof(log_buffer), "%15s %s %-8s %s - %s:%s:%d - %s", + nret = snprintf(log_buffer, sizeof(log_buffer), "%15s %s %-8s %s:%s:%d - %s", tmp_prefix ? tmp_prefix : "", timestamp, g_clibcni_log_prio_name[metadata->level], - g_clibcni_log_vmname ? g_clibcni_log_vmname : "clibcni", metadata->file, - metadata->func, metadata->line, "Large log message"); + metadata->file, metadata->func, metadata->line, "Large log message"); if (nret < 0) { return; } @@ -359,7 +352,7 @@ static void log_append_logfile(const struct clibcni_log_object_metadata *metadat } /* log append stderr */ -static void log_append_stderr(const struct clibcni_log_object_metadata *metadata, const char *timestamp, +static void do_stderr_log(const struct clibcni_log_object_metadata *metadata, const char *timestamp, const char *msg) { char *tmp_prefix = NULL; @@ -367,12 +360,11 @@ static void log_append_stderr(const struct clibcni_log_object_metadata *metadata return; } - tmp_prefix = g_clibcni_log_prefix ? g_clibcni_log_prefix : g_clibcni_log_vmname; + tmp_prefix = g_clibcni_log_prefix ? g_clibcni_log_prefix : g_clibcni_log_module; if (tmp_prefix != NULL && strlen(tmp_prefix) > MAX_LOG_PREFIX_LENGTH) { tmp_prefix = tmp_prefix + (strlen(tmp_prefix) - MAX_LOG_PREFIX_LENGTH); } COMMAND_ERROR("%15s %s %-8s ", tmp_prefix ? tmp_prefix : "", timestamp, g_clibcni_log_prio_name[metadata->level]); - COMMAND_ERROR("%s - ", (g_clibcni_log_vmname ? g_clibcni_log_vmname : "clibcni")); COMMAND_ERROR("%s:%s:%d - ", metadata->file, metadata->func, metadata->line); COMMAND_ERROR("%s\n", msg); } diff --git a/src/log.h b/src/log.h index 8882670..2fe54c0 100644 --- a/src/log.h +++ b/src/log.h @@ -26,22 +26,13 @@ extern "C" { #define O_CLOEXEC 02000000 #endif -#ifndef F_DUPFD_CLOEXEC -#define F_DUPFD_CLOEXEC 1030 -#endif - #define CLIBCNI_LOG_BUFFER_SIZE 4096 -/* We're logging in seconds and nanoseconds. Assuming that the underlying - * datatype is currently at maximum a 64bit integer, we have a date string that - * is of maximum length (2^64 - 1) * 2 = (21 + 21) = 42. - * */ -#define CLIBCNI_LOG_TIME_SIZE 42 +#define CLIBCNI_LOG_TIME_STR_MAX_LEN 21 enum clibcni_log_drivers { LOG_DRIVER_STDOUT, LOG_DRIVER_FIFO, - LOG_DRIVER_SYSLOG, LOG_DRIVER_NOSET, }; @@ -64,14 +55,8 @@ struct clibcni_log_config { const char *priority; const char *prefix; const char *driver; - bool quiet; }; -#define CLIBCNI_LOG_LOCINFO_INIT \ - { \ - .file = __FILE__, .func = __func__, .line = __LINE__, \ - } - /* brief logging event object */ struct clibcni_log_object_metadata { /* location information of the logging item */ @@ -88,13 +73,14 @@ void clibcni_set_log_prefix(const char *prefix); void clibcni_free_log_prefix(void); -int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const char *format, ...); +int clibcni_log(const struct clibcni_log_object_metadata *metadata, const char *format, ...); -#define COMMON_LOG(loglevel, format, ...) \ - do { \ - struct clibcni_log_object_metadata meta = CLIBCNI_LOG_LOCINFO_INIT; \ - meta.level = loglevel; \ - (void)clibcni_log_append(&meta, format, ##__VA_ARGS__); \ +#define COMMON_LOG(loglevel, format, ...) \ + do { \ + struct clibcni_log_object_metadata meta = { \ + .file = __FILENAME__, .func = __func__, .line = __LINE__, .level = loglevel, \ + }; \ + (void)clibcni_log(&meta, format, ##__VA_ARGS__); \ } while (0) #define DEBUG(format, ...) \ @@ -135,4 +121,4 @@ int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const } #endif -#endif /* __LCR_LOG_H */ +#endif /* __CLIBCNI_LOG_H */ -- Gitee