Use new logging system

pull/65/head
Andri Yngvason 2022-06-25 15:38:38 +00:00
parent 45da0fc157
commit ad4a834cfc
5 changed files with 37 additions and 66 deletions

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2019 - 2020 Andri Yngvason
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <stdio.h>
#ifdef NDEBUG
#define log_debug(...)
#else
#define log_debug(fmt, ...) \
fprintf(stderr, "%s:%d: " fmt, __FILE__, __LINE__, ## __VA_ARGS__)
#endif
#define log_error(...) \
fprintf(stderr, "ERROR: " __VA_ARGS__)

View File

@ -17,7 +17,6 @@
#include "fb.h" #include "fb.h"
#include "pixels.h" #include "pixels.h"
#include "neatvnc.h" #include "neatvnc.h"
#include "logging.h"
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -103,7 +102,7 @@ struct nvnc_fb* nvnc_fb_from_gbm_bo(struct gbm_bo* bo)
return fb; return fb;
#else #else
log_error("nvnc_fb_from_gbm_bo was not enabled during build time\n"); nvnc_log(NVNC_LOG_ERROR, "nvnc_fb_from_gbm_bo was not enabled during build time");
return NULL; return NULL;
#endif #endif
} }

View File

@ -21,7 +21,6 @@
#include "fb.h" #include "fb.h"
#include "rcbuf.h" #include "rcbuf.h"
#include "encoder.h" #include "encoder.h"
#include "logging.h"
#include <stdlib.h> #include <stdlib.h>
@ -69,7 +68,7 @@ static void open_h264_handle_packet(const void* data, size_t size, uint64_t pts,
// Let's not deplete the RAM if the client isn't pulling // Let's not deplete the RAM if the client isn't pulling
if (self->pending.len > 100000000) { if (self->pending.len > 100000000) {
// TODO: Drop buffer and request a keyframe? // TODO: Drop buffer and request a keyframe?
log_debug("Pending buffer grew too large. Dropping packet...\n"); nvnc_log(NVNC_LOG_DEBUG, "Pending buffer grew too large. Dropping packet...");
return; return;
} }

View File

@ -24,13 +24,13 @@
#include "pixels.h" #include "pixels.h"
#include "stream.h" #include "stream.h"
#include "config.h" #include "config.h"
#include "logging.h"
#include "usdt.h" #include "usdt.h"
#include "encoder.h" #include "encoder.h"
#include "tight.h" #include "tight.h"
#include "enc-util.h" #include "enc-util.h"
#include "cursor.h" #include "cursor.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <sys/queue.h> #include <sys/queue.h>
@ -98,7 +98,7 @@ static uint64_t nvnc__htonll(uint64_t x)
static void client_close(struct nvnc_client* client) static void client_close(struct nvnc_client* client)
{ {
log_debug("client_close(%p): ref %d\n", client, client->ref); nvnc_log(NVNC_LOG_DEBUG, "client_close(%p): ref %d", client, client->ref);
nvnc_cleanup_fn cleanup = client->common.cleanup_fn; nvnc_cleanup_fn cleanup = client->common.cleanup_fn;
if (cleanup) if (cleanup)
@ -142,7 +142,8 @@ static inline void client_ref(struct nvnc_client* client)
static void close_after_write(void* userdata, enum stream_req_status status) static void close_after_write(void* userdata, enum stream_req_status status)
{ {
struct nvnc_client* client = userdata; struct nvnc_client* client = userdata;
log_debug("close_after_write(%p): ref %d\n", client, client->ref); nvnc_log(NVNC_LOG_DEBUG, "close_after_write(%p): ref %d", client,
client->ref);
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
} }
@ -328,11 +329,11 @@ static int on_vencrypt_plain_auth_message(struct nvnc_client* client)
password[MIN(plen, sizeof(password) - 1)] = '\0'; password[MIN(plen, sizeof(password) - 1)] = '\0';
if (server->auth_fn(username, password, server->auth_ud)) { if (server->auth_fn(username, password, server->auth_ud)) {
log_debug("User \"%s\" authenticated\n", username); nvnc_log(NVNC_LOG_DEBUG, "User \"%s\" authenticated", username);
security_handshake_ok(client); security_handshake_ok(client);
client->state = VNC_CLIENT_STATE_WAITING_FOR_INIT; client->state = VNC_CLIENT_STATE_WAITING_FOR_INIT;
} else { } else {
log_debug("User \"%s\" rejected\n", username); nvnc_log(NVNC_LOG_DEBUG, "User \"%s\" rejected", username);
security_handshake_failed(client, "Invalid username or password"); security_handshake_failed(client, "Invalid username or password");
} }
@ -373,7 +374,8 @@ static void disconnect_all_other_clients(struct nvnc_client* client)
LIST_FOREACH_SAFE (node, &client->server->clients, link, tmp) LIST_FOREACH_SAFE (node, &client->server->clients, link, tmp)
if (node != client) { if (node != client) {
log_debug("disconnect other client %p (ref %d)\n", nvnc_log(NVNC_LOG_DEBUG,
"disconnect other client %p (ref %d)",
node, node->ref); node, node->ref);
stream_close(node->net_stream); stream_close(node->net_stream);
client_unref(node); client_unref(node);
@ -390,12 +392,12 @@ static void send_server_init_message(struct nvnc_client* client)
size_t size = sizeof(struct rfb_server_init_msg) + name_len; size_t size = sizeof(struct rfb_server_init_msg) + name_len;
if (!display) { if (!display) {
log_debug("Tried to send init message, but no display has been added\n"); nvnc_log(NVNC_LOG_DEBUG, "Tried to send init message, but no display has been added");
goto close; goto close;
} }
if (!display->buffer) { if (!display->buffer) {
log_debug("Tried to send init message, but no framebuffers have been set\n"); nvnc_log(NVNC_LOG_DEBUG, "Tried to send init message, but no framebuffers have been set");
goto close; goto close;
} }
@ -549,7 +551,7 @@ static void send_cursor_update(struct nvnc_client* client)
server->cursor.width, server->cursor.height, server->cursor.width, server->cursor.height,
server->cursor.hotspot_x, server->cursor.hotspot_y); server->cursor.hotspot_x, server->cursor.hotspot_y);
if (rc < 0) { if (rc < 0) {
log_error("Failed to send cursor to client\n"); nvnc_log(NVNC_LOG_ERROR, "Failed to send cursor to client");
vec_destroy(&payload); vec_destroy(&payload);
return; return;
} }
@ -642,7 +644,7 @@ static void process_fb_update_requests(struct nvnc_client* client)
encoder_destroy(client->encoder); encoder_destroy(client->encoder);
client->encoder = encoder_new(encoding, width, height); client->encoder = encoder_new(encoding, width, height);
if (!client->encoder) { if (!client->encoder) {
log_error("Failed to allocate new encoder"); nvnc_log(NVNC_LOG_ERROR, "Failed to allocate new encoder");
return; return;
} }
@ -701,7 +703,7 @@ static void process_fb_update_requests(struct nvnc_client* client)
if (encoder_encode(client->encoder, fb, &damage) >= 0) { if (encoder_encode(client->encoder, fb, &damage) >= 0) {
--client->n_pending_requests; --client->n_pending_requests;
} else { } else {
log_error("Failed to encode current frame"); nvnc_log(NVNC_LOG_ERROR, "Failed to encode current frame");
client_unref(client); client_unref(client);
client->is_updating = false; client->is_updating = false;
assert(client->current_fb); assert(client->current_fb);
@ -816,7 +818,7 @@ static int on_client_qemu_event(struct nvnc_client* client)
return on_client_qemu_key_event(client); return on_client_qemu_key_event(client);
} }
log_debug("Got uninterpretable qemu message from client: %p (ref %d)\n", nvnc_log(NVNC_LOG_DEBUG, "Got uninterpretable qemu message from client: %p (ref %d)",
client, client->ref); client, client->ref);
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
@ -878,7 +880,7 @@ static int on_client_cut_text(struct nvnc_client* client)
/* Messages greater than this size are unsupported */ /* Messages greater than this size are unsupported */
if (length > max_length) { if (length > max_length) {
log_error("Copied text length (%d) is greater than max supported length (%d)\n", nvnc_log(NVNC_LOG_ERROR, "Copied text length (%d) is greater than max supported length (%d)",
length, max_length); length, max_length);
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
@ -898,7 +900,7 @@ static int on_client_cut_text(struct nvnc_client* client)
client->cut_text.buffer = malloc(length); client->cut_text.buffer = malloc(length);
if (!client->cut_text.buffer) { if (!client->cut_text.buffer) {
log_error("OOM: %m\n"); nvnc_log(NVNC_LOG_ERROR, "OOM: %m");
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
return 0; return 0;
@ -933,7 +935,7 @@ static void process_big_cut_text(struct nvnc_client* client)
if (n_read < 0) { if (n_read < 0) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
log_debug("Client connection error: %p (ref %d)\n", nvnc_log(NVNC_LOG_DEBUG, "Client connection error: %p (ref %d)",
client, client->ref); client, client->ref);
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
@ -979,7 +981,7 @@ static int on_client_message(struct nvnc_client* client)
return on_client_qemu_event(client); return on_client_qemu_event(client);
} }
log_debug("Got uninterpretable message from client: %p (ref %d)\n", nvnc_log(NVNC_LOG_DEBUG, "Got uninterpretable message from client: %p (ref %d)",
client, client->ref); client, client->ref);
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
@ -1020,7 +1022,7 @@ static void on_client_event(struct stream* stream, enum stream_event event)
assert(client->net_stream && client->net_stream == stream); assert(client->net_stream && client->net_stream == stream);
if (event == STREAM_EVENT_REMOTE_CLOSED) { if (event == STREAM_EVENT_REMOTE_CLOSED) {
log_debug("Client %p (%d) hung up\n", client, client->ref); nvnc_log(NVNC_LOG_DEBUG, "Client %p (%d) hung up", client, client->ref);
stream_close(stream); stream_close(stream);
client_unref(client); client_unref(client);
return; return;
@ -1042,7 +1044,7 @@ static void on_client_event(struct stream* stream, enum stream_event event)
if (n_read < 0) { if (n_read < 0) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
log_debug("Client connection error: %p (ref %d)\n", nvnc_log(NVNC_LOG_DEBUG, "Client connection error: %p (ref %d)",
client, client->ref); client, client->ref);
stream_close(stream); stream_close(stream);
client_unref(client); client_unref(client);
@ -1083,18 +1085,18 @@ static void on_connection(void* obj)
int fd = accept(server->fd, NULL, 0); int fd = accept(server->fd, NULL, 0);
if (fd < 0) { if (fd < 0) {
log_debug("Failed to accept a connection\n"); nvnc_log(NVNC_LOG_DEBUG, "Failed to accept a connection");
goto accept_failure; goto accept_failure;
} }
client->net_stream = stream_new(fd, on_client_event, client); client->net_stream = stream_new(fd, on_client_event, client);
if (!client->net_stream) { if (!client->net_stream) {
log_debug("OOM\n"); nvnc_log(NVNC_LOG_DEBUG, "OOM");
goto stream_failure; goto stream_failure;
} }
if (!server->display->buffer) { if (!server->display->buffer) {
log_debug("No display buffer has been set\n"); nvnc_log(NVNC_LOG_DEBUG, "No display buffer has been set");
goto buffer_failure; goto buffer_failure;
} }
@ -1102,7 +1104,7 @@ static void on_connection(void* obj)
struct rcbuf* payload = rcbuf_from_string(RFB_VERSION_MESSAGE); struct rcbuf* payload = rcbuf_from_string(RFB_VERSION_MESSAGE);
if (!payload) { if (!payload) {
log_debug("OOM\n"); nvnc_log(NVNC_LOG_DEBUG, "OOM");
goto payload_failure; goto payload_failure;
} }
@ -1112,7 +1114,7 @@ static void on_connection(void* obj)
client->state = VNC_CLIENT_STATE_WAITING_FOR_VERSION; client->state = VNC_CLIENT_STATE_WAITING_FOR_VERSION;
log_debug("New client connection: %p (ref %d)\n", client, client->ref); nvnc_log(NVNC_LOG_DEBUG, "New client connection: %p (ref %d)", client, client->ref);
return; return;
@ -1198,7 +1200,7 @@ static int bind_address(const char* name, uint16_t port, enum addrtype type)
return bind_address_unix(name); return bind_address_unix(name);
} }
log_error("unknown socket address type"); nvnc_log(NVNC_LOG_ERROR, "unknown socket address type");
abort(); abort();
} }
@ -1402,7 +1404,7 @@ static void on_encode_frame_done(struct encoder* encoder, struct rcbuf* result,
static int send_desktop_resize(struct nvnc_client* client, struct nvnc_fb* fb) static int send_desktop_resize(struct nvnc_client* client, struct nvnc_fb* fb)
{ {
if (!client_has_encoding(client, RFB_ENCODING_DESKTOPSIZE)) { if (!client_has_encoding(client, RFB_ENCODING_DESKTOPSIZE)) {
log_error("Client does not support desktop resizing. Closing connection...\n"); nvnc_log(NVNC_LOG_ERROR, "Client does not support desktop resizing. Closing connection...");
stream_close(client->net_stream); stream_close(client->net_stream);
client_unref(client); client_unref(client);
return -1; return -1;
@ -1522,7 +1524,7 @@ EXPORT
void nvnc_add_display(struct nvnc* self, struct nvnc_display* display) void nvnc_add_display(struct nvnc* self, struct nvnc_display* display)
{ {
if (self->display) { if (self->display) {
log_error("Multiple displays are not implemented. Aborting!\n"); nvnc_log(NVNC_LOG_ERROR, "Multiple displays are not implemented. Aborting!");
abort(); abort();
} }
@ -1578,14 +1580,14 @@ int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
*/ */
int rc = gnutls_global_init(); int rc = gnutls_global_init();
if (rc != GNUTLS_E_SUCCESS) { if (rc != GNUTLS_E_SUCCESS) {
log_error("GnuTLS: Failed to initialise: %s\n", nvnc_log(NVNC_LOG_ERROR, "GnuTLS: Failed to initialise: %s",
gnutls_strerror(rc)); gnutls_strerror(rc));
return -1; return -1;
} }
rc = gnutls_certificate_allocate_credentials(&self->tls_creds); rc = gnutls_certificate_allocate_credentials(&self->tls_creds);
if (rc != GNUTLS_E_SUCCESS) { if (rc != GNUTLS_E_SUCCESS) {
log_error("GnuTLS: Failed to allocate credentials: %s\n", nvnc_log(NVNC_LOG_ERROR, "GnuTLS: Failed to allocate credentials: %s",
gnutls_strerror(rc)); gnutls_strerror(rc));
goto cert_alloc_failure; goto cert_alloc_failure;
} }
@ -1593,7 +1595,7 @@ int nvnc_enable_auth(struct nvnc* self, const char* privkey_path,
rc = gnutls_certificate_set_x509_key_file( rc = gnutls_certificate_set_x509_key_file(
self->tls_creds, cert_path, privkey_path, GNUTLS_X509_FMT_PEM); self->tls_creds, cert_path, privkey_path, GNUTLS_X509_FMT_PEM);
if (rc != GNUTLS_E_SUCCESS) { if (rc != GNUTLS_E_SUCCESS) {
log_error("GnuTLS: Failed to load credentials: %s\n", nvnc_log(NVNC_LOG_ERROR, "GnuTLS: Failed to load credentials: %s",
gnutls_strerror(rc)); gnutls_strerror(rc));
goto cert_set_failure; goto cert_set_failure;
} }

View File

@ -19,7 +19,6 @@
#include "common.h" #include "common.h"
#include "pixels.h" #include "pixels.h"
#include "vec.h" #include "vec.h"
#include "logging.h"
#include "tight.h" #include "tight.h"
#include "config.h" #include "config.h"
#include "enc-util.h" #include "enc-util.h"
@ -376,12 +375,13 @@ static int tight_encode_tile_jpeg(struct tight_encoder* self,
rc = tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer, rc = tjCompress2(handle, img, width, stride * 4, height, tjfmt, &buffer,
&size, TJSAMP_422, quality, TJFLAG_FASTDCT); &size, TJSAMP_422, quality, TJFLAG_FASTDCT);
if (rc < 0) { if (rc < 0) {
log_error("Failed to encode tight JPEG box: %s\n", tjGetErrorStr()); nvnc_log(NVNC_LOG_ERROR, "Failed to encode tight JPEG box: %s",
tjGetErrorStr());
goto failure; goto failure;
} }
if (size > MAX_TILE_SIZE) { if (size > MAX_TILE_SIZE) {
log_error("Whoops, encoded JPEG was too big for the buffer\n"); nvnc_log(NVNC_LOG_ERROR, "Whoops, encoded JPEG was too big for the buffer");
goto failure; goto failure;
} }