diff options
Diffstat (limited to 'tests/nettester.c')
-rw-r--r-- | tests/nettester.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/tests/nettester.c b/tests/nettester.c index 609f586e..9e68ebcc 100644 --- a/tests/nettester.c +++ b/tests/nettester.c @@ -47,6 +47,7 @@ #include <signal.h> #include <netinet/in.h> #include <getopt.h> +#include <errno.h> #include <ctype.h> #define EXIT_FAILURE 1 @@ -62,6 +63,7 @@ static char *testSuite = NULL; /* name of current test suite */ static int iPort = 12514; /* port which shall be used for sending data */ static char* pszCustomConf = NULL; /* custom config file, use -c conf to specify */ static int verbose = 0; /* verbose output? -v option */ +static int IPv4Only = 0; /* use only IPv4 in rsyslogd call? */ static char **ourEnvp; /* these two are quick hacks... */ @@ -92,6 +94,7 @@ void readLine(int fd, char *ln) if(verbose) fprintf(stderr, "begin readLine\n"); lenRead = read(fd, &c, 1); + while(lenRead == 1 && c != '\n') { if(c == '\0') { *ln = c; @@ -104,6 +107,11 @@ void readLine(int fd, char *ln) } *ln = '\0'; + if(lenRead < 0) { + printf("read from rsyslogd returned with error '%s' - aborting test\n", strerror(errno)); + exit(1); + } + if(verbose) fprintf(stderr, "end readLine, val read '%s'\n", orig); } @@ -157,7 +165,7 @@ tcpSend(char *buf, int lenBuf) iRet = 1; goto finalize_it; } else { - usleep(100000); /* 0.1 sec, these are us! */ + usleep(100000); /* ms = 1000 us! */ } } } @@ -236,13 +244,16 @@ int openPipe(char *configFile, pid_t *pid, int *pfd) int pipefd[2]; pid_t cpid; char *newargv[] = {"../tools/rsyslogd", "dummy", "-c4", "-u2", "-n", "-irsyslog.pid", - "-M../runtime/.libs:../.libs", NULL }; + "-M../runtime/.libs:../.libs", NULL, NULL}; char confFile[1024]; sprintf(confFile, "-f%s/testsuites/%s.conf", srcdir, (pszCustomConf == NULL) ? configFile : pszCustomConf); newargv[1] = confFile; + if(IPv4Only) + newargv[(sizeof(newargv)/sizeof(char*)) - 2] = "-4"; + if (pipe(pipefd) == -1) { perror("pipe"); exit(EXIT_FAILURE); @@ -384,12 +395,17 @@ processTestFile(int fd, char *pszFileName) /* pull response from server and then check if it meets our expectation */ //printf("try pull pipe...\n"); readLine(fd, buf); + if(strlen(buf) == 0) { + printf("something went wrong - read a zero-length string from rsyslogd\n"); + exit(1); + } if(strcmp(expected, buf)) { ++iFailed; printf("\nFile %s:\nExpected Response:\n'%s'\nActual Response:\n'%s'\n", pszFileName, expected, buf); ret = 1; } + /* we need to free buffers, as we have potentially modified them! */ free(testdata); testdata = NULL; @@ -397,7 +413,6 @@ processTestFile(int fd, char *pszFileName) expected = NULL; } - free(expected); fclose(fp); return(ret); } @@ -452,11 +467,24 @@ doTests(int fd, char *files) return(iFailed); } + +/* indicate that our child has died (where it is not permitted to!). + */ +void childDied(__attribute__((unused)) int sig) +{ + printf("ERROR: child died unexpectedly (maybe a segfault?)!\n"); + exit(1); +} + + /* cleanup */ void doAtExit(void) { int status; + /* disarm died-child handler */ + signal(SIGCHLD, SIG_IGN); + if(rsyslogdPid != 0) { kill(rsyslogdPid, SIGTERM); waitpid(rsyslogdPid, &status, 0); /* wait until instance terminates */ @@ -480,8 +508,11 @@ int main(int argc, char *argv[], char *envp[]) char testcases[4096]; ourEnvp = envp; - while((opt = getopt(argc, argv, "dc:i:p:t:v")) != EOF) { + while((opt = getopt(argc, argv, "4c:i:p:t:v")) != EOF) { switch((char)opt) { + case '4': + IPv4Only = 1; + break; case 'c': pszCustomConf = optarg; break; @@ -538,6 +569,9 @@ int main(int argc, char *argv[], char *envp[]) } fclose(fp); + /* arm died-child handler */ + signal(SIGCHLD, childDied); + /* make sure we do not abort if there is an issue with pipes. * our code does the necessary error handling. */ @@ -553,5 +587,6 @@ int main(int argc, char *argv[], char *envp[]) ret = 1; if(verbose) printf("End of nettester run (%d).\n", ret); + exit(ret); } |