sync openeuler

Signed-off-by: Grooooot <isula@huawei.com>
This commit is contained in:
Grooooot 2020-01-20 10:45:57 +08:00
parent efa9896c5f
commit 8fe3ede0cf
12 changed files with 174 additions and 161 deletions

View File

@ -25,6 +25,7 @@ endif()
set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler") 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_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_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( configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"

View File

@ -1,5 +1,5 @@
%global _version 1.0.8 %global _version 1.0.8
%global _release 20191225.122403.git49093ba7 %global _release 20200120.104549.gitefa9896c
Name: clibcni Name: clibcni
Version: %{_version} Version: %{_version}
Release: %{_release} Release: %{_release}

View File

@ -4,19 +4,24 @@ Description: commom source file
Interface: None Interface: None
History: 2019-06-17 History: 2019-06-17
''' '''
# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. #
# - clibcni licensed under the Mulan PSL v1. # libocispec - a C library for parsing OCI spec files.
# - 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: # Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# - http://license.coscl.org.cn/MulanPSL # Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - 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 # libocispec is free software; you can redistribute it and/or modify
# - PURPOSE. # it under the terms of the GNU General Public License as published by
# - See the Mulan PSL v1 for more details. # the Free Software Foundation; either version 3 of the License, or
# - Description: generate json # (at your option) any later version.
# - Author: tanyifeng #
# - Create: 2018-04-25 # libocispec is distributed in the hope that it will be useful,
#!/usr/bin/python -Es # 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 <http://www.gnu.org/licenses/>.
CODE = '''// Auto generated file. Do not edit! CODE = '''// Auto generated file. Do not edit!
# define _GNU_SOURCE # define _GNU_SOURCE

View File

@ -4,18 +4,25 @@ Description: commom header file
Interface: None Interface: None
History: 2019-06-17 History: 2019-06-17
''' '''
# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. #
# - clibcni licensed under the Mulan PSL v1. # libocispec - a C library for parsing OCI spec files.
# - 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: # Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# - http://license.coscl.org.cn/MulanPSL # Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - 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 # libocispec is free software; you can redistribute it and/or modify
# - PURPOSE. # it under the terms of the GNU General Public License as published by
# - See the Mulan PSL v1 for more details. # the Free Software Foundation; either version 3 of the License, or
# - Description: generate json # (at your option) any later version.
# - Author: tanyifeng #
# - Create: 2018-04-25 # 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 <http://www.gnu.org/licenses/>.
#
#!/usr/bin/python -Es #!/usr/bin/python -Es
""" """

View File

@ -4,19 +4,24 @@ Description: header class and functions
Interface: None Interface: None
History: 2019-06-17 History: 2019-06-17
''' '''
# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - clibcni licensed under the Mulan PSL v1. # libocispec - a C library for parsing OCI spec files.
# - 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: # Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# - http://license.coscl.org.cn/MulanPSL # Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - 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 # libocispec is free software; you can redistribute it and/or modify
# - PURPOSE. # it under the terms of the GNU General Public License as published by
# - See the Mulan PSL v1 for more details. # the Free Software Foundation; either version 3 of the License, or
# - Description: generate json # (at your option) any later version.
# - Author: tanyifeng #
# - Create: 2018-04-25 # libocispec is distributed in the hope that it will be useful,
#!/usr/bin/python -Es # 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 <http://www.gnu.org/licenses/>.
import traceback import traceback
import os import os

View File

@ -4,18 +4,25 @@ Description: header class and functions
Interface: None Interface: None
History: 2019-06-17 History: 2019-06-17
''' '''
# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. #
# - clibcni licensed under the Mulan PSL v1. # libocispec - a C library for parsing OCI spec files.
# - 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: # Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# - http://license.coscl.org.cn/MulanPSL # Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - 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 # libocispec is free software; you can redistribute it and/or modify
# - PURPOSE. # it under the terms of the GNU General Public License as published by
# - See the Mulan PSL v1 for more details. # the Free Software Foundation; either version 3 of the License, or
# - Description: generate json # (at your option) any later version.
# - Author: tanyifeng #
# - Create: 2018-04-25 # 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 <http://www.gnu.org/licenses/>.
#
#!/usr/bin/python -Es #!/usr/bin/python -Es
import helpers import helpers

View File

@ -4,18 +4,25 @@ Description: helper class and functions
Interface: None Interface: None
History: 2019-06-17 History: 2019-06-17
''' '''
# - Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved. #
# - clibcni licensed under the Mulan PSL v1. # libocispec - a C library for parsing OCI spec files.
# - 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: # Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# - http://license.coscl.org.cn/MulanPSL # Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
# - 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 # libocispec is free software; you can redistribute it and/or modify
# - PURPOSE. # it under the terms of the GNU General Public License as published by
# - See the Mulan PSL v1 for more details. # the Free Software Foundation; either version 3 of the License, or
# - Description: generate json # (at your option) any later version.
# - Author: tanyifeng #
# - Create: 2018-04-25 # 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 <http://www.gnu.org/licenses/>.
#
#!/usr/bin/python -Es #!/usr/bin/python -Es
import os import os
import sys import sys

View File

@ -1,17 +1,17 @@
/****************************************************************************** /*
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved. Copyright 2017 Giuseppe Scrivano
* clibcni licensed under the Mulan PSL v1. Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
* 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: Licensed under the Apache License, Version 2.0 (the "License");
* http://license.coscl.org.cn/MulanPSL you may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR You may obtain a copy of the License at
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR http://www.apache.org/licenses/LICENSE-2.0
* PURPOSE. Unless required by applicable law or agreed to in writing, software
* See the Mulan PSL v1 for more details. distributed under the License is distributed on an "AS IS" BASIS,
* Author: tanyifeng WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Create: 2018-11-1 See the License for the specific language governing permissions and
* Description: provide file read functions limitations under the License.
********************************************************************************/ */
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>

View File

@ -1,17 +1,17 @@
/***************************************************************************** /*
* Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved. Copyright 2017 Giuseppe Scrivano
* clibcni licensed under the Mulan PSL v1. Copyright (C) Huawei Technologies., Ltd. 2018-2019. All rights reserved.
* 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: Licensed under the Apache License, Version 2.0 (the "License");
* http://license.coscl.org.cn/MulanPSL you may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR You may obtain a copy of the License at
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR http://www.apache.org/licenses/LICENSE-2.0
* PURPOSE. Unless required by applicable law or agreed to in writing, software
* See the Mulan PSL v1 for more details. distributed under the License is distributed on an "AS IS" BASIS,
* Author: tanyifeng WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Create: 2018-11-08 See the License for the specific language governing permissions and
* Description: provide container read file definition limitations under the License.
****************************************************************************/ */
#ifndef __JSON_READ_FILE_H_ #ifndef __JSON_READ_FILE_H_
#define __JSON_READ_FILE_H_ #define __JSON_READ_FILE_H_

View File

@ -1,21 +1,24 @@
# -*- coding: utf-8 -*- # -*- 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 #!/usr/bin/python -Es
#
# libocispec - a C library for parsing OCI spec files.
#
# Copyright (C) 2017, 2019 Giuseppe Scrivano <giuseppe@scrivano.org>
# 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 <http://www.gnu.org/licenses/>.
#
import helpers import helpers

View File

@ -39,8 +39,7 @@ const char * const g_clibcni_log_prio_name[] = {
static __thread char *g_clibcni_log_prefix = NULL; static __thread char *g_clibcni_log_prefix = NULL;
static char *g_clibcni_log_vmname = NULL; static char *g_clibcni_log_module = NULL;
static bool g_clibcni_log_quiet = false;
static int g_clibcni_log_level = CLIBCNI_LOG_DEBUG; static int g_clibcni_log_level = CLIBCNI_LOG_DEBUG;
static int g_clibcni_log_driver = LOG_DRIVER_STDOUT; static int g_clibcni_log_driver = LOG_DRIVER_STDOUT;
int g_clibcni_log_fd = -1; 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 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); 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); const char *msg);
/* engine change str logdriver to enum */ /* engine change str logdriver to enum */
@ -156,7 +155,7 @@ static int do_check_log_configs(const struct clibcni_log_config *log)
return -1; 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) { if (invalid_arg) {
COMMAND_ERROR("Must set log file for driver %s", log->driver); COMMAND_ERROR("Must set log file for driver %s", log->driver);
return -1; return -1;
@ -185,10 +184,9 @@ int clibcni_log_enable(const struct clibcni_log_config *log)
return -1; return -1;
} }
free(g_clibcni_log_vmname); free(g_clibcni_log_module);
g_clibcni_log_vmname = util_strdup_s(log->name); g_clibcni_log_module = util_strdup_s(log->name);
g_clibcni_log_quiet = log->quiet;
full_path = util_strdup_s(log->file); full_path = util_strdup_s(log->file);
nret = util_build_dir(full_path); nret = util_build_dir(full_path);
@ -213,22 +211,19 @@ out:
return nret; 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) const char *date_time)
{ {
switch (g_clibcni_log_driver) { switch (g_clibcni_log_driver) {
case LOG_DRIVER_STDOUT: case LOG_DRIVER_STDOUT:
if (g_clibcni_log_quiet) { do_stderr_log(metadata, date_time, msg);
break;
}
log_append_stderr(metadata, date_time, msg);
break; break;
case LOG_DRIVER_FIFO: case LOG_DRIVER_FIFO:
if (g_clibcni_log_fd == -1) { if (g_clibcni_log_fd == -1) {
COMMAND_ERROR("Do not set log file\n"); COMMAND_ERROR("Do not set log file\n");
return -1; return -1;
} }
log_append_logfile(metadata, date_time, msg); do_fifo_log(metadata, date_time, msg);
break; break;
case LOG_DRIVER_NOSET: case LOG_DRIVER_NOSET:
break; break;
@ -243,7 +238,7 @@ static char *parse_timespec_to_human()
{ {
struct timespec timestamp; struct timespec timestamp;
struct tm ptm = {0}; struct tm ptm = {0};
char date_time[CLIBCNI_LOG_TIME_SIZE] = { 0 }; char date_time[CLIBCNI_LOG_TIME_STR_MAX_LEN] = { 0 };
int nret; int nret;
#define SEC_TO_NSEC 1000000 #define SEC_TO_NSEC 1000000
#define FIRST_YEAR_OF_GMT 1900 #define FIRST_YEAR_OF_GMT 1900
@ -258,11 +253,11 @@ static char *parse_timespec_to_human()
return NULL; 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, 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); 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"); COMMAND_ERROR("Sprintf failed");
return NULL; return NULL;
} }
@ -270,8 +265,8 @@ static char *parse_timespec_to_human()
return util_strdup_s(date_time); return util_strdup_s(date_time);
} }
/* use to append log to driver */ /* use to add log to driver */
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, ...)
{ {
int rc; int rc;
char msg[MAX_MSG_LENGTH] = { 0 }; char msg[MAX_MSG_LENGTH] = { 0 };
@ -294,7 +289,7 @@ int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const
goto out; goto out;
} }
ret = do_log_append_by_driver(metadata, msg, date_time); ret = do_log_by_driver(metadata, msg, date_time);
out: out:
free(date_time); 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 */ /* 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) const char *msg)
{ {
char log_buffer[CLIBCNI_LOG_BUFFER_SIZE] = { 0 }; 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; 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) { if (tmp_prefix != NULL && strlen(tmp_prefix) > MAX_LOG_PREFIX_LENGTH) {
tmp_prefix = tmp_prefix + (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 : "", 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], timestamp, g_clibcni_log_prio_name[metadata->level], metadata->file,
g_clibcni_log_vmname ? g_clibcni_log_vmname : "clibcni", metadata->file,
metadata->func, metadata->line, msg); metadata->func, metadata->line, msg);
if (nret < 0) { 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], tmp_prefix ? tmp_prefix : "", timestamp, g_clibcni_log_prio_name[metadata->level],
g_clibcni_log_vmname ? g_clibcni_log_vmname : "clibcni", metadata->file, metadata->file, metadata->func, metadata->line, "Large log message");
metadata->func, metadata->line, "Large log message");
if (nret < 0) { if (nret < 0) {
return; return;
} }
@ -359,7 +352,7 @@ static void log_append_logfile(const struct clibcni_log_object_metadata *metadat
} }
/* log append stderr */ /* 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) const char *msg)
{ {
char *tmp_prefix = NULL; char *tmp_prefix = NULL;
@ -367,12 +360,11 @@ static void log_append_stderr(const struct clibcni_log_object_metadata *metadata
return; 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) { if (tmp_prefix != NULL && strlen(tmp_prefix) > MAX_LOG_PREFIX_LENGTH) {
tmp_prefix = tmp_prefix + (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("%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:%s:%d - ", metadata->file, metadata->func, metadata->line);
COMMAND_ERROR("%s\n", msg); COMMAND_ERROR("%s\n", msg);
} }

View File

@ -26,22 +26,13 @@ extern "C" {
#define O_CLOEXEC 02000000 #define O_CLOEXEC 02000000
#endif #endif
#ifndef F_DUPFD_CLOEXEC
#define F_DUPFD_CLOEXEC 1030
#endif
#define CLIBCNI_LOG_BUFFER_SIZE 4096 #define CLIBCNI_LOG_BUFFER_SIZE 4096
/* We're logging in seconds and nanoseconds. Assuming that the underlying #define CLIBCNI_LOG_TIME_STR_MAX_LEN 21
* 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
enum clibcni_log_drivers { enum clibcni_log_drivers {
LOG_DRIVER_STDOUT, LOG_DRIVER_STDOUT,
LOG_DRIVER_FIFO, LOG_DRIVER_FIFO,
LOG_DRIVER_SYSLOG,
LOG_DRIVER_NOSET, LOG_DRIVER_NOSET,
}; };
@ -64,14 +55,8 @@ struct clibcni_log_config {
const char *priority; const char *priority;
const char *prefix; const char *prefix;
const char *driver; const char *driver;
bool quiet;
}; };
#define CLIBCNI_LOG_LOCINFO_INIT \
{ \
.file = __FILE__, .func = __func__, .line = __LINE__, \
}
/* brief logging event object */ /* brief logging event object */
struct clibcni_log_object_metadata { struct clibcni_log_object_metadata {
/* location information of the logging item */ /* location information of the logging item */
@ -88,13 +73,14 @@ void clibcni_set_log_prefix(const char *prefix);
void clibcni_free_log_prefix(void); 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, ...) \ #define COMMON_LOG(loglevel, format, ...) \
do { \ do { \
struct clibcni_log_object_metadata meta = CLIBCNI_LOG_LOCINFO_INIT; \ struct clibcni_log_object_metadata meta = { \
meta.level = loglevel; \ .file = __FILENAME__, .func = __func__, .line = __LINE__, .level = loglevel, \
(void)clibcni_log_append(&meta, format, ##__VA_ARGS__); \ }; \
(void)clibcni_log(&meta, format, ##__VA_ARGS__); \
} while (0) } while (0)
#define DEBUG(format, ...) \ #define DEBUG(format, ...) \
@ -135,4 +121,4 @@ int clibcni_log_append(const struct clibcni_log_object_metadata *metadata, const
} }
#endif #endif
#endif /* __LCR_LOG_H */ #endif /* __CLIBCNI_LOG_H */