mldonkey-commits
[Top][All Lists]
Advanced

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

[Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...


From: mldonkey-commits
Subject: [Mldonkey-commits] mldonkey distrib/ChangeLog src/daemon/common/co...
Date: Fri, 14 Jul 2006 13:15:39 +0000

CVSROOT:        /sources/mldonkey
Module name:    mldonkey
Changes by:     spiralvoice <spiralvoice>       06/07/14 13:15:39

Modified files:
        distrib        : ChangeLog 
        src/daemon/common: commonOptions.ml 
        src/daemon/driver: driverMain.ml 

Log message:
        patch #5235

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/mldonkey/distrib/ChangeLog?cvsroot=mldonkey&r1=1.910&r2=1.911
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/common/commonOptions.ml?cvsroot=mldonkey&r1=1.158&r2=1.159
http://cvs.savannah.gnu.org/viewcvs/mldonkey/src/daemon/driver/driverMain.ml?cvsroot=mldonkey&r1=1.115&r2=1.116

Patches:
Index: distrib/ChangeLog
===================================================================
RCS file: /sources/mldonkey/mldonkey/distrib/ChangeLog,v
retrieving revision 1.910
retrieving revision 1.911
diff -u -b -r1.910 -r1.911
--- distrib/ChangeLog   14 Jul 2006 13:14:01 -0000      1.910
+++ distrib/ChangeLog   14 Jul 2006 13:15:39 -0000      1.911
@@ -15,6 +15,7 @@
 =========
 
 2006/07/14
+5235: Lock config_files_space.tmp and delete unused file on startup
 5232: GUI: Fix decoding bug for Gnutella/G2/Fasttrack search results (zet)
 
 2006/06/29

Index: src/daemon/common/commonOptions.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/common/commonOptions.ml,v
retrieving revision 1.158
retrieving revision 1.159
diff -u -b -r1.158 -r1.159
--- src/daemon/common/commonOptions.ml  27 Jun 2006 21:20:28 -0000      1.158
+++ src/daemon/common/commonOptions.ml  14 Jul 2006 13:15:39 -0000      1.159
@@ -35,6 +35,10 @@
 
 let config_dir_basename = hidden_dir_prefix ^ "mldonkey"
 
+let pid_filename = Printf.sprintf "%s.pid" (Filename.basename Sys.argv.(0))
+
+let security_space_filename = "config_files_space.tmp"
+
 let home_dir =
   match Autoconf.system with
   | "cygwin"
@@ -107,6 +111,10 @@
 If you are using a chroot environment, create it inside the chroot.\n"
   file (if exit then ", exiting..." else "")
 
+let windows_sleep seconds =
+  lprintf_nl "waiting %d seconds to exit..." seconds;
+  Unix.sleep seconds
+
 let _ =
   lprintf_nl "Starting MLDonkey %s ... " Autoconf.current_version;
   let ulof_old = Unix2.c_getdtablesize () in
@@ -172,27 +180,9 @@
 
   Unix2.can_write_to_directory (Filename2.temp_directory ());
 
-  if (String2.starts_with (Filename.basename Sys.argv.(0)) "mlnet")
-    then
-      let pid_filename =
-        Printf.sprintf "%s.pid" (Filename.basename Sys.argv.(0)) in
-      let config_space = "config_files_space.tmp" in
-      if Sys.file_exists pid_filename || Sys.file_exists config_space
-      then begin
-        if Sys.file_exists pid_filename then
-          lprintf_nl "PID file %s exists."
-      (Filename.concat file_basedir pid_filename)
-  else
-    if Sys.file_exists config_space then begin
-            lprintf_nl "%s exists." (Filename.concat file_basedir 
config_space);
-      lprintf "%s" (exit_message config_space);
-      if Autoconf.windows then
-        begin
-          lprintf_nl "waiting 10 seconds to exit...";
-    Unix.sleep 10
-        end;
-      exit 2
-      end;
+  if (String2.starts_with (Filename.basename Sys.argv.(0)) "mlnet") then begin
+    if Sys.file_exists pid_filename then begin
+      lprintf_nl "PID file %s exists." (Filename.concat file_basedir 
pid_filename);
         let pid =
           try
       Unix2.tryopen_read pid_filename (fun pid_ci ->
@@ -200,29 +190,60 @@
           with _ ->
             lprintf_nl "But it couldn't be read to check if the process still 
exists.";
             lprintf_nl "To avoid doing any harm, MLDonkey will now stop.";
+         if Autoconf.windows then windows_sleep 10;
             exit 2
         in
           try
+       lprintf_nl "Checking whether PID %d is still used..." pid;
             Unix.kill pid 0;
       lprintf "%s" (exit_message pid_filename);
             exit 2
-          with
-            (* stalled pid file, disregard it *)
+      with (* stalled pid file, disregard it *)
             | Unix.Unix_error (Unix.ESRCH, _, _) ->
-         (lprintf_nl "Removing stalled file %s " pid_filename;
-         try Sys.remove pid_filename with _ -> ())
+         lprintf_nl "Removing stalled file %s..." pid_filename;
+         (try Sys.remove pid_filename with _ -> ())
       | e -> 
         lprintf "%s" (exit_message pid_filename);
         if Autoconf.system = "mingw" then lprintf_nl
           "can not check for stalled pid file because Unix.kill is not 
implemented on MinGW";
         lprintf_nl "Exception %s, exiting..." (Printexc2.to_string e);
-        if Autoconf.system = "mingw" then begin
-          lprintf_nl "waiting 10 seconds to exit...";
-    Unix.sleep 10;
+          if Autoconf.system = "mingw" then windows_sleep 10;
+          exit 2
         end;
+    if Sys.file_exists security_space_filename then begin
+      try
+        let security_space_oc =
+         Unix.openfile security_space_filename [Unix.O_WRONLY; Unix.O_CREAT] 
0o600 in
+        Unix.lockf security_space_oc Unix.F_TLOCK 0;
+        Unix.close security_space_oc;
+        lprintf_nl "Removing stalled file %s..."
+         (Filename.concat file_basedir security_space_filename);
+       begin
+         try
+           (try Unix.close security_space_oc with _ -> ());
+            Sys.remove security_space_filename
+          with e ->
+           lprintf_nl "can not remove %s: %s"
+             (Filename.concat file_basedir security_space_filename)
+             (Printexc2.to_string e);
+           if Autoconf.windows then windows_sleep 10;
         exit 2
+       end
+      with
+       Unix.Unix_error ((Unix.EAGAIN | Unix.EACCES), _, _) ->
+          lprintf_nl "%s exists and is locked by another process."
+           (Filename.concat file_basedir security_space_filename);
+          lprintf "%s" (exit_message security_space_filename);
+          if Autoconf.windows then windows_sleep 10;
+          exit 2
+      | e ->
+         lprintf_nl "error while checking file %s: %s"
+           (Filename.concat file_basedir security_space_filename)
+           (Printexc2.to_string e);
+         if Autoconf.windows then windows_sleep 10;
+         exit 2
+    end
       end;
-
   let filename =
         try
       Sys.getenv "MLDONKEY_STRINGS"

Index: src/daemon/driver/driverMain.ml
===================================================================
RCS file: /sources/mldonkey/mldonkey/src/daemon/driver/driverMain.ml,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -b -r1.115 -r1.116
--- src/daemon/driver/driverMain.ml     27 Jun 2006 21:17:30 -0000      1.115
+++ src/daemon/driver/driverMain.ml     14 Jul 2006 13:15:39 -0000      1.116
@@ -538,27 +538,27 @@
   if !verbose then lprintf_nl (_b "Activated system signal handling")
 
 let _ =
-  let security_space_filename = "config_files_space.tmp" in
+  let security_space_oc = ref None in
   begin
 (* Create a 'config_files_security_space' megabytes file to protect some space
 for config files at the end. *)
     try
-      let security_space_fd = Unix32.create_rw security_space_filename in
-      let _ =
+      let oc = Unix.openfile security_space_filename [Unix.O_WRONLY; 
Unix.O_CREAT] 0o600 in
         let len = 32768 in
-        let len64 = Int64.of_int len in
-        let s = String.create len in
+        let s = String.make len ' ' in
         let pos = ref zero in
         for i = 1 to !!config_files_security_space do
           for j = 1 to 32 do (* 32 = 1 MB / 32kB *)
-            Unix32.write security_space_fd !pos s 0 len;
-            pos := !pos ++ len64
+           ignore(Unix2.c_seek64 oc !pos Unix.SEEK_SET);
+            Unix2.really_write oc s 0 len;
+            pos := !pos ++ (Int64.of_int len)
           done
-        done
-      in
-      Unix32.close security_space_fd;
-    with _ ->
-        lprintf_nl (_b "Cannot create Security space file:");
+        done;
+       ignore(Unix2.c_seek64 oc zero Unix.SEEK_SET);
+       Unix.lockf oc Unix.F_LOCK (!!config_files_security_space * 1024 * 1024);
+       security_space_oc := Some oc
+    with e ->
+        lprintf_nl (_b "Cannot create Security space file: %s") 
(Printexc2.to_string e);
         lprintf_nl (_b " not enough space on device or bad permissions");
         lprintf_nl (_b "Exiting...");
         exit 73;
@@ -566,9 +566,6 @@
   Unix32.external_start ();
 
   (
-    let pid_filename =
-      Printf.sprintf "%s.pid" (Filename.basename Sys.argv.(0))
-    in
     let pid_file, s =
         Filename.concat !pid pid_filename,
        Printf.sprintf "%s\n" (string_of_int(Unix.getpid()))
@@ -605,7 +602,10 @@
       DriverGraphics.G.remove_files ();
       (* In case we have no more space on filesystem for
          config files, remove the security space file *)
-      Sys.remove security_space_filename;
+      (match !security_space_oc with
+       None -> ()
+      | Some oc -> Unix.close oc);
+      (try Sys.remove security_space_filename with _ -> ());
       CommonComplexOptions.allow_saving_ini_files := true;
       DriverInteractive.save_config ();
       CommonComplexOptions.save_sources ();




reply via email to

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