static volatile int proc_stat_thread_runs = 0;
static pthread_t proc_stat_thread_id;
-static int openFileProcess();
-static int openPort(int port);
static FILE *pipef;
static void *data_output_thread(void *arg)
{
do
{
- if (openFileProcess() != 0) {
- break;
- }
-
- if (dataPort > 0) {
- data_socket = openPort(dataPort);
- if (data_socket < 0) {
- break;
- }
- data_file_out = fdopen(data_socket, "w");
- if (data_file_out == NULL) {
- log_system_error("fdopen(data,w)");
- break;
- }
- if (fprintf(data_file_out, "ready\n") < 0 || fflush(data_file_out) != 0) {
- log_system_error("cannot write 'ready' prompt to data stream");
- break;
- }
- }
- else {
- data_file_out = stdout;
- }
-
int linesRead = 0;
char *buffer = NULL;
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
log_system_error("socket");
- return sock;
+ return -1;
}
int enable = 1;
ctrl_file_in = stdin;
}
+ if (pname) {
+ // TODO!! log to stderr as well if failed to start data_output_thread (i.e. before all 'return 1')
+ if (openFileProcess() != 0) {
+ return 1;
+ }
+
+ if (dataPort > 0) {
+ data_socket = openPort(dataPort);
+ if (data_socket < 0) {
+ return 1;
+ }
+ data_file_out = fdopen(data_socket, "w");
+ if (data_file_out == NULL) {
+ log_system_error("fdopen(data,w)");
+ return 1;
+ }
+ if (fprintf(data_file_out, "ready\n") < 0 || fflush(data_file_out) != 0) {
+ log_system_error("cannot write 'ready' prompt to data stream");
+ return 1;
+ }
+ }
+ else {
+ data_file_out = stdout;
+ }
+ }
+
if (doinfo && (statPort > 0)) {
stat_socket = openPort(statPort);
if (stat_socket < 0) {