20 #include "protocols.h"
22 #include "config.h" // for VERSION
24 char *progname
= NULL
;
26 unsigned int page_size
;
27 unsigned int num_online_cpus
;
28 unsigned int max_children
;
31 * just in case we're not using the test.sh harness, we
32 * change to the tmp dir if it exists.
34 static void change_tmp_dir(void)
37 const char tmpdir
[]="tmp/";
40 /* Check if it exists, bail early if it doesn't */
41 ret
= (lstat(tmpdir
, &sb
));
45 /* Just in case a previous run screwed the perms. */
46 ret
= chmod(tmpdir
, 0777);
48 output(0, "Couldn't chmod %s to 0777.\n", tmpdir
);
52 output(0, "Couldn't change to %s\n", tmpdir
);
55 int main(int argc
, char* argv
[])
57 int ret
= EXIT_SUCCESS
;
60 const char taskname
[13]="trinity-main";
62 outputstd("Trinity v" __stringify(VERSION
) " Dave Jones <davej@redhat.com>\n");
70 page_size
= getpagesize();
71 num_online_cpus
= sysconf(_SC_NPROCESSORS_ONLN
);
72 max_children
= num_online_cpus
; /* possibly overridden in params. */
74 select_syscall_tables();
76 parse_args(argc
, argv
);
81 kernel_taint_initial
= check_tainted();
82 if (kernel_taint_initial
!= 0)
83 output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
88 if (munge_tables() == FALSE
) {
93 if (show_syscall_list
== TRUE
) {
94 dump_syscall_tables();
100 if (show_ioctl_list
== TRUE
) {
107 if (do_specific_proto
== TRUE
)
108 find_specific_proto(specific_proto_optarg
);
116 setup_main_signals();
120 /* check if we ctrl'c or something went wrong during init. */
121 if (shm
->exit_reason
!= STILL_RUNNING
)
126 /* do an extra fork so that the watchdog and the children don't share a common parent */
130 shm
->mainpid
= getpid();
132 setup_main_signals();
134 output(0, "Main thread is alive.\n");
135 prctl(PR_SET_NAME
, (unsigned long) &taskname
);
138 if (setup_fds() == FALSE
) {
139 shm
->exit_reason
= EXIT_FD_INIT_FAILURE
; // FIXME: Later, push this down to multiple EXIT's.
143 if (no_files
== FALSE
) {
144 if (files_in_index
== 0) {
145 shm
->exit_reason
= EXIT_NO_FILES
;
150 if (dropprivs
== TRUE
) //FIXME: Push down into child processes later.
158 /* wait for main loop process to exit. */
159 (void)waitpid(pid
, &childstatus
, 0);
161 /* wait for watchdog to exit. */
162 waitpid(watchdog_pid
, &childstatus
, 0);
164 output(0, "\nRan %ld syscalls. Successes: %ld Failures: %ld\n",
165 shm
->total_syscalls_done
- 1, shm
->successes
, shm
->failures
);
171 destroy_shared_mappings();