X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fgenerator.ml;h=e3584ccc7f70f731e3bd9363046830cfad4ce8c2;hp=c261ea22a1f11f2f5d9a50e0df529e8b914925ec;hb=16c1b3164698900f52294e1396542ddd94a4cae4;hpb=60d020d363ec49a547fe047ac2f9bd88c8efcd5c diff --git a/src/generator.ml b/src/generator.ml old mode 100644 new mode 100755 index c261ea2..e3584cc --- a/src/generator.ml +++ b/src/generator.ml @@ -10176,18 +10176,39 @@ let output_to filename = in close +let perror msg = function + | Unix.Unix_error (err, _, _) -> + eprintf "%s: %s\n" msg (Unix.error_message err) + | exn -> + eprintf "%s: %s\n" msg (Printexc.to_string exn) + (* Main program. *) let () = - check_functions (); - - if not (Sys.file_exists "HACKING") then ( - eprintf "\ + let lock_fd = + try Unix.openfile "HACKING" [Unix.O_RDWR] 0 + with + | Unix.Unix_error (Unix.ENOENT, _, _) -> + eprintf "\ You are probably running this from the wrong directory. Run it from the top source directory using the command src/generator.ml "; - exit 1 - ); + exit 1 + | exn -> + perror "open: HACKING" exn; + exit 1 in + + (* Acquire a lock so parallel builds won't try to run the generator + * twice at the same time. Subsequent builds will wait for the first + * one to finish. Note the lock is released implicitly when the + * program exits. + *) + (try Unix.lockf lock_fd Unix.F_LOCK 1 + with exn -> + perror "lock: HACKING" exn; + exit 1); + + check_functions (); let close = output_to "src/guestfs_protocol.x" in generate_xdr ();