list_for_each_entry(conn, &server->connections, list) {
if(conn->fd == fds[idx].fd) {
+ ustcomm_close_app(conn);
list_del(&conn->list);
+ free(conn);
break;
}
}
return ustcomm_connect_path(path, conn, pid);
}
-/* Close a connection to a traceable app. */
+/* Close a connection to a traceable app. It frees the
+ * resources. It however does not free the
+ * ustcomm_connection itself.
+ */
int ustcomm_close_app(struct ustcomm_connection *conn)
{
}
}
+/* Free a traceable application server */
+
void ustcomm_fini_app(struct ustcomm_app *handle, int keep_socket_file)
{
ustcomm_fini_server(&handle->server, keep_socket_file);
}
+/* Free a ustd server */
+
void ustcomm_fini_ustd(struct ustcomm_ustd *handle)
{
ustcomm_fini_server(&handle->server, 0);
if(result != 2 && result != 1) {
ERR("unable to parse response to get_subbuffer");
retval = -1;
+ free(received_msg);
goto end_rep;
}
- DBG("received msg is %s", received_msg);
-
if(!strcmp(rep_code, "OK")) {
DBG("got subbuffer %s", buf->name);
retval = GET_SUBBUF_OK;
return NULL;
}
+static void destroy_buffer(struct buffer_info *buf)
+{
+ int result;
+
+ result = ustcomm_close_app(&buf->conn);
+ if(result == -1) {
+ WARN("problem calling ustcomm_close_app");
+ }
+
+ result = shmdt(buf->mem);
+ if(result == -1) {
+ PERROR("shmdt");
+ }
+
+ result = shmdt(buf->bufstruct_mem);
+ if(result == -1) {
+ PERROR("shmdt");
+ }
+
+ result = close(buf->file_fd);
+ if(result == -1) {
+ PERROR("close");
+ }
+
+ free(buf);
+}
+
int unwrite_last_subbuffer(struct buffer_info *buf)
{
int result;
return 0;
}
-void free_buffer(struct buffer_info *buf)
-{
-}
-
struct consumer_thread_args {
pid_t pid;
const char *bufname;
consumer_loop(buf);
- free_buffer(buf);
+ free(args->bufname);
+ destroy_buffer(buf);
end:
/* bufname is free'd in free_buffer() */
{
pthread_t thr;
struct consumer_thread_args *args;
+ int result;
DBG("beginning of start_consuming_buffer: args: pid %d bufname %s", pid, bufname);
args->bufname = strdup(bufname);
DBG("beginning2 of start_consuming_buffer: args: pid %d bufname %s", args->pid, args->bufname);
- pthread_create(&thr, NULL, consumer_thread, args);
+ result = pthread_create(&thr, NULL, consumer_thread, args);
+ if(result == -1) {
+ ERR("pthread_create failed");
+ return -1;
+ }
+ result = pthread_detach(thr);
+ if(result == -1) {
+ ERR("pthread_detach failed");
+ return -1;
+ }
DBG("end of start_consuming_buffer: args: pid %d bufname %s", args->pid, args->bufname);
return 0;