ustcomm structures are replaced with pointers so the compiler doesn't
have to know the contents of the structures. This is done so ustcmd.h
and libustd.h can be installed on a system without needing to install
ustcomm.h.
#include <stdlib.h>
#include <fcntl.h>
#include <stdlib.h>
#include <fcntl.h>
-#include "ustcomm.h"
-#include "ustcmd.h"
-
#define USTCMD_ERR_CONN 1 /* Process connection error */
#define USTCMD_ERR_ARG 2 /* Invalid function argument */
#define USTCMD_ERR_GEN 3 /* General ustcmd error */
#define USTCMD_ERR_CONN 1 /* Process connection error */
#define USTCMD_ERR_ARG 2 /* Invalid function argument */
#define USTCMD_ERR_GEN 3 /* General ustcmd error */
int result;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
int result;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
if((result == -1 && (errno == ECONNRESET || errno == EPIPE)) || result == 0) {
DBG("app died while being traced");
retval = GET_SUBBUF_DIED;
if((result == -1 && (errno == ECONNRESET || errno == EPIPE)) || result == 0) {
DBG("app died while being traced");
retval = GET_SUBBUF_DIED;
int result;
asprintf(&send_msg, "put_subbuffer %s %ld", buf->name, buf->consumed_old);
int result;
asprintf(&send_msg, "put_subbuffer %s %ld", buf->name, buf->consumed_old);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
if(result < 0 && (errno == ECONNRESET || errno == EPIPE)) {
retval = PUT_SUBBUF_DIED;
goto end;
if(result < 0 && (errno == ECONNRESET || errno == EPIPE)) {
retval = PUT_SUBBUF_DIED;
goto end;
+ buf->conn = malloc(sizeof(struct ustcomm_connection));
+ if(buf->conn == NULL) {
+ ERR("add_buffer: insufficient memory");
+ free(buf);
+ return NULL;
+ }
+
buf->name = bufname;
buf->pid = pid;
/* connect to app */
buf->name = bufname;
buf->pid = pid;
/* connect to app */
- result = ustcomm_connect_app(buf->pid, &buf->conn);
+ result = ustcomm_connect_app(buf->pid, buf->conn);
if(result) {
WARN("unable to connect to process, it probably died before we were able to connect");
return NULL;
if(result) {
WARN("unable to connect to process, it probably died before we were able to connect");
return NULL;
/* get pidunique */
asprintf(&send_msg, "get_pidunique");
/* get pidunique */
asprintf(&send_msg, "get_pidunique");
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_pidunique)");
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_pidunique)");
/* get shmid */
asprintf(&send_msg, "get_shmid %s", buf->name);
/* get shmid */
asprintf(&send_msg, "get_shmid %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_shmid)");
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_shmid)");
/* get n_subbufs */
asprintf(&send_msg, "get_n_subbufs %s", buf->name);
/* get n_subbufs */
asprintf(&send_msg, "get_n_subbufs %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(g_n_subbufs)");
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(g_n_subbufs)");
/* get subbuf size */
asprintf(&send_msg, "get_subbuf_size %s", buf->name);
/* get subbuf size */
asprintf(&send_msg, "get_subbuf_size %s", buf->name);
- result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ result = ustcomm_send_request(buf->conn, send_msg, &received_msg);
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_subbuf_size)");
free(send_msg);
if(result == -1) {
ERR("problem in ustcomm_send_request(get_subbuf_size)");
- result = ustcomm_close_app(&buf->conn);
+ result = ustcomm_close_app(buf->conn);
if(result == -1) {
WARN("problem calling ustcomm_close_app");
}
if(result == -1) {
WARN("problem calling ustcomm_close_app");
}
if(callbacks->on_close_buffer)
callbacks->on_close_buffer(callbacks, buf);
if(callbacks->on_close_buffer)
callbacks->on_close_buffer(callbacks, buf);
char *recvbuf;
/* check for requests on our public socket */
char *recvbuf;
/* check for requests on our public socket */
- result = ustcomm_ustd_recv_message(&instance->comm, &recvbuf, NULL, timeout);
+ result = ustcomm_ustd_recv_message(instance->comm, &recvbuf, NULL, timeout);
if(result == -1 && errno == EINTR) {
/* Caught signal */
}
if(result == -1 && errno == EINTR) {
/* Caught signal */
}
void libustd_delete_instance(struct libustd_instance *instance)
{
if(instance->is_init)
void libustd_delete_instance(struct libustd_instance *instance)
{
if(instance->is_init)
- ustcomm_fini_ustd(&instance->comm);
+ ustcomm_fini_ustd(instance->comm);
pthread_mutex_destroy(&instance->mutex);
free(instance->sock_path);
pthread_mutex_destroy(&instance->mutex);
free(instance->sock_path);
if(!instance)
return NULL;
if(!instance)
return NULL;
+ instance->comm = malloc(sizeof(struct ustcomm_ustd));
+ if(!instance->comm) {
+ free(instance);
+ return NULL;
+ }
+
instance->callbacks = callbacks;
instance->quit_program = 0;
instance->is_init = 0;
instance->callbacks = callbacks;
instance->quit_program = 0;
instance->is_init = 0;
int libustd_init_instance(struct libustd_instance *instance)
{
int result;
int libustd_init_instance(struct libustd_instance *instance)
{
int result;
- result = ustcomm_init_ustd(&instance->comm, instance->sock_path);
+ result = ustcomm_init_ustd(instance->comm, instance->sock_path);
if(result == -1) {
ERR("failed to initialize socket");
return 1;
if(result == -1) {
ERR("failed to initialize socket");
return 1;
#include <pthread.h>
#include <dirent.h>
#include <pthread.h>
#include <dirent.h>
+#include <ust/kcompat/kcompat.h>
#define USTD_DEFAULT_TRACE_PATH "/tmp/usttrace"
#define USTD_DEFAULT_TRACE_PATH "/tmp/usttrace"
+struct ustcomm_connection;
+struct ustcomm_ustd;
+
struct buffer_info {
const char *name;
pid_t pid;
struct buffer_info {
const char *name;
pid_t pid;
- struct ustcomm_connection conn;
+ struct ustcomm_connection *conn;
int shmid;
int bufstruct_shmid;
int shmid;
int bufstruct_shmid;
struct libustd_callbacks *callbacks;
int quit_program;
int is_init;
struct libustd_callbacks *callbacks;
int quit_program;
int is_init;
- struct ustcomm_ustd comm;
+ struct ustcomm_ustd *comm;
char *sock_path;
pthread_mutex_t mutex;
int active_buffers;
char *sock_path;
pthread_mutex_t mutex;
int active_buffers;