Parcourir la source

Change tmp name to improve multi-user compatibility

 + When multiple user use oclaunch without restart of the computeer, file
 /tmp/.oclaunch_trace.dat is shared. Beyond permission problem, we would get
 into trouble if two different users have the same command in rc file with the
 same name (the considered command would be run for the first user only,
 appearing to be already launched for the second one).
 + Now two different user have two different tmp file, with different name.
Leo il y a 8 ans
Parent
commit
6fdb9656bd
2 fichiers modifiés avec 10 ajouts et 1 suppressions
  1. 1 0
      CHANGELOG.md
  2. 9 1
      src/const.ml

+ 1 - 0
CHANGELOG.md

@@ -16,6 +16,7 @@ This version introduce major changes in the tmp and rc file.
     + Support multiple configuration file.
     + More natural behavior when starting from an empty file. (Don't increment
      number of launch when nothing is actually launched).
+    + Change name to improve multi-user compatibility.
     + For the future : Running infinite, daemon mode...
  + Beautified rc file:
     + Remove doubled entries before each write of the rc file. Trailing spaces

+ 9 - 1
src/const.ml

@@ -63,6 +63,11 @@ let home =
   get_var (lazy "HOME")
 ;;
 
+(* Get current loged in user (different of logname, original user loged in) *)
+let user =
+  get_var (lazy "USER")
+;;
+
 (* Get default editor *)
 let editor = (* If editor is not set, it gets "", but an exception is raised *)
   get_var (lazy "EDITOR")
@@ -110,7 +115,10 @@ let rc_file_default =
 let rc_file = ref rc_file_default;;
 (* Set tmp file, in witch stock launches, in biniou format *)
 let tmp_file =
-  get_var ~default:(lazy ("/tmp/.oclaunch_trace.dat")) (lazy "OC_TMP")
+  let default =
+    Lazy.(user >>| sprintf "/tmp/.oclaunch_trace_%s.dat")
+  in
+  get_var ~default (lazy "OC_TMP")
   |> Lazy.force
 ;;
 (* Default max number for launch *)