mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
This change was done almost entirely automatically using the script
below. This uses the OCaml lexer to read the source files and extract
the strings and locations. Strings which are "candidates" (in this
case, longer than 3 lines) are replaced in the output with quoted
string literals.
Since the OCaml lexer is used, it already substitutes all escape
sequences correctly. I diffed the output of the generator and it is
identical after this change, except for UUIDs, which change because of
how Utils.stable_uuid is implemented.
Thanks: Nicolas Ojeda Bar
$ ocamlfind opt -package unix,compiler-libs.common find_strings.ml \
-o find_strings.opt -linkpkg
$ for f in $( git ls-files -- \*.ml ) ; do ./find_strings.opt $f ; done
open Printf
let read_whole_file path =
let buf = Buffer.create 16384 in
let chan = open_in path in
let maxlen = 16384 in
let b = Bytes.create maxlen in
let rec loop () =
let r = input chan b 0 maxlen in
if r > 0 then (
Buffer.add_substring buf (Bytes.to_string b) 0 r;
loop ()
)
in
loop ();
close_in chan;
Buffer.contents buf
let count_chars c str =
let count = ref 0 in
for i = 0 to String.length str - 1 do
if c = String.unsafe_get str i then incr count
done;
!count
let subs = ref []
let consider_string str loc =
let nr_lines = count_chars '\n' str in
if nr_lines > 3 then
subs := (str, loc) :: !subs
let () =
Lexer.init ();
let filename = Sys.argv.(1) in
let content = read_whole_file filename in
let lexbuf = Lexing.from_string content in
let rec loop () =
let token = Lexer.token lexbuf in
(match token with
| Parser.EOF -> ();
| STRING (s, loc, sopt) ->
consider_string s loc; (* sopt? *)
loop ();
| token ->
loop ();
)
in
loop ();
(* The list of subs is already reversed, which is convenient
* because we must the file substitutions in reverse order.
*)
let subs = !subs in
let new_content = ref content in
List.iter (
fun (str, loc) ->
let { Location.loc_start = { pos_cnum = p1 };
loc_end = { pos_cnum = p2 } } = loc in
let len = String.length !new_content in
let before = String.sub !new_content 0 (p1-1) in
let after = String.sub !new_content (p2+1) (len - p2 - 1) in
new_content := before ^ "{|" ^ str ^ "|}" ^ after
) subs;
let new_content = !new_content in
if content <> new_content then (
(* Update the file in place. *)
let new_filename = filename ^ ".new"
and backup_filename = filename ^ ".bak" in
let chan = open_out new_filename in
fprintf chan "%s" new_content;
close_out chan;
Unix.rename filename backup_filename;
Unix.rename new_filename filename
)
158 lines
5.2 KiB
OCaml
158 lines
5.2 KiB
OCaml
(* libguestfs
|
|
* Copyright (C) 2009-2025 Red Hat Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*)
|
|
|
|
(* Please read generator/README first. *)
|
|
|
|
open Types
|
|
|
|
(* APIs related to handle properties.
|
|
* All the APIs in this file are deprecated.
|
|
*)
|
|
|
|
let non_daemon_functions = [
|
|
{ defaults with
|
|
name = "set_qemu"; added = (1, 0, 6);
|
|
style = RErr, [OptString "hv"], [];
|
|
fish_alias = ["qemu"]; config_only = true;
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "set_hv";
|
|
shortdesc = "set the hypervisor binary (usually qemu)";
|
|
longdesc = {|Set the hypervisor binary (usually qemu) that we will use.
|
|
|
|
The default is chosen when the library was compiled by the
|
|
configure script.
|
|
|
|
You can also override this by setting the C<LIBGUESTFS_HV>
|
|
environment variable.
|
|
|
|
Setting C<hv> to C<NULL> restores the default qemu binary.
|
|
|
|
Note that you should call this function as early as possible
|
|
after creating the handle. This is because some pre-launch
|
|
operations depend on testing qemu features (by running C<qemu -help>).
|
|
If the qemu binary changes, we don't retest features, and
|
|
so you might see inconsistent results. Using the environment
|
|
variable C<LIBGUESTFS_HV> is safest of all since that picks
|
|
the qemu binary at the same time as the handle is created.|} };
|
|
|
|
{ defaults with
|
|
name = "get_qemu"; added = (1, 0, 6);
|
|
style = RConstString "hv", [], [];
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "get_hv";
|
|
tests = [
|
|
InitNone, Always, TestRun (
|
|
[["get_qemu"]]), []
|
|
];
|
|
shortdesc = "get the hypervisor binary (usually qemu)";
|
|
longdesc = "\
|
|
Return the current hypervisor binary (usually qemu).
|
|
|
|
This is always non-NULL. If it wasn't set already, then this will
|
|
return the default qemu binary name." };
|
|
|
|
{ defaults with
|
|
name = "set_selinux"; added = (1, 0, 67);
|
|
style = RErr, [Bool "selinux"], [];
|
|
fish_alias = ["selinux"]; config_only = true;
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "selinux_relabel";
|
|
shortdesc = "set SELinux enabled or disabled at appliance boot";
|
|
longdesc = {|This sets the selinux flag that is passed to the appliance
|
|
at boot time. The default is C<selinux=0> (disabled).
|
|
|
|
Note that if SELinux is enabled, it is always in
|
|
Permissive mode (C<enforcing=0>).
|
|
|
|
For more information on the architecture of libguestfs,
|
|
see L<guestfs(3)>.|} };
|
|
|
|
{ defaults with
|
|
name = "get_selinux"; added = (1, 0, 67);
|
|
style = RBool "selinux", [], [];
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "selinux_relabel";
|
|
shortdesc = "get SELinux enabled flag";
|
|
longdesc = {|This returns the current setting of the selinux flag which
|
|
is passed to the appliance at boot time. See C<guestfs_set_selinux>.
|
|
|
|
For more information on the architecture of libguestfs,
|
|
see L<guestfs(3)>.|} };
|
|
|
|
{ defaults with
|
|
name = "set_attach_method"; added = (1, 9, 8);
|
|
style = RErr, [String (PlainString, "backend")], [];
|
|
fish_alias = ["attach-method"]; config_only = true;
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "set_backend";
|
|
shortdesc = "set the backend";
|
|
longdesc = "\
|
|
Set the method that libguestfs uses to connect to the backend
|
|
guestfsd daemon.
|
|
|
|
See L<guestfs(3)/BACKEND>." };
|
|
|
|
{ defaults with
|
|
name = "get_attach_method"; added = (1, 9, 8);
|
|
style = RString (RPlainString, "backend"), [], [];
|
|
blocking = false;
|
|
deprecated_by = Replaced_by "get_backend";
|
|
tests = [
|
|
InitNone, Always, TestRun (
|
|
[["get_attach_method"]]), []
|
|
];
|
|
shortdesc = "get the backend";
|
|
longdesc = "\
|
|
Return the current backend.
|
|
|
|
See C<guestfs_set_backend> and L<guestfs(3)/BACKEND>." };
|
|
|
|
{ defaults with
|
|
name = "set_direct"; added = (1, 0, 72);
|
|
style = RErr, [Bool "direct"], [];
|
|
deprecated_by = Replaced_by "internal_get_console_socket";
|
|
fish_alias = ["direct"]; config_only = true;
|
|
blocking = false;
|
|
shortdesc = "enable or disable direct appliance mode";
|
|
longdesc = {|If the direct appliance mode flag is enabled, then stdin and
|
|
stdout are passed directly through to the appliance once it
|
|
is launched.
|
|
|
|
One consequence of this is that log messages aren't caught
|
|
by the library and handled by C<guestfs_set_log_message_callback>,
|
|
but go straight to stdout.
|
|
|
|
You probably don't want to use this unless you know what you
|
|
are doing.
|
|
|
|
The default is disabled.|} };
|
|
|
|
{ defaults with
|
|
name = "get_direct"; added = (1, 0, 72);
|
|
style = RBool "direct", [], [];
|
|
deprecated_by = Replaced_by "internal_get_console_socket";
|
|
blocking = false;
|
|
shortdesc = "get direct appliance mode flag";
|
|
longdesc = "\
|
|
Return the direct appliance mode flag." };
|
|
|
|
]
|
|
|
|
let daemon_functions = [
|
|
]
|