Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.70 KB | None | 0 0
  1. diff --git a/src/zenroom.c b/src/zenroom.c
  2. index 2442872..5330ff4 100644
  3. --- a/src/zenroom.c
  4. +++ b/src/zenroom.c
  5. @@ -23,6 +23,10 @@
  6.  #include <string.h>
  7.  #include <ctype.h>
  8.  
  9. +#include <wait.h>
  10. +#include <sys/prctl.h>
  11. +#include <linux/seccomp.h>
  12. +
  13.  #include <errno.h>
  14.  
  15.  #include <lua.h>
  16. @@ -305,6 +309,7 @@ int main(int argc, char **argv) {
  17.      const char *short_options = "hdic:k:a:p:";
  18.      const char *help          =
  19.             "Usage: zenroom [-dh] [ -i ] [ -c config ] [ -k keys ] [ -a data ] [ [ -p ] script.lua ]\n";
  20. +    int pid, status, retval;
  21.      conffile   [0] = '\0';
  22.      scriptfile [0] = '\0';
  23.      keysfile   [0] = '\0';
  24. @@ -419,8 +424,28 @@ int main(int argc, char **argv) {
  25.         if(!Z) {
  26.                 error(NULL, "Initialisation failed.");
  27.                 return 1; }
  28. -       if( zen_exec_script(Z, script) ) error(NULL, "Blocked execution.");
  29. -       else notice(NULL, "Execution completed.");
  30. +    if (fork() == 0) {
  31. +        prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT);
  32. +        notice(NULL, "Starting execution.");
  33. +       if( zen_exec_script(Z, script) ) {
  34. +            error(NULL, "Blocked execution.");
  35. +            exit(1);
  36. +        }
  37. +        exit(0);
  38. +    }
  39. +
  40. +    do {
  41. +        pid = wait(&status);
  42. +    } while(pid == -1);
  43. +
  44. +    if (WIFEXITED(status)) {
  45. +        retval = WEXITSTATUS(status);
  46. +        if (retval == 0)
  47. +            notice(NULL, "Execution completed.");
  48. +    } else if (WIFSIGNALED(status)) {
  49. +           notice(NULL, "Execution interrupted by signal %d.", WTERMSIG(status));
  50. +    }
  51. +
  52.         // report experimental memory manager
  53.         // if((strcmp(conffile,"umm")==0) && zen_heap) {
  54.         //      lua_gc(L, LUA_GCCOLLECT, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement