0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConsoleOutputSquelcher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
27 
28 #include <Common/Compat.h>
29 
30 #include "ConsoleOutputSquelcher.h"
31 
32 extern "C" {
33 #include <fcntl.h>
34 #include <sys/stat.h>
35 #include <sys/types.h>
36 #include <unistd.h>
37 }
38 
39 #include <cstdio>
40 
41 using namespace Hypertable;
42 
44 #if defined(__WIN32__) || defined(_WIN32)
45  const char *devnull = "nul";
46 #else
47  const char *devnull = "/dev/null";
48 #endif
49  int fd;
50  // Redirect stdout
51  fflush(stdout);
52  m_backup_stdout_fd = dup(1);
53  fd = ::open(devnull, O_WRONLY);
54  dup2(fd, 1);
55  close(fd);
56  // Redirect stderr
57  fflush(stderr);
58  m_backup_stderr_fd = dup(2);
59  fd = ::open(devnull, O_WRONLY);
60  dup2(fd, 2);
61  close(fd);
62 }
63 
65  // Restore stdout
66  fflush(stdout);
67  dup2(m_backup_stdout_fd, 1);
68  close(m_backup_stdout_fd);
69  // Restore stderr
70  fflush(stderr);
71  dup2(m_backup_stderr_fd, 2);
72  close(m_backup_stderr_fd);
73 }
Declaration for ConsoleOutputSquelcher.
int m_backup_stdout_fd
Backup of stdout file descriptor.
Compatibility Macros for C/C++.
Hypertable definitions
int m_backup_stderr_fd
Backup of stderr file descriptor.