Skip to content

Commit 92d828b

Browse files
marc-hblgirdwood
authored andcommitted
sof-logger: make inotify optional
Restores ability to compile on Windows with MSYS. Fixes commit dcf0577 ("logger: allow starting before the driver is loaded") Signed-off-by: Marc Herbert <marc.herbert@intel.com>
1 parent 277985e commit 92d828b

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

tools/logger/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22

3+
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks
4+
INCLUDE (CheckIncludeFiles)
5+
CHECK_INCLUDE_FILES(sys/inotify.h HAS_INOTIFY)
6+
7+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
8+
${CMAKE_CURRENT_BINARY_DIR}/config.h)
9+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
10+
311
add_executable(sof-logger
412
logger.c
513
convert.c

tools/logger/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#cmakedefine01 HAS_INOTIFY

tools/logger/logger.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Author: Bartosz Kokoszko <bartoszx.kokoszko@linux.intel.com>
66
// Artur Kloniecki <arturx.kloniecki@linux.intel.com>
77

8+
#include <assert.h>
89
#include <stdlib.h>
910
#include <unistd.h>
1011
#include <stdint.h>
@@ -15,11 +16,17 @@
1516
#include <fcntl.h>
1617
#include <stdbool.h>
1718
#include <termios.h>
19+
20+
#include <sys/types.h>
21+
#include <dirent.h>
22+
23+
#include "config.h"
24+
25+
#if HAS_INOTIFY
1826
#include <poll.h>
1927
#include <sys/inotify.h>
20-
#include <sys/types.h>
2128
#include <sys/stat.h>
22-
#include <dirent.h>
29+
#endif
2330

2431
#include "convert.h"
2532
#include "misc.h"
@@ -176,6 +183,12 @@ static int append_filter_config(struct convert_config *config, const char *input
176183
return 0;
177184
}
178185

186+
#if !HAS_INOTIFY
187+
static void *wait_open(const char *watched_dir, const char *expected_file)
188+
{
189+
assert(HAS_INOTIFY); /* Should never be called */
190+
}
191+
#else
179192
/*
180193
* This 5 minutes timeout is for "backward compatible safety" in case
181194
* any user/script of an earlier, pre-inotify version of sof-logger
@@ -262,6 +275,8 @@ static void *wait_open(const char *watched_dir, const char *expected_file)
262275

263276
return ret_stream;
264277
}
278+
#endif // HAS_INOTIFY
279+
265280

266281
int main(int argc, char *argv[])
267282
{
@@ -436,9 +451,10 @@ int main(int argc, char *argv[])
436451
* for _any_ input file, not just for /sys/kernel/debug/sof/[e]trace
437452
*/
438453
config.in_fd = NULL;
439-
if (strncmp(config.in_file, sys_debug, strlen(sys_debug))) {
454+
if (!HAS_INOTIFY ||
455+
strncmp(config.in_file, sys_debug, strlen(sys_debug))) {
440456
config.in_fd = fopen(config.in_file, "rb");
441-
} else {
457+
} else { // both inotify and /sys/kernel/debug/
442458
DIR *dbg_sof = (DIR *)wait_open(sys_debug, "sof");
443459

444460
if (dbg_sof) {

0 commit comments

Comments
 (0)