summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-09 14:23:42 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-04-09 14:23:42 +0000
commit6cf4e97b3ede0d34511e2a7b70ca611a526dc554 (patch)
tree58bff39d94b876082edf64d9d0ccbefe259584fe /process.c
parent990cc562ed1b9d7519a1ecf19fe0178c54bd7dec (diff)
downloadruby-6cf4e97b3ede0d34511e2a7b70ca611a526dc554.tar.gz
move debug functions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/process.c b/process.c
index 2bb9577c51..a81a702732 100644
--- a/process.c
+++ b/process.c
@@ -282,6 +282,65 @@ static ID id_hertz;
extern ID ruby_static_id_status;
#define id_status ruby_static_id_status
+/*#define DEBUG_REDIRECT*/
+#if defined(DEBUG_REDIRECT)
+
+#include <stdarg.h>
+
+static void
+ttyprintf(const char *fmt, ...)
+{
+ va_list ap;
+ FILE *tty;
+ int save = errno;
+#ifdef _WIN32
+ tty = fopen("con", "w");
+#else
+ tty = fopen("/dev/tty", "w");
+#endif
+ if (!tty)
+ return;
+
+ va_start(ap, fmt);
+ vfprintf(tty, fmt, ap);
+ va_end(ap);
+ fclose(tty);
+ errno = save;
+}
+
+static int
+redirect_dup(int oldfd)
+{
+ int ret;
+ ret = dup(oldfd);
+ ttyprintf("dup(%d) => %d\n", oldfd, ret);
+ return ret;
+}
+
+static int
+redirect_dup2(int oldfd, int newfd)
+{
+ int ret;
+ ret = dup2(oldfd, newfd);
+ ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
+ return ret;
+}
+
+static int
+redirect_close(int fd)
+{
+ int ret;
+ ret = close(fd);
+ ttyprintf("close(%d)\n", fd);
+ return ret;
+}
+
+#else
+#define redirect_dup(oldfd) dup(oldfd)
+#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
+#define redirect_close(fd) close(fd)
+#endif
+
/*
* call-seq:
* Process.pid -> fixnum
@@ -2452,65 +2511,6 @@ rb_f_exec(int argc, const VALUE *argv)
#define ERRMSG(str) do { if (errmsg && 0 < errmsg_buflen) strlcpy(errmsg, (str), errmsg_buflen); } while (0)
-/*#define DEBUG_REDIRECT*/
-#if defined(DEBUG_REDIRECT)
-
-#include <stdarg.h>
-
-static void
-ttyprintf(const char *fmt, ...)
-{
- va_list ap;
- FILE *tty;
- int save = errno;
-#ifdef _WIN32
- tty = fopen("con", "w");
-#else
- tty = fopen("/dev/tty", "w");
-#endif
- if (!tty)
- return;
-
- va_start(ap, fmt);
- vfprintf(tty, fmt, ap);
- va_end(ap);
- fclose(tty);
- errno = save;
-}
-
-static int
-redirect_dup(int oldfd)
-{
- int ret;
- ret = dup(oldfd);
- ttyprintf("dup(%d) => %d\n", oldfd, ret);
- return ret;
-}
-
-static int
-redirect_dup2(int oldfd, int newfd)
-{
- int ret;
- ret = dup2(oldfd, newfd);
- ttyprintf("dup2(%d, %d)\n", oldfd, newfd);
- return ret;
-}
-
-static int
-redirect_close(int fd)
-{
- int ret;
- ret = close(fd);
- ttyprintf("close(%d)\n", fd);
- return ret;
-}
-
-#else
-#define redirect_dup(oldfd) dup(oldfd)
-#define redirect_dup2(oldfd, newfd) dup2((oldfd), (newfd))
-#define redirect_close(fd) close(fd)
-#endif
-
static int
save_redirect_fd(int fd, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
{