From 2e76bb466a82110ca80d5d6d982842cf2f9cc964 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 9 Jun 2015 17:30:15 -0700 Subject: [PATCH] Use pid_t on UN*X, and HANDLE on Windows, for the process ID. This avoids type punning; at least with Xcode 7 beta on El Capitan beta, that produces warnings that get turned into errors. Change-Id: I57f47455b9630f359828c07c92a190b5cb33816f Reviewed-on: https://code.wireshark.org/review/8862 Reviewed-by: Guy Harris --- capchild/capture_session.h | 8 ++++--- capchild/capture_sync.c | 24 ++++++++++----------- capchild/capture_sync.h | 6 +++--- tshark.c | 4 ++-- ui/capture.c | 4 ++-- ui/gtk/gui_utils.c | 4 ++-- ui/qt/main_window.cpp | 4 ++-- ui/qt/main_window.h | 4 ++-- ui/ui_util.h | 4 +++- wsutil/Makefile.common | 1 + wsutil/process.h | 43 ++++++++++++++++++++++++++++++++++++++ 11 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 wsutil/process.h diff --git a/capchild/capture_session.h b/capchild/capture_session.h index e21d182fe3..4f0de81b01 100644 --- a/capchild/capture_session.h +++ b/capchild/capture_session.h @@ -34,6 +34,8 @@ extern "C" { #include "capture_opts.h" +#include + #ifdef HAVE_LIBPCAP /* Current state of capture engine. XXX - differentiate states */ typedef enum { @@ -48,14 +50,14 @@ struct _capture_file; * State of a capture session. */ typedef struct _capture_session { - intptr_t fork_child; /**< If not -1, in parent, process ID of child */ + ws_process_id fork_child; /**< If not -1, in parent, process ID of child */ int fork_child_status; /**< Child exit status */ #ifdef _WIN32 int signal_pipe_write_fd; /**< the pipe to signal the child */ #endif - capture_state state; /**< current state of the capture engine */ + capture_state state; /**< current state of the capture engine */ #ifndef _WIN32 - uid_t owner; /**< owner of the cfile */ + uid_t owner; /**< owner of the cfile */ gid_t group; /**< group of the cfile */ #endif gboolean session_started; diff --git a/capchild/capture_sync.c b/capchild/capture_sync.c index b2a649be87..8efe26408a 100644 --- a/capchild/capture_sync.c +++ b/capchild/capture_sync.c @@ -118,12 +118,12 @@ static const char *sync_pipe_signame(int); static gboolean sync_pipe_input_cb(gint source, gpointer user_data); -static int sync_pipe_wait_for_child(intptr_t fork_child, gchar **msgp); +static int sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp); static void pipe_convert_header(const guchar *header, int header_len, char *indicator, int *block_len); static ssize_t pipe_read_block(int pipe_fd, char *indicator, int len, char *msg, char **err_msg); -static void (*fetch_dumpcap_pid)(int) = NULL; +static void (*fetch_dumpcap_pid)(ws_process_id) = NULL; void @@ -659,7 +659,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, voi g_free( (gpointer) argv); return FALSE; } - cap_session->fork_child = (intptr_t) pi.hProcess; + cap_session->fork_child = pi.hProcess; g_string_free(args, TRUE); /* associate the operating system filehandle to a C run-time file handle */ @@ -771,7 +771,7 @@ sync_pipe_start(capture_options *capture_opts, capture_session *cap_session, voi #define PIPE_BUF_SIZE 5120 static int sync_pipe_open_command(char** argv, int *data_read_fd, - int *message_read_fd, intptr_t *fork_child, gchar **msg, void(*update_cb)(void)) + int *message_read_fd, ws_process_id *fork_child, gchar **msg, void(*update_cb)(void)) { enum PIPES { PIPE_READ, PIPE_WRITE }; /* Constants 0 and 1 for PIPE_READ and PIPE_WRITE */ #ifdef _WIN32 @@ -875,7 +875,7 @@ sync_pipe_open_command(char** argv, int *data_read_fd, g_free( (gpointer) argv); return -1; } - *fork_child = (intptr_t) pi.hProcess; + *fork_child = pi.hProcess; g_string_free(args, TRUE); /* associate the operating system filehandles to C run-time file handles */ @@ -983,7 +983,7 @@ sync_pipe_open_command(char** argv, int *data_read_fd, */ static int sync_pipe_close_command(int *data_read_fd, int *message_read_fd, - intptr_t *fork_child, gchar **msgp) + ws_process_id *fork_child, gchar **msgp) { ws_close(*data_read_fd); if (message_read_fd != NULL) @@ -1018,7 +1018,7 @@ sync_pipe_run_command_actual(char** argv, gchar **data, gchar **primary_msg, { gchar *msg; int data_pipe_read_fd, sync_pipe_read_fd, ret; - intptr_t fork_child; + ws_process_id fork_child; char *wait_msg; gchar buffer[PIPE_BUF_SIZE+1] = {0}; ssize_t nread; @@ -1363,7 +1363,7 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode, * that must be g_free()d, and -1 will be returned. */ int -sync_interface_stats_open(int *data_read_fd, intptr_t *fork_child, gchar **msg, void (*update_cb)(void)) +sync_interface_stats_open(int *data_read_fd, ws_process_id *fork_child, gchar **msg, void (*update_cb)(void)) { int argc; char **argv; @@ -1515,7 +1515,7 @@ sync_interface_stats_open(int *data_read_fd, intptr_t *fork_child, gchar **msg, /* Close down the stats process */ int -sync_interface_stats_close(int *read_fd, intptr_t *fork_child, gchar **msg) +sync_interface_stats_close(int *read_fd, ws_process_id *fork_child, gchar **msg) { #ifndef _WIN32 /* @@ -1869,7 +1869,7 @@ sync_pipe_input_cb(gint source, gpointer user_data) * must be freed with g_free(). */ static int -sync_pipe_wait_for_child(intptr_t fork_child, gchar **msgp) +sync_pipe_wait_for_child(ws_process_id fork_child, gchar **msgp) { int fork_child_status; #ifndef _WIN32 @@ -2140,7 +2140,7 @@ sync_pipe_stop(capture_session *cap_session) /* Wireshark has to exit, force the capture child to close */ void -sync_pipe_kill(intptr_t fork_child) +sync_pipe_kill(ws_process_id fork_child) { if (fork_child != -1) { #ifndef _WIN32 @@ -2174,7 +2174,7 @@ sync_pipe_kill(intptr_t fork_child) } } -void capture_sync_set_fetch_dumpcap_pid_cb(void(*cb)(int pid)) { +void capture_sync_set_fetch_dumpcap_pid_cb(void(*cb)(ws_process_id pid)) { fetch_dumpcap_pid = cb; } diff --git a/capchild/capture_sync.h b/capchild/capture_sync.h index c56656bc09..485a41f9f2 100644 --- a/capchild/capture_sync.h +++ b/capchild/capture_sync.h @@ -54,7 +54,7 @@ sync_pipe_stop(capture_session *cap_session); /** User wants to stop the program, just kill the child as soon as possible */ extern void -sync_pipe_kill(intptr_t fork_child); +sync_pipe_kill(ws_process_id fork_child); /** Set wireless channel using dumpcap */ extern int @@ -75,11 +75,11 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode, /** Start getting interface statistics using dumpcap. */ extern int -sync_interface_stats_open(int *read_fd, intptr_t *fork_child, gchar **msg, void (*update_cb)(void)); +sync_interface_stats_open(int *read_fd, ws_process_id *fork_child, gchar **msg, void (*update_cb)(void)); /** Stop gathering statistics. */ extern int -sync_interface_stats_close(int *read_fd, intptr_t *fork_child, gchar **msg); +sync_interface_stats_close(int *read_fd, ws_process_id *fork_child, gchar **msg); /** Read a line from a pipe, similar to fgets. Non-blocking. */ extern int diff --git a/tshark.c b/tshark.c index 7b474a8920..1023c6fc0d 100644 --- a/tshark.c +++ b/tshark.c @@ -2278,7 +2278,7 @@ DIAG_ON(cast-qual) typedef struct pipe_input_tag { gint source; gpointer user_data; - intptr_t *child_process; + ws_process_id *child_process; pipe_input_cb_t input_cb; guint pipe_input_id; #ifdef _WIN32 @@ -2351,7 +2351,7 @@ pipe_timer_cb(gpointer data) void -pipe_input_set_handler(gint source, gpointer user_data, intptr_t *child_process, pipe_input_cb_t input_cb) +pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb) { pipe_input.source = source; diff --git a/ui/capture.c b/ui/capture.c index 18c3040edb..590c33a7b5 100644 --- a/ui/capture.c +++ b/ui/capture.c @@ -63,7 +63,7 @@ typedef struct if_stat_cache_item_s { struct if_stat_cache_s { int stat_fd; - intptr_t fork_child; + ws_process_id fork_child; GList *cache_list; /* List of if_stat_chache_entry_t */ }; @@ -645,7 +645,7 @@ capture_input_closed(capture_session *cap_session, gchar *msg) if_stat_cache_t * capture_stat_start(capture_options *capture_opts) { int stat_fd; - intptr_t fork_child; + ws_process_id fork_child; gchar *msg; if_stat_cache_t *sc = NULL; if_stat_cache_item_t *sc_item; diff --git a/ui/gtk/gui_utils.c b/ui/gtk/gui_utils.c index 761e1d8034..1e4ad67f09 100644 --- a/ui/gtk/gui_utils.c +++ b/ui/gtk/gui_utils.c @@ -580,7 +580,7 @@ main_window_quit(void) typedef struct pipe_input_tag { gint source; gpointer user_data; - intptr_t *child_process; + ws_process_id *child_process; pipe_input_cb_t input_cb; guint pipe_input_id; #ifdef _WIN32 @@ -693,7 +693,7 @@ pipe_input_cb(GIOChannel *source _U_, void pipe_input_set_handler(gint source, gpointer user_data, - intptr_t *child_process, + ws_process_id *child_process, pipe_input_cb_t input_cb) { static pipe_input_t pipe_input; diff --git a/ui/qt/main_window.cpp b/ui/qt/main_window.cpp index 3deb284bab..52af27a336 100644 --- a/ui/qt/main_window.cpp +++ b/ui/qt/main_window.cpp @@ -77,7 +77,7 @@ // If we ever add support for multiple windows this will need to be replaced. static MainWindow *gbl_cur_main_window_ = NULL; -void pipe_input_set_handler(gint source, gpointer user_data, intptr_t *child_process, pipe_input_cb_t input_cb) +void pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb) { gbl_cur_main_window_->setPipeInputHandler(source, user_data, child_process, input_cb); } @@ -472,7 +472,7 @@ QString MainWindow::getFilter() return df_combo_box_->itemText(df_combo_box_->count()); } -void MainWindow::setPipeInputHandler(gint source, gpointer user_data, intptr_t *child_process, pipe_input_cb_t input_cb) +void MainWindow::setPipeInputHandler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb) { pipe_source_ = source; pipe_child_process_ = child_process; diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index 172244e703..bf538d88fe 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -78,7 +78,7 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); - void setPipeInputHandler(gint source, gpointer user_data, intptr_t *child_process, pipe_input_cb_t input_cb); + void setPipeInputHandler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb); QString getFilter(); #ifdef HAVE_LIBPCAP @@ -140,7 +140,7 @@ private: // Pipe input gint pipe_source_; gpointer pipe_user_data_; - intptr_t *pipe_child_process_; + ws_process_id *pipe_child_process_; pipe_input_cb_t pipe_input_cb_; #ifdef _WIN32 QTimer *pipe_timer_; diff --git a/ui/ui_util.h b/ui/ui_util.h index 5eba626104..6f966361dc 100644 --- a/ui/ui_util.h +++ b/ui/ui_util.h @@ -27,6 +27,8 @@ #include +#include + #include "epan/packet_info.h" #include "epan/column-utils.h" @@ -58,7 +60,7 @@ extern void main_window_quit(void); /* read from a pipe (callback) */ typedef gboolean (*pipe_input_cb_t) (gint source, gpointer user_data); /* install callback function, called if pipe input is available */ -extern void pipe_input_set_handler(gint source, gpointer user_data, intptr_t *child_process, pipe_input_cb_t input_cb); +extern void pipe_input_set_handler(gint source, gpointer user_data, ws_process_id *child_process, pipe_input_cb_t input_cb); /* packet_list.c */ diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index f93f973546..60d843ab31 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -107,6 +107,7 @@ libwsutil_nonrepl_INCLUDES = \ os_version_info.h \ plugins.h \ privileges.h \ + process.h \ sha1.h \ sign_ext.h \ sober128.h \ diff --git a/wsutil/process.h b/wsutil/process.h new file mode 100644 index 0000000000..eb3fd4c597 --- /dev/null +++ b/wsutil/process.h @@ -0,0 +1,43 @@ +/* process.h + * Process utility definitions + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _WSUTIL_PROCESS_H_ +#define _WSUTIL_PROCESS_H_ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef _WIN32 +typedef HANDLE ws_process_id; /* on Windows, a process ID is a HANDLE */ +#else +typedef pid_t ws_process_id; /* on UN\*X, a process ID is a pid_t */ +#endif + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* _WSUTIL_PROCESS_H_ */ +