diff --git a/common/Makefile b/common/Makefile new file mode 100644 index 0000000..0bef1ae --- /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 fdbfd29..0000000 --- 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 0000000..5e01903 --- /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 2949a05..7974e23 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