From 086b16c0255c27fde3a54cee6f430b6c2073d266 Mon Sep 17 00:00:00 2001 From: Alexey Chernobaev Date: Mon, 3 Sep 2018 19:55:42 +0300 Subject: [PATCH] modifications to make possible profiling using one profctl instance --- profctl.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/profctl.c b/profctl.c index 1beabbd..5ddeb01 100644 --- a/profctl.c +++ b/profctl.c @@ -85,8 +85,28 @@ static pthread_t proc_stat_thread_id; static FILE *pipef; +static int openPort(int port); + static void *data_output_thread(void *arg) { + if (dataPort > 0) + { + data_socket = openPort(dataPort); + if (data_socket < 0) { + log_error("cannot open data port"); + return; + } + data_file_out = fdopen(data_socket, "w"); + if (data_file_out == NULL) { + log_system_error("fdopen(data,w)"); + return; + } + if (fprintf(data_file_out, "ready\n") < 0 || fflush(data_file_out) != 0) { + log_system_error("cannot write 'ready' prompt to data stream"); + return; + } + } + do { int linesRead = 0; @@ -241,6 +261,9 @@ static int openFileProcess() log_system_error("fopen(%s)", pname); return -1; } + if (verbose) { + log_message("pipe %s opened for read", pname); + } return 0; } @@ -480,7 +503,9 @@ static void *command_loop_thread(void *arg) } } else if (is_command(line, "exit", &pid, app_pid, NULL, 0) == 0) { - send_signal(pid, SIGHUP); + if (pid != -1) { + send_signal(pid, SIGHUP); + } if (verbose && !global_stop) { log_message("stop flag set (command_loop_thread)"); } @@ -604,6 +629,7 @@ int main(int argc, char **argv) if (controlPort > 0) { control_socket = openPort(controlPort); if (control_socket < 0) { + log_error("cannot open control port"); exit(1); } ctrl_file_in = fdopen(control_socket, "r"); @@ -629,6 +655,8 @@ int main(int argc, char **argv) } if (dataPort > 0) { + // data_output_thread will open the data port +/*!! data_socket = openPort(dataPort); if (data_socket < 0) { return 1; @@ -642,6 +670,7 @@ int main(int argc, char **argv) log_system_error("cannot write 'ready' prompt to data stream"); return 1; } +*/ } else { data_file_out = stdout; @@ -651,12 +680,17 @@ int main(int argc, char **argv) if (doinfo && (statPort > 0)) { stat_socket = openPort(statPort); if (stat_socket < 0) { + log_error("cannot open statistics port"); exit(1); } stat_file_out = fdopen(stat_socket, "w"); if (stat_file_out == NULL) { log_system_error_and_exit("fdopen(stat,w)"); } + if (fprintf(stat_file_out, "ready\n") < 0 || fflush(stat_file_out) != 0) { + log_system_error("cannot write 'ready' prompt to statistics stream"); + return; + } } pthread_t data_output_thread_id; -- 2.7.4