mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
capture: add sp_capture_writer_new_from_env()
This will return NULL if there is not sufficient data from the environment to setup tracing.
This commit is contained in:
@ -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,
|
||||
|
||||
Reference in New Issue
Block a user