Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Three small bugfixes, one of which was causing real issues for MLab servers in developing nations. A one-line compiler warning fix for test_c2s. Fixing watchdog timer issues in web100srv. (The server bug) Making end-to-end unit tests less flaky by no longer just assuming that every port in the range [1024, 31024) is fine for the server to take as its own. * Moved helper functions to testutils, so that they can be used by both c2s and s2c. Used those new helper functions to fix a freezing error in s2c, where the s2c test pauses until it hears back from the packet trace engine, and so if the packet trace engine fails to start, then the s2c test just freezes forever. * Updated in response to comments by Josh to eliminate `strlen()`.
- Loading branch information
Showing
5 changed files
with
93 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include "logging.h" | ||
#include "testoptions.h" | ||
#include "testutils.h" | ||
|
||
/** Makes the passed-in file descriptor into one that will not block. | ||
* @param fd the file descriptor | ||
* @returns non-zero if successful, zero on failure with errno as set by fcntl. | ||
*/ | ||
int make_non_blocking(int fd) { | ||
int flags; | ||
flags = fcntl(fd, F_GETFL, NULL); | ||
if (flags == -1) return 0; | ||
return fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0; | ||
} | ||
|
||
/** Attempts to use the pipe to shutdown packet tracing. Will not block. After | ||
* this function the file descriptors of the pipe are likely set to | ||
* non-blocking. This should not affect any code because any shutdown messages | ||
* sent should be the last usage of the pipe anyway. | ||
* @param mon_pipe the pipe on which to send shutdown messages. | ||
*/ | ||
void packet_trace_emergency_shutdown(int *mon_pipe) { | ||
// Attempt to shut down the trace, but only after making sure that all | ||
// attempts to write to the pipe will never block. | ||
if (make_non_blocking(mon_pipe[1]) && make_non_blocking(mon_pipe[0])) { | ||
stop_packet_trace(mon_pipe); | ||
} else { | ||
log_println(0, | ||
"Couldn't make pipe non-blocking (errno=%d) and so was " | ||
"unable to safely call stop_packet_trace", | ||
errno); | ||
} | ||
} | ||
|
||
/** Waits up to one second for the passed-in fd to become readable. | ||
* @param fd the file descriptor to wait for | ||
* @returns true if the fd is readable, false otherwise | ||
*/ | ||
int wait_for_readable_fd(int fd) { | ||
fd_set rfd; | ||
struct timeval sel_tv = {0}; | ||
FD_ZERO(&rfd); | ||
FD_SET(fd, &rfd); | ||
sel_tv.tv_sec = 1; // Wait for up to 1 second | ||
return (1 == select(fd + 1, &rfd, NULL, NULL, &sel_tv)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* These are helper methods which are used in multiple test_XXX_srv.c files. */ | ||
|
||
int make_non_blocking(int fd); | ||
int wait_for_readable_fd(int fd); | ||
void packet_trace_emergency_shutdown(int *mon_pipe); |