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.
This commit is contained in:
parent
b789648830
commit
a191009a26
@ -548,36 +548,32 @@ COMPILER_WARNING_IGNORED(-Wdeprecated-declarations)
|
|||||||
static pid_t
|
static pid_t
|
||||||
start_process(const char *abspath, char *const *argv)
|
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) {
|
if (mjit_opts.verbose >= 2) {
|
||||||
int i;
|
|
||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
fprintf(stderr, "Starting process: %s", abspath);
|
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, " %s", arg);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
#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;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = (pid_t)rb_w32_start_process(abspath, argv, out_fd);
|
// Not calling non-async-signal-safe functions between vfork
|
||||||
if (pid == 0) {
|
// and execv for safety
|
||||||
verbose(1, "MJIT: Failed to create process: %s", dlerror());
|
int dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);
|
||||||
return -1;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
#else
|
||||||
if ((pid = vfork()) == 0) { /* TODO: reuse some function in process.c */
|
if ((pid = vfork()) == 0) { /* TODO: reuse some function in process.c */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user