[Box Backup-commit] COMMIT r1734 - box/chris/general/lib/server

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Thu, 26 Jul 2007 22:32:33 +0100


Author: chris
Date: 2007-07-26 22:32:33 +0100 (Thu, 26 Jul 2007)
New Revision: 1734

Modified:
   box/chris/general/lib/server/Daemon.cpp
Log:
Hopefully reset getopt in a way that's compatible with BSD and GLIBC,
thanks to Tobias Balle-Petersen for pointing out this bug. (refs #3,
merges [1695])


Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp	2007-07-26 21:31:50 UTC (rev 1733)
+++ box/chris/general/lib/server/Daemon.cpp	2007-07-26 21:32:33 UTC (rev 1734)
@@ -110,8 +110,17 @@
 	#endif
 
 	signed int c;
-	optind = 0; // just in case anybody used getopt before
 
+	// reset getopt, just in case anybody used it before.
+	// unfortunately glibc and BSD differ on this point!
+	// http://www.ussg.iu.edu/hypermail/linux/kernel/0305.3/0262.html
+	#ifdef __GLIBC__
+		optind = 1;
+	#else
+		optind = 0;
+		optreset = 1;
+	#endif
+
 	while((c = getopt(argc, (char * const *)argv, "c:DqvVt:Tk")) != -1)
 	{
 		switch(c)