summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-08-21 09:06:34 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-08-21 09:18:23 +0100
commit31c343b77c7967f1c6c7eba4c8dca06c2df5ed89 (patch)
treee9403684c496829e455a6bf030597fdf5f1e30a6 /src/lib/ecore
parent49662fcb494b551c4acec090d60a0192c2a9384e (diff)
efl/ecore exe - more paranoia - block sig handlers between fork + exec
in theory signal handlers could kick in after fork and before exec... so block them until we're exec'd or exited so they don't change any program state.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/ecore_exe_posix.c47
-rw-r--r--src/lib/ecore/efl_exe.c45
2 files changed, 85 insertions, 7 deletions
diff --git a/src/lib/ecore/ecore_exe_posix.c b/src/lib/ecore/ecore_exe_posix.c
index 895875c8c3..85b7adee45 100644
--- a/src/lib/ecore/ecore_exe_posix.c
+++ b/src/lib/ecore/ecore_exe_posix.c
@@ -300,6 +300,45 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, Ecore_Exe_Data *exe)
300 } 300 }
301 else if (pid == 0) /* child */ 301 else if (pid == 0) /* child */
302 { 302 {
303 sigset_t newset;
304
305 sigemptyset(&newset);
306 sigaddset(&newset, SIGPIPE);
307 sigaddset(&newset, SIGALRM);
308 sigaddset(&newset, SIGCHLD);
309 sigaddset(&newset, SIGUSR1);
310 sigaddset(&newset, SIGUSR2);
311 sigaddset(&newset, SIGHUP);
312 sigaddset(&newset, SIGQUIT);
313 sigaddset(&newset, SIGINT);
314 sigaddset(&newset, SIGTERM);
315 sigaddset(&newset, SIGBUS);
316 sigaddset(&newset, SIGCONT);
317 sigaddset(&newset, SIGWINCH);
318#ifdef SIGEMT
319 sigaddset(&newset, SIGEMT);
320#endif
321#ifdef SIGIO
322 sigaddset(&newset, SIGIO);
323#endif
324#ifdef SIGTSTP
325 sigaddset(&newset, SIGTSTP);
326#endif
327#ifdef SIGTTIN
328 sigaddset(&newset, SIGTTIN);
329#endif
330#ifdef SIGTTOU
331 sigaddset(&newset, SIGTTOU);
332#endif
333#ifdef SIGVTALRM
334 sigaddset(&newset, SIGVTALRM);
335#endif
336#ifdef SIGPWR
337 sigaddset(&newset, SIGPWR);
338#endif
339 // block all those nasty signals we don't want messing with things
340 // in signal handlers while we go from fork to exec in the child
341 pthread_sigmask(SIG_BLOCK, &newset, NULL);
303#ifdef HAVE_SYSTEMD 342#ifdef HAVE_SYSTEMD
304 char **env = NULL, **e; 343 char **env = NULL, **e;
305 344
@@ -326,16 +365,16 @@ _impl_ecore_exe_efl_object_finalize(Eo *obj, Ecore_Exe_Data *exe)
326 } 365 }
327#endif 366#endif
328 if (run_pri != ECORE_EXE_PRIORITY_INHERIT) 367 if (run_pri != ECORE_EXE_PRIORITY_INHERIT)
329 { 368 {
330#ifdef PRIO_PROCESS 369#ifdef PRIO_PROCESS
331 if ((run_pri >= -20) && (run_pri <= 19)) 370 if ((run_pri >= -20) && (run_pri <= 19))
332 setpriority(PRIO_PROCESS, 0, run_pri); 371 setpriority(PRIO_PROCESS, 0, run_pri);
333#else 372#else
334#warning "Your OS/libc does not provide PRIO_PROCESS (and possibly setpriority())" 373#warning "Your OS/libc does not provide PRIO_PROCESS (and possibly setpriority())"
335#warning "This is a POSIX-1.2001 standard and it is highly encouraged that you" 374#warning "This is a POSIX-1.2001 standard and it is highly encouraged that you"
336#warning "Have support for this" 375#warning "Have support for this"
337#endif 376#endif
338 } 377 }
339 if (ok && (flags & ECORE_EXE_ISOLATE_IO)) 378 if (ok && (flags & ECORE_EXE_ISOLATE_IO))
340 { 379 {
341 int devnull; 380 int devnull;
diff --git a/src/lib/ecore/efl_exe.c b/src/lib/ecore/efl_exe.c
index a0fd7d4608..445a3dfab2 100644
--- a/src/lib/ecore/efl_exe.c
+++ b/src/lib/ecore/efl_exe.c
@@ -467,6 +467,45 @@ _efl_exe_efl_task_run(Eo *obj, Efl_Exe_Data *pd)
467 } 467 }
468 // this code is in the child here, and is temporary setup until we 468 // this code is in the child here, and is temporary setup until we
469 // exec() the child to replace everything. 469 // exec() the child to replace everything.
470 sigset_t newset;
471
472 sigemptyset(&newset);
473 sigaddset(&newset, SIGPIPE);
474 sigaddset(&newset, SIGALRM);
475 sigaddset(&newset, SIGCHLD);
476 sigaddset(&newset, SIGUSR1);
477 sigaddset(&newset, SIGUSR2);
478 sigaddset(&newset, SIGHUP);
479 sigaddset(&newset, SIGQUIT);
480 sigaddset(&newset, SIGINT);
481 sigaddset(&newset, SIGTERM);
482 sigaddset(&newset, SIGBUS);
483 sigaddset(&newset, SIGCONT);
484 sigaddset(&newset, SIGWINCH);
485# ifdef SIGEMT
486 sigaddset(&newset, SIGEMT);
487# endif
488# ifdef SIGIO
489 sigaddset(&newset, SIGIO);
490# endif
491# ifdef SIGTSTP
492 sigaddset(&newset, SIGTSTP);
493# endif
494# ifdef SIGTTIN
495 sigaddset(&newset, SIGTTIN);
496# endif
497# ifdef SIGTTOU
498 sigaddset(&newset, SIGTTOU);
499# endif
500# ifdef SIGVTALRM
501 sigaddset(&newset, SIGVTALRM);
502# endif
503# ifdef SIGPWR
504 sigaddset(&newset, SIGPWR);
505# endif
506 // block all those nasty signals we don't want messing with things
507 // in signal handlers while we go from fork to exec in the child
508 pthread_sigmask(SIG_BLOCK, &newset, NULL);
470 509
471 if (td->flags & EFL_TASK_FLAGS_USE_STDIN) close(pipe_stdin[1]); 510 if (td->flags & EFL_TASK_FLAGS_USE_STDIN) close(pipe_stdin[1]);
472 if (td->flags & EFL_TASK_FLAGS_USE_STDOUT) close(pipe_stdout[0]); 511 if (td->flags & EFL_TASK_FLAGS_USE_STDOUT) close(pipe_stdout[0]);
@@ -523,7 +562,7 @@ _efl_exe_efl_task_run(Eo *obj, Efl_Exe_Data *pd)
523 close(devnull); 562 close(devnull);
524 } 563 }
525 564
526 if (!tdl) exit(1); 565 if (!tdl) _exit(1);
527 566
528 // clear systemd notify socket... only relevant for systemd world, 567 // clear systemd notify socket... only relevant for systemd world,
529 // otherwise shouldn't be trouble 568 // otherwise shouldn't be trouble
@@ -599,8 +638,8 @@ _efl_exe_efl_task_run(Eo *obj, Efl_Exe_Data *pd)
599 // we couldn't exec... uh oh. HAAAAAAAALP! 638 // we couldn't exec... uh oh. HAAAAAAAALP!
600 if ((errno == EACCES) || (errno == EINVAL) || (errno == ELOOP) || 639 if ((errno == EACCES) || (errno == EINVAL) || (errno == ELOOP) ||
601 (errno == ENOEXEC) || (errno == ENOMEM)) 640 (errno == ENOEXEC) || (errno == ENOMEM))
602 exit(126); 641 _exit(126);
603 exit(127); 642 _exit(127);
604 return EINA_FALSE; 643 return EINA_FALSE;
605#endif 644#endif
606} 645}