Skip to content

Commit

Permalink
Forward error and log messages to obs
Browse files Browse the repository at this point in the history
  • Loading branch information
norihiro committed Jul 23, 2024
1 parent 200ac94 commit 40319d0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/obs-vnc-source-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <obs-module.h>
#include <util/platform.h>
#include <util/threading.h>
#include <util/dstr.h>
#ifndef _WIN32
#include <sys/time.h>
#include <sys/resource.h>
Expand All @@ -38,6 +39,40 @@
#define debug(fmt, ...) (void)0
// #define debug(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)

static char *blog_format(const char *format)
{
struct dstr msg = {0};
dstr_init_copy(&msg, "[" PLUGIN_NAME "/libvncclient] ");

size_t len = strlen(format);
if (len > 0 && format[len - 1] == '\n')
len--;

dstr_ncat(&msg, format, len);

return msg.array;
}

static void rfb_log_info(const char *format, ...)
{
char *fmt = blog_format(format);
va_list args;
va_start(args, format);
blogva(LOG_INFO, fmt, args);
va_end(args);
bfree(fmt);
}

static void rfb_log_error(const char *format, ...)
{
char *fmt = blog_format(format);
va_list args;
va_start(args, format);
blogva(LOG_ERROR, fmt, args);
va_end(args);
bfree(fmt);
}

static inline int max_int(int a, int b)
{
return (a < b) ? b : a;
Expand Down Expand Up @@ -842,6 +877,9 @@ static void interrupt_thread(struct vnc_source *src)

void vncsrc_thread_start(struct vnc_source *src)
{
rfbClientLog = rfb_log_info;
rfbClientErr = rfb_log_error;

#ifndef _WIN32
if (!sig_hander_set) {
struct sigaction sig_handler, prev;
Expand Down

0 comments on commit 40319d0

Please sign in to comment.