20 #include "protocols.h"
22 #include "config.h" // for VERSION
25 char *progname
= NULL
;
27 unsigned int page_size
;
28 unsigned int num_online_cpus
;
29 unsigned int max_children
;
32 * just in case we're not using the test.sh harness, we
33 * change to the tmp dir if it exists.
35 static void change_tmp_dir(void)
38 const char tmpdir
[]="tmp/";
41 /* Check if it exists, bail early if it doesn't */
42 ret
= (lstat(tmpdir
, &sb
));
46 /* Just in case a previous run screwed the perms. */
47 ret
= chmod(tmpdir
, 0777);
49 output(0, "Couldn't chmod %s to 0777.\n", tmpdir
);
53 output(0, "Couldn't change to %s\n", tmpdir
);
56 int main(int argc
, char* argv
[])
58 int ret
= EXIT_SUCCESS
;
61 const char taskname
[13]="trinity-main";
63 outputstd("Trinity v" __stringify(VERSION
) " Dave Jones <davej@redhat.com>\n");
69 page_size
= getpagesize();
70 num_online_cpus
= sysconf(_SC_NPROCESSORS_ONLN
);
71 max_children
= num_online_cpus
; /* possibly overridden in params. */
73 select_syscall_tables();
77 parse_args(argc
, argv
);
88 kernel_taint_initial
= check_tainted();
89 if (kernel_taint_initial
!= 0)
90 output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
92 if (munge_tables() == FALSE
) {
97 if (show_syscall_list
== TRUE
) {
98 dump_syscall_tables();
104 if (show_ioctl_list
== TRUE
) {
111 if (do_specific_proto
== TRUE
)
112 find_specific_proto(specific_proto_optarg
);
120 setup_main_signals();
124 /* check if we ctrl'c or something went wrong during init. */
125 if (shm
->exit_reason
!= STILL_RUNNING
)
130 /* do an extra fork so that the watchdog and the children don't share a common parent */
134 shm
->mainpid
= getpid();
136 setup_main_signals();
138 output(0, "Main thread is alive.\n");
139 prctl(PR_SET_NAME
, (unsigned long) &taskname
);
142 if (setup_fds() == FALSE
) {
143 shm
->exit_reason
= EXIT_FD_INIT_FAILURE
; // FIXME: Later, push this down to multiple EXIT's.
147 if (no_files
== FALSE
) {
148 if (files_in_index
== 0) {
149 shm
->exit_reason
= EXIT_NO_FILES
;
154 if (dropprivs
== TRUE
) //FIXME: Push down into child processes later.
162 /* wait for main loop process to exit. */
163 (void)waitpid(pid
, &childstatus
, 0);
165 /* wait for watchdog to exit. */
166 waitpid(watchdog_pid
, &childstatus
, 0);
168 output(0, "\nRan %ld syscalls. Successes: %ld Failures: %ld\n",
169 shm
->total_syscalls_done
- 1, shm
->successes
, shm
->failures
);
175 destroy_shared_mappings();