summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-11-11 14:25:44 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2021-11-11 14:25:44 +0000
commit8edf2fc0a388090da74db683a690e0aed8a33eb6 (patch)
tree6d4c54da937d663606d5418d8c57e8dadd1ce070
parent86dd52026a045cb26f8d8e6321af7b6b2ac52f9b (diff)
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.
-rw-r--r--src/bin/e_start_main.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/bin/e_start_main.c b/src/bin/e_start_main.c
index caa23962d..722063339 100644
--- a/src/bin/e_start_main.c
+++ b/src/bin/e_start_main.c
@@ -349,16 +349,35 @@ _e_ptrace_continue(int child, int back, Eina_Bool really_know)
349#endif 349#endif
350} 350}
351 351
352static void
353_e_start_stdout_err_redir(const char *home)
354{
355 int logfd;
356 char *logf = NULL, *logf_old = NULL;
357
358 // rename old olg file
359 myasprintf(&logf, "%s/.e-log.log", home);
360 myasprintf(&logf_old, "%s/.e-log.log.old", home);
361 rename(logf, logf_old);
362 // open new log file and move stdout/err to it
363 logfd = open(logf, O_WRONLY | O_CREAT | O_TRUNC, 0600);
364 printf("Enlightenment: See logs in: %s\n", logf);
365 if (logfd < 0) return;
366 dup2(logfd, 1); // stdout to file
367 dup2(logfd, 2); // stderr to file
368}
369
352static int 370static int
353_e_start_child(char **args, Eina_Bool really_know) 371_e_start_child(const char *home, char **args, Eina_Bool really_know)
354{ 372{
373 // have e process die with parent enlightenment_start
355#ifdef HAVE_PRCTL 374#ifdef HAVE_PRCTL
356 prctl(PR_SET_PDEATHSIG, SIGTERM); 375 prctl(PR_SET_PDEATHSIG, SIGTERM);
357#elif defined(HAVE_PROCCTL) 376#elif defined(HAVE_PROCCTL)
358 int sig = SIGTERM; 377 int sig = SIGTERM;
359 procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &sig); 378 procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &sig);
360#endif 379#endif
361 380 _e_start_stdout_err_redir(home);
362 _e_ptrace_traceme(really_know); 381 _e_ptrace_traceme(really_know);
363 execv(args[0], args); 382 execv(args[0], args);
364 // We failed, 0 means normal exit from E with no restart or crash so 383 // 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)
367} 386}
368 387
369static Eina_Bool 388static Eina_Bool
370_e_ptrace_kernel_check(void) 389_e_ptrace_kernel_check(const char *home)
371{ 390{
372#ifdef __linux__ 391#ifdef __linux__
373 // Check if patch to prevent ptrace to another process is present 392 // Check if patch to prevent ptrace to another process is present
@@ -380,6 +399,23 @@ _e_ptrace_kernel_check(void)
380 ret = read(fd, &c, (sizeof(c)) == sizeof(c)) && (c != '0'); 399 ret = read(fd, &c, (sizeof(c)) == sizeof(c)) && (c != '0');
381 close(fd); 400 close(fd);
382 } 401 }
402 if (ret)
403 {
404 char *buf = NULL;
405 FILE *f;
406
407 myasprintf(&buf, "%s/.e-crashdump.txt", home);
408 f = fopen(buf, "a");
409 if (f)
410 {
411 fprintf(f,
412 "ERROR: /proc/sys/kernel/yama/ptrace_scope is 1 disallowing remote\n"
413 "attachment to a process. This means a gdb backtrace cannot be logged.\n"
414 "To fix this, as root please do:\n"
415 " echo 0 > /proc/sys/kernel/yama/ptrace_scope\n");
416 fclose(f);
417 }
418 }
383 return ret; 419 return ret;
384#else 420#else
385 return EINA_FALSE; 421 return EINA_FALSE;
@@ -579,7 +615,7 @@ main(int argc, char **argv)
579 myasprintf(&buf, "%s/enlightenment", eina_prefix_bin_get(pfx)); 615 myasprintf(&buf, "%s/enlightenment", eina_prefix_bin_get(pfx));
580 616
581 args = alloca((argc + 1) * sizeof(char *)); 617 args = alloca((argc + 1) * sizeof(char *));
582 printf("CMD: [%s]\n", buf); 618 printf("Enlightenment: Command: %s\n", buf);
583 args[0] = buf; 619 args[0] = buf;
584 copy_args(&args[1], argv + 1, argc - 1); 620 copy_args(&args[1], argv + 1, argc - 1);
585 args[argc] = NULL; 621 args[argc] = NULL;
@@ -604,7 +640,7 @@ main(int argc, char **argv)
604 } 640 }
605 else if (child == 0) 641 else if (child == 0)
606 { // we are in the child fork - so exec 642 { // we are in the child fork - so exec
607 ret = _e_start_child(args, really_know); 643 ret = _e_start_child(home, args, really_know);
608 break; 644 break;
609 } 645 }
610 646
@@ -646,7 +682,7 @@ not_done:
646 usleep(200000); 682 usleep(200000);
647 683
648 /* And call gdb if available */ 684 /* And call gdb if available */
649 if (home && !_e_ptrace_kernel_check()) 685 if (home && !_e_ptrace_kernel_check(home))
650 r = _e_call_gdb(child, home, &backtrace_str); 686 r = _e_call_gdb(child, home, &backtrace_str);
651 else 687 else
652 r = 0; 688 r = 0;