#include "localerr.h"
#include "ustcomm.h"
+#define USE_CLONE
+
#define UNIX_PATH_MAX 108
#define SOCKETDIR "/tmp/socks"
char payload[94];
};
-pid_t mypid;
char mysocketfile[UNIX_PATH_MAX] = "";
//int pfd = -1;
void start_consumer(void)
{
+#ifdef USE_CLONE
int result;
result = clone(consumer, consumer_stack+sizeof(consumer_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
if(result == -1) {
perror("clone");
}
-// pthread_t thread;
-//
-// pthread_create(&thread, NULL, consumer, NULL);
+#else
+ pthread_t thread;
+
+ pthread_create(&thread, NULL, consumer, NULL);
+#endif
}
static void print_markers(void)
static int inform_consumer_daemon(void)
{
+ ustcomm_request_consumer(getpid(), "metadata");
+ ustcomm_request_consumer(getpid(), "ust");
}
int listener_main(void *p)
return;
}
}
+ else if(!strncmp(recvbuf, "get_shmid ", 10)) {
+ struct ltt_trace_struct *trace;
+ char trace_name[] = "auto";
+ int i;
+
+ DBG("get_shmid");
+
+ ltt_lock_traces();
+ trace = _ltt_trace_find(trace_name);
+ ltt_unlock_traces();
+
+ if(trace == NULL) {
+ CPRINTF("cannot find trace!");
+ return 1;
+ }
+
+ for(i=0; i<trace->nr_channels; i++) {
+ struct rchan *rchan = trace->channels[i].trans_channel_data;
+ struct rchan_buf *rbuf = rchan->buf;
+
+ DBG("the shmid is %d", rbuf->shmid);
+
+ }
+ }
free(recvbuf);
}
static char listener_stack[16384];
//char *listener_stack = malloc(16384);
+#ifdef USE_CLONE
result = clone(listener_main, listener_stack+sizeof(listener_stack)-1, CLONE_FS | CLONE_FILES | CLONE_VM | CLONE_SIGHAND | CLONE_THREAD, NULL);
if(result == -1) {
perror("clone");
}
- //pthread_t thread;
+#else
+ pthread_t thread;
- //pthread_create(&thread, NULL, listener_main, NULL);
+ pthread_create(&thread, NULL, listener_main, NULL);
+#endif
}
/* The signal handler itself. Signals must be setup so there cannot be
DBG("UST_TRACE constructor");
- mypid = getpid();
+ /* Must create socket before signal handler to prevent races.
+ */
+ result = init_socket();
+ if(result == -1) {
+ ERR("init_socket error");
+ return;
+ }
+ result = init_signal_handler();
+ if(result == -1) {
+ ERR("init_signal_handler error");
+ return;
+ }
if(getenv("UST_TRACE")) {
char trace_name[] = "auto";
ERR("ltt_trace_start failed");
return;
}
- start_consumer();
+ //start_consumer();
+ inform_consumer_daemon();
}
- /* Must create socket before signal handler to prevent races.
- */
- result = init_socket();
- if(result == -1) {
- ERR("init_socket error");
- return;
- }
- result = init_signal_handler();
- if(result == -1) {
- ERR("init_signal_handler error");
- return;
- }
return;
void *ptr;
int result;
- int shmid;
*size = PAGE_ALIGN(*size);
- result = shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
- if(shmid == -1) {
+ result = buf->shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
+ if(buf->shmid == -1) {
PERROR("shmget");
return -1;
}
- ptr = shmat(shmid, NULL, 0);
+ ptr = shmat(buf->shmid, NULL, 0);
if(ptr == (void *) -1) {
perror("shmat");
goto destroy_shmem;
/* Already mark the shared memory for destruction. This will occur only
* when all users have detached.
*/
- result = shmctl(shmid, IPC_RMID, NULL);
+ result = shmctl(buf->shmid, IPC_RMID, NULL);
if(result == -1) {
perror("shmctl");
return -1;
return 0;
destroy_shmem:
- result = shmctl(shmid, IPC_RMID, NULL);
+ result = shmctl(buf->shmid, IPC_RMID, NULL);
if(result == -1) {
perror("shmctl");
}
//ust// unsigned int page_count; /* number of current buffer pages */
unsigned int finalized; /* buffer has been finalized */
//ust// unsigned int cpu; /* this buf's cpu */
+ int shmid;
} ____cacheline_aligned;
/*
#define MSG_MAX 1000
-static void bt(void)
-{
- void *buffer[100];
- int result;
-
- result = backtrace(&buffer, 100);
- backtrace_symbols_fd(buffer, result, STDERR_FILENO);
-}
+//static void bt(void)
+//{
+// void *buffer[100];
+// int result;
+//
+// result = backtrace(&buffer, 100);
+// backtrace_symbols_fd(buffer, result, STDERR_FILENO);
+//}
static void signal_process(pid_t pid)
{
asprintf(&msg, "collect %d %s", pid, channel);
- send_message_path(path, msg, NULL, pid);
+ send_message_path(path, msg, NULL, -1);
free(msg);
return 0;
static int recv_message_fd(int fd, char **msg)
{
int result;
- struct sockaddr_un addr;
*msg = (char *) malloc(MSG_MAX+1);
result = recvfrom(fd, *msg, MSG_MAX, 0, NULL, NULL);
DBG("ustcomm_app_recv_message: result is %d, message is %s", result, (*msg));
- bt();
-
return 0;
}
int ustcomm_init_ustd(struct ustcomm_ustd *handle)
{
- handle->fd = init_named_socket("ustd", &handle->socketpath);
+ int result;
+ char *name;
+
+ result = asprintf(&name, "%s/%s", SOCK_DIR, "ustd");
+ if(result >= UNIX_PATH_MAX) {
+ ERR("string overflow allocating socket name");
+ return -1;
+ }
+
+ handle->fd = init_named_socket(name, &handle->socketpath);
if(handle->fd < 0)
return handle->fd;
+ free(name);
return 0;
}
int send_message(pid_t pid, const char *msg, char **reply);
+int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg);
+int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg);
+
int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
int ustcomm_init_ustd(struct ustcomm_ustd *handle);