From dd7fbdbc3bb0445050fc8045b4e015532badf4fc Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 11 May 2022 23:04:58 -0700 Subject: [PATCH] ... --- Makefile.am | 6 ++++++ configure.ac | 41 +++++++++++++++++++++++++++++++++++++++++ inc/main.h | 1 + src/main.c | 21 ++++++++++++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index c69add9..1634c27 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,12 @@ AM_CPPFLAGS = \ -Wall \ -Werror +if ENABLE_DEBUG +else +AM_CPPFLAGS += \ + -DNDEBUG +endif + bin_PROGRAMS = cold cold_SOURCES = \ diff --git a/configure.ac b/configure.ac index c486633..82d2bd2 100644 --- a/configure.ac +++ b/configure.ac @@ -9,6 +9,47 @@ AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([inc/config.h]) +AC_ARG_ENABLE([debug], + [AS_HELP_STRING([--enable-debug], + [enable debugging])], + [enable_debug=$enableval], + [enable_debug=no]) + +AC_ARG_ENABLE([memcheck], + [AS_HELP_STRING([--disable-memcheck], + [disable memcheck with valgrind (enabled by default)])], + [enable_memcheck=$enableval], + [enable_memcheck=yes]) + +AC_PATH_PROG([VALGRIND], [valgrind]) +AM_CONDITIONAL([HAVE_VALGRIND], [test -n "$VALGRIND"]) + +AC_MSG_CHECKING([if debugging]) +if test x$enable_debug != xno; then + AC_MSG_RESULT(yes) + CFLAGS="-ggdb3 -O0" +else + AC_MSG_RESULT(no) +fi + +AM_CONDITIONAL([ENABLE_DEBUG],[test x$enable_debug != xno]) + +dnl disable memcheck if valgrind not found +if test "x$enable_memcheck" != "xno"; then + if test -z "$VALGRIND"; then + enable_memcheck=no + fi +fi + +AC_MSG_CHECKING([if memcheck should be enabled]) +if test x$enable_memcheck != xno; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + +AM_CONDITIONAL([ENABLE_MEMCHECK],[test x$enable_memcheck = xyes]) + # Checks for programs. AC_PROG_CC diff --git a/inc/main.h b/inc/main.h index b073e2d..b3ec90b 100644 --- a/inc/main.h +++ b/inc/main.h @@ -1,6 +1,7 @@ #ifndef __MAIN_H_ #define __MAIN_H_ +#include #include #include diff --git a/src/main.c b/src/main.c index c38e52a..3eeea7e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,10 +1,29 @@ #include int main(int argc, char **argv) { - struct udev *monitor; + struct udev *monitor; //, *dev; + struct udev_enumerate *enumerate; + struct udev_list_entry *devices, *dev_list_entry; + const char *path; monitor = udev_new(); if(NULL==monitor) { return EXIT_FAILURE; } + + enumerate = udev_enumerate_new(monitor); + + udev_enumerate_add_match_subsystem(enumerate, "usb"); + udev_enumerate_add_nomatch_sysattr(enumerate, "bDeviceClass", "09"); + udev_enumerate_add_nomatch_sysattr(enumerate, "bInterfaceNumber", NULL); + udev_enumerate_scan_devices(enumerate); + + devices = udev_enumerate_get_list_entry(enumerate); + + udev_list_entry_foreach(dev_list_entry, devices) { + path = udev_list_entry_get_name(dev_list_entry); +// dev = udev_device_new_from_syspath(monitor, path); + + printf("found: %s\n",path); + } udev_unref(monitor); -- 2.30.2