public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/30563] New: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command
@ 2023-06-18 23:48 echron at yahoo dot com
  2023-06-19  0:01 ` [Bug libc/30563] " echron at yahoo dot com
  2023-06-19  7:46 ` schwab@linux-m68k.org
  0 siblings, 2 replies; 3+ messages in thread
From: echron at yahoo dot com @ 2023-06-18 23:48 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30563

            Bug ID: 30563
           Summary: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect
                    output for linux dmesg -r command
           Product: glibc
           Version: 2.39
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: echron at yahoo dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

dmesg -r: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output

Submission to Project: glibc
Component: libc
Header File: misc/sys/syslog.h (from /usr/include/sys/syslog.h)
Macro: LOG_MAKEPRI
BUG: Shift needed for or of syslog facility with loglevel priority fields

Using glibc source from: git://sourceware.org/git/glibc.git
Date of source pulled: 2023/06/18 16:00:45


Where is error seen? With the output from the linux dmesg -r command

In glibc file misc/sys/syslog.h the macro LOG_MAKEPRI is erronously
defined as:

    #define LOG_MAKEPRI(fac, pri) ((fac) | (pri)

and returns the wrong facility and loglevel priority values, it should
be defined as:

    #define LOG_MAKEPRI(fac, pri) ((fac) << 3 | (pri))

to return the correct raw value.

This macro is used by the linux utility program:
utils-linux/sys-utils/dmesg.c  when running with the raw option:

    dmesg -r

Adding 3 records to the dmesg buffer from linux user space by writing to
/dev/kmsg is accomplished like this:

    echo "<14> Test Message Facility 8 Logevel 6" >> /dev/kmsg
    echo "<15> Test Message Facility 8 Logevel 7" >> /dev/kmsg
    echo "<30> Test Message Facility 24 Loglevel 6" >> /dev/kmsg

these commands add 3 records to the dmesg buffer. Then when we print the
records using the dmesg command with the raw option:

Here is what dmesg erronously produces:
--------------------------------------
[echron@capistano syslog_raw]$ dmesg -r | grep "Test Message Facility"
<7>[1879346.077678]  Test Message Facility 8 LogLevel 6
<7>[1880050.125549]  Test Message Facility 8 LogLevel 7
<7>[1881313.244898]  Test Message Facility 24 LogLevel 6

However, if we run the dmesg -r command using the corrected LOG_MAKEPRI
macro we get the correct output:

Here is the corrected output:
----------------------------
[echron@capistano syslog_raw]$ dmesg -r | grep "Test Message Facility"
<14>[1879346.077678]  Test Message Facility 8 LogLevel 6
<15>[1880050.125549]  Test Message Facility 8 LogLevel 7
<30>[1881313.244898]  Test Message Facility 24 LogLevel 6

shifting the facility index value by 3 bits in the LOG_MAKEPRI macro
provides the correct ouput as shown.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libc/30563] misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command
  2023-06-18 23:48 [Bug libc/30563] New: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command echron at yahoo dot com
@ 2023-06-19  0:01 ` echron at yahoo dot com
  2023-06-19  7:46 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: echron at yahoo dot com @ 2023-06-19  0:01 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30563

--- Comment #1 from Edward Chron <echron at yahoo dot com> ---
Typo error in description, the corrected LOG_MAKEPRI should be:

    #define LOG_MAKEPRI(fac, pri) ((fac << 3) | (pri)) 

not:

    #define LOG_MAKEPRI(fac, pri) ((fac) << 3 | (pri))

The patch being submitted has the correct comment and the macro is correct.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libc/30563] misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command
  2023-06-18 23:48 [Bug libc/30563] New: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command echron at yahoo dot com
  2023-06-19  0:01 ` [Bug libc/30563] " echron at yahoo dot com
@ 2023-06-19  7:46 ` schwab@linux-m68k.org
  1 sibling, 0 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2023-06-19  7:46 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=30563

Andreas Schwab <schwab@linux-m68k.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |MOVED

--- Comment #2 from Andreas Schwab <schwab@linux-m68k.org> ---
LOG_MAKEPRI is correct.  It is supposed to be used with the predefined facility
macros, which are already correctly shifted.  Note that this is an almost
literal import from *BSD, see
<https://github.com/freebsd/freebsd-src/blob/main/sys/sys/syslog.h>.  Please
report that to the util-linux developer.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-19  7:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-18 23:48 [Bug libc/30563] New: misc/sys syslog.h macro LOG_MAKEPRI produces incorrect output for linux dmesg -r command echron at yahoo dot com
2023-06-19  0:01 ` [Bug libc/30563] " echron at yahoo dot com
2023-06-19  7:46 ` schwab@linux-m68k.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).