X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Fgenerator.ml;h=6bc9b28c58276015faa0b1551e2dcc373dfdcece;hb=c372c7c23a298a940b8a0868396ef2ae0d824e4d;hp=e3584ccc7f70f731e3bd9363046830cfad4ce8c2;hpb=16c1b3164698900f52294e1396542ddd94a4cae4;p=libguestfs.git diff --git a/src/generator.ml b/src/generator.ml index e3584cc..6bc9b28 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -35,6 +35,7 @@ #load "unix.cma";; #load "str.cma";; +open Unix open Printf type style = ret * args @@ -346,13 +347,13 @@ and cmd = string list (* Generate a random UUID (used in tests). *) let uuidgen () = - let chan = Unix.open_process_in "uuidgen" in + let chan = open_process_in "uuidgen" in let uuid = input_line chan in - (match Unix.close_process_in chan with - | Unix.WEXITED 0 -> () - | Unix.WEXITED _ -> + (match close_process_in chan with + | WEXITED 0 -> () + | WEXITED _ -> failwith "uuidgen: process exited with non-zero status" - | Unix.WSIGNALED _ | Unix.WSTOPPED _ -> + | WSIGNALED _ | WSTOPPED _ -> failwith "uuidgen: process signalled or stopped by signal" ); uuid @@ -4696,7 +4697,7 @@ let check_functions () = ) all_functions (* 'pr' prints to the current output file. *) -let chan = ref stdout +let chan = ref Pervasives.stdout let pr fs = ksprintf (output_string !chan) fs (* Generate a header block in a number of standard styles. *) @@ -5974,7 +5975,7 @@ int main (int argc, char *argv[]) g = guestfs_create (); if (g == NULL) { printf (\"guestfs_create FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } guestfs_set_error_handler (g, print_error, NULL); @@ -5985,94 +5986,94 @@ int main (int argc, char *argv[]) fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } filename = \"test2.img\"; fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } filename = \"test3.img\"; fd = open (filename, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_TRUNC, 0666); if (fd == -1) { perror (filename); - exit (1); + exit (EXIT_FAILURE); } if (lseek (fd, %d, SEEK_SET) == -1) { perror (\"lseek\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (write (fd, &c, 1) == -1) { perror (\"write\"); close (fd); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (close (fd) == -1) { perror (filename); unlink (filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive (g, filename) == -1) { printf (\"guestfs_add_drive %%s FAILED\\n\", filename); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_add_drive_ro (g, \"../images/test.iso\") == -1) { printf (\"guestfs_add_drive_ro ../images/test.iso FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } if (guestfs_launch (g) == -1) { printf (\"guestfs_launch FAILED\\n\"); - exit (1); + exit (EXIT_FAILURE); } /* Set a timeout in case qemu hangs during launch (RHBZ#505329). */ @@ -6104,11 +6105,11 @@ int main (int argc, char *argv[]) pr " if (n_failed > 0) {\n"; pr " printf (\"***** %%lu / %%d tests FAILED *****\\n\", n_failed, nr_tests);\n"; - pr " exit (1);\n"; + pr " exit (EXIT_FAILURE);\n"; pr " }\n"; pr "\n"; - pr " exit (0);\n"; + pr " exit (EXIT_SUCCESS);\n"; pr "}\n" and generate_one_test name i (init, prereq, test) = @@ -8650,7 +8651,7 @@ and pod2text ~width name longdesc = fprintf chan "=head1 %s\n\n%s\n" name longdesc; close_out chan; let cmd = sprintf "pod2text -w %d %s" width (Filename.quote filename) in - let chan = Unix.open_process_in cmd in + let chan = open_process_in cmd in let lines = ref [] in let rec loop i = let line = input_line chan in @@ -8662,12 +8663,12 @@ and pod2text ~width name longdesc = loop (i+1) ) in let lines = try loop 1 with End_of_file -> List.rev !lines in - Unix.unlink filename; - (match Unix.close_process_in chan with - | Unix.WEXITED 0 -> () - | Unix.WEXITED i -> + unlink filename; + (match close_process_in chan with + | WEXITED 0 -> () + | WEXITED i -> failwithf "pod2text: process exited with non-zero status (%d)" i - | Unix.WSIGNALED i | Unix.WSTOPPED i -> + | WSIGNALED i | WSTOPPED i -> failwithf "pod2text: process signalled or stopped by signal %d" i ); Hashtbl.add pod2text_memo key lines; @@ -10161,49 +10162,49 @@ let output_to filename = chan := open_out filename_new; let close () = close_out !chan; - chan := stdout; + chan := Pervasives.stdout; (* Is the new file different from the current file? *) if Sys.file_exists filename && files_equal filename filename_new then - Unix.unlink filename_new (* same, so skip it *) + unlink filename_new (* same, so skip it *) else ( (* different, overwrite old one *) - (try Unix.chmod filename 0o644 with Unix.Unix_error _ -> ()); - Unix.rename filename_new filename; - Unix.chmod filename 0o444; + (try chmod filename 0o644 with Unix_error _ -> ()); + rename filename_new filename; + chmod filename 0o444; printf "written %s\n%!" filename; ) in close let perror msg = function - | Unix.Unix_error (err, _, _) -> - eprintf "%s: %s\n" msg (Unix.error_message err) + | Unix_error (err, _, _) -> + eprintf "%s: %s\n" msg (error_message err) | exn -> eprintf "%s: %s\n" msg (Printexc.to_string exn) (* Main program. *) let () = let lock_fd = - try Unix.openfile "HACKING" [Unix.O_RDWR] 0 + try openfile "HACKING" [O_RDWR] 0 with - | Unix.Unix_error (Unix.ENOENT, _, _) -> - eprintf "\ + | Unix_error (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 + 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 + (try lockf lock_fd F_LOCK 1 with exn -> perror "lock: HACKING" exn; exit 1);