提交 33c8ddd4 编写于 作者: S Shuduo Sang

add --random-file-fail-output argument to support redirect debug info to a file.

上级 1e97755d
......@@ -70,7 +70,13 @@ int32_t main(int32_t argc, char *argv[]) {
}
#endif
#ifdef TAOS_RANDOM_FILE_FAIL
else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
else if (strcmp(argv[i], "--random-file-fail-output") == 0) {
if ((i < argc - 1) && (argv[i + 1][0] != '-')) {
taosSetRandomFileFailOutput(argv[++i]);
} else {
taosSetRandomFileFailOutput(NULL);
}
} else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
if ( (i+1) < argc ) {
int factor = atoi(argv[i+1]);
printf("The factor of random failure is %d\n", factor);
......
......@@ -19,13 +19,14 @@
#ifdef TAOS_RANDOM_FILE_FAIL
void taosSetRandomFileFailFactor(int factor);
ssize_t taos_tread(int fd, void *buf, size_t count);
ssize_t taos_twrite(int fd, void *buf, size_t count);
off_t taos_lseek(int fd, off_t offset, int whence);
void taosSetRandomFileFailOutput(const char *path);
ssize_t taos_tread(int fd, void *buf, size_t count, const char *file, uint32_t line);
ssize_t taos_twrite(int fd, void *buf, size_t count, const char *file, uint32_t line);
off_t taos_lseek(int fd, off_t offset, int whence, const char *file, uint32_t line);
#define tread(fd, buf, count) taos_tread(fd, buf, count)
#define twrite(fd, buf, count) taos_twrite(fd, buf, count)
#define lseek(fd, offset, whence) taos_lseek(fd, offset, whence)
#define tread(fd, buf, count) taos_tread(fd, buf, count, __FILE__, __LINE__)
#define twrite(fd, buf, count) taos_twrite(fd, buf, count, __FILE__, __LINE__)
#define lseek(fd, offset, whence) taos_lseek(fd, offset, whence, __FILE__, __LINE__)
#endif // TAOS_RANDOM_FILE_FAIL
......
......@@ -29,14 +29,55 @@
#ifdef TAOS_RANDOM_FILE_FAIL
static int random_file_fail_factor = 20;
static FILE *fpRandomFileFailOutput = NULL;
void taosSetRandomFileFailFactor(int factor)
{
random_file_fail_factor = factor;
}
static void close_random_file_fail_output()
{
if (fpRandomFileFailOutput != NULL) {
if (fpRandomFileFailOutput != stdout) {
fclose(fpRandomFileFailOutput);
}
fpRandomFileFailOutput = NULL;
}
}
static void random_file_fail_output_sig(int sig)
{
fprintf(fpRandomFileFailOutput, "signal %d received.\n", sig);
struct sigaction act = {0};
act.sa_handler = SIG_DFL;
sigaction(sig, &act, NULL);
close_random_file_fail_output();
exit(EXIT_FAILURE);
}
void taosSetRandomFileFailOutput(const char *path)
{
if (path == NULL) {
fpRandomFileFailOutput = stdout;
} else if ((fpRandomFileFailOutput = fopen(path, "w")) != NULL) {
atexit(close_random_file_fail_output);
} else {
printf("failed to open random file fail log file '%s', errno=%d\n", path, errno);
return;
}
struct sigaction act = {0};
act.sa_handler = random_file_fail_output_sig;
sigaction(SIGFPE, &act, NULL);
sigaction(SIGSEGV, &act, NULL);
sigaction(SIGILL, &act, NULL);
}
#endif
ssize_t taos_tread(int fd, void *buf, size_t count)
ssize_t taos_tread(int fd, void *buf, size_t count, const char *file, uint32_t line)
{
#ifdef TAOS_RANDOM_FILE_FAIL
if (random_file_fail_factor > 0) {
......@@ -49,7 +90,7 @@ ssize_t taos_tread(int fd, void *buf, size_t count)
return tread(fd, buf, count);
}
ssize_t taos_twrite(int fd, void *buf, size_t count)
ssize_t taos_twrite(int fd, void *buf, size_t count, const char *file, uint32_t line)
{
#ifdef TAOS_RANDOM_FILE_FAIL
if (random_file_fail_factor > 0) {
......@@ -62,7 +103,7 @@ ssize_t taos_twrite(int fd, void *buf, size_t count)
return twrite(fd, buf, count);
}
off_t taos_lseek(int fd, off_t offset, int whence)
off_t taos_lseek(int fd, off_t offset, int whence, const char *file, uint32_t line)
{
#ifdef TAOS_RANDOM_FILE_FAIL
if (random_file_fail_factor > 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册