Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to rotate snmpd.log

617 views
Skip to first unread message

madanagopal

unread,
Apr 6, 2004, 7:22:59 AM4/6/04
to
On Fri, 26 Mar 2004, madanagopal wrote:

> On Thu, 25 Mar 2004, Dave Shield wrote:
>
> > > /var/log/snmpd.log {
> > > rotate 10
> > > size=100
> > > postrotate
> > > /bin/kill -HUP `pidof snmpd 2> /dev/null` 2> /dev/null || true
> > > endscript
> > > }
> >
> > Throwing away error messages
> > <shudder>
> > I *hate* it when people do that!
> >
>
> Accepted. I simply copied whatever was there in /etc/logrotate.d/syslog
> and didn't care about ignoring errors.
>
> >
> > > Then, i executed the command "logrotate /etc/logrotate.d/snmpd" manually.
> > > This results in the file /var/log/snmpd.log.1 getting created with the
> > > line "netsnmp 5.1 restarted" at the end. But the file /var/log/snmpd.log
> > > is not there and further logging takes place still in the file
> > > /var/log/snmpd.log.1
> >
> > OK - a couple of things to try:
> >
> > pidof snmpd
> >
> > Does this give you the expected result?
> > I.e. the PID of the running snmpd agent?
> >
> > What about running
> >
> > /bin/kill -HUP {PID}
> >
> > manually (using the appropriate PID value, naturally!)
> > Does the agent start using the new log file then?
> >
>
> even if tried using /bin/kill -HUP {PID}
>
> /var/log/snmpd.log.1 is created and it contains the lines
>
> Reconfiguring daemon
> NET-SNMP version 5.1 restarted
>
> which means that the signal is properly received. But the problem is that
> further logging takes place in the file /var/log/snmpd.log.1 and
> /var/log/snmpd.log is not present. I think the old file handle(to the file
> /var/log/snmpd.log) is not closed and opened again so that further logging
> takes place once again in the file /var/log/snmpd.log
>
> Any help in this would be greatly appreciated. Thanks.
>

Going through the snmpd.c, i find the following call in the main()
function:

setup_log(0, dont_zero_log, stderr_log, syslog_log, logfile);

When the SIGHUP signal is sent to the agent it sets a variable reconfig to
1 and in the receive() function when this variable is set the following
call is executed:

setup_log(1, 0, 0, 0, NULL);

The following is the definition of the setup_log() function:

static void
setup_log(int restart, int dont_zero, int stderr_log, int syslog_log,
char *logfile)
{
static char logfile_s[PATH_MAX + 1] = { 0 };
static int dont_zero_s = 0;
static int stderr_log_s = 0;
static int syslog_log_s = 0;

if (restart == 0) {
if (logfile != NULL) {
strncpy(logfile_s, logfile, PATH_MAX);
}
dont_zero_s = dont_zero;
stderr_log_s = stderr_log;
syslog_log_s = syslog_log;
}

if (stderr_log_s) {
snmp_enable_stderrlog();
} else {
snmp_disable_stderrlog();
}

if (logfile_s[0]) {
snmp_enable_filelog(logfile_s, dont_zero_s);
}

if (syslog_log_s) {
snmp_enable_syslog_ident("snmpd", Facility);
}
}

In this function the local variable logfile_s contains the name of the log
file name in the first case(when the agent is started) and nothing in the
second case(when the agent is reconfigured using SIGHUP). Since this local
variable has nothing in the second case the file log enabling function is
not called. The following check is responsible for this:

if (logfile_s[0]) {
snmp_enable_filelog(logfile_s, dont_zero_s);
}

Is my analysis wrong or is this a problem? Thanks.

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
Net-snmp-coders mailing list
Net-snm...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Niels Baggesen

unread,
Apr 6, 2004, 2:51:42 PM4/6/04
to
On Tue, Apr 06, 2004 at 04:53:35PM +0530, madanagopal wrote:
> On Fri, 26 Mar 2004, madanagopal wrote:
> static void
> setup_log(int restart, int dont_zero, int stderr_log, int syslog_log,
> char *logfile)
> {
> static char logfile_s[PATH_MAX + 1] =3D { 0 };
[snip]
> if (restart =3D=3D 0) {
> if (logfile !=3D NULL) {
> strncpy(logfile_s, logfile, PATH_MAX);
> }
[snip]
> }
[snip]

> if (logfile_s[0]) {
> snmp_enable_filelog(logfile_s, dont_zero_s);
> }
>=20
> In this function the local variable logfile_s contains the name of the =
log=20
> file name in the first case(when the agent is started) and nothing in t=
he=20
> second case(when the agent is reconfigured using SIGHUP). Since this lo=
cal=20
> variable has nothing in the second case the file log enabling function =
is=20

> not called. The following check is responsible for this:
>=20

> if (logfile_s[0]) {
> snmp_enable_filelog(logfile_s, dont_zero_s);
> }
>=20

> Is my analysis wrong or is this a problem? Thanks.

First, note that logfile_s is declared static, which means that its
value from the first call survives to the second. Also note, that the
function only attempts to assign to it if restart=3D=3D0, so it should ha=
ve
the original value from the first call.

Your analysis is wrong.

/Niels

--=20
Niels Baggesen - @home - =C5rhus - Denmark - n...@users.sourceforge.net
The purpose of computing is insight, not numbers --- R W Hamming

0 new messages