aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/shutdown.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-04-13 20:47:18 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2016-04-13 20:47:18 -0400
commitc85acb7ba71b153806632256b511b915b872c5bc (patch)
tree0b7d6a11cde99266be994fd319b6edaa4ccd21cf /src/firejail/shutdown.c
parentprofile fixes (diff)
downloadfirejail-c85acb7ba71b153806632256b511b915b872c5bc.tar.gz
firejail-c85acb7ba71b153806632256b511b915b872c5bc.tar.zst
firejail-c85acb7ba71b153806632256b511b915b872c5bc.zip
wait up to 10 seconds for sandbox shutdown
Diffstat (limited to 'src/firejail/shutdown.c')
-rw-r--r--src/firejail/shutdown.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/src/firejail/shutdown.c b/src/firejail/shutdown.c
index 94ca0a816..8d8035bfb 100644
--- a/src/firejail/shutdown.c
+++ b/src/firejail/shutdown.c
@@ -77,26 +77,46 @@ void shut(pid_t pid) {
77 EUID_ROOT(); 77 EUID_ROOT();
78 printf("Sending SIGTERM to %u\n", pid); 78 printf("Sending SIGTERM to %u\n", pid);
79 kill(pid, SIGTERM); 79 kill(pid, SIGTERM);
80 sleep(2);
81 80
82 // if the process is still running, terminate it using SIGKILL 81 // wait for not more than 10 seconds
83 // try to open stat file 82 sleep(2);
84 char *file; 83 int monsec = 8;
85 if (asprintf(&file, "/proc/%u/status", pid) == -1) { 84 char *monfile;
86 perror("asprintf"); 85 if (asprintf(&monfile, "/proc/%d/cmdline", pid) == -1)
87 exit(1); 86 errExit("asprintf");
87 int killdone = 0;
88
89 while (monsec) {
90 FILE *fp = fopen(monfile, "r");
91 if (!fp) {
92 killdone = 1;
93 break;
94 }
95
96 char c;
97 size_t count = fread(&c, 1, 1, fp);
98 fclose(fp);
99 if (count == 0) {
100 // all done
101 killdone = 1;
102 break;
103 }
104
105 sleep(1);
106 monsec--;
88 } 107 }
89 FILE *fp = fopen(file, "r"); 108 free(monfile);
90 if (!fp) 109
91 return; 110
92 fclose(fp); 111 // force SIGKILL
93 112 if (!killdone) {
94 // kill the process and also the parent 113 // kill the process and also the parent
95 printf("Sending SIGKILL to %u\n", pid); 114 printf("Sending SIGKILL to %u\n", pid);
96 kill(pid, SIGKILL); 115 kill(pid, SIGKILL);
97 if (parent != pid) { 116 if (parent != pid) {
98 printf("Sending SIGKILL to %u\n", parent); 117 printf("Sending SIGKILL to %u\n", parent);
99 kill(parent, SIGKILL); 118 kill(parent, SIGKILL);
119 }
100 } 120 }
101 121
102 clear_run_files(parent); 122 clear_run_files(parent);