summaryrefslogtreecommitdiff
path: root/mjit_worker.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-07-15 10:29:39 +0900
committerTakashi Kokubun <takashikkbn@gmail.com>2019-07-15 10:31:01 +0900
commita191009a266e97453971f9b24f750861855aaa7b (patch)
tree55301c5b0104bc9c41b08053a2cf3cb8aef82a89 /mjit_worker.c
parentb78964883037470f25755db740c09e835eadb5c9 (diff)
Simplify start_process by exploiting C99
Having a block for mixing a declaration was confusing. Also I moved `dev_null` and `pid` to limit their scope.
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index 2ee9a53..27af15b 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -548,36 +548,32 @@ COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
static pid_t
start_process(const char *abspath, char *const *argv)
{
- pid_t pid;
- // Not calling non-async-signal-safe functions between vfork
- // and execv for safety
- int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
-
if (mjit_opts.verbose >= 2) {
- int i;
const char *arg;
-
fprintf(stderr, "Starting process: %s", abspath);
- for (i = 0; (arg = argv[i]) != NULL; i++)
+ for (int i = 0; (arg = argv[i]) != NULL; i++)
fprintf(stderr, " %s", arg);
fprintf(stderr, "\n");
}
+
+ // Not calling non-async-signal-safe functions between vfork
+ // and execv for safety
+ int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
+ pid_t pid;
#ifdef _WIN32
- {
- extern HANDLE rb_w32_start_process(const char *abspath, char *const *argv, int out_fd);
- int out_fd = 0;
- if (mjit_opts.verbose <= 1) {
- // Discard cl.exe's outputs like:
- // _ruby_mjit_p12u3.c
- // Creating library C:.../_ruby_mjit_p12u3.lib and object C:.../_ruby_mjit_p12u3.exp
- out_fd = dev_null;
- }
+ extern HANDLE rb_w32_start_process(const char *abspath, char *const *argv, int out_fd);
+ int out_fd = 0;
+ if (mjit_opts.verbose <= 1) {
+ // Discard cl.exe's outputs like:
+ // _ruby_mjit_p12u3.c
+ // Creating library C:.../_ruby_mjit_p12u3.lib and object C:.../_ruby_mjit_p12u3.exp
+ out_fd = dev_null;
+ }
- pid = (pid_t)rb_w32_start_process(abspath, argv, out_fd);
- if (pid == 0) {
- verbose(1, "MJIT: Failed to create process: %s", dlerror());
- return -1;
- }
+ pid = (pid_t)rb_w32_start_process(abspath, argv, out_fd);
+ if (pid == 0) {
+ verbose(1, "MJIT: Failed to create process: %s", dlerror());
+ return -1;
}
#else
if ((pid = vfork()) == 0) { /* TODO: reuse some function in process.c */