Generalize some ustcomm functionality
[ust.git] / ustd / ustd.c
index cca9520589015f255992f8fcb7da1e2b68ed605a..e75fd9d75501a6d4d914dd19889eb8cb041e502a 100644 (file)
@@ -32,7 +32,7 @@
 #include <assert.h>
 #include <getopt.h>
 
-#include "libustd.h"
+#include "ust/ustd.h"
 #include "usterr.h"
 
 char *sock_path=NULL;
@@ -150,8 +150,7 @@ int on_read_partial_subbuffer(struct libustd_callbacks *data, struct buffer_info
        /* pad with empty bytes */
        pad_size = PAGE_ALIGN(valid_length)-valid_length;
        if(pad_size) {
-               tmp = malloc(pad_size);
-               memset(tmp, 0, pad_size);
+               tmp = zmalloc(pad_size);
                result = patient_write(buf_local->file_fd, tmp, pad_size);
                if(result == -1) {
                        ERR("Error writing to buffer file");
@@ -168,7 +167,7 @@ int on_open_buffer(struct libustd_callbacks *data, struct buffer_info *buf)
        int result;
        int fd;
        struct buffer_info_local *buf_local =
-               malloc(sizeof(struct buffer_info_local));
+               zmalloc(sizeof(struct buffer_info_local));
 
        if(!buf_local) {
                ERR("could not allocate buffer_info_local struct");
@@ -192,7 +191,11 @@ int on_open_buffer(struct libustd_callbacks *data, struct buffer_info *buf)
                trace_path = USTD_DEFAULT_TRACE_PATH;
        }
 
-       asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique);
+       if (asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique) < 0) {
+               ERR("on_open_buffer : asprintf failed (%s/%u_%lld)",
+                   trace_path, buf->pid, buf->pidunique);
+               return 1;
+       }
        result = create_dir_if_needed(tmp);
        if(result == -1) {
                ERR("could not create directory %s", tmp);
@@ -201,7 +204,11 @@ int on_open_buffer(struct libustd_callbacks *data, struct buffer_info *buf)
        }
        free(tmp);
 
-       asprintf(&tmp, "%s/%u_%lld/%s", trace_path, buf->pid, buf->pidunique, buf->name);
+       if (asprintf(&tmp, "%s/%u_%lld/%s", trace_path, buf->pid, buf->pidunique, buf->name) < 0) {
+               ERR("on_open_buffer : asprintf failed (%s/%u_%lld/%s)",
+                   trace_path, buf->pid, buf->pidunique, buf->name);
+               return 1;
+       }
        result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 00600);
        if(result == -1) {
                PERROR("open");
@@ -233,7 +240,7 @@ int on_put_error(struct libustd_callbacks *data, struct buffer_info *buf)
 struct libustd_callbacks *new_callbacks()
 {
        struct libustd_callbacks *callbacks =
-               malloc(sizeof(struct libustd_callbacks));
+               zmalloc(sizeof(struct libustd_callbacks));
 
        if(!callbacks)
                return NULL;
@@ -343,11 +350,9 @@ void sigterm_handler(int sig)
 
 int start_ustd(int fd)
 {
-       struct ustcomm_ustd ustd;
        int result;
        sigset_t sigset;
        struct sigaction sa;
-       int timeout = -1;
 
        struct libustd_callbacks *callbacks = new_callbacks();
        if(!callbacks) {
This page took 0.025142 seconds and 4 git commands to generate.