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();
78 parse_args(argc
, argv
);
87 kernel_taint_initial
= check_tainted();
88 if (kernel_taint_initial
!= 0)
89 output(0, "Kernel was tainted on startup. Will ignore flags that are already set.\n");
91 if (munge_tables() == FALSE
) {
96 if (show_syscall_list
== TRUE
) {
97 dump_syscall_tables();
103 if (show_ioctl_list
== TRUE
) {
110 if (do_specific_proto
== TRUE
)
111 find_specific_proto(specific_proto_optarg
);
119 setup_main_signals();
123 /* check if we ctrl'c or something went wrong during init. */
124 if (shm
->exit_reason
!= STILL_RUNNING
)
129 /* do an extra fork so that the watchdog and the children don't share a common parent */
133 shm
->mainpid
= getpid();
135 setup_main_signals();
137 output(0, "Main thread is alive.\n");
138 prctl(PR_SET_NAME
, (unsigned long) &taskname
);
141 if (setup_fds() == FALSE
) {
142 shm
->exit_reason
= EXIT_FD_INIT_FAILURE
; // FIXME: Later, push this down to multiple EXIT's.
146 if (no_files
== FALSE
) {
147 if (files_in_index
== 0) {
148 shm
->exit_reason
= EXIT_NO_FILES
;
153 if (dropprivs
== TRUE
) //FIXME: Push down into child processes later.
161 /* wait for main loop process to exit. */
162 (void)waitpid(pid
, &childstatus
, 0);
164 /* wait for watchdog to exit. */
165 waitpid(watchdog_pid
, &childstatus
, 0);
167 output(0, "\nRan %ld syscalls. Successes: %ld Failures: %ld\n",
168 shm
->total_syscalls_done
- 1, shm
->successes
, shm
->failures
);
174 destroy_shared_mappings();