aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/firejail/firejail.h1
-rw-r--r--src/firejail/main.c15
-rw-r--r--src/firejail/sandbox.c20
-rw-r--r--src/include/common.h11
4 files changed, 36 insertions, 11 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index 6b1786a93..fba4c4fe2 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -354,6 +354,7 @@ extern int login_shell;
354extern int parent_to_child_fds[2]; 354extern int parent_to_child_fds[2];
355extern int child_to_parent_fds[2]; 355extern int child_to_parent_fds[2];
356extern pid_t sandbox_pid; 356extern pid_t sandbox_pid;
357extern unsigned long long start_timestamp;
357 358
358#define MAX_ARGS 128 // maximum number of command arguments (argc) 359#define MAX_ARGS 128 // maximum number of command arguments (argc)
359extern char *fullargv[MAX_ARGS]; 360extern char *fullargv[MAX_ARGS];
diff --git a/src/firejail/main.c b/src/firejail/main.c
index 4357ddaa4..9e5c31c32 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -37,15 +37,6 @@
37#include <net/if.h> 37#include <net/if.h>
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39 39
40#if 0
41#include <sys/times.h>
42{
43struct tms tm;
44clock_t systick = times(&tm);
45printf("time %s:%d %u\n", __FILE__, __LINE__, (uint32_t) systick);
46}
47#endif
48
49uid_t firejail_uid = 0; 40uid_t firejail_uid = 0;
50gid_t firejail_gid = 0; 41gid_t firejail_gid = 0;
51 42
@@ -127,6 +118,7 @@ char *fullargv[MAX_ARGS]; // expanded argv for restricted shell
127int fullargc = 0; 118int fullargc = 0;
128static pid_t child = 0; 119static pid_t child = 0;
129pid_t sandbox_pid; 120pid_t sandbox_pid;
121unsigned long long start_timestamp;
130 122
131static void set_name_file(pid_t pid); 123static void set_name_file(pid_t pid);
132static void delete_name_file(pid_t pid); 124static void delete_name_file(pid_t pid);
@@ -826,6 +818,11 @@ int main(int argc, char **argv) {
826 char *custom_profile_dir = NULL; // custom profile directory 818 char *custom_profile_dir = NULL; // custom profile directory
827 int arg_noprofile = 0; // use default.profile if none other found/specified 819 int arg_noprofile = 0; // use default.profile if none other found/specified
828 820
821
822 // get starting timestamp
823 start_timestamp = getticks();
824
825
829 // build /run/firejail directory structure 826 // build /run/firejail directory structure
830 preproc_build_firejail_dir(); 827 preproc_build_firejail_dir();
831 828
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index e6deddac5..9ecb1c8cc 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -274,6 +274,22 @@ void start_audit(void) {
274 exit(1); 274 exit(1);
275} 275}
276 276
277static void print_time(void) {
278 if (start_timestamp) {
279 unsigned long long end_timestamp = getticks();
280 // measure 1 ms
281 usleep(1000);
282 unsigned long long onems = getticks() - end_timestamp;
283 if (onems) {
284 printf("Child process initialized in %.02f ms\n",
285 (float) (end_timestamp - start_timestamp) / (float) onems);
286 return;
287 }
288 }
289
290 printf("Child process initialized\n");
291}
292
277void start_application(void) { 293void start_application(void) {
278//if (setsid() == -1) 294//if (setsid() == -1)
279//errExit("setsid"); 295//errExit("setsid");
@@ -315,7 +331,7 @@ void start_application(void) {
315 } 331 }
316 332
317 if (!arg_command && !arg_quiet) 333 if (!arg_command && !arg_quiet)
318 printf("Child process initialized\n"); 334 print_time();
319 335
320#ifdef HAVE_GCOV 336#ifdef HAVE_GCOV
321 __gcov_dump(); 337 __gcov_dump();
@@ -366,7 +382,7 @@ void start_application(void) {
366 } 382 }
367 383
368 if (!arg_command && !arg_quiet) 384 if (!arg_command && !arg_quiet)
369 printf("Child process initialized\n"); 385 print_time();
370#ifdef HAVE_GCOV 386#ifdef HAVE_GCOV
371 __gcov_dump(); 387 __gcov_dump();
372#endif 388#endif
diff --git a/src/include/common.h b/src/include/common.h
index fc4059334..59b7f6213 100644
--- a/src/include/common.h
+++ b/src/include/common.h
@@ -109,6 +109,17 @@ static inline int mac_not_zero(const unsigned char mac[6]) {
109 return 0; 109 return 0;
110} 110}
111 111
112// rtdsc timestamp on x86-64/amd64 processors
113static inline unsigned long long getticks(void) {
114#if defined(__x86_64__)
115 unsigned a, d;
116 asm volatile("rdtsc" : "=a" (a), "=d" (d));
117 return ((unsigned long long)a) | (((unsigned long long)d) << 32);
118#else
119 return 0; // not implemented
120#endif
121}
122
112int join_namespace(pid_t pid, char *type); 123int join_namespace(pid_t pid, char *type);
113int name2pid(const char *name, pid_t *pid); 124int name2pid(const char *name, pid_t *pid);
114char *pid_proc_comm(const pid_t pid); 125char *pid_proc_comm(const pid_t pid);