projects
/
lttng-ust.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
kernelcompat: remove local ops as they are now in libkcompat
[lttng-ust.git]
/
ustd
/
ustd.c
diff --git
a/ustd/ustd.c
b/ustd/ustd.c
index b66f1ced7e9e83788ee88ce00a72012464f83388..c5a3d8bed26b10bbfdcbd885efb189209d67b332 100644
(file)
--- a/
ustd/ustd.c
+++ b/
ustd/ustd.c
@@
-27,35
+27,21
@@
#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
+#include "ustd.h"
#include "localerr.h"
#include "ustcomm.h"
struct list_head buffers = LIST_HEAD_INIT(buffers);
#include "localerr.h"
#include "ustcomm.h"
struct list_head buffers = LIST_HEAD_INIT(buffers);
-struct buffer_info {
- char *name;
- pid_t pid;
- struct ustcomm_connection conn;
-
- int shmid;
- void *mem;
- int memlen;
-
- int n_subbufs;
- int subbuf_size;
-
- int file_fd; /* output file */
-
- struct list_head list;
-
- long consumed_old;
-};
-
/* return value: 0 = subbuffer is finished, it won't produce data anymore
* 1 = got subbuffer successfully
* <0 = error
*/
/* return value: 0 = subbuffer is finished, it won't produce data anymore
* 1 = got subbuffer successfully
* <0 = error
*/
+#define GET_SUBBUF_OK 1
+#define GET_SUBBUF_DONE 0
+#define GET_SUBBUF_DIED 2
+
int get_subbuffer(struct buffer_info *buf)
{
char *send_msg;
int get_subbuffer(struct buffer_info *buf)
{
char *send_msg;
@@
-65,12
+51,16
@@
int get_subbuffer(struct buffer_info *buf)
int result;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
int result;
asprintf(&send_msg, "get_subbuffer %s", buf->name);
- result = send_message(buf->pid, send_msg, &received_msg);
+ result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+ free(send_msg);
if(result < 0) {
if(result < 0) {
- ERR("get_subbuffer:
send_message
failed");
+ ERR("get_subbuffer:
ustcomm_send_request
failed");
return -1;
}
return -1;
}
- free(send_msg);
+ else if(result == 0) {
+ DBG("app died while being traced");
+ return GET_SUBBUF_DIED;
+ }
result = sscanf(received_msg, "%as %ld", &rep_code, &buf->consumed_old);
if(result != 2 && result != 1) {
result = sscanf(received_msg, "%as %ld", &rep_code, &buf->consumed_old);
if(result != 2 && result != 1) {
@@
-82,10
+72,10
@@
int get_subbuffer(struct buffer_info *buf)
if(!strcmp(rep_code, "OK")) {
DBG("got subbuffer %s", buf->name);
if(!strcmp(rep_code, "OK")) {
DBG("got subbuffer %s", buf->name);
- retval =
1
;
+ retval =
GET_SUBBUF_OK
;
}
else if(nth_token_is(received_msg, "END", 0) == 1) {
}
else if(nth_token_is(received_msg, "END", 0) == 1) {
- return
0
;
+ return
GET_SUBBUF_DONE
;
}
else {
DBG("error getting subbuffer %s", buf->name);
}
else {
DBG("error getting subbuffer %s", buf->name);
@@
-107,7
+97,7
@@
int put_subbuffer(struct buffer_info *buf)
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 =
send_message(buf->pid
, send_msg, &received_msg);
+ result =
ustcomm_send_request(&buf->conn
, send_msg, &received_msg);
if(result < 0) {
ERR("put_subbuffer: send_message failed");
return -1;
if(result < 0) {
ERR("put_subbuffer: send_message failed");
return -1;
@@
-160,15
+150,20
@@
void *consumer_thread(void *arg)
int result;
for(;;) {
int result;
for(;;) {
+ /* get the subbuffer */
result = get_subbuffer(buf);
if(result == -1) {
ERR("error getting subbuffer");
continue;
}
result = get_subbuffer(buf);
if(result == -1) {
ERR("error getting subbuffer");
continue;
}
-
if(result == 0
) {
+
else if(result == GET_SUBBUF_DONE
) {
/* this is done */
break;
}
/* this is done */
break;
}
+ else if(result == GET_SUBBUF_DIED) {
+ finish_consuming_dead_subbuffer(buf);
+ break;
+ }
/* write data to file */
result = patient_write(buf->file_fd, buf->mem + (buf->consumed_old & (buf->n_subbufs * buf->subbuf_size-1)), buf->subbuf_size);
/* write data to file */
result = patient_write(buf->file_fd, buf->mem + (buf->consumed_old & (buf->n_subbufs * buf->subbuf_size-1)), buf->subbuf_size);
@@
-177,6
+172,7
@@
void *consumer_thread(void *arg)
/* FIXME: maybe drop this trace */
}
/* FIXME: maybe drop this trace */
}
+ /* put the subbuffer */
result = put_subbuffer(buf);
if(result == -1) {
ERR("error putting subbuffer");
result = put_subbuffer(buf);
if(result == -1) {
ERR("error putting subbuffer");
@@
-186,6
+182,8
@@
void *consumer_thread(void *arg)
DBG("thread for buffer %s is stopping", buf->name);
DBG("thread for buffer %s is stopping", buf->name);
+ /* FIXME: destroy, unalloc... */
+
return NULL;
}
return NULL;
}
@@
-221,13
+219,13
@@
int add_buffer(pid_t pid, char *bufname)
free(send_msg);
DBG("got buffer name %s", buf->name);
free(send_msg);
DBG("got buffer name %s", buf->name);
- result = sscanf(received_msg, "%d
", &buf->
shmid);
- if(result !=
1
) {
+ result = sscanf(received_msg, "%d
%d", &buf->shmid, &buf->bufstruct_
shmid);
+ if(result !=
2
) {
ERR("unable to parse response to get_shmid");
return -1;
}
free(received_msg);
ERR("unable to parse response to get_shmid");
return -1;
}
free(received_msg);
- DBG("got shmid
%d", buf->
shmid);
+ DBG("got shmid
s %d %d", buf->shmid, buf->bufstruct_
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);
@@
-261,13
+259,21
@@
int add_buffer(pid_t pid, char *bufname)
perror("shmat");
return -1;
}
perror("shmat");
return -1;
}
- DBG("successfully attached memory");
+ DBG("successfully attached buffer memory");
+
+ buf->bufstruct_mem = shmat(buf->bufstruct_shmid, NULL, 0);
+ if(buf->bufstruct_mem == (void *) 0) {
+ perror("shmat");
+ return -1;
+ }
+ DBG("successfully attached buffer bufstruct memory");
/* open file for output */
asprintf(&tmp, "/tmp/trace/%s_0", buf->name);
result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600);
if(result == -1) {
PERROR("open");
/* open file for output */
asprintf(&tmp, "/tmp/trace/%s_0", buf->name);
result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600);
if(result == -1) {
PERROR("open");
+ ERR("failed opening trace file %s", tmp);
return -1;
}
buf->file_fd = fd;
return -1;
}
buf->file_fd = fd;
This page took
0.026495 seconds
and
4
git commands to generate.