tinnedkarma commented on code in PR #16493: URL: https://github.com/apache/nuttx/pull/16493#discussion_r2137189292
########## drivers/syslog/vsyslog_rfc5424.c: ########## @@ -0,0 +1,262 @@ +/**************************************************************************** + * drivers/syslog/vsyslog_rfc5424.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 <errno.h> +#include <stdio.h> +#include <syslog.h> + +#include <nuttx/arch.h> +#include <nuttx/clock.h> +#include <nuttx/init.h> +#include <nuttx/streams.h> +#include <nuttx/syslog/syslog.h> + +#include "syslog.h" + +/**************************************************************************** + * Preprocessor definitions + ****************************************************************************/ + +/* Get logging severity level from priority */ + +#define SEVERITY(prio) ((prio) & 0x7) + +/* Get logging facility from priority */ + +#define FACILITY(prio) (((prio) & (~0x7)) >> 3) + +/* RFC5424 NILVALUE encoding */ + +#define NILVALUE "-" +#define NILVALUE_SPACE NILVALUE " " + +/* RFC5424 timestamp format string (fractional seconds and 'Z' added by + * appending to format string) + */ + +#define RFC_STRFTIME "%Y-%m-%dT%H:%M:%S" + +/* RFC5424 structured data options were selected */ + +#if defined(CONFIG_SYSLOG_RFC5424_TIMEQUALITY) +#define HAVE_RFC5424_SDATA 1 +#else +#define HAVE_RFC5424_SDATA 0 +#endif /* defined(CONFIG_SYSLOG_RFC5424_TIMEQUALITY) || ... */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_vsyslog + * + * Description: + * nx_vsyslog() handles the system logging system calls. It is functionally + * equivalent to vsyslog() except that (1) the per-process priority + * filtering has already been performed and the va_list parameter is + * passed by reference. That is because the va_list is a structure in + * some compilers and passing of structures in the NuttX sycalls does + * not work. + * + ****************************************************************************/ + +int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) +{ + struct lib_syslograwstream_s stream; + int ret = 0; +#ifdef CONFIG_SYSLOG_PROCESS_NAME + FAR struct tcb_s *tcb = nxsched_self(); +#endif +#ifdef CONFIG_SYSLOG_TIMESTAMP + struct timespec ts; + struct tm tm; + char date_buf[64]; +#endif +#ifdef CONFIG_SYSLOG_RFC5424_HOSTNAME + char hostname_buf[HOST_NAME_MAX + 1]; +#endif + + /* Wrap the low-level output in a stream object and let lib_vsprintf + * do the work. + */ + + lib_syslograwstream_open(&stream); + +#ifdef CONFIG_SYSLOG_TIMESTAMP + ts.tv_sec = 0; + ts.tv_nsec = 0; + + memset(&tm, 0, sizeof(tm)); Review Comment: Small hint here. Using memset over structs may have some caveats, NuttX supports 8 to 32 bit architectures, so types will have different widths (int on atmega is 16bit while on stm32 is 32bit). Compiler optimization for speed also alters the size of the structs. Also, memset is "handled" at runtime, less compile time checks. My point is, for simple zero-initialization is safer to use `struct tm tm = {0}` (this will work only at declaration), it gets more compile time checks and will yield same behavior. -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org