[Guessnet-devel] [svn] r166 - in trunk: . src tests
Enrico Zini
enrico at costa.debian.org
Sat Sep 23 12:04:15 UTC 2006
Author: enrico
Date: Sat Sep 23 12:04:14 2006
New Revision: 166
Removed:
trunk/src/ChildProcess.cc
trunk/src/ChildProcess.h
trunk/src/Exec.cc
trunk/src/Exec.h
trunk/src/Mutex.h
trunk/src/Thread.cc
trunk/src/Thread.h
Modified:
trunk/ (props changed)
trunk/src/DHCPScanner.h
trunk/src/IFace.cc
trunk/src/Makefile.am
trunk/src/NetSender.cc
trunk/src/NetWatcher.cc
trunk/src/PeerScanner.h
trunk/src/ProcessRunner.cc
trunk/src/ScriptScanner.cc
trunk/src/ScriptScanner.h
trunk/src/TrafficScanner.h
trunk/src/guessnet-scan.cc
trunk/src/guessnet.cc
trunk/tests/Makefile.am
Log:
r431 at viaza: enrico | 2006-09-23 13:04:10 +0100
Use the process and thread functions from wibble
Modified: trunk/src/DHCPScanner.h
==============================================================================
--- trunk/src/DHCPScanner.h (original)
+++ trunk/src/DHCPScanner.h Sat Sep 23 12:04:14 2006
@@ -23,7 +23,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "Mutex.h"
+#include <wibble/sys/mutex.h>
#include "Scanner.h"
#include "NetWatcher.h"
#include "NetSender.h"
@@ -34,7 +34,7 @@
class DHCPScanner : public Scanner, public PacketListener
{
protected:
- Mutex candMutex;
+ wibble::sys::Mutex candMutex;
NetSender sender;
Modified: trunk/src/IFace.cc
==============================================================================
--- trunk/src/IFace.cc (original)
+++ trunk/src/IFace.cc Sat Sep 23 12:04:14 2006
@@ -56,8 +56,6 @@
#include <iostream>
-#include "Exec.h"
-#include "ChildProcess.h"
#include "Environment.h"
#ifndef SIOCGMIIPHY
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sat Sep 23 12:04:14 2006
@@ -8,9 +8,6 @@
sbin_PROGRAMS = guessnet guessnet-scan
guessnet_SOURCES = \
- Thread.cc \
- Exec.cc \
- ChildProcess.cc \
Parser.cc \
Scans.cc \
ScanBag.cc \
@@ -31,9 +28,6 @@
guessnet_LDADD = @LIBNET_LIBS@ @LIBWIBBLE_LIBS@
guessnet_scan_SOURCES = \
- Thread.cc \
- Exec.cc \
- ChildProcess.cc \
IFace.cc \
Environment.cc \
nettypes.cc \
@@ -49,17 +43,14 @@
INCLUDES=@LIBNET_CFLAGS@ @LIBWIBBLE_CFLAGS@ -DSCRIPTDIR=\"@scriptdir@\" -DCOMPILE_TESTSUITE
EXTRA_DIST = \
- ChildProcess.h \
DHCPScanner.h \
Environment.h \
ethtool-kernel.h \
ethtool-local.h \
- Exec.h \
GuessnetEnvironment.h \
GuessnetParser.h \
IFace.h \
IfaceParser.h \
- Mutex.h \
NetSender.h \
nettypes.h \
NetWatcher.h \
@@ -72,7 +63,6 @@
Scanner.h \
Scans.h \
ScriptScanner.h \
- Thread.h \
TrafficScanner.h \
wireless.15.h \
wireless.16.h \
Modified: trunk/src/NetSender.cc
==============================================================================
--- trunk/src/NetSender.cc (original)
+++ trunk/src/NetSender.cc Sat Sep 23 12:04:14 2006
@@ -19,11 +19,11 @@
*/
#include "NetSender.h"
-
-#include "Thread.h"
-#include "Mutex.h"
#include "Environment.h"
+#include <wibble/sys/thread.h>
+#include <wibble/sys/mutex.h>
+
extern "C" {
#include <libnet.h>
}
Modified: trunk/src/NetWatcher.cc
==============================================================================
--- trunk/src/NetWatcher.cc (original)
+++ trunk/src/NetWatcher.cc Sat Sep 23 12:04:14 2006
@@ -20,8 +20,8 @@
#include "NetWatcher.h"
-#include "Thread.h"
-#include "Mutex.h"
+#include <wibble/sys/thread.h>
+#include <wibble/sys/mutex.h>
extern "C" {
#include <pcap.h>
Modified: trunk/src/PeerScanner.h
==============================================================================
--- trunk/src/PeerScanner.h (original)
+++ trunk/src/PeerScanner.h Sat Sep 23 12:04:14 2006
@@ -23,7 +23,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "Mutex.h"
+#include <wibble/sys/mutex.h>
#include "Scanner.h"
#include "NetWatcher.h"
#include "NetSender.h"
@@ -36,7 +36,7 @@
class PeerScanner : public Scanner, public PacketListener
{
protected:
- Mutex candMutex;
+ wibble::sys::Mutex candMutex;
NetSender sender;
Modified: trunk/src/ProcessRunner.cc
==============================================================================
--- trunk/src/ProcessRunner.cc (original)
+++ trunk/src/ProcessRunner.cc Sat Sep 23 12:04:14 2006
@@ -20,10 +20,10 @@
#include "ProcessRunner.h"
-#include "Thread.h"
-#include "Mutex.h"
-#include "Exec.h"
-#include "ChildProcess.h"
+#include <wibble/sys/thread.h>
+#include <wibble/sys/mutex.h>
+#include <wibble/sys/exec.h>
+#include <wibble/sys/childprocess.h>
#include "Environment.h"
#include <sys/types.h> // pid_t
@@ -34,6 +34,7 @@
#include <sstream>
using namespace std;
+using namespace wibble::sys;
//#define DEBUG(args...) fprintf(stderr, ##args)
#define DEBUG(args...) do {} while(0)
@@ -45,7 +46,7 @@
return access(file.c_str(), X_OK) != -1;
}
-class Script : public Process
+class Script : public ChildProcess
{
protected:
string tag;
@@ -63,37 +64,16 @@
int Script::main() throw ()
{
try {
- Exec runner("/bin/sh");
-
- runner.addEnv("NAME=" + tag);
- runner.addEnv("IFACE=" + iface);
- runner.addEnv("GUESSNET=true");
- runner.addEnv(string("PATH=") + SCRIPTDIR + ":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
-
- runner.addArg("/bin/sh");
- runner.addArg("-c");
-
- //// This does not make any sense, since we set a reasonable path
- //
- // Try to find the command in known locations
- //string cmd = cmdline;
- //if (cmdline[0] != '/')
- //{
- // cmd = string(SCRIPTDIR) + "/" + cmdline;
- //}
-
- // This test does not make any sense: it does not add security against
- // malicious PATHs, since we are executing an arbitrary shell line
- // which can have pipelines and all sorts of other problems, it
- // does not add a useful feature, and it adds confusion when users use
- // relative paths and see guessnet trying to search exotic locations.
- //if (!canRun(cmd))
- // throw wibble::exception::System("checking if " + cmd + " can be executed");
- runner.addArg(cmdline);
+ ShellCommand cmd(cmdline);
+ cmd.envFromParent = false;
+ cmd.env.push_back("NAME=" + tag);
+ cmd.env.push_back("IFACE=" + iface);
+ cmd.env.push_back("GUESSNET=true");
+ cmd.env.push_back(string("PATH=") + SCRIPTDIR + ":/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
DEBUG("SCRIPT MAIN Running %.*s\n", PFSTR(cmdline));
- runner.exec();
+ cmd.exec();
} catch (std::exception& e) {
fprintf(stderr, "%s\n", e.what());
}
@@ -112,7 +92,6 @@
{
string tag;
Script* script;
- ChildProcess* proc;
ProcessListener* listener;
ProcData(const string& tag, const string& cmdline, ProcessListener* listener) throw ();
@@ -162,14 +141,11 @@
throw () : tag(tag), listener(listener)
{
script = new Script(tag, Environment::get().iface(), cmdline);
- proc = new ChildProcess(script);
}
void ProcessRunnerImpl::ProcData::run() throw (wibble::exception::System)
{
- proc->fork();
- delete script;
- script = 0;
+ script->fork();
}
void ProcessRunnerImpl::addProcess(
@@ -239,8 +215,8 @@
ProcData d = queuedForRunning.front();
queuedForRunning.pop();
d.run();
- proclist.insert(make_pair(d.proc->pid(), d));
- debug("run process %s pid: %d\n", d.tag.c_str(), d.proc->pid());
+ proclist.insert(make_pair(d.script->pid(), d));
+ debug("run process %s pid: %d\n", d.tag.c_str(), d.script->pid());
}
}
}
@@ -253,10 +229,10 @@
i != proclist.end(); i++)
{
DEBUG("PRI Perform shutdown of %s\n", i->second.tag.c_str());
- debug("still running: %s (%d)\n", i->second.tag.c_str(), i->second.proc->pid());
- i->second.proc->kill(9);
- i->second.proc->wait();
- delete i->second.proc;
+ debug("still running: %s (%d)\n", i->second.tag.c_str(), i->second.script->pid());
+ i->second.script->kill(9);
+ i->second.script->wait();
+ delete i->second.script;
DEBUG("PRI Performed shutdown of %s\n", i->second.tag.c_str());
}
proclist.clear();
@@ -311,7 +287,7 @@
string tag = i->second.tag;
// Remove the process from the proclist
- delete i->second.proc;
+ delete i->second.script;
proclist.erase(i);
// Notify the listener
Modified: trunk/src/ScriptScanner.cc
==============================================================================
--- trunk/src/ScriptScanner.cc (original)
+++ trunk/src/ScriptScanner.cc Sat Sep 23 12:04:14 2006
@@ -21,6 +21,7 @@
#include "ScriptScanner.h"
using namespace std;
+using namespace wibble::sys;
void ScriptScanner::handleTermination(const std::string& signature, int status) throw ()
Modified: trunk/src/ScriptScanner.h
==============================================================================
--- trunk/src/ScriptScanner.h (original)
+++ trunk/src/ScriptScanner.h Sat Sep 23 12:04:14 2006
@@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "Mutex.h"
+#include <wibble/sys/mutex.h>
#include "Scanner.h"
#include "ProcessRunner.h"
@@ -32,7 +32,7 @@
{
protected:
ProcessRunner runner;
- Mutex candMutex;
+ wibble::sys::Mutex candMutex;
std::map<std::string, const Scan*> scans;
public:
Modified: trunk/src/TrafficScanner.h
==============================================================================
--- trunk/src/TrafficScanner.h (original)
+++ trunk/src/TrafficScanner.h Sat Sep 23 12:04:14 2006
@@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "Mutex.h"
+#include <wibble/sys/mutex.h>
#include "Scanner.h"
#include "NetWatcher.h"
#include "NetSender.h"
Modified: trunk/src/guessnet-scan.cc
==============================================================================
--- trunk/src/guessnet-scan.cc (original)
+++ trunk/src/guessnet-scan.cc Sat Sep 23 12:04:14 2006
@@ -29,11 +29,11 @@
#endif
#include "TrafficScanner.h"
-#include "Mutex.h"
#include "Environment.h"
-
#include "IFace.h"
+#include <wibble/sys/mutex.h>
+
#include <stdio.h>
#include <ctype.h>
#include <errno.h> /* errno */
@@ -86,6 +86,7 @@
}
using namespace std;
+using namespace wibble::sys;
class MainScanner
{
Modified: trunk/src/guessnet.cc
==============================================================================
--- trunk/src/guessnet.cc (original)
+++ trunk/src/guessnet.cc Sat Sep 23 12:04:14 2006
@@ -34,12 +34,14 @@
#include "ScriptScanner.h"
#include "DHCPScanner.h"
#include "ScanConsumer.h"
-#include "Mutex.h"
#include "GuessnetEnvironment.h"
#include "ScanBag.h"
#include "IFace.h"
+#include <wibble/sys/mutex.h>
+#include <wibble/sys/thread.h>
+
#include <stdio.h>
#include <ctype.h>
#include <errno.h> /* errno */
@@ -56,9 +58,8 @@
#include <vector>
#include <iostream>
-#include "Thread.h"
-
using namespace std;
+using namespace wibble::sys;
class ScanRunner : public ScannerListener, public ScanConsumer
{
Modified: trunk/tests/Makefile.am
==============================================================================
--- trunk/tests/Makefile.am (original)
+++ trunk/tests/Makefile.am Sat Sep 23 12:04:14 2006
@@ -2,10 +2,8 @@
check_PROGRAMS = guessnet-test
guessnet_test_SOURCES = tut-main.cpp
guessnet_test_LDADD = \
- ../src/ChildProcess.o \
../src/DHCPScanner.o \
../src/Environment.o \
- ../src/Exec.o \
../src/GuessnetEnvironment.o \
../src/GuessnetParser.o \
../src/IFace.o \
@@ -20,7 +18,6 @@
../src/ScanBag.o \
../src/Scans.o \
../src/ScriptScanner.o \
- ../src/Thread.o \
../src/TrafficScanner.o \
@LIBNET_LIBS@ @LIBWIBBLE_LIBS@
@@ -50,7 +47,6 @@
test_netsender_LDADD = \
../src/nettypes.o \
../src/Environment.o \
- ../src/Thread.o \
../src/IFace.o \
../src/PacketMaker.o \
../src/NetWatcher.o \
@@ -61,7 +57,6 @@
test-netwatcher.cc
test_netwatcher_LDADD = \
../src/Environment.o \
- ../src/Thread.o \
../src/IFace.o \
../src/NetWatcher.o \
@LIBNET_LIBS@ @LIBWIBBLE_LIBS@
@@ -70,9 +65,6 @@
test-processrunner.cc
test_processrunner_LDADD = \
../src/Environment.o \
- ../src/Thread.o \
- ../src/Exec.o \
- ../src/ChildProcess.o \
../src/ProcessRunner.o \
@LIBNET_LIBS@ @LIBWIBBLE_LIBS@
More information about the Guessnet-devel
mailing list