commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-346-ga8001bb


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-346-ga8001bb
Date: Sun, 16 Jan 2011 15:54:52 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=a8001bb2e4684d7144e9a2217704e8f6635c5603

The branch, master has been updated
       via  a8001bb2e4684d7144e9a2217704e8f6635c5603 (commit)
      from  ec0d5f94acb17be7357a6a819a706189b02cf2da (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a8001bb2e4684d7144e9a2217704e8f6635c5603
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun Jan 16 17:49:34 2011 +0200

    Add useful debugging hooks.
    
    * libmailutils/diag/bt.c: New file.
    * libmailutils/diag/wd.c: New file.
    * libmailutils/diag/Makefile.am (libdiag_la_SOURCES): Add bt.c and wd.c
    
    * include/mailutils/debug.h (mu_gdb_bt, mu_wd): New protos.
    * include/mailutils/util.h (mu_getmaxfd): New protos.
    * libmailutils/base/getmaxfd.c: New file.
    * libmailutils/base/Makefile.am (libbase_la_SOURCES): Add getmaxfd.c
    
    * libmailutils/server/acl.c: Use mu_getmaxfd.
    * libmailutils/stream/prog_stream.c: Likewise.
    * mh/mh_whatnow.c: Likewise.
    
    * libmu_scm/mu_body.c (mu-body?): Bugfix.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/debug.h                    |    9 ++-
 include/mailutils/util.h                     |    1 +
 libmailutils/base/Makefile.am                |    1 +
 libmailutils/{url/flag.c => base/getmaxfd.c} |   30 +++++-----
 libmailutils/diag/Makefile.am                |    4 +-
 libmailutils/diag/bt.c                       |   87 ++++++++++++++++++++++++++
 libmailutils/diag/wd.c                       |   69 ++++++++++++++++++++
 libmailutils/server/acl.c                    |   11 +---
 libmailutils/stream/prog_stream.c            |   10 +---
 libmu_scm/mu_body.c                          |    2 +-
 mh/mh_whatnow.c                              |   10 +---
 11 files changed, 188 insertions(+), 46 deletions(-)
 copy libmailutils/{url/flag.c => base/getmaxfd.c} (66%)
 create mode 100644 libmailutils/diag/bt.c
 create mode 100644 libmailutils/diag/wd.c

diff --git a/include/mailutils/debug.h b/include/mailutils/debug.h
index 1b18c8d..4c7b930 100644
--- a/include/mailutils/debug.h
+++ b/include/mailutils/debug.h
@@ -83,7 +83,6 @@ void mu_debug_log_begin (const char *fmt, ...) 
MU_PRINTFLIKE(1,2);
 void mu_debug_log_cont (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_end (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_nl (void);
-
   
   
 #define MU_ASSERT(expr)                                                \
@@ -115,7 +114,13 @@ void mu_debug_log_nl (void);
          mu_debug_log s;                                                \
       }                                                                  \
   while (0)
- 
+
+  /* Debugging hooks. */
+  /* Dump a stack trace and terminate the program. */
+void mu_gdb_bt (void);
+  /* Sleep till attached to by gdb. */
+void mu_wd (unsigned to);
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index b8027bc..3ea257f 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -177,6 +177,7 @@ int mu_getpass (mu_stream_t in, mu_stream_t out, const char 
*prompt,
   /* ----------------------- */
   /* Assorted functions.     */
   /* ----------------------- */
+int mu_getmaxfd (void);
 /* Get the host name, doing a gethostbyname() if possible. */
 int mu_get_host_name (char **host);
 int mu_spawnvp (const char *prog, char *av[], int *stat);
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index acb6b62..592eb7c 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -31,6 +31,7 @@ libbase_la_SOURCES = \
  filename.c\
  freeitem.c\
  getcwd.c\
+ getmaxfd.c\
  getpass.c\
  hostname.c\
  iterator.c\
diff --git a/libmailutils/url/flag.c b/libmailutils/base/getmaxfd.c
similarity index 66%
copy from libmailutils/url/flag.c
copy to libmailutils/base/getmaxfd.c
index 586c881..b905ac8 100644
--- a/libmailutils/url/flag.c
+++ b/libmailutils/base/getmaxfd.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -19,22 +19,22 @@
 # include <config.h>
 #endif
 
-#include <errno.h>
-#include <mailutils/sys/url.h>
+#include <unistd.h>
+#include <limits.h>
 
-int
-mu_url_get_flags (mu_url_t url, int *pf)
-{
-  if (!url || !pf)
-    return EINVAL;
-  *pf = url->flags;
-  return 0;
-}
+#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
+# define __getmaxfd() sysconf (_SC_OPEN_MAX)
+#elif defined (HAVE_GETDTABLESIZE)
+# define __getmaxfd() getdtablesize ()
+#elif defined OPEN_MAX
+# define __getmaxfd() OPEN_MAX
+#else
+# define __getmaxfd() 256
+#endif
 
 int
-mu_url_has_flag (mu_url_t url, int flags)
+mu_getmaxfd ()
 {
-  if (!url)
-    return 0;
-  return url->flags & flags;
+  return __getmaxfd ();
 }
+
diff --git a/libmailutils/diag/Makefile.am b/libmailutils/diag/Makefile.am
index 93c1fce..ba5a715 100644
--- a/libmailutils/diag/Makefile.am
+++ b/libmailutils/diag/Makefile.am
@@ -18,11 +18,13 @@
 noinst_LTLIBRARIES = libdiag.la
 
 libdiag_la_SOURCES = \
+ bt.c\
  debug.c\
  diag.c\
  muerror.c\
  muerrno.c\
- syslog.c
+ syslog.c\
+ wd.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
 
diff --git a/libmailutils/diag/bt.c b/libmailutils/diag/bt.c
new file mode 100644
index 0000000..6bdae8b
--- /dev/null
+++ b/libmailutils/diag/bt.c
@@ -0,0 +1,87 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <argp.h>
+#include <mailutils/util.h>
+
+/* Dump a stack trace and terminate current program.
+
+   The trace is written to file /tmp/mailutils.PROG.PID, where PROG
+   is the file name of the program, and PID its PID. */
+   
+void
+mu_gdb_bt ()
+{
+  int i;
+  pid_t master_pid = getpid ();
+  pid_t pid;
+  static char buf[1024];
+  static char fname[1024];
+  char *p;
+  int fd;
+  char *argv[8];
+  
+  p = strrchr (program_invocation_name, '/');
+  if (p)
+    p++;
+  else
+    p = program_invocation_name;
+  sprintf (fname, "/tmp/mailutils.%s.%lu", p, (unsigned long) master_pid);
+  
+  pid = fork ();
+  if (pid == (pid_t)-1)
+    abort ();
+  if (pid)
+    {
+      sleep (10);
+      abort ();
+    }
+
+  for (i = mu_getmaxfd (); i >= 0; i--)
+    close (i);
+
+  fd = open (fname, O_WRONLY|O_CREAT, 0600);
+  if (fd == -1)
+    abort ();
+
+  dup2 (fd, 1);
+  dup2 (fd, 2);
+  close (fd);
+  
+  argv[0] = "/usr/bin/gdb";
+  argv[1] = program_invocation_name;
+  sprintf (buf, "%lu", (unsigned long) master_pid);
+  argv[2] = buf;
+  argv[3] = "-ex";
+  argv[4] = "bt";
+  argv[5] = "-ex";
+  argv[6] = "kill";
+  argv[7] = NULL;
+
+  execvp (argv[0], argv);
+  abort ();
+}
+
diff --git a/libmailutils/diag/wd.c b/libmailutils/diag/wd.c
new file mode 100644
index 0000000..9b78c12
--- /dev/null
+++ b/libmailutils/diag/wd.c
@@ -0,0 +1,69 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <argp.h>
+#include <mailutils/diag.h>
+
+/* A debugging hook.
+
+   Suspend execution to let the developer to attach to the current process
+   using gdb.
+
+   Wait at most TO seconds.  If TO is 0, wait forever. */
+
+void
+mu_wd (unsigned to)
+{
+  unsigned volatile _count_down;
+  pid_t pid = getpid ();
+
+  if (to)
+    mu_diag_output (MU_DIAG_CRIT,
+                   "process %lu is waiting for debug (%u seconds left)",
+                   (unsigned long) pid, to);
+  else
+    mu_diag_output (MU_DIAG_CRIT,
+                   "process %lu is waiting for debug",
+                   (unsigned long) pid);
+  mu_diag_output (MU_DIAG_CRIT,
+                 "to attach: gdb -ex 'set variable mu_wd::_count_down=0' %s 
%lu",
+                 program_invocation_name, (unsigned long) pid);
+  if (to)
+    {
+      _count_down = to;
+      while (_count_down)
+       {
+         sleep (1);
+         _count_down--;
+       }
+    }
+  else
+    {
+      _count_down = 1;
+      while (_count_down)
+       {
+         sleep (1);
+       }
+    }
+  mu_diag_output (MU_DIAG_CRIT, "process %lu finished waiting",
+                 (unsigned long) pid);
+}
diff --git a/libmailutils/server/acl.c b/libmailutils/server/acl.c
index 1b6b01b..b7f508a 100644
--- a/libmailutils/server/acl.c
+++ b/libmailutils/server/acl.c
@@ -39,6 +39,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/kwd.h>
 #include <mailutils/io.h>
+#include <mailutils/util.h>
 
 struct _mu_acl_entry
 {
@@ -473,14 +474,6 @@ struct run_closure
   mu_acl_result_t *result;
 };
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 #define SEQ(s, n, l) \
   (((l) == (sizeof(s) - 1)) && memcmp (s, n, l) == 0)
 
@@ -604,7 +597,7 @@ spawn_prog (const char *cmdline, int *pstatus, struct 
run_closure *rp)
          _exit (127);
        }
       
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
        close (i);
       execvp (ws.ws_wordv[0], ws.ws_wordv);
       _exit (127);
diff --git a/libmailutils/stream/prog_stream.c 
b/libmailutils/stream/prog_stream.c
index 2718be6..2f4e94a 100644
--- a/libmailutils/stream/prog_stream.c
+++ b/libmailutils/stream/prog_stream.c
@@ -60,14 +60,6 @@ _prog_stream_unregister (struct _mu_prog_stream *stream)
 
 
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 #define REDIRECT_STDIN_P(f) ((f) & MU_STREAM_WRITE)
 #define REDIRECT_STDOUT_P(f) ((f) & MU_STREAM_READ)
 
@@ -260,7 +252,7 @@ start_program_filter (int *p, struct _mu_prog_stream *fs, 
int flags)
        }
        
       /* Close unneded descripitors */
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
        close (i);
 
       /*FIXME: Switch to other uid/gid if desired */
diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c
index 8dbe42c..8add9b5 100644
--- a/libmu_scm/mu_body.c
+++ b/libmu_scm/mu_body.c
@@ -100,7 +100,7 @@ SCM_DEFINE_PUBLIC (scm_mu_body_p, "mu-body?", 1, 0, 0,
 "Return @code{true} if @var{scm} is a Mailutils message body object.\n")
 #define FUNC_NAME s_scm_mu_body_p
 {
-  return mu_scm_is_body (scm);
+  return scm_from_bool (mu_scm_is_body (scm));
 }
 #undef FUNC_NAME
 
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index ca9bbdc..85a13d6 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -17,14 +17,6 @@
 
 #include <mh.h>
 
-#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
-# define getmaxfd() sysconf (_SC_OPEN_MAX)
-#elif defined (HAVE_GETDTABLESIZE)
-# define getmaxfd() getdtablesize ()
-#else
-# define getmaxfd() 64
-#endif
-
 typedef int (*handler_fp) (struct mh_whatnow_env *wh,
                           int argc, char **argv,
                           int *status);
@@ -620,7 +612,7 @@ mh_whatnowproc (struct mh_whatnow_env *wh, int 
initial_edit, const char *prog)
       
       set_default_editor (wh);
       mh_whatnow_env_to_environ (wh);
-      for (i = getmaxfd (); i > 2; i--)
+      for (i = mu_getmaxfd (); i > 2; i--)
        close (i);
       execvp (ws.ws_wordv[0], ws.ws_wordv);
       mu_diag_funcall (MU_DIAG_ERROR, "execvp", prog, errno);


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]