X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=uname%2Fvirt_uname.ml;h=6004bb860201c2b5c381e54fe09ee7a91b8d739a;hb=d8fa024d7e4d25b99c1e71acc8fa330d3ef4195c;hp=dcdf5c8e90f3e2f5027317dd7b8c7e669e6324cd;hpb=91d5f5dedf46f607388e0a1cd77f540e24b0b0ba;p=virt-mem.git diff --git a/uname/virt_uname.ml b/uname/virt_uname.ml index dcdf5c8..6004bb8 100644 --- a/uname/virt_uname.ml +++ b/uname/virt_uname.ml @@ -23,20 +23,7 @@ open Virt_mem_gettext.Gettext open Virt_mem_utils open Virt_mem_mmap -let usage = s_"NAME - virt-uname - uname command for virtual machines - -SUMMARY - virt-uname [-options] [domains] - -DESCRIPTION - virt-uname prints the uname information such as OS version, - architecture and node name for virtual machines running under - libvirt." - -let verbose, images = Virt_mem.start usage - -let () = +let run debug images = (* Print new_utsname structure from bitstring. *) let print_new_utsname name bs = (* Truncate an OCaml string at the first ASCII NUL character, ie. as @@ -49,16 +36,20 @@ let () = with Not_found -> str in + (* Expect the first (sysname) field to always be "Linux", which is + * also a good way to tell if we're synchronized to the right bit of + * memory. + *) bitmatch bs with - | { sysname : 65*8 : string; + | { "Linux\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" : 65*8 : string; nodename : 65*8 : string; release : 65*8 : string; version : 65*8 : string; machine : 65*8 : string; domainname : 65*8 : string } -> - printf "%s: %s %s %s %s %s %s\n" + printf "%s: Linux %s %s %s %s %s\n" name - (truncate sysname) (truncate nodename) (truncate release) + (truncate nodename) (truncate release) (truncate version) (truncate machine) (truncate domainname) | { _ } -> eprintf (f_"%s: unexpected system_utsname in kernel image\n") @@ -66,15 +57,14 @@ let () = in List.iter ( - fun (name, arch, mem, lookup_ksym) -> + fun (_, name, arch, mem, lookup_ksym) -> (* In Linux 2.6.25, the symbol is init_uts_ns. * http://lxr.linux.no/linux/init/version.c *) try let addr = lookup_ksym "init_uts_ns" in - if verbose then printf "init_uts_ns at %Lx\n" addr; - let bs = Bitmatch.bitstring_of_string (get_bytes mem addr (65*6+4)) in + let bs = Bitstring.bitstring_of_string (get_bytes mem addr (65*6+4)) in (bitmatch bs with | { _ : 32 : int; (* the kref, atomic_t, always 32 bits *) new_utsname : -1 : bitstring } -> @@ -89,12 +79,19 @@ let () = *) try let addr = lookup_ksym "system_utsname" in - if verbose then printf "system_utsname at %Lx\n" addr; let bs = - Bitmatch.bitstring_of_string (get_bytes mem addr (65*6)) in + Bitstring.bitstring_of_string (get_bytes mem addr (65*6)) in print_new_utsname name bs with Not_found -> eprintf (f_"%s: could not find utsname in kernel image\n") name ) images + +let summary = s_"uname command for virtual machines" +let description = s_"\ +virt-uname prints the uname information such as OS version, +architecture and node name for virtual machines running under +libvirt." + +let () = Virt_mem.register "uname" summary description ~run