static int controlPort = -1;
static int dataPort = -1;
static int statPort = -1;
+static int control_socket = -1;
+static int data_socket = -1;
+static int stat_socket = -1;
static FILE *ctrl_file_in = NULL;
static FILE *ctrl_file_out = NULL;
static FILE *data_file_out = NULL;
openFileProcess();
if (dataPort > 0) {
- int s = openPort(dataPort);
- data_file_out = fdopen(s, "w");
+ data_socket = openPort(dataPort);
+ data_file_out = fdopen(data_socket, "w");
if (data_file_out == NULL) {
log_system_error_and_exit("fdopen(data,w)");
}
unlink(pname);
}
}
+ if (ctrl_file_in != NULL) {
+ if (ctrl_file_in != orig_stdin) {
+ fclose(ctrl_file_in);
+ }
+ }
+ if (ctrl_file_out != NULL) {
+ if (ctrl_file_out != orig_stdout) {
+ fclose(ctrl_file_out);
+ }
+ }
if (data_file_out != NULL) {
fflush(data_file_out);
if (data_file_out != orig_stdout) {
fclose(data_file_out);
}
}
+ if (control_socket >= 0) {
+ close(control_socket);
+ }
+ if (data_socket >= 0) {
+ close(data_socket);
+ }
+ if (stat_socket >= 0) {
+ close(stat_socket);
+ }
log_error("=== finished ===");
+ if (stderr != orig_stderr) {
+ fclose(stderr);
+ }
finish_close_stdio();
kill(getpid(), SIGKILL);
}
}
int enable = 1;
- if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0)
- {
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
log_system_error_and_exit("setsockopt");
}
saddr.sin_addr.s_addr = INADDR_ANY;
saddr.sin_port = htons(port);
- if (bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
- {
+ if (bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
log_system_error_and_exit("bind");
}
- listen(sock, 5);
+ if (listen(sock, 5) < 0) {
+ log_system_error_and_exit("listen");
+ }
if (verbose) {
log_error("waiting for connection to port %d", port);
if (verbose) {
log_error("accepted connection to port %d", port);
}
+ close(sock);
return result;
}
#endif /* TIZEN */
if (controlPort > 0) {
- int s = openPort(controlPort);
- ctrl_file_in = fdopen(s, "r");
+ control_socket = openPort(controlPort);
+ ctrl_file_in = fdopen(control_socket, "r");
if (ctrl_file_in == NULL) {
log_system_error_and_exit("fdopen(control,r)");
}
- ctrl_file_out = fdopen(s, "w");
+ ctrl_file_out = fdopen(control_socket, "w");
if (ctrl_file_out == NULL) {
log_system_error_and_exit("fdopen(control,w)");
}
}
if (doinfo && (statPort > 0)) {
- int s = openPort(statPort);
- stat_file_out = fdopen(s, "w");
+ stat_socket = openPort(statPort);
+ stat_file_out = fdopen(stat_socket, "w");
if (stat_file_out == NULL) {
log_system_error_and_exit("fdopen(stat,w)");
}