create meminfo in memory --> to head
Sat Feb 21 12:13:15 CET 2009 tobias@rautenkranz.ch
tagged 2.0
Sat Feb 21 12:08:59 CET 2009 tobias@rautenkranz.ch
* create meminfo in memory
diff -rN -u old-myth2/Makefile new-myth2/Makefile
--- old-myth2/Makefile 2014-10-30 08:04:44.000000000 +0100
+++ new-myth2/Makefile 1970-01-01 01:00:00.000000000 +0100
@@ -1,23 +0,0 @@
-all: fopenr.so
-
-fopenr.so: fopenRedirect.o
- $(CC) -shared -ldl -o fopenr.so fopenRedirect.o
-
-fopenRedirect.o: fopenRedirect.c
- $(CC) -Wall -fpic -c fopenRedirect.c
-
-## testing
-tests/fopen-cat: tests/fopen_cat.o
- $(CC) -o $@ $<
-
-.PHONY: test
-test: fopenr.so tests/fopen-cat
- @LD_PRELOAD=./fopenr.so ./tests/fopen-cat 2 "/proc/meminfo" \
- | awk '/Mem:/ { print $$2 }' | cmp tests/mem
-
-## clean
-.PHONY: clean
-clean:
- rm -f -- *.o
- rm -f -- *.so
- rm -f -- test/*.o test/fopen-cat
diff -rN -u old-myth2/README new-myth2/README
--- old-myth2/README 2014-10-30 08:04:44.000000000 +0100
+++ new-myth2/README 1970-01-01 01:00:00.000000000 +0100
@@ -1,17 +0,0 @@
-Myth2 for Linux parses /proc/meminfo,
-but its format changed some time ago.
-Therefore it won't activate OpenGL.
-
-Error message:
-~$ myth2
-Warning: You may not have enough free memory (-811245713) !
-
-By suppling an old meminfo this can be fixed:
-
-* Compile with: make
-* Start myth2: LD_PRELOAD=./fopenr.so myth2
-
-Changelog:
- 21.2.2009: Release 0.2 (thanks to Alan Swanson)
- * link to ld library
- * create meminfo dynamically
diff -rN -u old-myth2/fopenRedirect.c new-myth2/fopenRedirect.c
--- old-myth2/fopenRedirect.c 2014-10-30 08:04:44.000000000 +0100
+++ new-myth2/fopenRedirect.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2004, 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-
-#define __USE_GNU
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <dlfcn.h>
-
-/* Old meminfo emulating 256Mb */
-static const char meminfo_str[] =
-"root: total: used: free: shared: buffers: cached:\n"
-"Mem: 268435456 0 268435456 0 0 0\n"
-"Swap: 268435456 0 268435456\n";
-
-int tmp_meminfo = -1;
-
-/** Returns a stream to an meminfo file. */
-FILE*
-make_meminfo()
-{
- FILE* tmp_meminfo = tmpfile();
-
- if (!tmp_meminfo)
- {
- perror("myth-meminfo: creating temponary meminfo");
- return NULL;
- }
-
- size_t len = fwrite(meminfo_str, 1, sizeof(meminfo_str), tmp_meminfo);
- if (len != sizeof(meminfo_str))
- {
- perror("myth-meminfo: writing temporary meminfo");
- return NULL;
- }
-
- rewind(tmp_meminfo);
-
- return tmp_meminfo;
-}
-
-FILE* fopen(const char *filename, const char *mode)
-{
- FILE* (*_fopen)(const char*,const char*) = dlsym(RTLD_NEXT, "fopen");
- if (!_fopen)
- {
- fprintf(stderr, "myth-meminfo: dlsym: %s\n", dlerror());
- return NULL;
- }
-
- if (strcmp(filename, "/proc/meminfo") == 0)
- {
- fprintf(stderr, "myth-meminfo: fixing /proc/meminfo\n");
-
- return make_meminfo();
- }
- else
- return _fopen(filename, mode);
-}
diff -rN -u old-myth2/tests/fopen_cat.c new-myth2/tests/fopen_cat.c
--- old-myth2/tests/fopen_cat.c 2014-10-30 08:04:44.000000000 +0100
+++ new-myth2/tests/fopen_cat.c 1970-01-01 01:00:00.000000000 +0100
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <error.h>
-#include <errno.h>
-
-int
-main(int argc, char* argv[])
-{
- if (argc != 3)
- error(EXIT_FAILURE, errno, "usage: %s TIMES FILENAME", argv[0]);
-
- int count = atoi(argv[1]);
- const char* filename = argv[2];
-
- int i;
- for(i=0; i < count; i++)
- {
- FILE* file = fopen(filename, "r");
- if (!file)
- error(EXIT_FAILURE, errno, "open %s", filename);
-
- char buffer[100];
- size_t len;
- do {
- len = fread(buffer, 1, sizeof(buffer), file);
- size_t write_len = fwrite(buffer, 1, len, stdout);
-
- if (write_len != len)
- error(EXIT_FAILURE, 0, "write to stdout");
- } while (sizeof(buffer) == len || !feof(file));
- }
-
- return EXIT_SUCCESS;
-}
diff -rN -u old-myth2/tests/mem new-myth2/tests/mem
--- old-myth2/tests/mem 2014-10-30 08:04:44.000000000 +0100
+++ new-myth2/tests/mem 1970-01-01 01:00:00.000000000 +0100
@@ -1,2 +0,0 @@
-268435456
-268435456