Skip to content

Commit 419bf15

Browse files
committed
log: buffer on the stack (not global), lock
1 parent 9169f3b commit 419bf15

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

source/log.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "netlog.h"
77
#include "util.h"
88

9+
static Mutex g_log_mutex;
910
static uint32_t g_device_mask;
1011

1112
const char log_file_path[] = "sdmc:/vita2hos/log.txt";
@@ -26,13 +27,16 @@ void file_log(const char *str)
2627

2728
void log_init(uint32_t device_mask)
2829
{
30+
mutexInit(&g_log_mutex);
2931
g_device_mask = device_mask;
3032
}
3133

3234
void log_print(const char *str)
3335
{
3436
const size_t len = strlen(str);
3537

38+
mutexLock(&g_log_mutex);
39+
3640
if (g_device_mask & LOG_DEVICE_SVC) {
3741
svcOutputDebugString(str, len);
3842
svcOutputDebugString("\n", 1);
@@ -45,11 +49,13 @@ void log_print(const char *str)
4549

4650
if (g_device_mask & LOG_DEVICE_FILE)
4751
file_log(str);
52+
53+
mutexUnlock(&g_log_mutex);
4854
}
4955

5056
void log_printf(const char *restrict format, ...)
5157
{
52-
static char buf[2048];
58+
char buf[512];
5359
va_list argptr;
5460

5561
va_start(argptr, format);

0 commit comments

Comments
 (0)