diff options
author | Marcus Müller <marcus.mueller@ettus.com> | 2016-01-13 17:06:06 +0100 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2016-01-26 17:19:39 +0100 |
commit | 45335d1e1ca9da7872f4ab9a91b9d214e5ef6ba6 (patch) | |
tree | 359dd6db30e30a7d47b15d778c97368e87cae4fc /host | |
parent | 17712af3b8f1f4cc1bdd11f0f4377c79cb6da87b (diff) | |
download | uhd-45335d1e1ca9da7872f4ab9a91b9d214e5ef6ba6.tar.gz uhd-45335d1e1ca9da7872f4ab9a91b9d214e5ef6ba6.tar.bz2 uhd-45335d1e1ca9da7872f4ab9a91b9d214e5ef6ba6.zip |
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
Diffstat (limited to 'host')
-rw-r--r-- | host/utils/fx2_init_eeprom.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
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 <uhd/property_tree.hpp> #include <boost/program_options.hpp> #include <boost/format.hpp> +#include <boost/algorithm/string/predicate.hpp> #include <iostream> -#include <cstdlib> +//#include <cstdlib> +#ifdef UHD_PLATFORM_LINUX +#include <fstream> +#include <unistd.h> // syscall constants +#include <fcntl.h> // O_NONBLOCK +#include <sys/syscall.h> +#include <cerrno> +#include <cstring> // 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; |