Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions runtime/launcher.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@
return -1;
}

return 0;
return fd;
}

static void
init_logdir (void)
{
// If redirected we will not be closing the returned file descriptors anywhere.
// That's "by design" so they will keep logging as long as the app is alive.
static int redirected_stdout = -1;
static int redirected_stderr = -1;
const char *env;
size_t dirlen;
char *path;
Expand All @@ -72,12 +76,14 @@
path[dirlen++] = '/';

strcpy (path + dirlen, "stdout.log");
if (redirect_io (STDOUT_FILENO, path) == -1)
fprintf (stderr, PRODUCT ": Could not redirect stdout to `%s': %s\n", path, strerror (errno));
redirected_stdout = redirect_io (STDOUT_FILENO, path);
if (redirected_stdout == -1)
fprintf (stderr, PRODUCT ": Could not redirect %s to `%s': %s\n", "stdout", path, strerror (errno));

strcpy (path + dirlen, "stderr.log");
if (redirect_io (STDERR_FILENO, path) == -1)
fprintf (stderr, PRODUCT ": Could not redirect stderr to `%s': %s\n", path, strerror (errno));
redirected_stderr = redirect_io (STDERR_FILENO, path);
if (redirected_stderr == -1)
fprintf (stderr, PRODUCT ": Could not redirect %s to `%s': %s\n", "stderr", path, strerror (errno));

free (path);
}
Expand Down