Skip to content

Commit

Permalink
Move to procutil
Browse files Browse the repository at this point in the history
  • Loading branch information
udzura committed Jul 15, 2016
1 parent 8d563ad commit 5663b09
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
2 changes: 1 addition & 1 deletion mrblib/haconiwa/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def wrap_daemonize(&b)
r, w = IO.pipe
ppid = Process.fork do
# TODO: logging
Haconiwa.daemon_fd_reopen
Procutil.daemon_fd_reopen
b.call(@base, w)
end
w.close
Expand Down
17 changes: 0 additions & 17 deletions src/haconiwa.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "mruby.h"
#include "mruby/error.h"
#include "mruby/string.h"
#include "mruby/hash.h"

Expand All @@ -26,27 +25,11 @@ static mrb_value mrb_haconiwa_mrgbem_revisions(mrb_state *mrb, mrb_value self)
return ha;
}

#define TRY_REOPEN(fp, newfile, mode, oldfp) \
fp = freopen("/dev/null", "w", stdout); \
if(fp == NULL) mrb_sys_fail(mrb, "freopen failed")

static mrb_value mrb_haconiwa_daemon_fd_reopen(mrb_state *mrb, mrb_value self)
{
/* TODO reopen to log file */
FILE *fp;
TRY_REOPEN(fp, "/dev/null", "r", stdin);
TRY_REOPEN(fp, "/dev/null", "w", stdout);
TRY_REOPEN(fp, "/dev/null", "w", stderr);

return mrb_true_value();
}

void mrb_haconiwa_gem_init(mrb_state *mrb)
{
struct RClass *haconiwa;
haconiwa = mrb_define_module(mrb, "Haconiwa");
mrb_define_class_method(mrb, haconiwa, "mrbgem_revisions", mrb_haconiwa_mrgbem_revisions, MRB_ARGS_NONE());
mrb_define_class_method(mrb, haconiwa, "daemon_fd_reopen", mrb_haconiwa_daemon_fd_reopen, MRB_ARGS_NONE());

DONE;
}
Expand Down

0 comments on commit 5663b09

Please sign in to comment.