#include "localerr.h"
#include "ustcomm.h"
-#define USE_CLONE
+//#define USE_CLONE
#define UNIX_PATH_MAX 108
char trace_type[] = "ustrelay";
char *recvbuf;
int len;
+ struct ustcomm_source src;
- result = ustcomm_app_recv_message(&ustcomm_app, &recvbuf);
+ result = ustcomm_app_recv_message(&ustcomm_app, &recvbuf, &src);
DBG("HERE");
if(result) {
WARN("error in ustcomm_app_recv_message");
return;
}
}
- else if(!strncmp(recvbuf, "get_shmid ", 10)) {
+ else if(nth_token_is(recvbuf, "get_shmid", 0) == 1) {
struct ltt_trace_struct *trace;
char trace_name[] = "auto";
int i;
}
}
+ else if(nth_token_is(recvbuf, "load_probe_lib", 0) == 1) {
+ char *libfile;
+
+ libfile = nth_token(recvbuf, 1);
+
+ DBG("load_probe_lib loading %s", libfile);
+ }
free(recvbuf);
}
return 0;
}
-static int recv_message_fd(int fd, char **msg)
+static int recv_message_fd(int fd, char **msg, struct ustcomm_source *src)
{
int result;
+ size_t initial_addrlen,addrlen;
*msg = (char *) malloc(MSG_MAX+1);
- result = recvfrom(fd, *msg, MSG_MAX, 0, NULL, NULL);
+
+ if(src) {
+ initial_addrlen = addrlen = sizeof(src->addr);
+
+ result = recvfrom(fd, *msg, MSG_MAX, 0, &src->addr, &addrlen);
+ if(initial_addrlen != addrlen) {
+ ERR("recvfrom: unexpected address length");
+ return -1;
+ }
+ }
+ else {
+ result = recvfrom(fd, *msg, MSG_MAX, 0, NULL, NULL);
+ }
+
if(result == -1) {
PERROR("recvfrom");
return -1;
return 0;
}
-int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg)
+int ustcomm_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src)
{
- return recv_message_fd(ustd->fd, msg);
+ return recv_message_fd(ustd->fd, msg, src);
}
-int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg)
+int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src)
{
- return recv_message_fd(app->fd, msg);
+ return recv_message_fd(app->fd, msg, src);
}
static int init_named_socket(char *name, char **path_out)
return 0;
}
+
+char *find_tok(const char *str)
+{
+ while(*str == ' ') {
+ str++;
+
+ if(*str == 0)
+ return NULL;
+ }
+
+ return str;
+}
+
+static char *find_sep(char *str)
+{
+ while(*str != ' ') {
+ str++;
+
+ if(*str == 0)
+ break;
+ }
+
+ return str;
+}
+
+int nth_token_is(char *str, char *token, int tok_no)
+{
+ int i;
+ char *start;
+ char *end;
+
+ for(i=0; i<=tok_no; i++) {
+ str = find_tok(str);
+ if(str == NULL)
+ return -1;
+
+ start = str;
+
+ str = find_sep(str);
+ if(str == NULL)
+ return -1;
+
+ end = str;
+ }
+
+ if(end-start != strlen(token))
+ return 0;
+
+ if(strncmp(start, token, end-start))
+ return 0;
+
+ return 1;
+}
+
+char *nth_token(char *str, int tok_no)
+{
+ static char *retval = NULL;
+ int i;
+ char *start;
+ char *end;
+
+ for(i=0; i<=tok_no; i++) {
+ str = find_tok(str);
+ if(str == NULL)
+ return NULL;
+
+ start = str;
+
+ str = find_sep(str);
+ if(str == NULL)
+ return NULL;
+
+ end = str;
+ }
+
+ if(retval) {
+ free(retval);
+ retval = NULL;
+ }
+
+ retval = strndupa(start, end-start);
+
+ return retval;
+}
+
#define USTCOMM_H
#include <sys/types.h>
+#include <sys/un.h>
struct ustcomm_app {
/* the "server" socket for serving the external requests */
char *socketpath;
};
+struct ustcomm_source {
+ struct sockaddr_un addr;
+};
+
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_ustd_recv_message(struct ustcomm_ustd *ustd, char **msg, struct ustcomm_source *src);
+int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src);
int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
int ustcomm_init_ustd(struct ustcomm_ustd *handle);
+int nth_token_is(char *str, char *token, int tok_no);
+
+char *nth_token(char *str, int tok_no);
+
#endif /* USTCOMM_H */