]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bsys.c
Move bnet_despool() into class in bsock.c
[bacula/bacula] / bacula / src / lib / bsys.c
index c35dde977061e5309dcd36e1e6cd5c0520597b86..b869d51d1c2ebd8acaf63d67c72d37f8d77bff31 100644 (file)
@@ -1,16 +1,7 @@
-/*
- * Miscellaneous Bacula memory and thread safe routines
- *   Generally, these are interfaces to system or standard
- *   library routines.
- *
- *  Bacula utility functions are in util.c
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
-
+/*
+ * Miscellaneous Bacula memory and thread safe routines
+ *   Generally, these are interfaces to system or standard
+ *   library routines.
+ *
+ *  Bacula utility functions are in util.c
+ *
+ *   Version $Id$
+ */
 
 #include "bacula.h"
 #ifdef HAVE_PWD_H
@@ -233,9 +232,6 @@ void bfree(void *buf)
 #endif
 }
 
-
-
-
 void *brealloc (void *buf, size_t size)
 {
    buf = realloc(buf, size);
@@ -471,8 +467,18 @@ void create_pid_file(char *dir, const char *progname, int port)
            sscanf(pidbuf, "%d", &oldpid) != 1) {
          Emsg2(M_ERROR_TERM, 0, _("Cannot open pid file. %s ERR=%s\n"), fname, strerror(errno));
       }
-      /* See if other Bacula is still alive */
-      if (kill(oldpid, 0) != -1 || errno != ESRCH) {
+      /* Some OSes (IRIX) don't bother to clean out the old pid files after a crash, and
+       * since they use a deterministic algorithm for assigning PIDs, we can have
+       * pid conflicts with the old PID file after a reboot.
+       * The intent the following code is to check if the oldpid read from the pid
+       * file is the same as the currently executing process's pid,
+       * and if oldpid == getpid(), skip the attempt to
+       * kill(oldpid,0), since the attempt is guaranteed to succeed,
+       * but the success won't actually mean that there is an
+       * another Bacula process already running.
+       * For more details see bug #797.
+       */
+       if ((oldpid != (int)getpid()) && (kill(oldpid, 0) != -1 || errno != ESRCH)) {
          Emsg3(M_ERROR_TERM, 0, _("%s is already running. pid=%d\nCheck file %s\n"),
                progname, oldpid, fname);
       }
@@ -776,4 +782,3 @@ char *escape_filename(const char *file_path)
 
    return escaped_path;
 }
-