Commit 86b7cbe2 authored by Yoni Fogel's avatar Yoni Fogel

closes[t:2309] [t:2308] Deprecate dup2, _dup2 (wrap with toku_dup2), and...

closes[t:2309] [t:2308] Deprecate dup2, _dup2 (wrap with toku_dup2), and replace /dev/null with DEV_NULL_FILE
Fixes some recovery tests in windows

git-svn-id: file:///svn/toku/tokudb@17020 c7de825b-a66e-492c-adef-691d508d4ae1
parent 10c74e91
...@@ -282,6 +282,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) { ...@@ -282,6 +282,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) {
return r; return r;
} }
int
toku_dup2(int fd, int fd2) {
int r;
r = dup2(fd, fd2);
return r;
}
#if __GNUC__ && __i386__ #if __GNUC__ && __i386__
// workaround for a gcc 4.1.2 bug on 32 bit platforms. // workaround for a gcc 4.1.2 bug on 32 bit platforms.
......
...@@ -991,7 +991,7 @@ toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash, BR ...@@ -991,7 +991,7 @@ toku_deserialize_brtnode_from (int fd, BLOCKNUM blocknum, u_int32_t fullhash, BR
#if DO_TOKU_TRACE #if DO_TOKU_TRACE
if (toku_trace_fd == -1) if (toku_trace_fd == -1)
toku_trace_fd = open("/dev/null", O_WRONLY); toku_trace_fd = open(DEV_NULL_FILE, O_WRONLY);
toku_trace("deserial start"); toku_trace("deserial start");
#endif #endif
......
...@@ -34,9 +34,9 @@ run_test(void) { ...@@ -34,9 +34,9 @@ run_test(void) {
} }
// redirect stderr // redirect stderr
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0); r = close(devnul); assert(r==0);
// run recovery // run recovery
......
...@@ -22,10 +22,12 @@ run_test(void) { ...@@ -22,10 +22,12 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0); r = toku_logger_close(&logger); assert(r == 0);
// run recovery // run recovery
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr));
r = close(devnul); assert(r==0); assert(r==fileno(stderr));
r = close(devnul);
assert(r==0);
r = tokudb_recover(TESTDIR, TESTDIR, 0, 0, NULL, NULL, NULL, NULL, 0); r = tokudb_recover(TESTDIR, TESTDIR, 0, 0, NULL, NULL, NULL, NULL, 0);
assert(r == 0); assert(r == 0);
......
...@@ -28,9 +28,9 @@ run_test(void) { ...@@ -28,9 +28,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0); r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr // redirect stderr
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0); r = close(devnul); assert(r==0);
// run recovery // run recovery
......
...@@ -28,9 +28,9 @@ run_test(void) { ...@@ -28,9 +28,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0); r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr // redirect stderr
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0); r = close(devnul); assert(r==0);
// run recovery // run recovery
......
...@@ -22,9 +22,9 @@ run_test(void) { ...@@ -22,9 +22,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0); r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr // redirect stderr
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0); r = close(devnul); assert(r==0);
// run recovery // run recovery
......
...@@ -14,9 +14,9 @@ run_test(void) { ...@@ -14,9 +14,9 @@ run_test(void) {
r = toku_os_mkdir(TESTDIR, S_IRWXU); assert(r == 0); r = toku_os_mkdir(TESTDIR, S_IRWXU); assert(r == 0);
// redirect stderr // redirect stderr
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0); r = close(devnul); assert(r==0);
// run recovery // run recovery
......
...@@ -222,7 +222,7 @@ static void scanscan_lwc (void) { ...@@ -222,7 +222,7 @@ static void scanscan_lwc (void) {
#endif #endif
static void scanscan_range (void) { static void scanscan_range (void) {
int fnull = open("/dev/null", O_WRONLY); assert(fnull >= 0); // use with strace int fnull = open(DEV_NULL_FILE, O_WRONLY); assert(fnull >= 0); // use with strace
int r; int r;
double tstart = gettime(); double tstart = gettime();
DBC *dbc; DBC *dbc;
......
...@@ -178,9 +178,9 @@ do_writes_that_fail (void) { ...@@ -178,9 +178,9 @@ do_writes_that_fail (void) {
write_count=0; write_count=0;
pid_t child; pid_t child;
if ((child=fork())==0) { if ((child=fork())==0) {
int devnul = open("/dev/null", O_WRONLY); int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0); assert(devnul>=0);
{ int r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); } { int r = toku_dup2(devnul, fileno(stderr)); assert(r==fileno(stderr)); }
{ int r = close(devnul); assert(r==0); } { int r = close(devnul); assert(r==0); }
do_db_work(); do_db_work();
exit(1); exit(1);
......
...@@ -119,7 +119,7 @@ do_abort_delete_first_or_last(int N, ...@@ -119,7 +119,7 @@ do_abort_delete_first_or_last(int N,
r=db->close(db, 0); CKERR(r); r=db->close(db, 0); CKERR(r);
r=env->close(env, 0); CKERR(r); r=env->close(env, 0); CKERR(r);
#if defined(TOKUDB) && defined(__unix__) #if defined(TOKUDB) && defined(__unix__)
r=system("../../utils/tokudb_dump_static -h " ENVDIR " foo.db > /dev/null"); r=system("../../utils/tokudb_dump_static -h " ENVDIR " foo.db > " DEV_NULL_FILE);
CKERR(r); CKERR(r);
#endif #endif
} }
......
...@@ -79,6 +79,9 @@ int toku_stat(const char *name, toku_struct_stat *statbuf) __attribute__((__visi ...@@ -79,6 +79,9 @@ int toku_stat(const char *name, toku_struct_stat *statbuf) __attribute__((__visi
// Portable linux 'fstat' // Portable linux 'fstat'
int toku_fstat(int fd, toku_struct_stat *statbuf) __attribute__((__visibility__("default"))); int toku_fstat(int fd, toku_struct_stat *statbuf) __attribute__((__visibility__("default")));
// Portable linux 'dup2'
int toku_dup2(int fd, int fd2) __attribute__((__visibility__("default")));
#if defined __cplusplus #if defined __cplusplus
}; };
#endif #endif
......
...@@ -94,6 +94,10 @@ typedef int64_t toku_off_t; ...@@ -94,6 +94,10 @@ typedef int64_t toku_off_t;
# ifndef DONT_DEPRECATE_MALLOC # ifndef DONT_DEPRECATE_MALLOC
# pragma deprecated (malloc, free, realloc) # pragma deprecated (malloc, free, realloc)
# endif # endif
# ifndef TOKU_WINDOWS_ALLOW_DEPRECATED
# pragma poison dup2
# pragma poison _dup2
# endif
# else # else
int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__)); int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__));
int fstat(int fd, struct stat *buf) __attribute__((__deprecated__)); int fstat(int fd, struct stat *buf) __attribute__((__deprecated__));
...@@ -103,6 +107,8 @@ long int syscall(long int __sysno, ...) __attribute__((__deprecated_ ...@@ -103,6 +107,8 @@ long int syscall(long int __sysno, ...) __attribute__((__deprecated_
// Sadly, dlmalloc needs sysconf, and on linux this causes trouble with -combine. So let the warnings show up under windows only. // Sadly, dlmalloc needs sysconf, and on linux this causes trouble with -combine. So let the warnings show up under windows only.
// long int sysconf(int) __attribute__((__deprecated__)); // long int sysconf(int) __attribute__((__deprecated__));
int mkdir(const char *pathname, mode_t mode) __attribute__((__deprecated__)); int mkdir(const char *pathname, mode_t mode) __attribute__((__deprecated__));
int dup2(int fd, int fd2) __attribute__((__deprecated__));
int _dup2(int fd, int fd2) __attribute__((__deprecated__));
// strdup is a macro in some libraries. // strdup is a macro in some libraries.
#undef strdup #undef strdup
char* strdup(const char *) __attribute__((__deprecated__)); char* strdup(const char *) __attribute__((__deprecated__));
......
...@@ -26,6 +26,8 @@ $(TARGET): $(OBJS) ...@@ -26,6 +26,8 @@ $(TARGET): $(OBJS)
check: $(TARGET) check: $(TARGET)
cd tests && $(MAKE) check cd tests && $(MAKE) check
$(OBJS): CFLAGS += -DTOKU_WINDOWS_ALLOW_DEPRECATED
clean: clean:
rm -rf $(TARGET) $(LIBPORTABILITY) $(PTHREAD_LIB) rm -rf $(TARGET) $(LIBPORTABILITY) $(PTHREAD_LIB)
cd tests && $(MAKE) clean cd tests && $(MAKE) clean
...@@ -315,3 +315,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) { ...@@ -315,3 +315,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) {
return 0; return 0;
} }
int
toku_dup2(int fd, int fd2) {
int r;
r = _dup2(fd, fd2);
if (r==0) //success
r = fd2;
return r;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment