Skip to contentSkip to conversation

98syslog: try to dynamically check for rsyslog moddir

PATCH In review Andrey Borzenkov 3 participants 3 messages Sep 8, 2010 – Sep 10, 2010 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 98syslog: try to dynamically check for rsyslog moddir

Thomas pointed out that default module path may not be correct (Mandriva installs modules under architecture dependent path). Unfortunately rsyslog does not seem to offer any way to query for default configuration values. Here is rather hack - try to load non-existing module and fetch path from error message.

Example of error message from version 4.6.4:

rsyslogd: could not load module '/lib64/rsyslog/_No_sUcH_MOduLe.so', dlopen: /lib64/rsyslog/_No_sUcH_MOduLe.so: cannot open shared object file: No such file or directory

---

 modules.d/98syslog/install |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
modules.d/98syslog/install +16 -1
index 1fd1b6f..e3d02bf 100755
@@ -1,6 +1,21 @@
 #!/bin/sh
 if type -P rsyslogd >/dev/null; then
-	installs="rsyslogd /lib/rsyslog/lmnet.so /lib/rsyslog/imklog.so /lib/rsyslog/imuxsock.so"
+	# module path can be changed during build and currently rsyslog
+	# does not provide any means to query for it. Use hack - try to
+	# load non-existent module and look at error message
+	R_CONF=/tmp/dracut.rsyslog.conf.$$
+	R_ERR=/tmp/dracut.rsyslog.err.$$
+	R_MODDIR=
+	echo '$ModLoad _No_sUcH_MOduLe' > $R_CONF
+	if [ -s $R_CONF ]; then
+		rsyslogd -N 1 -f $R_CONF 2> $R_ERR > /dev/null
+		R_MODDIR=$(grep ' could not load module .*_No_sUcH_MOduLe' $R_ERR)
+		R_MODDIR=${R_MODDIR#*could not load module \'}
+		R_MODDIR=${R_MODDIR%\', *}
+		R_MODDIR=${R_MODDIR%/*}
+	fi
+	[ -n "$R_MODDIR" ] || R_MODDIR=/lib/rsyslog
+	installs="rsyslogd $R_MODDIR/lmnet.so $R_MODDIR/imklog.so $R_MODDIR/imuxsock.so"
 elif type -P syslogd >/dev/null; then
     installs="syslogd"
 elif type -P syslog-ng >/dev/null; then
#1 lore raw

Dnia 2010-09-08, o godz. 18:52:13
Andrey Borzenkov <arvidjaar-JGs/[email protected]> napisa³(a):

Quoted 47 lines

Thomas pointed out that default module path may not be correct (Mandriva installs modules under architecture dependent path). Unfortunately rsyslog does not seem to offer any way to query for default configuration values. Here is rather hack - try to load non-existing module and fetch path from error message.

Example of error message from version 4.6.4:

rsyslogd: could not load module '/lib64/rsyslog/_No_sUcH_MOduLe.so',
dlopen: /lib64/rsyslog/_No_sUcH_MOduLe.so: cannot open shared object
file: No such file or directory

---

 modules.d/98syslog/install |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)
modules.d/98syslog/install +0 -1
index 1fd1b6f..e3d02bf 100755
@@ -1,6 +1,21 @@
 #!/bin/sh
 if type -P rsyslogd >/dev/null; then
-

installs="rsyslogd /lib/rsyslog/lmnet.so /lib/rsyslog/imklog.so /lib/rsyslog/imuxsock.so"

modules.d/98syslog/install +1 -0
+	# module path can be changed during build and currently

rsyslog

modules.d/98syslog/install +1 -0
+	# does not provide any means to query for it. Use hack - try

to

modules.d/98syslog/install +8 -0
+	# load non-existent module and look at error message
+	R_CONF=/tmp/dracut.rsyslog.conf.$$
+	R_ERR=/tmp/dracut.rsyslog.err.$$
+	R_MODDIR=
+	echo '$ModLoad _No_sUcH_MOduLe' > $R_CONF
+	if [ -s $R_CONF ]; then
+		rsyslogd -N 1 -f $R_CONF 2> $R_ERR > /dev/null
+		R_MODDIR=$(grep ' could not load

module .*_No_sUcH_MOduLe' $R_ERR)

modules.d/98syslog/install +6 -0
+		R_MODDIR=${R_MODDIR#*could not load module \'}
+		R_MODDIR=${R_MODDIR%\', *}
+		R_MODDIR=${R_MODDIR%/*}
+	fi
+	[ -n "$R_MODDIR" ] || R_MODDIR=/lib/rsyslog
+	installs="rsyslogd $R_MODDIR/lmnet.so $R_MODDIR/imklog.so
Quoted 5 lines

$R_MODDIR/imuxsock.so" elif type -P syslogd >/dev/null; then
installs="syslogd"
elif type -P syslog-ng >/dev/null; then

Indeed this patch is more precise than my simplified one ;)

Signature · 5 lines
Regards
TPG

http://cia.vc/stats/author/tpg
---

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 49 lines · Tomasz Pawe³ Gajc

Dnia 2010-09-08, o godz. 18:52:13
Andrey Borzenkov<arvidjaar-JGs/[email protected]> napisa³(a):

Quoted 46 lines

Thomas pointed out that default module path may not be correct (Mandriva installs modules under architecture dependent path). Unfortunately rsyslog does not seem to offer any way to query for default configuration values. Here is rather hack - try to load non-existing module and fetch path from error message.

Example of error message from version 4.6.4:

rsyslogd: could not load module '/lib64/rsyslog/_No_sUcH_MOduLe.so',
dlopen: /lib64/rsyslog/_No_sUcH_MOduLe.so: cannot open shared object
file: No such file or directory

---

  modules.d/98syslog/install |   17 ++++++++++++++++-
  1 files changed, 16 insertions(+), 1 deletions(-)
modules.d/98syslog/install +0 -1
index 1fd1b6f..e3d02bf 100755
@@ -1,6 +1,21 @@
  #!/bin/sh
  if type -P rsyslogd>/dev/null; then
-

installs="rsyslogd /lib/rsyslog/lmnet.so /lib/rsyslog/imklog.so /lib/rsyslog/imuxsock.so"

modules.d/98syslog/install +1 -0
+	# module path can be changed during build and currently

rsyslog

modules.d/98syslog/install +1 -0
+	# does not provide any means to query for it. Use hack - try

to

modules.d/98syslog/install +8 -0
+	# load non-existent module and look at error message
+	R_CONF=/tmp/dracut.rsyslog.conf.$$
+	R_ERR=/tmp/dracut.rsyslog.err.$$
+	R_MODDIR=
+	echo '$ModLoad _No_sUcH_MOduLe'>  $R_CONF
+	if [ -s $R_CONF ]; then
+		rsyslogd -N 1 -f $R_CONF 2>  $R_ERR>  /dev/null
+		R_MODDIR=$(grep ' could not load

module .*_No_sUcH_MOduLe' $R_ERR)

modules.d/98syslog/install +5 -0
+		R_MODDIR=${R_MODDIR#*could not load module \'}
+		R_MODDIR=${R_MODDIR%\', *}
+		R_MODDIR=${R_MODDIR%/*}
+	fi
+	[ -n "$R_MODDIR" ] || R_MODDIR=/lib/rsyslog
Quoted 9 lines
Quoted 6 lines
modules.d/98syslog/install +1 -0
+	installs="rsyslogd $R_MODDIR/lmnet.so $R_MODDIR/imklog.so

$R_MODDIR/imuxsock.so" elif type -P syslogd>/dev/null; then
installs="syslogd"
elif type -P syslog-ng>/dev/null; then

Indeed this patch is more precise than my simplified one ;)

ugly hack :-/ plus you want mktemp to prevent attacks..