mkinitrd unification across distributions
 help / color / mirror / Atom feed
* [PATCH 1/9] dracut-logger: 'user' facility for build-time and 'daemon' for boot-time
@ 2011-03-25 14:56 Amadeusz Żołnowski
       [not found] ` <1301065012-16356-1-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Amadeusz Żołnowski @ 2011-03-25 14:56 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA; +Cc: Amadeusz Żołnowski

---
 dracut-logger |   66 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/dracut-logger b/dracut-logger
index ce7dbd0..7bd2a7c 100755
--- a/dracut-logger
+++ b/dracut-logger
@@ -76,9 +76,11 @@ __DRACUT_LOGGER__=1
 #   - @var kmsgloglvl - logging level to /dev/kmsg (only for boot-time)
 #   - @var logfile - log file which is used when @var fileloglvl is higher
 #   than 0
-# and one global variable @var maxloglvl which <b>must not</b> be overwritten.
-# @var maxloglvl is set by dlog_init() and holds maximum logging level of those
-# three and indicates that dlog_init() was run.
+# and two global variables: @var maxloglvl and @var syslogfacility which <b>must
+# not</b> be overwritten. Both are set by dlog_init(). @var maxloglvl holds
+# maximum logging level of those three and indicates that dlog_init() was run.
+# @var syslogfacility is set either to 'user' (when building initramfs) or
+# 'daemon' (when booting).
 #
 # Logging level set by the variable means that messages from this logging level
 # and above (FATAL is the highest) will be shown. Logging levels may be set
@@ -101,8 +103,8 @@ __DRACUT_LOGGER__=1
 #   - @var kmsgloglvl = 0 (no logging)
 #   set to 0
 #
-# @warning Function sets global variable @var maxloglvl. See file doc for
-# details.
+# @warning Function sets global variables @var maxloglvl and @syslogfacility.
+# See file doc comment for details.
 dlog_init() {
     # Skip initialization if it's already done.
     [ -n "$maxloglvl" ] && return 0
@@ -144,6 +146,15 @@ dlog_init() {
         fi
     fi
 
+    if [ $sysloglvl -gt 0 -o $kmsgloglvl -gt 0 ]; then
+        if [ -n "$dracutbasedir" ]; then
+            readonly syslogfacility=user
+        else
+            readonly syslogfacility=daemon
+        fi
+        export syslogfacility
+    fi
+
     local lvl; local maxloglvl_l=0
     for lvl in $stdloglvl $sysloglvl $fileloglvl $kmsgloglvl; do
         [ $lvl -gt $maxloglvl_l ] && maxloglvl_l=$lvl
@@ -180,7 +191,8 @@ _lvl2char() {
 # @retval 1 if @a lvl is out of range.
 # @retval 0 if @a lvl is correct.
 # @result Echoes logger priority.
-_lvl2syslogpri() {
+_lvl2syspri() {
+    printf $syslogfacility.
     case "$1" in
         1) echo crit;;
         2) echo error;;
@@ -192,7 +204,7 @@ _lvl2syslogpri() {
     esac
 }
 
-## @brief Converts dracut-logger numeric level to kernel console log level
+## @brief Converts dracut-logger numeric level to syslog log level
 #
 # @param lvl Numeric logging level in range from 1 to 6.
 # @retval 1 if @a lvl is out of range.
@@ -202,26 +214,32 @@ _lvl2syslogpri() {
 # Conversion is done as follows:
 #
 # <tt>
-#   none     -> KERN_EMERG (0)
-#   FATAL(1) -> KERN_ALERT (1)
-#   none     -> KERN_CRIT (2)
-#   ERROR(2) -> KERN_ERR (3)
-#   WARN(3)  -> KERN_WARNING (4)
-#   none     -> KERN_NOTICE (5)
-#   INFO(4)  -> KERN_INFO (6)
-#   DEBUG(5) -> KERN_DEBUG (7)
+#   FATAL(1) -> LOG_EMERG (0)
+#   none     -> LOG_ALERT (1)
+#   none     -> LOG_CRIT (2)
+#   ERROR(2) -> LOG_ERR (3)
+#   WARN(3)  -> LOG_WARNING (4)
+#   none     -> LOG_NOTICE (5)
+#   INFO(4)  -> LOG_INFO (6)
+#   DEBUG(5) -> LOG_DEBUG (7)
 #   TRACE(6) /
 # </tt>
-_dlvl2klvl() {
+#
+# @see /usr/include/sys/syslog.h
+_dlvl2syslvl() {
+    local lvl
+
     case "$1" in
-        1) echo 1;;
-        2) echo 3;;
-        3) echo 4;;
-        4) echo 6;;
-        5) echo 7;;
-        6) echo 7;;
+        1) lvl=0;;
+        2) lvl=3;;
+        3) lvl=4;;
+        4) lvl=6;;
+        5) lvl=7;;
+        6) lvl=7;;
         *) return 1;;
     esac
+
+    [ "$syslogfacility" = user ] && echo $((8+$lvl)) || echo $((24+$lvl))
 }
 
 ## @brief Prints to stderr and/or writes to file, to syslog and/or /dev/kmsg
@@ -261,13 +279,13 @@ _do_dlog() {
 
     [ $lvl -le $stdloglvl ] && echo "$msg" >&2
     if [ $lvl -le $sysloglvl ]; then
-        logger -t "dracut[$$]" -p $(_lvl2syslogpri $lvl) "$msg"
+        logger -t "dracut[$$]" -p $(_lvl2syspri $lvl) "$msg"
     fi
     if [ $lvl -le $fileloglvl -a -w "$logfile" -a -f "$logfile" ]; then
         echo "$msg" >>"$logfile"
     fi
     [ $lvl -le $kmsgloglvl ] && \
-        echo "<$(_dlvl2klvl $lvl)>dracut[$$] $msg" >/dev/kmsg
+        echo "<$(_dlvl2syslvl $lvl)>dracut[$$] $msg" >/dev/kmsg
 }
 
 ## @brief Internal helper function for _do_dlog()
-- 
1.7.4.1

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

end of thread, other threads:[~2011-03-28  9:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 14:56 [PATCH 1/9] dracut-logger: 'user' facility for build-time and 'daemon' for boot-time Amadeusz Żołnowski
     [not found] ` <1301065012-16356-1-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56   ` [PATCH 2/9] dracut: when stdloglvl not set defaulted to 0 - should be 4 Amadeusz Żołnowski
     [not found]     ` <1301065012-16356-2-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56       ` [PATCH 3/9] dracut-functions: code formatting corrected Amadeusz Żołnowski
     [not found]         ` <1301065012-16356-3-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56           ` [PATCH 4/9] dracut-functions: logging functions adjusted to dracut-logger Amadeusz Żołnowski
     [not found]             ` <1301065012-16356-4-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56               ` [PATCH 5/9] modules.d: " Amadeusz Żołnowski
     [not found]                 ` <1301065012-16356-5-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56                   ` [PATCH 6/9] 40network: install dhclient, brctl and ifenslave optionally Amadeusz Żołnowski
     [not found]                     ` <1301065012-16356-6-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56                       ` [PATCH 7/9] dracut-logger: /dev/log is socket, not character device Amadeusz Żołnowski
     [not found]                         ` <1301065012-16356-7-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56                           ` [PATCH 8/9] dracut: new option: -M, --show-modules - lists modules on build Amadeusz Żołnowski
     [not found]                             ` <1301065012-16356-8-git-send-email-aidecoe-2qtfh70TtYba5EbDDlwbIw@public.gmane.org>
2011-03-25 14:56                               ` [PATCH 9/9] dracut.conf.5.xml, dracut.8.xml: logging options and -M documented Amadeusz Żołnowski
2011-03-25 15:30                       ` [PATCH 6/9] 40network: install dhclient, brctl and ifenslave optionally Seewer Philippe
     [not found]                         ` <4D8CB520.60504-omB+W0Dpw2o@public.gmane.org>
2011-03-28  9:40                           ` Amadeusz Żołnowski
2011-03-28  9:51                             ` Seewer Philippe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox