e start - force stdout/err to go to specific log files

~/.e-log.log is now the stdout/err from e and child processes. finally
it always goes to a single known file. always. e will rename the old
old ~/.e-log.log.old on start - e_start handles this before it execs e.
This commit is contained in:
Carsten Haitzler 2021-11-11 14:25:44 +00:00
parent 86dd52026a
commit 8edf2fc0a3
1 changed files with 43 additions and 7 deletions

View File

@ -349,16 +349,35 @@ _e_ptrace_continue(int child, int back, Eina_Bool really_know)
#endif #endif
} }
static int static void
_e_start_child(char **args, Eina_Bool really_know) _e_start_stdout_err_redir(const char *home)
{ {
int logfd;
char *logf = NULL, *logf_old = NULL;
// rename old olg file
myasprintf(&logf, "%s/.e-log.log", home);
myasprintf(&logf_old, "%s/.e-log.log.old", home);
rename(logf, logf_old);
// open new log file and move stdout/err to it
logfd = open(logf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
printf("Enlightenment: See logs in: %s\n", logf);
if (logfd < 0) return;
dup2(logfd, 1); // stdout to file
dup2(logfd, 2); // stderr to file
}
static int
_e_start_child(const char *home, char **args, Eina_Bool really_know)
{
// have e process die with parent enlightenment_start
#ifdef HAVE_PRCTL #ifdef HAVE_PRCTL
prctl(PR_SET_PDEATHSIG, SIGTERM); prctl(PR_SET_PDEATHSIG, SIGTERM);
#elif defined(HAVE_PROCCTL) #elif defined(HAVE_PROCCTL)
int sig = SIGTERM; int sig = SIGTERM;
procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &sig); procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &sig);
#endif #endif
_e_start_stdout_err_redir(home);
_e_ptrace_traceme(really_know); _e_ptrace_traceme(really_know);
execv(args[0], args); execv(args[0], args);
// We failed, 0 means normal exit from E with no restart or crash so // We failed, 0 means normal exit from E with no restart or crash so
@ -367,7 +386,7 @@ _e_start_child(char **args, Eina_Bool really_know)
} }
static Eina_Bool static Eina_Bool
_e_ptrace_kernel_check(void) _e_ptrace_kernel_check(const char *home)
{ {
#ifdef __linux__ #ifdef __linux__
// Check if patch to prevent ptrace to another process is present // Check if patch to prevent ptrace to another process is present
@ -380,6 +399,23 @@ _e_ptrace_kernel_check(void)
ret = read(fd, &c, (sizeof(c)) == sizeof(c)) && (c != '0'); ret = read(fd, &c, (sizeof(c)) == sizeof(c)) && (c != '0');
close(fd); close(fd);
} }
if (ret)
{
char *buf = NULL;
FILE *f;
myasprintf(&buf, "%s/.e-crashdump.txt", home);
f = fopen(buf, "a");
if (f)
{
fprintf(f,
"ERROR: /proc/sys/kernel/yama/ptrace_scope is 1 disallowing remote\n"
"attachment to a process. This means a gdb backtrace cannot be logged.\n"
"To fix this, as root please do:\n"
" echo 0 > /proc/sys/kernel/yama/ptrace_scope\n");
fclose(f);
}
}
return ret; return ret;
#else #else
return EINA_FALSE; return EINA_FALSE;
@ -579,7 +615,7 @@ main(int argc, char **argv)
myasprintf(&buf, "%s/enlightenment", eina_prefix_bin_get(pfx)); myasprintf(&buf, "%s/enlightenment", eina_prefix_bin_get(pfx));
args = alloca((argc + 1) * sizeof(char *)); args = alloca((argc + 1) * sizeof(char *));
printf("CMD: [%s]\n", buf); printf("Enlightenment: Command: %s\n", buf);
args[0] = buf; args[0] = buf;
copy_args(&args[1], argv + 1, argc - 1); copy_args(&args[1], argv + 1, argc - 1);
args[argc] = NULL; args[argc] = NULL;
@ -604,7 +640,7 @@ main(int argc, char **argv)
} }
else if (child == 0) else if (child == 0)
{ // we are in the child fork - so exec { // we are in the child fork - so exec
ret = _e_start_child(args, really_know); ret = _e_start_child(home, args, really_know);
break; break;
} }
@ -646,7 +682,7 @@ not_done:
usleep(200000); usleep(200000);
/* And call gdb if available */ /* And call gdb if available */
if (home && !_e_ptrace_kernel_check()) if (home && !_e_ptrace_kernel_check(home))
r = _e_call_gdb(child, home, &backtrace_str); r = _e_call_gdb(child, home, &backtrace_str);
else else
r = 0; r = 0;