Re: [evlog-dev] [Bug] [PATCH] daemon evlogd, evlnotifyd, evlactiond can be starte d more than once with scripts in /etc/rc.d/init.d/evl*

Hien Q Nguyen <[email protected]> Thu, 19 Dec 2002 09:24:51 -0800
Newsgroups gmane.linux.kernel.event-logging
Message-ID <[email protected]>



Hi all,

Oops, please disregard the my earlier message, it is still early in the
morning :-).
I understand the problem now. Yes, it is a bug.

Thanks, Hien.
Hien Nguyen
[email protected]
(503) 578-4347


|---------+-------------------------------------------->
|         |           "Zhu, Yi" <[email protected]>     |
|         |           Sent by:                         |
|         |           [email protected]|
|         |           ceforge.net                      |
|         |                                            |
|         |                                            |
|         |           12/19/2002 01:53 AM              |
|         |                                            |
|---------+-------------------------------------------->
  >-----------------------------------------------------------------------------------------------|
  |                                                                                               |
  |       To:       "'[email protected]'"                                    |
  |        <[email protected]>                                               |
  |       cc:                                                                                     |
  |       Subject:  [evlog-dev] [Bug] [PATCH] daemon evlogd, evlnotifyd, evlactiond can be starte |
  |        d more than once with scripts in /etc/rc.d/init.d/evl*                                 |
  |                                                                                               |
  |                                                                                               |
  >-----------------------------------------------------------------------------------------------|



Hi,

I found daemon evlogd can be started more than once using
"/etc/rc.d/init.d/evlog start". Though evlogd.c has some code to prevent
from being started more than once, the buggy script /etc/rc.d/init.d/evlog
makes the effort go to waste. It just deleted the pid file
/var/run/evlogd.pid everytime start() is called!

I fixed this bug in below patch. If it is not a redhat distribution, we can
get "Starting enterprise event logger: /sbin/evlogd: Already running.",
otherwise just "Starting enterprise event logger: " (without the green [ OK
]) because the daemon() prevent everything coming out.

The same thing happens for evlnotifyd, evlactiond but not evlogrmtd,
because
the second evlogrmtd cannot bind() successfully and exit. While the pid
file
/var/run/evlogrmtd.pid refers to wrong process id.


diff -Naur evlog/user/cmd/evlactiond/evlactiond.c
evlog-new/user/cmd/evlactiond/evlactiond.c
--- evlog/user/cmd/evlactiond/evlactiond.c             2002-08-10
01:17:54.000000000 +0800
+++ evlog-new/user/cmd/evlactiond/evlactiond.c         2002-12-19
17:28:35.000000000 +0800
@@ -408,11 +408,17 @@
  * RETURN         :
  *
  */
- void
- _daemonize()
- {
+void
+_daemonize()
+{
             pid_t pid;
             int num_fds, i;
+
+            if (_evlValidate_pid(PidFile)) {
+                        fprintf(stderr, "evlactiond: Already running.\n");
+                        exit(1);
+            }
+
             /*
              * Fork a child and let the parent exit. This guarentees that
              * the first child is not a process group leader.
@@ -440,7 +446,6 @@

             (void)signal(SIGHUP, SIG_IGN);

-
             if ((pid = fork()) < 0) {
                         fprintf(stderr,
                                                 "evlactiond: Cannot fork
child process.
Check system process usage.\n");
@@ -454,18 +459,13 @@
              * We allow only one instance of this process at a time.
              *
              */
-            if (!_evlValidate_pid(PidFile)) {
-                        if (!_evlUpdate_pid(PidFile)) {
+            if (!_evlUpdate_pid(PidFile)) {
 #if 0
-                                    LOGERROR(EVLOG_WRITE_PID, "evlactiond:
Cannot write
'evlactiond' PID to '%s' file\n",
-                                                            PidFile);
+                        LOGERROR(EVLOG_WRITE_PID, "evlactiond: Cannot
write
'evlactiond' PID to '%s' file\n",
+                                                PidFile);
 #endif
-                                    exit(1);
-                        }
-    } else {
-                        fprintf(stderr, "evlactiond: Already running.\n");
-                  exit(1);
-    }
+                        exit(1);
+            }

             /*
              * Clear any inherited file mode creation mask.
diff -Naur evlog/user/cmd/evlnotifyd/evlnotifyd.c
evlog-new/user/cmd/evlnotifyd/evlnotifyd.c
--- evlog/user/cmd/evlnotifyd/evlnotifyd.c             2002-12-16
10:35:12.000000000 +0800
+++ evlog-new/user/cmd/evlnotifyd/evlnotifyd.c         2002-12-19
16:34:45.000000000 +0800
@@ -351,6 +351,10 @@

             (void)signal(SIGHUP, SIG_IGN);

+            if (_evlValidate_pid(PidFile)) {
+                        fprintf(stderr, "evlnotifyd: Already running.\n");
+                        exit(1);
+            }

             if ((pid = fork()) < 0) {
                         fprintf(stderr,
@@ -365,18 +369,13 @@
              * We allow only one instance of this process at a time.
              *
              */
-            if (!_evlValidate_pid(PidFile)) {
-                        if (!_evlUpdate_pid(PidFile)) {
+            if (!_evlUpdate_pid(PidFile)) {
 #if 0
-                                    LOGERROR(EVLOG_WRITE_PID, "evlnotifyd:
Cannot write
'evlnotifyd' PID to '%s' file\n",
-                                                            PidFile);
+                        LOGERROR(EVLOG_WRITE_PID, "evlnotifyd: Cannot
write
'evlnotifyd' PID to '%s' file\n",
+                                                PidFile);
 #endif
-                                    exit(1);
-                        }
-    } else {
-                        fprintf(stderr, "evlnotifyd: Already running.\n");
-                  exit(1);
-    }
+                        exit(1);
+            }

             /*
              * Clear any inherited file mode creation mask.
diff -Naur evlog/user/cmd/evlogd/evlogd.c
evlog-new/user/cmd/evlogd/evlogd.c
--- evlog/user/cmd/evlogd/evlogd.c         2002-12-16 10:35:14.000000000
+0800
+++ evlog-new/user/cmd/evlogd/evlogd.c           2002-12-19
16:12:52.000000000 +0800
@@ -267,6 +267,10 @@
             for (i=0; i < SHMSZ; i++)
                         sharedData[i] = 0;

+            if (_evlValidate_pid(PidFile)) {
+                        fprintf(stdout, "%s: Already running.\n",
argv[0]);
+                        exit(1);
+            }
             if (bg) {
                         /*
                          * Fork a child and let the parent exit. This
guarentees
that
@@ -305,17 +309,12 @@
             }

             /* stuck my process id away */
-            if (!_evlValidate_pid(PidFile)) {
-                        if (!_evlUpdate_pid(PidFile)) {
-                                    mk_evl_rec(&evl_log, LOG_LOGMGMT,
EVLOG_WRITE_PID,
-
LOG_CRIT,"%s: Cannot write
'evlogd' PID to '%s' file\n",
-                                                               argv[0],
PidFile);
-                                    exit(1);
-                        }
-            } else {
-                        fprintf(stdout, "%s: Already running.\n",
argv[0]);
+            if (!_evlUpdate_pid(PidFile)) {
+                        mk_evl_rec(&evl_log, LOG_LOGMGMT, EVLOG_WRITE_PID,

+                                                   LOG_CRIT,"%s: Cannot
write 'evlogd' PID
to '%s' file\n",
+                                                   argv[0], PidFile);
                         exit(1);
-            }
+            }

             /*
              * Second child process.
diff -Naur evlog/user/cmd/evlogd/evlogrmtd.c
evlog-new/user/cmd/evlogd/evlogrmtd.c
--- evlog/user/cmd/evlogd/evlogrmtd.c            2002-12-13
06:06:14.000000000 +0800
+++ evlog-new/user/cmd/evlogd/evlogrmtd.c        2002-12-19
17:00:01.000000000 +0800
@@ -365,6 +365,10 @@

             (void)signal(SIGHUP, SIG_IGN);

+            if (_evlValidate_pid(PidFile)) {
+                        fprintf(stderr, "evlogrmtd: Already running.\n");
+                        exit(1);
+            }

             if ((pid = fork()) < 0) {
                         fprintf(stderr,
@@ -379,18 +383,13 @@
              * We allow only one instance of this process at a time.
              *
              */
-            if (!_evlValidate_pid(PidFile)) {
-                        if (!_evlUpdate_pid(PidFile)) {
+            if (!_evlUpdate_pid(PidFile)) {
 #if 0
-                                    LOGERROR(EVLOG_WRITE_PID, "evlogrmtd:
Cannot write
'evlogrmtd' PID to '%s' file\n",
-                                                             PidFile);
+                        LOGERROR(EVLOG_WRITE_PID, "evlogrmtd: Cannot write
'evlogrmtd' PID to '%s' file\n",
+                                                 PidFile);
 #endif
-                                    exit(1);
-                        }
-    } else {
-                        fprintf(stderr, "evlogrmtd: Already running.\n");
-                  exit(1);
-    }
+                        exit(1);
+            }

             /*
              * Clear any inherited file mode creation mask.
diff -Naur evlog/user/sysfiles/etc/init.d/evlaction
evlog-new/user/sysfiles/etc/init.d/evlaction
--- evlog/user/sysfiles/etc/init.d/evlaction           2002-12-16
10:35:29.000000000 +0800
+++ evlog-new/user/sysfiles/etc/init.d/evlaction             2002-12-19
17:32:27.
000000000 +0800
@@ -25,18 +25,12 @@
 start() {
             echo -n $"Starting notification action daemon: "

-            if [ -e /var/lock/subsys/evlaction ]
-            then
-                        # this means system not shutdown gracefully
-                        rm -f /var/run/evlactiond.pid
-            fi
-
             if [ ! -z "$REDHAT" ]
-            then
+            then
                         daemon /sbin/evlactiond
-    else
+            else
                         /sbin/evlactiond
-            fi
+            fi

             RETVAL=$?
             echo
@@ -45,10 +39,11 @@
 }
 stop() {
             echo -n $"Shutting down notification action daemon: "
+
             if [ ! -z "$REDHAT" ]
-            then
+            then
                         killproc evlactiond
-    else
+            else
                         PID=`ps -ef | grep evlactiond | grep -v grep | awk
'{print
$2}'`
                         if [ ! -z "$PID" ]
                         then
@@ -64,7 +59,7 @@
             then
                         rm -f /var/run/evlactiond.pid
             fi
-
+
             return $RETVAL
 }
 rhstatus() {
diff -Naur evlog/user/sysfiles/etc/init.d/evlnotify
evlog-new/user/sysfiles/etc/init.d/evlnotify
--- evlog/user/sysfiles/etc/init.d/evlnotify           2002-12-16
10:35:29.000000000 +0800
+++ evlog-new/user/sysfiles/etc/init.d/evlnotify             2002-12-19
17:32:57.
000000000 +0800
@@ -25,12 +25,6 @@
 start() {
             echo -n $"Starting enterprise event log notification: "

-            if [ -e /var/lock/subsys/evlnotify ]
-            then
-                        # this means system not shutdown gracefully
-                        rm -f /var/run/evlnotifyd.pid
-            fi
-
             if [ ! -z "$REDHAT" ]
             then
                         daemon /sbin/evlnotifyd
@@ -47,7 +41,7 @@
             echo -n $"Shutting down enterprise event log notification: "

             if [ ! -z "$REDHAT" ]
-            then
+            then
                         killproc evlnotifyd
             else
                         PID=`ps -ef | grep evlnotifyd | grep -v grep | awk
'{print
$2}'`
@@ -56,16 +50,16 @@
                                     kill -s SIGTERM $PID
                         fi
             fi
-
+
             RETVAL=$?
             echo
             rm -f /var/lock/subsys/evlnotify
-
+
             if [ -e /var/run/evlnotifyd.pid ]
             then
                         rm -f /var/run/evlnotifyd.pid
             fi
-
+
             return $RETVAL
 }
 rhstatus() {
diff -Naur evlog/user/sysfiles/etc/init.d/evlog
evlog-new/user/sysfiles/etc/init.d/evlog
--- evlog/user/sysfiles/etc/init.d/evlog         2002-12-16
10:35:29.000000000 +0800
+++ evlog-new/user/sysfiles/etc/init.d/evlog           2002-12-19
16:16:48.000000000 +0800
@@ -31,12 +31,6 @@
 start() {
             echo -n $"Starting enterprise event logger: "

-            if [ -e /var/lock/subsys/evlog ]
-            then
-                        # this means system not shutdown gracefully
-                        rm -f /var/run/evlogd.pid
-            fi
-
             record_last_recid /var/evlog/eventlog /var/evlog/bootrecid
             record_last_recid /var/evlog/privatelog /var/evlog/pbootrecid

diff -Naur evlog/user/sysfiles/etc/init.d/evlogrmt
evlog-new/user/sysfiles/etc/init.d/evlogrmt
--- evlog/user/sysfiles/etc/init.d/evlogrmt            2002-12-13
09:10:56.000000000 +0800
+++ evlog-new/user/sysfiles/etc/init.d/evlogrmt        2002-12-19
16:51:58.000000000 +0800
@@ -31,13 +31,6 @@
 start() {
             echo -n $"Starting remote event logger: "

-            if [ -e /var/lock/subsys/evlogrmt ]
-            then
-                        # this means system not shutdown gracefully
-                        rm -f /var/run/evlogrmtd.pid
-            fi
-
-
             if [ ! -z "$REDHAT" ]
             then
                         daemon /sbin/evlogrmtd


Thanks,
----------------------------------------------------------------------------

----------------------------------------------------
Opinions expressed are those of the author and do not represent Intel Corp.

Zhu Yi (Chuyee)
Intel China Software Lab (ICSL)
22nd Floor, ShanghaiMart Tower No. 2299 Yan'an Road(West) Shanghai 200336,
PRC
Tel: 8621-52574545-1261 Fax: 8621-62366119

GnuPG v1.0.6 (GNU/Linux)
http://cn.geocities.com/chewie_chuyee/gpg.txt
1024D/71C34820 C939 2B0B FBCE 1D51 109A  55E5 8650 DB90 71C3 4820


-------------------------------------------------------
This SF.NET email is sponsored by: Geek Gift Procrastinating?
Get the perfect geek gift now!  Before the Holidays pass you by.
T H I N K G E E K . C O M      http://www.thinkgeek.com/sf/
_______________________________________________
evlog-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/evlog-developers





-------------------------------------------------------
This SF.NET email is sponsored by: Geek Gift Procrastinating?
Get the perfect geek gift now!  Before the Holidays pass you by.
T H I N K G E E K . C O M      http://www.thinkgeek.com/sf/