/[mldonkey]/mldonkey/src/config/unix/mlUnix.ml
ViewVC logotype

Diff of /mldonkey/src/config/unix/mlUnix.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by spiralvoice, Sun Aug 7 17:39:30 2005 UTC revision 1.11 by spiralvoice, Fri Dec 2 12:08:26 2005 UTC
# Line 54  let execvp_command cmd args handler = Line 54  let execvp_command cmd args handler =
54        let sock = handler in_read out_write in        let sock = handler in_read out_write in
55        sock, id        sock, id
56    
57  let fork_and_exec cmd args =  let fork_and_exec cmd ?vars args =
58      let env =
59        match vars with
60          | None -> None
61          | Some vars ->
62              (* convert environment to an alist *)
63              let env = List.map (fun kev ->
64                try
65                  let len = String.length kev in
66                  let equal_sign = String.index kev '=' in
67                    (String.sub kev 0 equal_sign,
68                     String.sub kev (equal_sign + 1) (len - 1 - equal_sign))
69                with Not_found -> (* May that happen ? *)
70                  (kev, "")
71              ) (Array.to_list (Unix.environment ())) in
72              (* update parent's environment with vars alist *)
73              let env = List.fold_left (fun acc ((k, v) as assoc) ->
74                assoc :: List.remove_assoc k acc
75              ) env vars in
76              Some (Array.of_list (List.map (fun (k, v) -> k ^ "=" ^ v) env)) in
77    match Unix.fork() with    match Unix.fork() with
78      0 -> begin      0 -> begin
79          try          try
80            match Unix.fork() with            match Unix.fork() with
81              0 -> begin              0 -> begin
82                  try                  try
83                    Unix.execv cmd args;                    match env with
84                        | None ->
85                            Unix.execv cmd args;
86                        | Some env ->
87                            Unix.execve cmd args env;
88                    exit 0                    exit 0
89                  with e ->                  with e ->
90                      lprintf "Exception %s while starting file_completed_cmd\n" (Printexc2.to_string e);                      lprintf "Exception %s while starting file_completed_cmd\n" (Printexc2.to_string e);

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26