[libvirt] [PATCH 4/7] Add a sysinfo util module and read host info API

Move existing routines about virSysinfoDef to an util module, add a new entry point virSysinfoRead() to read the host values with dmidecode * src/conf/domain_conf.c src/conf/domain_conf.h src/util/sysinfo.c src/util/sysinfo.h: move to a new module, add virSysinfoRead() * src/Makefile.am: handle the new module build * src/libvirt_private.syms: new internal symbols * include/libvirt/virterror.h src/util/virterror.c: defined a new error code for that module Signed-off-by: Daniel Veillard <veillard@redhat.com> --- include/libvirt/virterror.h | 3 +- po/POTFILES.in | 1 + src/Makefile.am | 1 + src/conf/domain_conf.c | 19 ---- src/conf/domain_conf.h | 25 +---- src/libvirt_private.syms | 5 + src/util/sysinfo.c | 250 +++++++++++++++++++++++++++++++++++++++++++ src/util/sysinfo.h | 58 ++++++++++ src/util/virterror.c | 3 + 9 files changed, 321 insertions(+), 44 deletions(-) create mode 100644 src/util/sysinfo.c create mode 100644 src/util/sysinfo.h

On Tue, Nov 02, 2010 at 05:36:46PM +0100, Daniel Veillard wrote:
+virSysinfoDefPtr +virSysinfoRead(void) { + char *path, *cur, *eol, *base; + int pid, outfd = -1, errfd = -1; + virSysinfoDefPtr ret = NULL; + const char **argv; + int n, res, waitret, exitstatus; + char *outbuf = NULL; + char *errbuf = NULL; + + path = virFindFileInPath(SYSINFO_SMBIOS_DECODER); + if (path == NULL) { + virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to find path for %s binary"), + SYSINFO_SMBIOS_DECODER); + return(NULL); + } + + n = 1 + /* dmidecode */ + 1 + /* -q */ + 2; /* -t 0,1 */ + + if (VIR_ALLOC_N(argv, n + 1) < 0) + return(NULL); + + n = 0; + argv[n++] = path; + argv[n++] = "-q"; + argv[n++] = "-t"; + argv[n++] = "0,1"; + argv[n] = NULL;
Since there's no conditionally included args here, it is simpler to avoid the counting of args & alloc & just pre-declare argv const char *argv[] = { path, "-q", "-t", "0,1", NULL }; Regards, Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On Wed, Nov 03, 2010 at 11:48:50AM +0000, Daniel P. Berrange wrote:
On Tue, Nov 02, 2010 at 05:36:46PM +0100, Daniel Veillard wrote:
+virSysinfoDefPtr +virSysinfoRead(void) { + char *path, *cur, *eol, *base; + int pid, outfd = -1, errfd = -1; + virSysinfoDefPtr ret = NULL; + const char **argv; + int n, res, waitret, exitstatus; + char *outbuf = NULL; + char *errbuf = NULL; + + path = virFindFileInPath(SYSINFO_SMBIOS_DECODER); + if (path == NULL) { + virSmbiosReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to find path for %s binary"), + SYSINFO_SMBIOS_DECODER); + return(NULL); + } + + n = 1 + /* dmidecode */ + 1 + /* -q */ + 2; /* -t 0,1 */ + + if (VIR_ALLOC_N(argv, n + 1) < 0) + return(NULL); + + n = 0; + argv[n++] = path; + argv[n++] = "-q"; + argv[n++] = "-t"; + argv[n++] = "0,1"; + argv[n] = NULL;
Since there's no conditionally included args here, it is simpler to avoid the counting of args & alloc & just pre-declare argv
const char *argv[] = { path, "-q", "-t", "0,1", NULL };
Right, I initially made 2 invokations of dmidecode, and then discovered that -t could take 0,1 ... that's a leftover ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/
participants (2)
-
Daniel P. Berrange
-
Daniel Veillard