Skip to content

Commit 076e22b

Browse files
Add launcher logging back
1 parent d49d828 commit 076e22b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

launcher/main.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,33 @@
33
#include <stdio.h>
44
#include <string.h>
55
#include <sys/stat.h>
6+
#include <sys/syslog.h>
67
#include <sys/wait.h>
78
#include <stdbool.h>
89
#include <stdlib.h>
910
#include <time.h>
1011
#include "utils.h"
12+
#include <syslog.h>
1113

1214
#define SERVICE_NAME "com.notmarek.shell_integration.launcher"
1315

1416
void Log(const char* format, ...)
1517
{
1618
va_list args;
1719
va_start (args, format);
18-
vprintf (format, args);
19-
printf("\n");
20+
va_list args2;
21+
va_copy (args2, args);
22+
int size = vsnprintf (NULL, 0, format, args);
23+
char* buffer = malloc((unsigned long) size);
24+
vsnprintf (buffer, (unsigned long) size, format, args2);
25+
printf("%s\n", buffer);
26+
syslog(LOG_INFO, buffer);
27+
free(buffer);
2028
va_end (args);
29+
va_end (args2);
2130
}
2231

32+
2333
pid_t app_pid = -1;
2434
bool shouldExit = false;
2535

@@ -151,6 +161,7 @@ LIPCcode go_callback(LIPC* lipc, const char* property, void* value, void* data)
151161

152162
#ifndef LAUNCHER_TESTING
153163
int main(void) {
164+
openlog(SERVICE_NAME, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_USER);
154165
LIPCcode code;
155166
LIPC* lipc = LipcOpenEx(SERVICE_NAME, &code);
156167
if (code != LIPC_OK)
@@ -180,6 +191,7 @@ int main(void) {
180191

181192
Log("Running exit routine with PID: %d", app_pid);
182193
LipcClose(lipc);
194+
closelog();
183195
return 0;
184196
}
185197
#endif

0 commit comments

Comments
 (0)