>Thanks.

> Would you kindly send a unified diff (preferably against CVS)?

I've applied my patch with adjustments for differences in the CVS
version, however I'm unable to test it; autoconf falls over
with this:
--
configure.ac:27: error: possibly undefined macro: AM_INIT_AUTOMAKE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:29: error: possibly undefined macro: AM_MAINTAINER_MODE
configure.ac:34: error: possibly undefined macro: AC_PROG_LIBTOOL
configure.ac:324: error: possibly undefined macro: AM_CONDITIONAL
--
both on Fedora FC11 (autoconf-2.63.2) and on Solaris 9 (with autoconf-2.65)

I've spent a bit of time trying to figure this out to no avail;
I'm not an expert in any way with autoconf.

Lots of similar complaints on google, with nothing obvious.

I'm attaching the patch anyway; can somebody else see if its ok perhaps
with an older autoconf.

Ian D
diff -ru mbuni-CVS/configure.ac mbuni-CVS+patch/configure.ac
--- mbuni-CVS/configure.ac      2009-07-02 07:08:11.000000000 +0000
+++ mbuni-CVS+patch/configure.ac        2009-12-08 07:14:50.155011000 +0000
@@ -71,7 +71,7 @@
 EXE_EXT=""
 LIB_EXT="a"
 case "$host" in
-  *-sun-solaris* | *SunOS*) 
+  *-sun-solaris* | *-pc-solaris* | *SunOS*) 
     CFLAGS="$CFLAGS -DSunOS=1 -D_POSIX_PTHREAD_SEMANTICS"
     ;;
   *-cygwin*)
diff -ru mbuni-CVS/mmlib/mms_mmbox.c mbuni-CVS+patch/mmlib/mms_mmbox.c
--- mbuni-CVS/mmlib/mms_mmbox.c 2008-09-04 17:20:14.000000000 +0000
+++ mbuni-CVS+patch/mmlib/mms_mmbox.c   2009-12-08 07:15:08.285394000 +0000
@@ -178,7 +178,7 @@
          if (fd >= 0 && 
              mm_lockfile(fd,ctmp,1) != 0) {
               unlink(ctmp);
-              close(fd);
+              unlock_and_close(fd);
               fd = -1;
          }
          octstr_destroy(tmp);
@@ -202,7 +202,7 @@
                     fbuf, strerror(errno));
               break;
          }  else if (mm_lockfile(fd, fbuf, shouldblock) != 0) {          
-              close(fd);
+              unlock_and_close(fd);
               fd = -1;
          }
      while (i++ < MAXTRIES && fd < 0);
@@ -272,7 +272,7 @@
          mms_error(0, "mmbox", NULL,"Failed lock  temp file %s: error = %s\n", 
                     fbuf, strerror(errno));
 
-         close(tempfd);
+         unlock_and_close(tempfd);
          tempfd = -1;
          goto done;
          
@@ -284,7 +284,7 @@
                
                fbuf, strerror(errno));
                  
-         close(tempfd);
+         unlock_and_close(tempfd);
          tempfd = -1;
          goto done;
      }
@@ -434,9 +434,9 @@
      octstr_replace(sdf, octstr_imm("/"), octstr_imm("-"));
  done:
      if (dfd > 0) 
-         close(dfd);
+         unlock_and_close(dfd);
      if (ifd > 0) 
-         close(ifd);
+         unlock_and_close(ifd);
 
      if (s)
          octstr_destroy(s);
@@ -513,7 +513,7 @@
      s = mms_tobinary(m);
      msize = octstr_len(s);
 
-     octstr_write_to_socket(tmpfd, s);    
+     octstr_write_to_socket(tmpfd, s);
 
      rename(octstr_get_cstr(ftmp), octstr_get_cstr(fname));
      close(tmpfd);
@@ -529,7 +529,7 @@
 
  done:
      if (ifd > 0) 
-         close(ifd);
+         unlock_and_close(ifd);
 
      if (fname)
          octstr_destroy(fname);
@@ -588,7 +588,7 @@
      res = 0;
  done:
      if (ifd > 0) 
-         close(ifd);
+         unlock_and_close(ifd);
 
      if (fname)
          octstr_destroy(fname);
@@ -708,7 +708,7 @@
          close(tmpfd);
      
      if (ifd > 0)
-         close(ifd);
+         unlock_and_close(ifd);
 
      if (flags)
          gwlist_destroy(flags, (gwlist_item_destructor_t *)octstr_destroy);    
 
@@ -748,7 +748,7 @@
          *msize = 0;
  done:
      if (ifd > 0) 
-         close(ifd);
+         unlock_and_close(ifd);
 
      if (fname)
          octstr_destroy(fname);
@@ -805,7 +805,7 @@
          close(tmpfd);
      
      if (ifd > 0)
-         close(ifd);
+         unlock_and_close(ifd);
 
      return ret;
 }
diff -ru mbuni-CVS/mmlib/mms_queue.c mbuni-CVS+patch/mmlib/mms_queue.c
--- mbuni-CVS/mmlib/mms_queue.c 2008-12-24 19:00:30.000000000 +0000
+++ mbuni-CVS+patch/mmlib/mms_queue.c   2009-12-08 07:15:08.315396000 +0000
@@ -21,8 +21,8 @@
 #include <ctype.h>
 #ifdef SunOS
 #include <strings.h>
-#include <fcntl.h>
 #endif
+#include <fcntl.h>
 #include <dirent.h>
 
 #include "mms_queue.h"
@@ -563,10 +563,10 @@
               mms_error(0,  "mms_queue", NULL, "Failed to rename %s to %s: 
error = %s\n", 
                     octstr_get_cstr(qfname), octstr_get_cstr(tfname), 
strerror(errno));
 
-              close(fd); /* Close new one, keep old one. */
+              unlock_and_close(fd); /* Close new one, keep old one. */
               res = -1;                
          } else { /* On success, new descriptor replaces old one and we close 
old one. */
-              close(qfs->fd);
+              unlock_and_close(qfs->fd);
               qfs->fd = fd;
          }
          octstr_destroy(qfname);
@@ -630,7 +630,7 @@
          if (fd >= 0 && 
              mm_lockfile(fd,ctmp,1) != 0) {
               unlink(ctmp);
-              close(fd);
+              unlock_and_close(fd);
               fd = -1;
          }
          octstr_destroy(tmp);
@@ -659,7 +659,7 @@
      dfname = octstr_format("%s/%s%s", mms_queuedir, subdir, df);
 
      fd = open(octstr_get_cstr(dfname), 
-              O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);        
+              O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
      if (fd < 0) {
          mms_error(0,  "mms_queue", NULL, "Failed to open data file %s: error 
= %s\n",
                octstr_get_cstr(dfname), strerror(errno));
@@ -804,7 +804,7 @@
          snprintf(fname, -1 + sizeof fname, "%s/%s%s", qfs->dir, qfs->subdir, 
qfs->name); 
          unlink(fname);          
      }
-     close(qfs->fd); /* close and unlock now that we have deleted it. */
+     unlock_and_close(qfs->fd); /* close and unlock now that we have deleted 
it. */
 
      mms_queue_free_envelope(e);
 
diff -ru mbuni-CVS/mmlib/mms_util.c mbuni-CVS+patch/mmlib/mms_util.c
--- mbuni-CVS/mmlib/mms_util.c  2009-03-05 04:15:38.000000000 +0000
+++ mbuni-CVS+patch/mmlib/mms_util.c    2009-12-08 07:15:08.355398000 +0000
@@ -20,7 +20,10 @@
 
 #ifdef SunOS
 #include <fcntl.h>
+#include <pthread.h>
+#include <sys/types.h>
 #endif
+#include <sys/stat.h>
 
 #include <errno.h>
 #include <sys/types.h>
@@ -913,25 +916,199 @@
 }
 
 
-static int lockfile(int fd, int shouldblock)
+/* Compare a file_lock(lhs) to the file_key(rhs)
+   and see if they match
+*/
+int file_lock_inode_cmp(void *_lhs, void *_rhs);
+
+/* Each file gets a condition, there is only a single file_loc
+   for each inode number.  Assumes a uni
+*/
+typedef struct {
+    dev_t dev;
+    ino_t inode;
+} file_key;
+
+typedef struct {
+    file_key key;
+    pthread_cond_t condition;
+    int fd;
+} file_lock;
+
+static List *openFileList = NULL;
+static pthread_mutex_t listMutex = PTHREAD_MUTEX_INITIALIZER;
+
+void release_file_lock(int fd, file_key *key) {
+    debug("mm_util",0,"----->Locked");
+    pthread_mutex_lock(&listMutex);
+
+    if (openFileList == NULL) {
+        openFileList = (List *)gwlist_create();
+    }
+    
+    file_lock *item = (file_lock*)gwlist_search(openFileList, key, 
file_lock_inode_cmp);
+    if (item && item->fd == fd) {
+        /* we own the lock */
+        gwlist_delete_equal(openFileList, item);
+        pthread_cond_broadcast(&item->condition);
+        pthread_cond_destroy(&item->condition);
+        gw_free(item);
+    }
+    debug("mm_util",0,"<-----UnLocked");
+    pthread_mutex_unlock(&listMutex);
+}
+
+int unlock_and_close(int fd) {
+#ifdef SunOS
+    struct stat buf;
+    if (fstat(fd, &buf)) {
+        perror("Unable to fstat file for lock");
+        return close(fd);
+    }
+
+    file_key key;
+    key.inode = buf.st_ino;
+    key.dev   = buf.st_dev;
+    
+    release_file_lock(fd, &key);
+#endif
+
+    return close(fd);
+}
+
+int unlock_and_fclose(FILE *fp) {
+#ifdef SunOS
+    int   fd = fileno(fp);
+    struct stat buf;
+    if (fstat(fd, &buf)) {
+        perror("Unable to fstat file for lock");
+        return fclose(fp);
+    }
+
+    file_key key;
+    key.inode = buf.st_ino;
+    key.dev   = buf.st_dev;
+
+    release_file_lock(fd, &key);
+#endif
+    return fclose(fp);
+}
+
+/* Compare a file_lock(lhs) to the file_key(rhs)
+   and see if they match
+*/
+int file_lock_inode_cmp(void *_lhs, void *_rhs) {
+    file_key *rhs = (file_key*)_rhs;
+    file_lock *lhs = (file_lock *)_lhs;
+
+    return (
+            lhs && 
+            lhs->key.inode == rhs->inode && 
+            lhs->key.dev   == rhs->dev
+            );
+}
+
+int sun_lockfile(int fd, int shouldblock)
 {
-     int n, stop;     
 #ifdef SunOS
-     int flg = shouldblock ? F_SETLKW : F_SETLK;
-     flock_t lock;
+    int n, stop;     
+    int flg = shouldblock ? F_SETLKW : F_SETLK;
+    flock_t lock;
+
+    struct stat buf;
+    if (fstat(fd, &buf)) {
+       int e = errno;
+        perror("Unable to fstat file for lock");
+       errno = e;
+       return(-1);
+    }
+
+    file_key key;
+    key.inode = buf.st_ino;
+    key.dev   = buf.st_dev;
+    
+    debug("mm_util",0,"----->Locked");
+    pthread_mutex_lock(&listMutex);
+    
+    if (openFileList == NULL) {
+        openFileList = (List *)gwlist_create();
+    }
+
+    /* See if the inode exists in the list */
+    file_lock *item = NULL;
+    do {
+        item = (file_lock*)gwlist_search(openFileList, &key, 
file_lock_inode_cmp);
+        if (item) {
+            /* It exists, that means that someone has already locked the file 
*/
+            if (!shouldblock) {
+                n = -1;
+                debug("mm_util",0,"<-----UnLocked");
+                pthread_mutex_unlock(&listMutex);
+                errno = EWOULDBLOCK;
+                return n;
+            }
+            
+            pthread_cond_wait(&item->condition, &listMutex);
+            /* O.k. we've got the file, but now item is invalid, 
+               the unlock_and_close removes it.
+            */
+        } 
+    } while (item != NULL);
+
+    /* No one else has locked the file, create the condition for 
+       anyone else. 
+    */
+    item = (file_lock*)gw_malloc(sizeof(file_lock));
+    item->key.inode = key.inode;
+    item->key.dev = key.dev;
+    item->fd = fd;
+    pthread_cond_init(&item->condition, NULL);
+    gwlist_append(openFileList, item);
+
+    /* Release the global lock so that we don't block the 
+       entire system waiting for fnctl to return
+    */
+    debug("mm_util",0,"<-----UnLocked");
+    pthread_mutex_unlock(&listMutex);
+
+    do {
+        lock.l_whence = SEEK_SET;
+        lock.l_start = 0;
+        lock.l_len = 0;
+        lock.l_type = F_WRLCK;
+        n = fcntl(fd, flg, &lock);
+        if (n < 0) {
+           if (errno == EINTR)
+                stop = 0;
+           else
+                stop = 1;
+        } else     
+           stop = 1;
+    } while (!stop);
+
+    /* If we failed to get the fcntl lock, then we need to 
+       release the local lock */
+    if (n != 0) {
+        release_file_lock(fd, &key);
+    }
+
+    return (n == 0) ? 0 : errno; 
+#else
+    panic(0, "Attempt to call sun_lockfile on a non-solaris system");
+#endif
+}
+
+int lockfile(int fd, int shouldblock)
+{
+#ifdef SunOS
+     return sun_lockfile(fd, shouldblock);
 #else 
+     int n, stop;     
      unsigned flg = shouldblock ? 0 : LOCK_NB;
-#endif
+
      do {
-#ifdef SunOS
-         lock.l_whence = SEEK_SET;
-         lock.l_start = 0;
-         lock.l_len = 0;
-         lock.l_type = F_WRLCK;
-         n = fcntl(fd, flg, &lock);
-#else
          n = flock(fd, LOCK_EX|flg);
-#endif
+
        if (n < 0) {
            if (errno == EINTR)
                 stop = 0;
@@ -942,6 +1119,7 @@
      } while (!stop);
      
      return (n == 0) ? 0 : errno; 
+#endif
 }
 
 static int check_lock(int fd, char *fname)
@@ -969,6 +1147,12 @@
 {
      int ret = lockfile(fd,shouldblock);
 
+     if (ret && errno != EWOULDBLOCK) {
+         debug("mm_util", 0, "Unable to lock '%s', error= %d, %s, 
shouldblock=%d", 
+               fname, errno, strerror(errno), shouldblock);
+         perror("Unable to lock file");
+     }
+
      if (ret != 0 || 
         (ret = check_lock(fd,fname)) != 0)
          return ret;     
diff -ru mbuni-CVS/mmlib/mms_util.h mbuni-CVS+patch/mmlib/mms_util.h
--- mbuni-CVS/mmlib/mms_util.h  2009-02-16 07:30:53.000000000 +0000
+++ mbuni-CVS+patch/mmlib/mms_util.h    2009-12-08 07:15:08.375399000 +0000
@@ -147,6 +147,13 @@
 /* Returns true if the character is printable or space */
 int _mms_gw_isprint(int c);
 
+int lockfile(int fd, int shouldblock);
+/*
+ * unlock_and_fclose/unlock_and_close are wrappers around fclose/close
+ * needed to maintain the state of the global list on Solaris.
+ */
+int unlock_and_fclose(FILE *fp);
+int unlock_and_close(int fd);
 /* Special form of cfg_get which returns zero-length string when there is 
nothing. */
 Octstr *_mms_cfg_getx(mCfg *cfg, mCfgGrp *grp, Octstr *item);
 
diff -ru mbuni-CVS/mmsbox/dlr.c mbuni-CVS+patch/mmsbox/dlr.c
--- mbuni-CVS/mmsbox/dlr.c      2008-09-13 06:37:23.000000000 +0000
+++ mbuni-CVS+patch/mmsbox/dlr.c        2009-12-08 07:21:29.683428000 +0000
@@ -72,7 +72,7 @@
                      p, strerror(errno));
                break;
           }  else if (mm_lockfile(fd, p, 1) != 0) {          
-               close(fd);
+               unlock_and_close(fd);
                fd = -1;
           }
      while (i++ < MAXTRIES && fd < 0);
@@ -92,7 +92,7 @@
      if (fd >= 0) {
          Octstr *x = octstr_format("%S %S", transid ? transid : 
octstr_imm("x"), dlr_url); /* better have no spaces in transid! */
          octstr_write_data(x, fd, 0);
-         close(fd);
+         unlock_and_close(fd);
          octstr_destroy(x);
      }     
 }
@@ -106,7 +106,7 @@
          Octstr *s  = octstr_read_pipe(f);
          int i, ret;
          
-         fclose(f);
+         unlock_and_fclose(f);
          if (s && octstr_len(s) == 0) {
               ret = -1;
          } else if ((i = octstr_search_char(s, ' ', 0)) >= 0) {
@@ -118,7 +118,7 @@
          octstr_destroy(s);
          return ret;
      } else if (fd >= 0)
-         close(fd);
+         unlock_and_close(fd);
      return -1;
 }
 
@@ -132,6 +132,6 @@
          octstr_destroy(fname);
      }
      if (fd >= 0)
-         close(fd);   
+         unlock_and_close(fd);   
 
 }
diff -ru mbuni-CVS/mmsbox/mmsbox.c mbuni-CVS+patch/mmsbox/mmsbox.c
--- mbuni-CVS/mmsbox/mmsbox.c   2009-06-23 05:14:22.000000000 +0000
+++ mbuni-CVS+patch/mmsbox/mmsbox.c     2009-12-08 07:15:08.435404000 +0000
@@ -759,7 +759,18 @@
      mms_info(0,  "mmsbox", NULL," " MM_NAME " MMSBox  version %s starting", 
MMSC_VERSION);
      
      
+#ifdef SA_RESTART
+     {
+            struct sigaction nact;
+
+            memset(&nact, 0, sizeof(nact));
+            nact.sa_handler = relog_now;
+            nact.sa_flags = SA_RESTART;
+            sigaction(SIGHUP, &nact, (struct sigaction *)0);
+     }
+#else
      signal(SIGHUP, relog_now);
+#endif
      signal(SIGTERM, quit_now);
      signal(SIGINT,  quit_now);   
      signal(SIGPIPE,SIG_IGN); /* Ignore pipe errors. They kill us sometimes 
for nothing*/
diff -ru mbuni-CVS/mmsc/mms_billing_shell.c 
mbuni-CVS+patch/mmsc/mms_billing_shell.c
--- mbuni-CVS/mmsc/mms_billing_shell.c  2009-12-07 01:28:50.307702000 +0000
+++ mbuni-CVS+patch/mmsc/mms_billing_shell.c    2009-12-08 07:15:08.455402000 
+0000
@@ -12,6 +12,7 @@
  */
 #include <stdio.h>
 #include <stdlib.h>
+#include <wait.h>
 
 #include <sys/wait.h>
 
diff -ru mbuni-CVS/mmsc/mmsc.c mbuni-CVS+patch/mmsc/mmsc.c
--- mbuni-CVS/mmsc/mmsc.c       2009-02-16 07:30:53.000000000 +0000
+++ mbuni-CVS+patch/mmsc/mmsc.c 2009-12-08 07:24:14.276895000 +0000
@@ -60,7 +60,18 @@
          panic(0, "No MMSC configuration!");
 
 
+#ifdef SA_RESTART
+     {
+           struct sigaction nact;
+
+           memset(&nact, 0, sizeof(nact));
+           nact.sa_handler = relog_now;
+           nact.sa_flags = SA_RESTART;
+           sigaction(SIGHUP, &nact, (struct sigaction *)0);
+     }
+#else
      signal(SIGHUP, relog_now);
+#endif
      signal(SIGTERM, quit_now);
      signal(SIGINT,  quit_now);   
      signal(SIGPIPE,SIG_IGN); /* Ignore pipe errors. They kill us sometimes 
for no reason*/
_______________________________________________
Devel mailing list
Devel@mbuni.org
http://lists.mbuni.org/mailman/listinfo/devel

Reply via email to