From 45335d1e1ca9da7872f4ab9a91b9d214e5ef6ba6 Mon Sep 17 00:00:00 2001 From: Marcus Müller Date: Wed, 13 Jan 2016 17:06:06 +0100 Subject: fx2: std::system("/sbin/rmmod usbtest") not portable, fixed that FX2 code has complications on Windows machine due to shell misinterpreting the "/sbin/rmmod usbtest" string. * path should not be hardcoded * std::system error message means "possible success" (which is confusing, and contains little information) * replaced std::system by matching syscall * used #ifdef UHD_PLATFORM_LINUX to make checking & removal Linux-only --- host/utils/fx2_init_eeprom.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'host/utils') diff --git a/host/utils/fx2_init_eeprom.cpp b/host/utils/fx2_init_eeprom.cpp index 5711b73e0..cf7fb2de2 100644 --- a/host/utils/fx2_init_eeprom.cpp +++ b/host/utils/fx2_init_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2010,2014 Ettus Research LLC +// Copyright 2010,2014,2016 Ettus Research LLC // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,8 +20,17 @@ #include #include #include +#include #include -#include +//#include +#ifdef UHD_PLATFORM_LINUX +#include +#include // syscall constants +#include // O_NONBLOCK +#include +#include +#include // for std::strerror +#endif //UHD_PLATFORM_LINUX const std::string FX2_VENDOR_ID("0x04b4"); const std::string FX2_PRODUCT_ID("0x8613"); @@ -49,10 +58,22 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ return EXIT_FAILURE; } - //cant find a uninitialized usrp with this mystery module in the way... - if (std::system("/sbin/rmmod usbtest") != 0){ - std::cerr << "Did not rmmod usbtest, this may be ok..." << std::endl; +#ifdef UHD_PLATFORM_LINUX + //can't find an uninitialized usrp with this mystery usbtest in the way... + std::string module("usbtest"); + std::ifstream modules("/proc/modules"); + bool module_found = false; + std::string module_line; + while(std::getline(modules, module_line) && (!module_found)) { + module_found = boost::starts_with(module_line, module); } + if(module_found) { + std::cout << boost::format("Found the '%s' module. Unloading it.\n" ) % module; + int fail = syscall(__NR_delete_module, module.c_str(), O_NONBLOCK); + if(fail) + std::cerr << ( boost::format("Removing the '%s' module failed with error '%s'.\n") % module % std::strerror(errno) ); + } +#endif //UHD_PLATFORM_LINUX //load the options into the address uhd::device_addr_t device_addr; -- cgit v1.2.3