commit-hurd
[Top][All Lists]
Advanced

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

[hurd] 17/25: trans/crash: Fix setting core file template at runtime.


From: Samuel Thibault
Subject: [hurd] 17/25: trans/crash: Fix setting core file template at runtime.
Date: Mon, 24 Oct 2016 00:16:45 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 74998f9ded99c41d34c0db20e6eb7088fe51d742
Author: Justus Winter <address@hidden>
Date:   Wed Oct 5 10:45:08 2016 +0200

    trans/crash: Fix setting core file template at runtime.
    
    * trans/crash.c (corefile_template_lock): New variable.
    (S_crash_dump_task): Serialize access to 'corefile_template'.
    (parse_opt): Likewise.  Also strdup the template.
    (trivfs_append_args): Serialize access to 'corefile_template'.
---
 trans/crash.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/trans/crash.c b/trans/crash.c
index 0171cd7..f8e1658 100644
--- a/trans/crash.c
+++ b/trans/crash.c
@@ -30,6 +30,7 @@
 #include <argz.h>
 #include <sys/mman.h>
 #include <assert.h>
+#include <pthread.h>
 
 #include <version.h>
 
@@ -71,6 +72,7 @@ enum crash_action
 
 static enum crash_action crash_how, crash_orphans_how;
 static char *corefile_template;
+pthread_mutex_t corefile_template_lock = PTHREAD_MUTEX_INITIALIZER;
 
 
 
@@ -336,12 +338,15 @@ S_crash_dump_task (mach_port_t port,
       if (!err)
        {
          file_t sink = core_file;
+         pthread_mutex_lock (&corefile_template_lock);
          if (corefile_template)
            {
              char *file_name;
 
              file_name = template_make_file_name (corefile_template,
                                                   task, signo);
+             pthread_mutex_unlock (&corefile_template_lock);
+
              if (file_name == NULL)
                error (0, errno, "template_make_file_name");
              else
@@ -356,6 +361,8 @@ S_crash_dump_task (mach_port_t port,
                  free (file_name);
                }
            }
+         else
+           pthread_mutex_unlock (&corefile_template_lock);
 
          err = dump_core (task, sink,
                           (off_t) -1,  /* XXX should get core limit in RPC */
@@ -645,10 +652,21 @@ parse_opt (int opt, char *arg, struct argp_state *state)
            return EINVAL;
          }
       }
+      pthread_mutex_lock (&corefile_template_lock);
+      free (corefile_template);
       if (strlen (arg) == 0)
        corefile_template = NULL;
       else
-       corefile_template = arg;
+       {
+         corefile_template = strdup (arg);
+         if (corefile_template == NULL)
+           {
+             pthread_mutex_unlock (&corefile_template_lock);
+             argp_failure (state, 1, errno, "strdup");
+             return errno;
+           }
+       }
+      pthread_mutex_unlock (&corefile_template_lock);
       break;
 
     case ARGP_KEY_SUCCESS:
@@ -692,6 +710,7 @@ trivfs_append_args (struct trivfs_control *fsys,
       err = argz_add (argz, argz_len, opt);
     }
 
+  pthread_mutex_lock (&corefile_template_lock);
   if (!err && corefile_template)
     {
       char *template;
@@ -703,6 +722,7 @@ trivfs_append_args (struct trivfs_control *fsys,
          free (template);
        }
     }
+  pthread_mutex_unlock (&corefile_template_lock);
 
   return err;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

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