casaroli commented on code in PR #21128: URL: https://github.com/apache/nuttx/pull/21128#discussion_r4415942972
########## libs/libc/syslog/lib_openlog.c: ########## @@ -0,0 +1,123 @@ +/**************************************************************************** + * libs/libc/syslog/lib_openlog.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdbool.h> +#include <string.h> +#include <syslog.h> + +#include <nuttx/mutex.h> +#include <nuttx/tls.h> + +#include "syslog/syslog.h" + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +bool g_openlog_used; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +/* In the KERNEL build the data of libc is naturally process-specific. In + * the other builds each task group has its settings in its task_info_s. + */ + +static struct openlog_s g_openlog; Review Comment: Done. ########## libs/libc/syslog/lib_syslog.c: ########## @@ -27,12 +27,145 @@ #include <nuttx/config.h> #include <stdarg.h> +#include <stdio.h> +#include <string.h> #include <syslog.h> +#include <unistd.h> +#include <nuttx/lib/lib.h> +#include <nuttx/mutex.h> #include <nuttx/syslog/syslog.h> +#include <nuttx/tls.h> #include "syslog/syslog.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#if !defined(__KERNEL__) && defined(va_copy) +/**************************************************************************** + * Name: syslog_string + ****************************************************************************/ + +static void syslog_string(int priority, FAR const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + nx_vsyslog(priority, fmt, &ap); + va_end(ap); +} + +/**************************************************************************** + * Name: vsyslog_openlog + * + * Description: + * Send a message with the settings of openlog(): the ident and the + * process ID before it, and a copy to stderr with LOG_PERROR. The OS + * (__KERNEL__) does not use the settings of the processes. + * + * Returned Value: + * true if the message was sent, false if the caller must send it + * without the settings (none set, no memory, interrupt context). + * + ****************************************************************************/ + +static bool vsyslog_openlog(int priority, FAR const IPTR char *fmt, + va_list ap) +{ + FAR struct task_info_s *info = task_get_info(); + FAR struct openlog_s *state; + char prefix[OPENLOG_IDENT_SIZE + 16]; + FAR char *buf; + va_list copy; + size_t len; + bool sent = false; + int option; + int plen = 0; + int mlen; + + if (info == NULL +#ifdef CONFIG_BUILD_FLAT + || up_interrupt_context() || sched_idletask() +#endif + ) + { + return false; + } + + /* ol_busy: lib_malloc() or vsnprintf() can log too (CONFIG_DEBUG_MM): + * such a message goes out without the settings. + */ + + nxrmutex_lock(&info->ta_lock); Review Comment: Done. ########## libs/libc/syslog/lib_syslog.c: ########## @@ -27,12 +27,145 @@ #include <nuttx/config.h> #include <stdarg.h> +#include <stdio.h> +#include <string.h> #include <syslog.h> +#include <unistd.h> +#include <nuttx/lib/lib.h> +#include <nuttx/mutex.h> #include <nuttx/syslog/syslog.h> +#include <nuttx/tls.h> #include "syslog/syslog.h" +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#if !defined(__KERNEL__) && defined(va_copy) +/**************************************************************************** + * Name: syslog_string + ****************************************************************************/ + +static void syslog_string(int priority, FAR const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + nx_vsyslog(priority, fmt, &ap); + va_end(ap); +} + +/**************************************************************************** + * Name: vsyslog_openlog + * + * Description: + * Send a message with the settings of openlog(): the ident and the + * process ID before it, and a copy to stderr with LOG_PERROR. The OS + * (__KERNEL__) does not use the settings of the processes. + * + * Returned Value: + * true if the message was sent, false if the caller must send it + * without the settings (none set, no memory, interrupt context). + * + ****************************************************************************/ + +static bool vsyslog_openlog(int priority, FAR const IPTR char *fmt, Review Comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
