[glick2] add more conditional tracing



commit a942222d26c96fe673784c7835a90b1416f9570b
Author: Stefan Sauer <ensonic users sf net>
Date:   Mon Oct 17 13:35:41 2011 +0200

    add more conditional tracing

 fs.c     |   12 +++++++++---
 helper.c |   15 +++++++++++++++
 runner.c |   26 ++++++++++++++++++++++++--
 3 files changed, 48 insertions(+), 5 deletions(-)
---
diff --git a/fs.c b/fs.c
index 8c24c2f..a8ff47e 100644
--- a/fs.c
+++ b/fs.c
@@ -3133,6 +3133,7 @@ main_loop (struct fuse_session *se)
   bundle_dir = g_build_filename (g_get_home_dir (), ".local", BUNDLES_DIR, NULL);
   add_public_dir (bundle_dir);
 
+  __debug__(("run main loop\n"));
   g_main_loop_run (mainloop);
 
   fuse_session_reset (se);
@@ -3273,6 +3274,7 @@ main (int argc, char *argv[])
 #endif
     }
 
+  __debug__(("starting\n"));
   if ((ch = fuse_mount (glick_mountpoint, NULL)) != NULL)
     {
       struct fuse_session *se;
@@ -3284,19 +3286,22 @@ main (int argc, char *argv[])
 	  int sync_pipe[2];
 	  pid_t pid;
 	  char c = 'x';
-	  struct sockaddr_un local;
+	  struct sockaddr_un local = {0, };
 	  int len;
+	  int res;
 
 	  fuse_session_add_chan (se, ch);
 
-	  pipe (sync_pipe);
+	  res == pipe (sync_pipe);
+	  if (res == -1)
+	    perror ("pipe");
+
 	  master_socket_ready_pipe = sync_pipe[0];
 	  master_socket = socket (AF_UNIX, SOCK_SEQPACKET, 0);
 
 	  pid = fork ();
 	  if (pid == 0) {
 	    char *socket_path;
-	    int res;
 
 	    close (sync_pipe[0]);
 
@@ -3321,6 +3326,7 @@ main (int argc, char *argv[])
 	  }
 	  close (sync_pipe[1]);
 
+          __debug__(("setup main loop\n"));
 	  err = main_loop (se);
 	  fuse_session_remove_chan (ch);
 
diff --git a/helper.c b/helper.c
index 63d2190..4d86e18 100644
--- a/helper.c
+++ b/helper.c
@@ -9,6 +9,12 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#if 0
+#define __debug__(x) g_print x
+#else
+#define __debug__(x)
+#endif
+
 char *
 strconcat (const char *s1,
 	   const char *s2,
@@ -102,12 +108,14 @@ main (int argc,
       argv_offset += 2;
     }
 
+  __debug__(("creating new namespace\n"));
   res = unshare (CLONE_NEWNS);
   if (res != 0) {
     perror ("Creating new namespace failed");
     return 1;
   }
 
+  __debug__(("mount bundle (private)\n"));
   mount_count = 0;
   res = mount (BUNDLE_PREFIX, BUNDLE_PREFIX,
 	       NULL, MS_PRIVATE, NULL);
@@ -115,12 +123,14 @@ main (int argc,
     /* Maybe if failed because there is no mount
        to be made private at that point, letsa
        add a bind mount there. */
+    __debug__(("mount bundle (bind)\n"));
     res = mount (BUNDLE_PREFIX, BUNDLE_PREFIX,
 		 NULL, MS_BIND, NULL);
     /* And try again */
     if (res == 0)
       {
 	mount_count++; /* Bind mount succeeded */
+        __debug__(("mount bundle (private)\n"));
 	res = mount (BUNDLE_PREFIX, BUNDLE_PREFIX,
 		     NULL, MS_PRIVATE, NULL);
       }
@@ -133,8 +143,11 @@ main (int argc,
 
   if (extra_mount_source != NULL)
     {
+      __debug__(("mount extra source (private)\n"));
       mount (extra_mount_source, extra_mount_source,
 	     NULL, MS_PRIVATE, NULL);
+
+      __debug__(("mount extra source (bind)\n"));
       res = mount (extra_mount_source, extra_mount_source,
 		   NULL, MS_BIND, NULL);
       if (res != 0) {
@@ -144,6 +157,7 @@ main (int argc,
       mount_count++; /* Extra mount succeeded */
     }
 
+  __debug__(("mount source\n"));
   res = mount (mount_source, BUNDLE_PREFIX,
 	       NULL, MS_BIND, NULL);
   if (res != 0) {
@@ -190,6 +204,7 @@ main (int argc,
 
   update_env_var_list ("LD_LIBRARY_PATH", BUNDLE_PREFIX "/lib");
 
+  __debug__(("launch executable\n"));
   return execv (executable, child_argv);
 
  oom:
diff --git a/runner.c b/runner.c
index 12bdc68..7a96329 100644
--- a/runner.c
+++ b/runner.c
@@ -22,6 +22,12 @@
 #include "glick.h"
 #include "format.h"
 
+#if 0
+#define __debug__(x) g_print x
+#else
+#define __debug__(x)
+#endif
+
 static void
 dummy_getattr (fuse_req_t req, fuse_ino_t ino,
 	       struct fuse_file_info *fi)
@@ -123,6 +129,7 @@ run_dummy_fs (char *argv0,
     0
   };
 
+  __debug__(("mounting client fs at %s\n", mountpoint));
   /* Mount the filesystem */
   fuse_args.argv[0] = argv0;
   if ((ch = fuse_mount (mountpoint, &fuse_args)) != NULL)
@@ -137,19 +144,23 @@ run_dummy_fs (char *argv0,
 	    {
 	      fuse_session_add_chan (se, ch);
 
+              __debug__(("mounted client fs\n"));
 	      /* Mounted the filesystem, tell the parent */
 	      wrote_ok = 1;
 	      write (mounted_signal_fd, &c_ok, 1);
 	      close (mounted_signal_fd);
 
+              __debug__(("waiting until we can unmount\n"));
 	      /* Wait for the parent to bind mount the filesystem into
 	       * its own namespace */
 	      res = read (wait_to_unmount_fd, &b, 1);
 
+              __debug__(("unmount client fs\n"));
 	      /* Unmount the fuse filesystem in the global namespace
 	       * so that it will be auto-unmounted when the namespace dies */
 	      unmount_fuse_fs (mountpoint);
 
+              __debug__(("run fuse session loop\n"));
 	      /* Handle the fuse calls */
 	      err = fuse_session_loop (se);
 	      fuse_remove_signal_handlers (se);
@@ -210,7 +221,10 @@ connect_to_socket (const char *path)
 
   socket_fd = socket (PF_UNIX, SOCK_SEQPACKET, 0);
   if (socket_fd < 0)
-    return -1;
+    {
+      __debug__(("failed to open socket: %d, %s\n", errno, strerror(errno)));
+      return -1;
+    }
 
   address.sun_family = AF_UNIX;
   snprintf(address.sun_path, sizeof (address.sun_path), path);
@@ -218,7 +232,10 @@ connect_to_socket (const char *path)
   if (connect (socket_fd,
 	       (struct sockaddr *) &address,
 	       sizeof(struct sockaddr_un)) != 0)
-    return -1;
+    {
+      __debug__(("failed to connect to socket: %d, %s\n", errno, strerror(errno)));
+      return -1;
+    }
 
   return socket_fd;
 }
@@ -345,6 +362,7 @@ main (int argc, char *argv[])
       return 1;
     }
 
+  __debug__ (("loading bundle %s\n", bundle_path));
   data = map_and_verify_bundle (exe_fd, &header_size);
   if (data == NULL)
     {
@@ -370,6 +388,7 @@ main (int argc, char *argv[])
   retry_count = 0;
   do
     {
+      __debug__ (("connecting socket (%d)\n", retry_count));
       socket_fd = connect_to_socket (glick_socket);
       if (socket_fd == -1)
 	{
@@ -402,6 +421,7 @@ main (int argc, char *argv[])
 
   g_free (glick_socket);
 
+  __debug__ (("talking to glick-fs\n"));
   msg.version = 0;
   msg.padding = 0;
   msg.offset = 0;
@@ -435,6 +455,7 @@ main (int argc, char *argv[])
   if (mkdtemp (dummy_mountpoint) == NULL)
     return 1;
 
+  __debug__ (("launching glick-watcher\n"));
   pid = fork ();
   if (pid == 0)
     {
@@ -489,6 +510,7 @@ main (int argc, char *argv[])
   if (argv0 == NULL)
     argv0 = exec;
 
+  __debug__ (("launching app %s\n", exec));
   /* Spawn the make-private-namespace handler */
   child_argv = malloc ((1 + 5 + (argc) + 1 ) * sizeof (char *));
   i = 0;



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