Commit 05314dd2 authored by Christian Hergert's avatar Christian Hergert

capture: add sp_capture_writer_new_from_env()

This will return NULL if there is not sufficient data from the
environment to setup tracing.
parent 209b342e
......@@ -23,6 +23,7 @@
#include <errno.h>
#include <fcntl.h>
#include <glib/gstdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
......@@ -415,6 +416,9 @@ sp_capture_writer_new_from_fd (int fd,
GTimeVal tv;
gsize header_len = sizeof(*header);
if (fd < 0)
return NULL;
if (buffer_size == 0)
buffer_size = DEFAULT_BUFFER_SIZE;
......@@ -1221,3 +1225,22 @@ do_end:
return TRUE;
}
SpCaptureWriter *
sp_capture_writer_new_from_env (gsize buffer_size)
{
const gchar *fdstr;
int fd;
if (!(fdstr = g_getenv ("SYSPROF_TRACE_FD")))
return NULL;
if (!(fd = atoi (fdstr)))
return NULL;
/* ignore stdin/stdout/stderr */
if (fd < 2)
return NULL;
return sp_capture_writer_new_from_fd (dup (fd), buffer_size);
}
......@@ -38,6 +38,7 @@ typedef struct
gsize padding[48];
} SpCaptureStat;
SpCaptureWriter *sp_capture_writer_new_from_env (gsize buffer_size);
SpCaptureWriter *sp_capture_writer_new (const gchar *filename,
gsize buffer_size);
SpCaptureWriter *sp_capture_writer_new_from_fd (int fd,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment