diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-12-04 20:25:51 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-12-05 04:27:49 +0000 |
commit | 037c64aa34d4196da5a39dfb59af16abceb1247b (patch) | |
tree | c0b9dc86dee52d5d513d911d9d394667be324a2d /captype.c | |
parent | faf70602a8e96433ae888278cccaac057091fbca (diff) |
Clean up initialization code for programs.
Make the init_progfile_dir() call unconditionally, even if plugins
aren't supported, as that doesn't necessarily mean nobody uses the
directory containing the executable.
Report the error the same way in all programs, and free the error string
after we're finished with it.
Make the error - and the comment before the code - reflect what
init_progfile_dir() is actually doing (the goal is to get the full
pathname of the directory *containing* the executable; that's generally
done by getting the pathname of the executable and stripping off the
name of the executable, but that's won't necessarily always be the
case). Also note for TShark that we won't be able to capture traffic,
just as we do for Wireshark (if we don't have the pathname of the
program file, we don't have a pathname to use to find dumpcap).
Have the plugin scanner just fail silently if we weren't able to get the
plugin directory path, so we don't have to worry about calling it if
init_progfile_dir() fails.
Clean up white space while we're at it.
Change-Id: I8e580c719aab6fbf74a764bf6629962394fff7c8
Reviewed-on: https://code.wireshark.org/review/19076
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'captype.c')
-rw-r--r-- | captype.c | 40 |
1 files changed, 22 insertions, 18 deletions
@@ -86,6 +86,7 @@ main(int argc, char *argv[]) { GString *comp_info_str; GString *runtime_info_str; + char *init_progfile_dir_error; wtap *wth; int err; gchar *err_info; @@ -98,10 +99,6 @@ main(int argc, char *argv[]) {0, 0, 0, 0 } }; -#ifdef HAVE_PLUGINS - char *init_progfile_dir_error; -#endif - /* Set the C-language locale to the native environment. */ setlocale(LC_ALL, ""); @@ -131,26 +128,33 @@ main(int argc, char *argv[]) */ init_process_policies(); + /* + * Attempt to get the pathname of the directory containing the + * executable file. + */ + init_progfile_dir_error = init_progfile_dir(argv[0], main); + if (init_progfile_dir_error != NULL) { + fprintf(stderr, + "captype: Can't get pathname of directory containing the captype program: %s.\n", + init_progfile_dir_error); + g_free(init_progfile_dir_error); + } + wtap_init(); #ifdef HAVE_PLUGINS - if ((init_progfile_dir_error = init_progfile_dir(argv[0], main))) { - g_warning("captype: init_progfile_dir(): %s", init_progfile_dir_error); - g_free(init_progfile_dir_error); - } else { - init_report_err(failure_message,NULL,NULL,NULL); + init_report_err(failure_message,NULL,NULL,NULL); - /* Scan for plugins. This does *not* call their registration routines; - that's done later. + /* Scan for plugins. This does *not* call their registration routines; + that's done later. - Don't report failures to load plugins because most (non-wiretap) - plugins *should* fail to load (because we're not linked against - libwireshark and dissector plugins need libwireshark). */ - scan_plugins(DONT_REPORT_LOAD_FAILURE); + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); - /* Register all libwiretap plugin modules. */ - register_all_wiretap_modules(); - } + /* Register all libwiretap plugin modules. */ + register_all_wiretap_modules(); #endif /* Process the options */ |