From 1c337db989e4a3abe63b54233c854e4eaff72b1f Mon Sep 17 00:00:00 2001 From: Rafal Wojtczuk Date: Fri, 3 Sep 2010 16:23:09 +0200 Subject: [PATCH] qmemman: make meminfo-writer a C program --- common/Makefile | 7 +++++ common/meminfo-writer | 4 --- common/meminfo-writer.c | 62 ++++++++++++++++++++++++++++++++++++++++ rpm_spec/core-appvm.spec | 1 + rpm_spec/core-dom0.spec | 1 + 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 common/Makefile delete mode 100755 common/meminfo-writer create mode 100644 common/meminfo-writer.c diff --git a/common/Makefile b/common/Makefile new file mode 100644 index 00000000..0bef1ae7 --- /dev/null +++ b/common/Makefile @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS=-Wall -g +all: meminfo-writer +meminfo-writer: meminfo-writer.o + $(CC) -g -o meminfo-writer meminfo-writer.o -lxenstore +clean: + rm -f meminfo-writer *.o *~ diff --git a/common/meminfo-writer b/common/meminfo-writer deleted file mode 100755 index fdbfd29f..00000000 --- a/common/meminfo-writer +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -while sleep 1 ; do - xenstore-write memory/meminfo "`cat /proc/meminfo`" -done diff --git a/common/meminfo-writer.c b/common/meminfo-writer.c new file mode 100644 index 00000000..5e019039 --- /dev/null +++ b/common/meminfo-writer.c @@ -0,0 +1,62 @@ +/* + * The Qubes OS Project, http://www.qubes-os.org + * + * Copyright (C) 2010 Rafal Wojtczuk + * + * 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. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +int main() +{ + struct xs_handle *xs; + int fd, n; + char buf[4096]; + + openlog("meminfo-writer", LOG_CONS | LOG_PID, LOG_DAEMON); + xs = xs_domain_open(); + if (!xs) { + syslog(LOG_DAEMON | LOG_ERR, "xs_domain_open"); + exit(1); + } + for (;;) { + fd = open("/proc/meminfo", O_RDONLY); + if (fd < 0) { + syslog(LOG_DAEMON | LOG_ERR, + "error opening /proc/meminfo ?"); + exit(1); + } + n = read(fd, buf, sizeof(buf)); + if (n <= 0) { + syslog(LOG_DAEMON | LOG_ERR, + "error reading /proc/meminfo ?"); + exit(1); + } + close(fd); + if (!xs_write(xs, XBT_NULL, "memory/meminfo", buf, n)) { + syslog(LOG_DAEMON | LOG_ERR, + "error writing xenstore ?"); + exit(1); + } + sleep(1); + } +} diff --git a/rpm_spec/core-appvm.spec b/rpm_spec/core-appvm.spec index 2949a059..7974e23d 100644 --- a/rpm_spec/core-appvm.spec +++ b/rpm_spec/core-appvm.spec @@ -52,6 +52,7 @@ fi %build make clean all +make -C ../common %install diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index f4af95d8..25b3e407 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -47,6 +47,7 @@ The Qubes core files for installation on Dom0. python -m compileall qvm-core qmemman python -O -m compileall qvm-core qmemman make -C restore +make -C ../common %install