casaroli commented on code in PR #21128:
URL: https://github.com/apache/nuttx/pull/21128#discussion_r4431468601
##########
drivers/syslog/syslog.h:
##########
@@ -53,6 +59,58 @@ const
#endif
g_syslog_channel[CONFIG_SYSLOG_MAX_CHANNELS];
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: syslog_add_openlog
+ *
+ * Description:
+ * Output the ident that the task group set with openlog() and, with
+ * LOG_PID, its process ID: "ident: " or "ident[pid]: ". The caller is
+ * in a syslog() call of that task group, so its task information is in
+ * memory. openlog() does not lock out this reader: the ident is read up
+ * to its maximum length. Nothing in an interrupt handler.
+ *
+ ****************************************************************************/
+
+static inline int syslog_add_openlog(FAR struct lib_outstream_s *stream)
+{
+ FAR struct task_info_s *info;
+ FAR struct tcb_s *tcb;
+ int option;
+
+ if (up_interrupt_context())
+ {
+ return 0;
+ }
+
+ tcb = nxsched_self();
+ if (tcb == NULL || tcb->group == NULL || tcb->group->tg_info == NULL)
+ {
+ return 0;
+ }
+
+ info = tcb->group->tg_info;
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PID) != 0)
Review Comment:
Done.
##########
drivers/syslog/vsyslog.c:
##########
Review Comment:
Done.
##########
drivers/syslog/vsyslog_rfc5424.c:
##########
@@ -106,6 +106,10 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR
va_list *ap)
char hostname_buf[HOST_NAME_MAX + 1];
#endif
+ bool ident = (priority & SYSLOG_OPENLOG) != 0;
Review Comment:
Done.
##########
libs/libc/syslog/lib_syslog.c:
##########
@@ -27,12 +27,89 @@
#include <nuttx/config.h>
#include <stdarg.h>
+#include <stdio.h>
#include <syslog.h>
+#include <unistd.h>
#include <nuttx/syslog/syslog.h>
+#include <nuttx/tls.h>
#include "syslog/syslog.h"
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* A message of a program: the OS adds the ident of openlog() */
+
+#ifdef __KERNEL__
+# define VSYSLOG_FLAGS 0
+#else
+# define VSYSLOG_FLAGS SYSLOG_OPENLOG
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#if !defined(__KERNEL__) && defined(va_copy)
+/****************************************************************************
+ * Name: vsyslog_perror
+ *
+ * Description:
+ * With LOG_PERROR of openlog(), write the message to stderr too, with the
+ * ident and the process ID before it and a newline after it.
+ *
+ ****************************************************************************/
+
+static void vsyslog_perror(FAR const IPTR char *fmt, va_list ap)
+{
+ FAR struct task_info_s *info = task_get_info();
+ FAR const IPTR char *end;
+ va_list copy;
+ int option;
+
+ if (info == NULL
+#ifdef CONFIG_BUILD_FLAT
+ || up_interrupt_context()
+#endif
+ )
+ {
+ return;
+ }
+
+ option = info->ta_openlog.ol_option;
+ if ((option & LOG_PERROR) == 0)
Review Comment:
With `LOG_PERROR`, glibc and musl write only `ident[pid]: message` to
stderr. The syslog header (timestamp, CPU, priority, color codes) in stderr
would change what the program and its scripts read there.
--
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]