Skip to content

Commit 204d45a

Browse files
committed
resize: Use stderr consistently for debug messages
Also ensure that debug messages are flushed at the point of printing.
1 parent 30084d2 commit 204d45a

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

resize/resize.ml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,29 @@ and partition_id =
7676
| GPT_Type of string (* GPT UUID. *)
7777

7878
let rec debug_partition ?(sectsize=512L) p =
79-
printf "%s:\n" p.p_name;
80-
printf "\tpartition data: %ld %Ld-%Ld (%Ld bytes)\n"
79+
eprintf "%s:\n" p.p_name;
80+
eprintf "\tpartition data: %ld %Ld-%Ld (%Ld bytes)\n"
8181
p.p_part.G.part_num p.p_part.G.part_start p.p_part.G.part_end
8282
p.p_part.G.part_size;
83-
printf "\tpartition sector data: %Ld-%Ld (%Ld sectors)\n"
83+
eprintf "\tpartition sector data: %Ld-%Ld (%Ld sectors)\n"
8484
(p.p_part.G.part_start /^ sectsize) (p.p_part.G.part_end /^ sectsize)
8585
((p.p_part.G.part_end +^ 1L -^ p.p_part.G.part_start) /^ sectsize);
86-
printf "\ttarget partition sector data: %Ld-%Ld (%Ld sectors)\n"
86+
eprintf "\ttarget partition sector data: %Ld-%Ld (%Ld sectors)\n"
8787
p.p_target_start p.p_target_end (p.p_target_end +^ 1L -^ p.p_target_start);
88-
printf "\tbootable: %b\n" p.p_bootable;
89-
printf "\tpartition ID: %s\n"
88+
eprintf "\tbootable: %b\n" p.p_bootable;
89+
eprintf "\tpartition ID: %s\n"
9090
(match p.p_id with
9191
| No_ID -> "(none)"
9292
| MBR_ID i -> sprintf "0x%x" i
9393
| GPT_Type i -> i
9494
);
95-
printf "\tcontent: %s\n" (string_of_partition_content p.p_type);
96-
printf "\tlabel: %s\n"
95+
eprintf "\tcontent: %s\n" (string_of_partition_content p.p_type);
96+
eprintf "\tlabel: %s\n"
9797
(match p.p_label with
9898
| Some label -> label
9999
| None -> "(none)"
100100
);
101-
printf "\tGUID: %s\n"
101+
eprintf "\tGUID: %s\n"
102102
(match p.p_guid with
103103
| Some guid -> guid
104104
| None -> "(none)"
@@ -131,8 +131,8 @@ and logvol_operation =
131131
| LVOpExpand (* expand it *)
132132

133133
let debug_logvol lv =
134-
printf "%s:\n" lv.lv_name;
135-
printf "\tcontent: %s\n" (string_of_partition_content lv.lv_type)
134+
eprintf "%s:\n" lv.lv_name;
135+
eprintf "\tcontent: %s\n" (string_of_partition_content lv.lv_type)
136136

137137
type expand_content_method =
138138
| PVResize | Resize2fs | NTFSResize | BtrfsFilesystemResize | XFSGrowFS
@@ -230,9 +230,9 @@ read the man page virt-resize(1).
230230
Getopt.parse opthandle.getopt;
231231

232232
if verbose () then (
233-
printf "command line:";
234-
List.iter (printf " %s") (Array.to_list Sys.argv);
235-
print_newline ()
233+
eprintf "command line:";
234+
List.iter (eprintf " %s") (Array.to_list Sys.argv);
235+
eprintf "\n%!";
236236
);
237237

238238
(* Dereference the rest of the args. *)
@@ -530,7 +530,8 @@ read the man page virt-resize(1).
530530

531531
if verbose () then (
532532
eprintf "%d partitions found\n" (List.length partitions);
533-
List.iter debug_partition partitions
533+
List.iter debug_partition partitions;
534+
flush stderr
534535
);
535536

536537
(* Check content isn't larger than partitions. If it is then
@@ -581,8 +582,9 @@ read the man page virt-resize(1).
581582
) lvs in
582583

583584
if verbose () then (
584-
printf "%d logical volumes found\n" (List.length lvs);
585-
List.iter debug_logvol lvs
585+
eprintf "%d logical volumes found\n" (List.length lvs);
586+
List.iter debug_logvol lvs;
587+
flush stderr
586588
);
587589

588590
lvs in
@@ -1246,8 +1248,9 @@ read the man page virt-resize(1).
12461248
loop 1 start partitions in
12471249

12481250
if verbose () then (
1249-
printf "After calculate target partitions:\n";
1250-
List.iter (debug_partition ~sectsize) partitions
1251+
eprintf "After calculate target partitions:\n";
1252+
List.iter (debug_partition ~sectsize) partitions;
1253+
flush stderr
12511254
);
12521255

12531256
(* Now partition the target disk. *)
@@ -1349,7 +1352,7 @@ read the man page virt-resize(1).
13491352

13501353
if verbose () then (
13511354
let old_hidden = int_of_le32 (g#pread_device target 4 0x1c_L) in
1352-
debug "old hidden sectors value: 0x%Lx" old_hidden
1355+
eprintf "old hidden sectors value: 0x%Lx\n%!" old_hidden
13531356
);
13541357

13551358
let new_hidden = le32_of_int start in

0 commit comments

Comments
 (0)