summaryrefslogtreecommitdiff
path: root/infrastructure/buildenv-testmain-template.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'infrastructure/buildenv-testmain-template.cpp')
-rw-r--r--infrastructure/buildenv-testmain-template.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/infrastructure/buildenv-testmain-template.cpp b/infrastructure/buildenv-testmain-template.cpp
index b646a27b..287c4bff 100644
--- a/infrastructure/buildenv-testmain-template.cpp
+++ b/infrastructure/buildenv-testmain-template.cpp
@@ -29,9 +29,23 @@
#include <getopt.h>
#endif
+<<<<<<< HEAD
#include <sys/stat.h>
#include <sys/types.h>
+=======
+#ifdef HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#endif
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_UN_H
+# include <sys/un.h>
+#endif
+
+>>>>>>> 0.12
#include <exception>
#include <string>
@@ -76,7 +90,19 @@ inline bool checkfilesleftopen() { return false; }
#define FILEDES_MAX 256
+<<<<<<< HEAD
bool filedes_open[FILEDES_MAX];
+=======
+typedef enum
+{
+ OPEN,
+ CLOSED,
+ SYSLOG
+}
+filedes_t;
+
+filedes_t filedes_open[FILEDES_MAX];
+>>>>>>> 0.12
bool check_filedes(bool report)
{
@@ -87,11 +113,59 @@ bool check_filedes(bool report)
{
if(::fcntl(d, F_GETFD) != -1)
{
+<<<<<<< HEAD
// File descriptor obviously exists
if (report && !filedes_open[d])
{
struct stat st;
if (fstat(d, &st) == 0)
+=======
+ // File descriptor obviously exists, but is it /dev/log?
+
+ struct stat st;
+ bool stat_success = false;
+ bool is_syslog_socket = false;
+
+ if(fstat(d, &st) == 0)
+ {
+ stat_success = true;
+ }
+
+ if(stat_success && (st.st_mode & S_IFSOCK))
+ {
+ char buffer[256];
+ socklen_t addrlen = sizeof(buffer);
+
+#ifdef HAVE_GETPEERNAME
+ if(getpeername(d, (sockaddr*)buffer, &addrlen) != 0)
+ {
+ BOX_WARNING("Failed to getpeername(" <<
+ d << "), cannot identify /dev/log");
+ }
+ else
+ {
+ struct sockaddr_un *sa =
+ (struct sockaddr_un *)buffer;
+ if(sa->sun_family == PF_UNIX &&
+ !strcmp(sa->sun_path, "/dev/log"))
+ {
+ is_syslog_socket = true;
+ }
+ }
+#endif // HAVE_GETPEERNAME
+ }
+
+ if(report && filedes_open[d] != OPEN)
+ {
+ if(filedes_open[d] == SYSLOG)
+ {
+ // Different libcs have different ideas
+ // about when to open and close this
+ // socket, and it's not a leak, so
+ // ignore it.
+ }
+ else if(stat_success)
+>>>>>>> 0.12
{
int m = st.st_mode;
#define flag(x) ((m & x) ? #x " " : "")
@@ -105,11 +179,16 @@ bool check_filedes(bool report)
flag(S_IFLNK) <<
flag(S_IFSOCK) <<
" or " << m << ")");
+<<<<<<< HEAD
+=======
+ allOk = false;
+>>>>>>> 0.12
}
else
{
BOX_FATAL("File descriptor " << d <<
" left open (and stat failed)");
+<<<<<<< HEAD
}
allOk = false;
@@ -118,10 +197,19 @@ bool check_filedes(bool report)
else if (!report)
{
filedes_open[d] = true;
+=======
+ allOk = false;
+ }
+ }
+ else if (!report)
+ {
+ filedes_open[d] = is_syslog_socket ? SYSLOG : OPEN;
+>>>>>>> 0.12
}
}
else
{
+<<<<<<< HEAD
if (report && filedes_open[d])
{
BOX_FATAL("File descriptor " << d <<
@@ -131,6 +219,27 @@ bool check_filedes(bool report)
else
{
filedes_open[d] = false;
+=======
+ if (report && filedes_open[d] != CLOSED)
+ {
+ if (filedes_open[d] == SYSLOG)
+ {
+ // Different libcs have different ideas
+ // about when to open and close this
+ // socket, and it's not a leak, so
+ // ignore it.
+ }
+ else if(filedes_open[d] == OPEN)
+ {
+ BOX_FATAL("File descriptor " << d <<
+ " was open, now closed");
+ allOk = false;
+ }
+ }
+ else
+ {
+ filedes_open[d] = CLOSED;
+>>>>>>> 0.12
}
}
}
@@ -183,7 +292,11 @@ int main(int argc, char * const * argv)
int ch;
+<<<<<<< HEAD
while ((ch = getopt_long(argc, argv, "c:d:qs:t:vPTUV", longopts, NULL))
+=======
+ while ((ch = getopt_long(argc, argv, "c:d:qs:t:vPTUVW:", longopts, NULL))
+>>>>>>> 0.12
!= -1)
{
switch(ch)
@@ -255,6 +368,20 @@ int main(int argc, char * const * argv)
}
break;
+<<<<<<< HEAD
+=======
+ case 'W':
+ {
+ logLevel = Logging::GetNamedLevel(optarg);
+ if (logLevel == Log::INVALID)
+ {
+ BOX_FATAL("Invalid logging level: " << optarg);
+ return 2;
+ }
+ }
+ break;
+
+>>>>>>> 0.12
case 't':
{
Logging::SetProgramName(optarg);
@@ -292,6 +419,10 @@ int main(int argc, char * const * argv)
}
Logging::SetGlobalLevel((Log::Level)logLevel);
+<<<<<<< HEAD
+=======
+ Logging::FilterConsole((Log::Level)logLevel);
+>>>>>>> 0.12
argc -= optind - 1;
argv += optind - 1;
@@ -369,6 +500,15 @@ int main(int argc, char * const * argv)
return returncode;
}
+<<<<<<< HEAD
+=======
+ catch(BoxException &e)
+ {
+ printf("FAILED: Exception caught: %s: %s\n", e.what(),
+ e.GetMessage().c_str());
+ return 1;
+ }
+>>>>>>> 0.12
catch(std::exception &e)
{
printf("FAILED: Exception caught: %s\n", e.what());