[Box Backup-commit] COMMIT r1891 - in box/trunk: bin/bbackupd bin/bbstored lib/server

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Wed Oct 17 13:54:17 BST 2007


Author: chris
Date: 2007-10-17 13:54:17 +0100 (Wed, 17 Oct 2007)
New Revision: 1891

Modified:
   box/trunk/bin/bbackupd/BackupDaemon.cpp
   box/trunk/bin/bbackupd/BackupDaemon.h
   box/trunk/bin/bbstored/BackupStoreDaemon.cpp
   box/trunk/bin/bbstored/BackupStoreDaemon.h
   box/trunk/lib/server/Daemon.cpp
   box/trunk/lib/server/Daemon.h
Log:
Add "-h" and "/?" options to display usage in Daemon.

Extend usage info with service commands in BackupDaemon.

Disable useless -D, -V and -k options on Windows.

(merges 1855])


Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp	2007-10-17 12:54:17 UTC (rev 1891)
@@ -38,6 +38,8 @@
 	#include <process.h>
 #endif
 
+#include <iostream>
+
 #include "Configuration.h"
 #include "IOStream.h"
 #include "MemBlockStream.h"
@@ -209,13 +211,21 @@
 //		Created: 1/1/04
 //
 // --------------------------------------------------------------------------
-const char *BackupDaemon::DaemonBanner() const
+std::string BackupDaemon::DaemonBanner() const
 {
-#ifndef NDEBUG
-	// Don't display banner in debug builds
-	return 0;
-#else
 	return BANNER_TEXT("Backup Client");
+}
+
+void BackupDaemon::Usage()
+{
+	this->Daemon::Usage();
+
+#ifdef WIN32
+	std::cout <<
+	"  -s         Run as a Windows Service, for internal use only\n"
+	"  -i         Install Windows Service (you may want to specify a config file)\n"
+	"  -r         Remove Windows Service\n"
+	"  -S <name>  Service name for -i and -r options\n";
 #endif
 }
 

Modified: box/trunk/bin/bbackupd/BackupDaemon.h
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.h	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/bin/bbackupd/BackupDaemon.h	2007-10-17 12:54:17 UTC (rev 1891)
@@ -69,7 +69,8 @@
 
 	void Run();
 	virtual const char *DaemonName() const;
-	virtual const char *DaemonBanner() const;
+	virtual std::string DaemonBanner() const;
+	virtual void Usage();
 	const ConfigurationVerify *GetConfigVerify() const;
 
 	bool FindLocationPathName(const std::string &rLocationName, std::string &rPathOut) const;

Modified: box/trunk/bin/bbstored/BackupStoreDaemon.cpp
===================================================================
--- box/trunk/bin/bbstored/BackupStoreDaemon.cpp	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/bin/bbstored/BackupStoreDaemon.cpp	2007-10-17 12:54:17 UTC (rev 1891)
@@ -93,14 +93,9 @@
 //		Created: 1/1/04
 //
 // --------------------------------------------------------------------------
-const char *BackupStoreDaemon::DaemonBanner() const
+std::string BackupStoreDaemon::DaemonBanner() const
 {
-#ifndef NDEBUG
-	// Don't display banner in debug builds
-	return 0;
-#else
 	return BANNER_TEXT("Backup Store Server");
-#endif
 }
 
 

Modified: box/trunk/bin/bbstored/BackupStoreDaemon.h
===================================================================
--- box/trunk/bin/bbstored/BackupStoreDaemon.h	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/bin/bbstored/BackupStoreDaemon.h	2007-10-17 12:54:17 UTC (rev 1891)
@@ -56,7 +56,7 @@
 	void Connection2(SocketStreamTLS &rStream);
 	
 	virtual const char *DaemonName() const;
-	virtual const char *DaemonBanner() const;
+	virtual std::string DaemonBanner() const;
 
 	const ConfigurationVerify *GetConfigVerify() const;
 	

Modified: box/trunk/lib/server/Daemon.cpp
===================================================================
--- box/trunk/lib/server/Daemon.cpp	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/lib/server/Daemon.cpp	2007-10-17 12:54:17 UTC (rev 1891)
@@ -23,6 +23,8 @@
 	#include <ws2tcpip.h>
 #endif
 
+#include <iostream>
+
 #include "Daemon.h"
 #include "Configuration.h"
 #include "ServerException.h"
@@ -51,7 +53,8 @@
 	  mSingleProcess(false),
 	  mRunInForeground(false),
 	  mKeepConsoleOpenAfterFork(false),
-	  mHaveConfigFile(false)
+	  mHaveConfigFile(false),
+	  mAppName(DaemonName())
 {
 	if(spDaemon != NULL)
 	{
@@ -99,9 +102,35 @@
 // --------------------------------------------------------------------------
 std::string Daemon::GetOptionString()
 {
-	return "c:DFqvVt:Tk";
+	return "c:"
+	#ifndef WIN32
+		"DFk"
+	#endif
+		"hqvVt:T";
 }
 
+void Daemon::Usage()
+{
+	std::cout << 
+	DaemonBanner() << "\n"
+	"\n"
+	"Usage: " << mAppName << " [options] [config file]\n" <<
+	"\n"
+	"Options:\n"
+	"  -c <file>  Use the specified configuration file. If -c is omitted, the last\n"
+	"             argument is the configuration file\n"
+#ifndef WIN32
+	"  -D         Debugging mode, do not fork, one process only, one client only\n"
+	"  -F         Do not fork into background, but fork to serve multiple clients\n"
+	"  -k         Keep console open after fork, keep writing log messages to it\n"
+#endif
+	"  -q         Run more quietly, reduce verbosity level by one, can repeat\n"
+	"  -v         Run more verbosely, increase verbosity level by one, can repeat\n"
+	"  -V         Run at maximum verbosity\n"
+	"  -t <tag>   Tag console output with specified marker\n"
+	"  -T         Timestamp console output\n";
+}
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -124,6 +153,7 @@
 		}
 		break;
 
+#ifndef WIN32
 		case 'D':
 		{
 			mSingleProcess = true;
@@ -136,6 +166,20 @@
 		}
 		break;
 
+		case 'k':
+		{
+			mKeepConsoleOpenAfterFork = true;
+		}
+		break;
+#endif
+
+		case 'h':
+		{
+			Usage();
+			return 2;
+		}
+		break;
+
 		case 'q':
 		{
 			if(mLogLevel == Log::NOTHING)
@@ -180,12 +224,6 @@
 		}
 		break;
 
-		case 'k':
-		{
-			mKeepConsoleOpenAfterFork = true;
-		}
-		break;
-
 		case '?':
 		{
 			BOX_FATAL("Unknown option on command line: " 
@@ -219,6 +257,7 @@
 {
 	// Find filename of config file
 	mConfigFileName = DefaultConfigFile;
+	mAppName = argv[0];
 
 	#ifdef NDEBUG
 	mLogLevel = Log::NOTICE; // need an int to do math with
@@ -226,6 +265,12 @@
 	mLogLevel = Log::INFO; // need an int to do math with
 	#endif
 
+	if (argc == 2 && strcmp(argv[1], "/?") == 0)
+	{
+		Usage();
+		return 2;
+	}
+
 	signed int c;
 
 	// reset getopt, just in case anybody used it before.
@@ -283,11 +328,9 @@
 {
 	// Banner (optional)
 	{
-		const char *banner = DaemonBanner();
-		if(banner != 0)
-		{
-			BOX_NOTICE(banner);
-		}
+		#ifndef NDEBUG
+		BOX_NOTICE(DaemonBanner());
+		#endif
 	}
 
 	std::string pidFileName;
@@ -671,9 +714,9 @@
 //		Created: 1/1/04
 //
 // --------------------------------------------------------------------------
-const char *Daemon::DaemonBanner() const
+std::string Daemon::DaemonBanner() const
 {
-	return 0;
+	return "Generic daemon using the Box Application Framework";
 }
 
 

Modified: box/trunk/lib/server/Daemon.h
===================================================================
--- box/trunk/lib/server/Daemon.h	2007-10-17 12:53:52 UTC (rev 1890)
+++ box/trunk/lib/server/Daemon.h	2007-10-17 12:54:17 UTC (rev 1891)
@@ -50,8 +50,9 @@
 	const std::string &GetConfigFileName() const {return mConfigFileName;}
 
 	virtual const char *DaemonName() const;
-	virtual const char *DaemonBanner() const;
+	virtual std::string DaemonBanner() const;
 	virtual const ConfigurationVerify *GetConfigVerify() const;
+	virtual void Usage();
 	
 	bool StopRun() {return mReloadConfigWanted | mTerminateWanted;}
 	bool IsReloadConfigWanted() {return mReloadConfigWanted;}
@@ -87,6 +88,7 @@
 	bool mHaveConfigFile;
 	int mLogLevel; // need an int to do math with
 	static Daemon *spDaemon;
+	std::string mAppName;
 };
 
 #define DAEMON_VERIFY_SERVER_KEYS 	{"PidFile", 0, ConfigTest_Exists, 0}, \




More information about the Boxbackup-commit mailing list