summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/intercept/intercept.cpp (renamed from test/raidfile/intercept.cpp)57
-rw-r--r--modules.txt5
2 files changed, 51 insertions, 11 deletions
diff --git a/test/raidfile/intercept.cpp b/lib/intercept/intercept.cpp
index 0a5b4ab9..4f8ef785 100644
--- a/test/raidfile/intercept.cpp
+++ b/lib/intercept/intercept.cpp
@@ -66,6 +66,7 @@ off_t intercept_errorafter = 0;
int intercept_errno = 0;
int intercept_syscall = 0;
off_t intercept_filepos = 0;
+int intercept_delay_ms = 0;
#define SIZE_ALWAYS_ERROR -773
@@ -77,6 +78,7 @@ void intercept_clear_setup()
intercept_errorafter = 0;
intercept_syscall = 0;
intercept_filepos = 0;
+ intercept_delay_ms = 0;
}
bool intercept_triggered()
@@ -94,8 +96,23 @@ void intercept_setup_error(const char *filename, unsigned int errorafter, int er
intercept_syscall = syscalltoerror;
intercept_errno = errortoreturn;
intercept_filepos = 0;
+ intercept_delay_ms = 0;
}
+void intercept_setup_delay(const char *filename, unsigned int delay_after,
+ int delay_ms, int syscall_to_delay)
+{
+ TRACE4("Setup for delay: %s, after %d, wait %d ms, syscall %d\n",
+ filename, delay_after, delay_ms, syscall_to_delay);
+ intercept_enabled = true;
+ intercept_filename = filename;
+ intercept_filedes = -1;
+ intercept_errorafter = delay_after;
+ intercept_syscall = syscall_to_delay;
+ intercept_errno = 0;
+ intercept_filepos = 0;
+ intercept_delay_ms = delay_ms;
+}
bool intercept_errornow(int d, int size, int syscallnum)
{
if(intercept_filedes != -1 && d == intercept_filedes && syscallnum == intercept_syscall)
@@ -110,7 +127,19 @@ bool intercept_errornow(int d, int size, int syscallnum)
// where are we in the file?
if(intercept_filepos >= intercept_errorafter || intercept_filepos >= ((off_t)intercept_errorafter - size))
{
- TRACE3("Returning error %d for syscall %d, file pos %d\n", intercept_errno, syscallnum, (int)intercept_filepos);
+ if (intercept_errno != 0)
+ {
+ TRACE3("Returning error %d for syscall %d, "
+ "file pos %d\n", intercept_errno,
+ syscallnum, (int)intercept_filepos);
+ }
+ else if (intercept_delay_ms != 0)
+ {
+ TRACE3("Delaying %d ms for syscall %d, "
+ "file pos %d\n", intercept_delay_ms,
+ syscallnum, (int)intercept_filepos);
+ }
+
return true;
}
}
@@ -119,12 +148,9 @@ bool intercept_errornow(int d, int size, int syscallnum)
int intercept_reterr()
{
- intercept_enabled = false;
- intercept_filename = 0;
- intercept_filedes = -1;
- intercept_errorafter = 0;
- intercept_syscall = 0;
- return intercept_errno;
+ int err = intercept_errno;
+ intercept_clear_setup();
+ return err;
}
#define CHECK_FOR_FAKE_ERROR_COND(D, S, CALL, FAILRES) \
@@ -132,8 +158,21 @@ int intercept_reterr()
{ \
if(intercept_errornow(D, S, CALL)) \
{ \
- errno = intercept_reterr(); \
- return FAILRES; \
+ if(intercept_delay_ms > 0) \
+ { \
+ struct timespec tm; \
+ tm.tv_sec = intercept_delay_ms / 1000; \
+ tm.tv_nsec = (intercept_delay_ms % 1000) \
+ * 1000000; \
+ while (nanosleep(&tm, &tm) != 0 && \
+ errno == EINTR) { } \
+ intercept_clear_setup(); \
+ } \
+ else \
+ { \
+ errno = intercept_reterr(); \
+ return FAILRES; \
+ } \
} \
}
diff --git a/modules.txt b/modules.txt
index de00f08b..eb8c156d 100644
--- a/modules.txt
+++ b/modules.txt
@@ -18,6 +18,7 @@ lib/crypto
lib/server
lib/win32 lib/server
lib/compress
+lib/intercept
test/common lib/win32
test/crypto lib/crypto lib/win32
test/compress lib/compress lib/win32
@@ -25,7 +26,7 @@ test/compress lib/compress lib/win32
OMIT:mingw32
test/basicserver lib/server lib/win32
OMIT:CYGWIN
-test/raidfile lib/raidfile
+test/raidfile lib/raidfile lib/intercept
END-OMIT
# IF_DISTRIBUTION(boxbackup)
@@ -52,7 +53,7 @@ test/backupstore bin/bbstored bin/bbstoreaccounts lib/server lib/backupstore lib
test/backupstorefix bin/bbstored bin/bbstoreaccounts lib/backupstore lib/raidfile bin/bbackupquery bin/bbackupd
test/backupstorepatch bin/bbstored bin/bbstoreaccounts lib/backupstore lib/raidfile
test/backupdiff lib/backupclient
-test/bbackupd bin/bbackupd bin/bbstored bin/bbstoreaccounts bin/bbackupquery bin/bbackupctl lib/server lib/backupstore lib/backupclient
+test/bbackupd bin/bbackupd bin/bbstored bin/bbstoreaccounts bin/bbackupquery bin/bbackupctl lib/server lib/backupstore lib/backupclient lib/intercept
END-OMIT
# END_IF_DISTRIBUTION