Commit a0d3657e 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 7c4622f5
......@@ -282,6 +282,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) {
return r;
}
int
toku_dup2(int fd, int fd2) {
int r;
r = dup2(fd, fd2);
return r;
}
#if __GNUC__ && __i386__
// 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
#if DO_TOKU_TRACE
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");
#endif
......
......@@ -34,9 +34,9 @@ run_test(void) {
}
// redirect stderr
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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);
// run recovery
......
......@@ -22,10 +22,12 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0);
// run recovery
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
assert(devnul>=0);
r = dup2(devnul, fileno(stderr)); assert(r==fileno(stderr));
r = close(devnul); assert(r==0);
r = toku_dup2(devnul, fileno(stderr));
assert(r==fileno(stderr));
r = close(devnul);
assert(r==0);
r = tokudb_recover(TESTDIR, TESTDIR, 0, 0, NULL, NULL, NULL, NULL, 0);
assert(r == 0);
......
......@@ -28,9 +28,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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);
// run recovery
......
......@@ -28,9 +28,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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);
// run recovery
......
......@@ -22,9 +22,9 @@ run_test(void) {
r = toku_logger_close(&logger); assert(r == 0);
// redirect stderr
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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);
// run recovery
......
......@@ -14,9 +14,9 @@ run_test(void) {
r = toku_os_mkdir(TESTDIR, S_IRWXU); assert(r == 0);
// redirect stderr
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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);
// run recovery
......
......@@ -222,7 +222,7 @@ static void scanscan_lwc (void) {
#endif
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;
double tstart = gettime();
DBC *dbc;
......
......@@ -178,9 +178,9 @@ do_writes_that_fail (void) {
write_count=0;
pid_t child;
if ((child=fork())==0) {
int devnul = open("/dev/null", O_WRONLY);
int devnul = open(DEV_NULL_FILE, O_WRONLY);
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); }
do_db_work();
exit(1);
......
......@@ -119,7 +119,7 @@ do_abort_delete_first_or_last(int N,
r=db->close(db, 0); CKERR(r);
r=env->close(env, 0); CKERR(r);
#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);
#endif
}
......
......@@ -79,6 +79,9 @@ int toku_stat(const char *name, toku_struct_stat *statbuf) __attribute__((__visi
// Portable linux 'fstat'
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
};
#endif
......
......@@ -94,6 +94,10 @@ typedef int64_t toku_off_t;
# ifndef DONT_DEPRECATE_MALLOC
# pragma deprecated (malloc, free, realloc)
# endif
# ifndef TOKU_WINDOWS_ALLOW_DEPRECATED
# pragma poison dup2
# pragma poison _dup2
# endif
# else
int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__));
int fstat(int fd, struct stat *buf) __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.
// long int sysconf(int) __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.
#undef strdup
char* strdup(const char *) __attribute__((__deprecated__));
......
......@@ -26,6 +26,8 @@ $(TARGET): $(OBJS)
check: $(TARGET)
cd tests && $(MAKE) check
$(OBJS): CFLAGS += -DTOKU_WINDOWS_ALLOW_DEPRECATED
clean:
rm -rf $(TARGET) $(LIBPORTABILITY) $(PTHREAD_LIB)
cd tests && $(MAKE) clean
......@@ -315,3 +315,13 @@ toku_os_get_processor_frequency(uint64_t *hzret) {
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