diff -Naur repos/m0n0cored/configure.ac repos-r278/m0n0cored/configure.ac
--- repos/m0n0cored/configure.ac	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/configure.ac	2007-07-05 01:16:34.000000000 +0800
@@ -47,6 +47,8 @@
 # we need libcrypt (for crypt(3))
 AC_SEARCH_LIBS([crypt], [crypt],, [AC_MSG_ERROR([can't find crypt() function])])
 
+AC_HEADER_DIRENT
+
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_FILES([
 	Makefile
diff -Naur repos/m0n0cored/lib/xmlrpc++/XmlRpcDispatch.cpp repos-r278/m0n0cored/lib/xmlrpc++/XmlRpcDispatch.cpp
--- repos/m0n0cored/lib/xmlrpc++/XmlRpcDispatch.cpp	2007-06-24 03:56:07.000000000 +0800
+++ repos-r278/m0n0cored/lib/xmlrpc++/XmlRpcDispatch.cpp	2007-07-01 04:02:52.000000000 +0800
@@ -6,6 +6,7 @@
 #include <math.h>
 #include <sys/timeb.h>
 #include <errno.h>
+#include <assert.h>
 
 #if defined(_WINDOWS)
 # include <winsock2.h>
diff -Naur repos/m0n0cored/src/EventPipeReader.cpp repos-r278/m0n0cored/src/EventPipeReader.cpp
--- repos/m0n0cored/src/EventPipeReader.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/EventPipeReader.cpp	2007-07-01 04:04:24.000000000 +0800
@@ -46,6 +46,8 @@
 	delete logger;
 }
 
+void* pipeThreadRun(void* arg);
+
 void EventPipeReader::start() {
 	
 	if (running)
diff -Naur repos/m0n0cored/src/ModuleInstaller.cpp repos-r278/m0n0cored/src/ModuleInstaller.cpp
--- repos/m0n0cored/src/ModuleInstaller.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/ModuleInstaller.cpp	2007-07-05 01:44:27.000000000 +0800
@@ -7,6 +7,7 @@
  * (c) 2006-2007 Manuel Kasper <mkasper@hsr.ch> & Daniel Spoerri <dspoerri@hsr.ch>.
  * All rights reserved.
  */
+#include "global.h"
 #include "ModuleInstaller.h"
 #include "ModuleManager.h"
 #include "ModuleInfo.h"
@@ -18,7 +19,22 @@
 #include "Partition.h"
 
 #include <errno.h>
-#include <dirent.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 #include <sys/stat.h>
 
 ModuleInstaller::ModuleInstaller(CoreApplication *coreApp) : coreApp(coreApp) {
@@ -248,7 +264,9 @@
 	struct dirent* curent;
 	while ((curent = readdir(dir)) != NULL) {
 	
-		if (curent->d_namlen <= 2 && (!strcmp(curent->d_name, ".") ||
+		//if (curent->d_namlen <= 2 && (!strcmp(curent->d_name, ".") ||
+		//if ((strlen(curent->d_name)) <= 2 && (!strcmp(curent->d_name, ".") ||
+		if (NAMLEN(curent) <= 2 && (!strcmp(curent->d_name, ".") ||
 			!strcmp(curent->d_name, "..")))
 			continue;
 	
diff -Naur repos/m0n0cored/src/ModuleManager.cpp repos-r278/m0n0cored/src/ModuleManager.cpp
--- repos/m0n0cored/src/ModuleManager.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/ModuleManager.cpp	2007-07-05 01:43:34.000000000 +0800
@@ -15,7 +15,22 @@
 
 #include <sys/types.h>
 #include <dlfcn.h>
-#include <dirent.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 #include <iostream>
 
 ModuleManager::ModuleManager(CoreApplication *coreApp) : coreApp(coreApp) {
diff -Naur repos/m0n0cored/src/SystemUpgrader.cpp repos-r278/m0n0cored/src/SystemUpgrader.cpp
--- repos/m0n0cored/src/SystemUpgrader.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/SystemUpgrader.cpp	2007-07-05 01:42:05.000000000 +0800
@@ -14,15 +14,32 @@
 #include "CoreApplication.h"
 #include "CoreUtils.h"
 #include "Partition.h"
+#include "config.h"
 
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <errno.h>
-#include <dirent.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/types.h>
 
 #define PART_BLOCK_SIZE 65536
 #define SYSTEM_CA_FILENAME "systemca.crt"
@@ -238,7 +255,9 @@
 	struct dirent* curent;
 	while ((curent = readdir(dir)) != NULL) {
 	
-		if (curent->d_namlen <= 2 && (!strcmp(curent->d_name, ".") ||
+		//if (curent->d_namlen <= 2 && (!strcmp(curent->d_name, ".") ||
+		//if ((strlen(curent->d_name)) <= 2 && (!strcmp(curent->d_name, ".") ||
+		if (NAMLEN(curent) <= 2 && (!strcmp(curent->d_name, ".") ||
 			!strcmp(curent->d_name, "..")))
 			continue;
 	
diff -Naur repos/m0n0cored/src/WorkQueue.cpp repos-r278/m0n0cored/src/WorkQueue.cpp
--- repos/m0n0cored/src/WorkQueue.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/WorkQueue.cpp	2007-07-01 04:13:23.000000000 +0800
@@ -17,6 +17,8 @@
 
 using namespace std;
 
+void* workThreadRun(void* arg);
+
 WorkQueue::WorkQueue(CoreApplication *coreApp) : quit(false) {
 
 	logger = new LogSource("WorkQueue", coreApp->getLogManager());
diff -Naur repos/m0n0cored/src/WorkQueueServiceCall.h repos-r278/m0n0cored/src/WorkQueueServiceCall.h
--- repos/m0n0cored/src/WorkQueueServiceCall.h	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/WorkQueueServiceCall.h	2007-07-10 21:11:26.000000000 +0800
@@ -36,7 +36,7 @@
 	 * @param param parameter for service call (or NULL)
 	 */
 	WorkQueueServiceCall(CoreApplication *coreApp, const string& serviceName, Param *param, const string& username);
-	~WorkQueueServiceCall();
+	virtual ~WorkQueueServiceCall();
 	
 	/**
 	 * Blocks the calling thread until this service call has been completed.
diff -Naur repos/m0n0cored/src/WorkQueueTriggerEvent.h repos-r278/m0n0cored/src/WorkQueueTriggerEvent.h
--- repos/m0n0cored/src/WorkQueueTriggerEvent.h	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/WorkQueueTriggerEvent.h	2007-07-10 20:59:19.000000000 +0800
@@ -37,7 +37,7 @@
 	 */
 	WorkQueueTriggerEvent(CoreApplication *coreApp, const string& eventName, Param *param);
 	
-	~WorkQueueTriggerEvent();
+	virtual ~WorkQueueTriggerEvent();
 	
 protected:
 	void execute();
diff -Naur repos/m0n0cored/src/coreservices/SvcSystem.cpp repos-r278/m0n0cored/src/coreservices/SvcSystem.cpp
--- repos/m0n0cored/src/coreservices/SvcSystem.cpp	2007-06-24 03:56:07.000000000 +0800
+++ repos-r278/m0n0cored/src/coreservices/SvcSystem.cpp	2007-07-02 00:46:49.000000000 +0800
@@ -229,10 +229,12 @@
 	return NULL;
 }
 
+#ifdef __FreeBSD__
 Param* SvcSystem::getUptime() const {
 	int mib[2];
 	int uptime = 0;
-	int now;
+	//int now;
+	time_t now;
 	size_t size;
 	struct timeval  boottime;
 	
@@ -246,6 +248,70 @@
 	
 	return new ParamInt(uptime);
 }
+#endif
+
+#ifdef __linux__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <locale.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#define BAD_OPEN_MESSAGE					\
+   "Error: /proc must be mounted\n"				\
+   "  To mount /proc at boot you need an /etc/fstab line like:\n"	\
+   "      /proc   /proc   proc    defaults\n"			\
+   "  In the meantime, run \"mount /proc /proc -t proc\"\n"
+#define UPTIME_FILE  "/proc/uptime"
+static int uptime_fd = -1;
+static char buf[1024];
+
+/* This macro opens filename only if necessary and seeks to 0 so
+ * that successive calls to the functions are more efficient.
+ * It also reads the current contents of the file into the global buf.
+ */
+#define FILE_TO_BUF(filename, fd) do{				\
+    static int local_n;						\
+    if (fd == -1 && (fd = open(filename, O_RDONLY)) == -1) {	\
+	fputs(BAD_OPEN_MESSAGE, stderr);			\
+	fflush(NULL);						\
+	_exit(102);						\
+    }								\
+    lseek(fd, 0L, SEEK_SET);					\
+    if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) {	\
+	perror(filename);					\
+	fflush(NULL);						\
+	_exit(103);						\
+    }								\
+    buf[local_n] = '\0';					\
+}while(0)
+
+/* evals 'x' twice */
+#define SET_IF_DESIRED(x,y) do{  if(x) *(x) = (y); }while(0)
+   	
+Param* SvcSystem::getUptime() const {
+	
+	//int uptime = 0;
+   	/***********************************************************************/
+    double up=0, idle=0;
+    //char *restrict savelocale;
+    char * savelocale;
+
+    FILE_TO_BUF(UPTIME_FILE,uptime_fd);
+    savelocale = setlocale(LC_NUMERIC, NULL);
+    setlocale(LC_NUMERIC,"C");
+    if (sscanf(buf, "%lf %lf", &up, &idle) < 2) {
+        setlocale(LC_NUMERIC,savelocale);
+        fputs("bad data in " UPTIME_FILE "\n", stderr);
+	    return 0;
+    }
+    setlocale(LC_NUMERIC,savelocale);
+    return new ParamInt((int)up);	/* assume never be zero seconds in practice */
+}
+#endif
 
 Param* SvcSystem::getConfig() const {
 
diff -Naur repos/m0n0cored/src/utils/ModuleMetaParser.cpp repos-r278/m0n0cored/src/utils/ModuleMetaParser.cpp
--- repos/m0n0cored/src/utils/ModuleMetaParser.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/ModuleMetaParser.cpp	2007-07-02 00:17:51.000000000 +0800
@@ -15,7 +15,10 @@
 using namespace std;
 
 #define READ_BUFFER_SIZE	16384
-
+void mmp_startElement(void *userData, const XML_Char *name, const XML_Char **atts);
+void mmp_endElement(void *userData, const XML_Char *name);
+void mmp_cData(void *userData, const XML_Char *s, int len);
+	
 ModuleMetaParser::ModuleMetaParser(const string& metaFileName) : metaFileName(metaFileName) {
 	parser = XML_ParserCreate("UTF-8");
 	curLevel = 0;
diff -Naur repos/m0n0cored/src/utils/ModuleVerifier.cpp repos-r278/m0n0cored/src/utils/ModuleVerifier.cpp
--- repos/m0n0cored/src/utils/ModuleVerifier.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/ModuleVerifier.cpp	2007-07-05 01:44:50.000000000 +0800
@@ -7,6 +7,7 @@
  * (c) 2006-2007 Manuel Kasper <mkasper@hsr.ch> & Daniel Spoerri <dspoerri@hsr.ch>.
  * All rights reserved.
  */
+#include "../global.h"
 #include "ModuleVerifier.h"
 #include "SignatureTools.h"
 #include "../ModuleMetaInfo.h"
@@ -14,7 +15,22 @@
 #include <iostream>
 #include <stdexcept>
 #include <string.h>
-#include <dirent.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -108,7 +124,9 @@
 	while ((ent = readdir(dirp)) != NULL) {
 		string name(ent->d_name);
 		
-		if (ent->d_namlen <= 2 && (name == "." || name == ".."))
+		//if (ent->d_namlen <= 2 && (name == "." || name == ".."))
+		//if ((strlen(ent->d_name)) <= 2 && (name == "." || name == ".."))
+		if (NAMLEN(ent) <= 2 && (name == "." || name == ".."))
 			continue;
 		
 		/* is it a directory? */
diff -Naur repos/m0n0cored/src/utils/SignatureTools.cpp repos-r278/m0n0cored/src/utils/SignatureTools.cpp
--- repos/m0n0cored/src/utils/SignatureTools.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/SignatureTools.cpp	2007-07-02 00:19:10.000000000 +0800
@@ -24,6 +24,8 @@
 
 #define READ_BUFFER_SIZE 16384
 
+int verifyCallback(int ok, X509_STORE_CTX *context);
+	
 X509* SignatureTools::readCertFile(const string& filename) {
 	FILE *f;
 	X509* cert;
diff -Naur repos/m0n0cored/src/utils/SystemConfigParser.cpp repos-r278/m0n0cored/src/utils/SystemConfigParser.cpp
--- repos/m0n0cored/src/utils/SystemConfigParser.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/SystemConfigParser.cpp	2007-07-02 00:30:40.000000000 +0800
@@ -19,6 +19,9 @@
 
 #define READ_BUFFER_SIZE	16384
 
+void st_startElement(void *userData, const XML_Char *name, const XML_Char **atts);
+void st_endElement(void *userData, const XML_Char *name);
+void st_cData(void *userData, const XML_Char *s, int len);		
 SystemConfigParser::SystemConfigParser(const string& configFileName, SystemConfig *config) : configFileName(configFileName), config(config) {
 	parser = XML_ParserCreate("UTF-8");
 	curLevel = 0;
@@ -82,6 +85,7 @@
 				paramStack.push(new ParamStruct());
 				break;
 			case module:
+			{
 				tagStack.push_back(module);
 				
 				// find an attribute named "name"
@@ -91,6 +95,7 @@
 				
 				lastModuleName = nameAttr;
 				break;
+			}
 			default:
 				handled = false;
 		}
@@ -101,6 +106,7 @@
 				handled = handleStructSection(tag, atts);
 				break;
 			case module:
+			{	
 				if (curLevel == 3) {
 					switch (tag) {
 						case common:
@@ -108,6 +114,7 @@
 							paramStack.push(new ParamStruct());
 							break;
 						case service:
+						{
 							tagStack.push_back(service);
 							paramStack.push(new ParamStruct());
 							
@@ -118,6 +125,7 @@
 								
 							lastServiceName = nameAttr;
 							break;
+						}
 						default:
 							handled = false;
 					}
@@ -126,6 +134,7 @@
 					handled = handleStructSection(tag, atts);
 				}
 				break;
+			}
 			default:
 				handled = false;
 		}
@@ -150,6 +159,7 @@
 	
 	switch (tag) {
 		case param:
+		{
 			tagStack.push_back(param);
 			lastParamName = nameAttr;
 			
@@ -159,6 +169,7 @@
 			else
 				lastParamType = "string";
 			break;
+		}
 		case array: {
 			tagStack.push_back(array);
 			ParamArray *child = new ParamArray();
@@ -192,19 +203,21 @@
 	switch (lastParam->getType()) {
 	
 		case PARAMTYPE_ARRAY:
+		{
 			ParamArray*	lastParamArray = (ParamArray*)lastParam;
 			if (name != "")
 				throw SystemConfigParseException("unexpected name attribute in tag inside array");
 			lastParamArray->addParam(child);
 			break;
-			
+		}	
 		case PARAMTYPE_STRUCT:
+		{
 			ParamStruct* lastParamStruct = (ParamStruct*)lastParam;
 			if (name == "")
 				throw SystemConfigParseException("expected name attribute in tag inside struct");
 			lastParamStruct->setParam(name, child);
 			break;
-			
+		}	
 		default:
 			throw SystemConfigParseException("unexpected array tag");
 	}
@@ -262,7 +275,8 @@
 		if (curLevel >= 2) {
 		
 			switch (tagStack[1]) {
-				case version:					
+				case version:		
+				{			
 					/* only conf version 1.0 is supported at this time */
 					if (cDataBuf != "1.0")
 						throw SystemConfigParseException("unknown configuration version " + cDataBuf);
@@ -275,7 +289,9 @@
 					
 					config->setVersion(majorVersion, minorVersion);
 					break;
+				}
 				case lastChange:
+				{
 					int lastChange;
 					char *endptr;
 					lastChange = strtol(cDataBuf.c_str(), &endptr, 10);
@@ -283,6 +299,7 @@
 						throw SystemConfigParseException("invalid lastChange: " + cDataBuf);
 					config->setLastChange(lastChange);
 					break;
+				}
 				case global:
 					if (curLevel == 2) {
 						/* end of global section */
diff -Naur repos/m0n0cored/src/utils/SystemImageVerifier.cpp repos-r278/m0n0cored/src/utils/SystemImageVerifier.cpp
--- repos/m0n0cored/src/utils/SystemImageVerifier.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/SystemImageVerifier.cpp	2007-07-05 01:45:37.000000000 +0800
@@ -7,13 +7,29 @@
  * (c) 2006-2007 Manuel Kasper <mkasper@hsr.ch> & Daniel Spoerri <dspoerri@hsr.ch>.
  * All rights reserved.
  */
+#include "../global.h"
 #include "SystemImageVerifier.h"
 #include "SignatureTools.h"
 
 #include <iostream>
 #include <stdexcept>
 #include <string.h>
-#include <dirent.h>
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 
diff -Naur repos/m0n0cored/src/utils/TarReader.cpp repos-r278/m0n0cored/src/utils/TarReader.cpp
--- repos/m0n0cored/src/utils/TarReader.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/utils/TarReader.cpp	2007-07-02 00:25:40.000000000 +0800
@@ -16,6 +16,10 @@
 
 #define READ_BLOCK_SIZE 65536
 
+ssize_t myread(struct archive *a, void *client_data, const void **buff);
+int myopen(struct archive *a, void *client_data);
+int myclose(struct archive *a, void *client_data);
+
 TarReader::TarReader(const string& dirName) : dirName(dirName) {
 }
 
diff -Naur repos/m0n0cored/src/xmlrpc/ParamConverter.cpp repos-r278/m0n0cored/src/xmlrpc/ParamConverter.cpp
--- repos/m0n0cored/src/xmlrpc/ParamConverter.cpp	2007-06-24 03:56:08.000000000 +0800
+++ repos-r278/m0n0cored/src/xmlrpc/ParamConverter.cpp	2007-07-02 00:26:22.000000000 +0800
@@ -27,6 +27,7 @@
 			return new ParamString(value);
 		
 		case XmlRpcValue::TypeArray:
+		{
 			ParamArray *arr = new ParamArray();
 			
 			for (int i = 0; i < value.size(); i++) {
@@ -34,8 +35,9 @@
 			}
 			
 			return arr;
-		
+		}
 		case XmlRpcValue::TypeStruct:
+		{
 			ParamStruct *stc = new ParamStruct();
 			
 			for (XmlRpcValue::ValueStruct::iterator it = value.struct_begin();
@@ -45,7 +47,7 @@
 			}
 			
 			return stc;
-		
+		}
 		case XmlRpcValue::TypeBase64: {
 			XmlRpcValue::BinaryData& bin = value;
 			return new ParamBinary(&bin[0], bin.size());
diff -Naur repos/m0n0cored/test/Makefile repos-r278/m0n0cored/test/Makefile
--- repos/m0n0cored/test/Makefile	2007-06-24 03:56:07.000000000 +0800
+++ repos-r278/m0n0cored/test/Makefile	2007-07-07 01:06:47.000000000 +0800
@@ -2,7 +2,7 @@
 all: deptest moduleverifiertest tarReaderTest
 
 moduleverifiertest: moduleverifiertest.cpp ../src/utils/ModuleVerifier.cpp ../src/utils/ModuleMetaParser.cpp
-	g++ -o moduleverifiertest -lcrypto -lexpat -L/usr/local/lib -I/usr/local/include moduleverifiertest.cpp ../src/utils/ModuleVerifier.cpp ../src/utils/ModuleMetaParser.cpp
+	g++ -o moduleverifiertest -lcrypto -lexpat -L/usr/local/lib -I/usr/local/include moduleverifiertest.cpp ../src/utils/ModuleVerifier.cpp ../src/utils/ModuleMetaParser.cpp -I ../
 
 deptest: deptest.cpp
 	g++ -o deptest deptest.cpp
