Skip to content

Commit a50c398

Browse files
committed
add logging functionality to vanilla pipe
1 parent c72f179 commit a50c398

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

pipe/linux/main.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, const char **argv)
1313
return 1;
1414
}
1515

16-
if (argc != 3) {
16+
if (argc < 3) {
1717
nlprint("vanilla-pipe - brokers a connection between Vanilla and the Wii U");
1818
nlprint("--------------------------------------------------------------------------------");
1919
nlprint("");
@@ -37,19 +37,31 @@ int main(int argc, const char **argv)
3737
nlprint("sockets by a compatible frontend. By choosing '-local' or '-udp', you can");
3838
nlprint("choose what type of socket to use to best suit the environment.");
3939
nlprint("");
40+
nlprint("External logging can be enabled with '-log <log-file>'.");
41+
nlprint("");
4042

4143
return 1;
4244
}
4345

4446
int udp_mode = 0;
4547
int local_mode = 0;
4648
const char *wireless_interface = 0;
49+
const char *log_file = 0;
4750

4851
for (int i = 1; i < argc; i++) {
4952
if (!strcmp(argv[i], "-udp")) {
5053
udp_mode = 1;
5154
} else if (!strcmp(argv[i], "-local")) {
5255
local_mode = 1;
56+
} else if (!strcmp(argv[i], "-log")) {
57+
// Increment index
58+
i++;
59+
if (i < argc) {
60+
log_file = argv[i];
61+
} else {
62+
nlprint("-log requires an argument");
63+
return 1;
64+
}
5365
} else {
5466
wireless_interface = argv[i];
5567
}
@@ -65,7 +77,7 @@ int main(int argc, const char **argv)
6577
return 1;
6678
}
6779

68-
pipe_listen(local_mode, wireless_interface);
80+
pipe_listen(local_mode, wireless_interface, log_file);
6981

7082
return 0;
7183
}

pipe/linux/wpa.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct relay_info {
7979

8080
#define THREADRESULT(x) ((void *) (uintptr_t) (x))
8181

82+
static const char *ext_logfile = 0;
8283
void nlprint(const char *fmt, ...)
8384
{
8485
va_list args;
@@ -87,6 +88,15 @@ void nlprint(const char *fmt, ...)
8788
vfprintf(stderr, fmt, args);
8889
fprintf(stderr, "\n");
8990

91+
if (ext_logfile) {
92+
FILE *f = fopen(ext_logfile, "a");
93+
if (f) {
94+
vfprintf(f, fmt, args);
95+
fprintf(f, "\n");
96+
fclose(f);
97+
}
98+
}
99+
90100
va_end(args);
91101
}
92102

@@ -944,8 +954,11 @@ void *vanilla_connect_to_console(void *data)
944954
return wpa_setup_environment(args);
945955
}
946956

947-
void pipe_listen(int local, const char *wireless_interface)
957+
void pipe_listen(int local, const char *wireless_interface, const char *log_file)
948958
{
959+
// Store reference to log file
960+
ext_logfile = log_file;
961+
949962
// Ensure local domain sockets can be written to by everyone
950963
umask(0000);
951964

pipe/linux/wpa.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ int enable_networkmanager_on_device(const char *wireless_interface);
1717

1818
void nlprint(const char *fmt, ...);
1919

20-
void pipe_listen(int local, const char *wireless_interface);
20+
void pipe_listen(int local, const char *wireless_interface, const char *log_file);
2121

2222
#endif // VANILLA_WPA_H

0 commit comments

Comments
 (0)