00001 /*****************************************************************************\ 00002 * * 00003 * Name : lock_library * 00004 * Author : Chris Koeritz * 00005 * * 00006 * Purpose: * 00007 * * 00008 * Puts a stranglehold on dlls passed on the command line. This forces * 00009 * the dlls to be treated as locked and in use. * 00010 * * 00011 ******************************************************************************* 00012 * Copyright (c) 2007-$now By Author. This program is free software; you can * 00013 * redistribute it and/or modify it under the terms of the GNU General Public * 00014 * License as published by the Free Software Foundation; either version 2 of * 00015 * the License or (at your option) any later version. This is online at: * 00016 * http://www.fsf.org/copyleft/gpl.html * 00017 * Please send any updates to: fred@gruntose.com * 00018 \*****************************************************************************/ 00019 00020 #include <basis/common_templates.h> 00021 #include <data_struct/amorph.cpp> 00022 #include <opsystem/byte_filer.h> 00023 #include <opsystem/console_logger.h> 00024 #include <opsystem/dynamic_loader.h> 00025 #include <opsystem/filename.h> 00026 #include <opsystem/startup_code.h> 00027 00028 HOOPLE_STARTUP_CODE; 00029 00030 #define LOG(to_print) program_wide_logger().log(to_print) 00031 00032 int main(int argc, char *argv[]) 00033 { 00034 SET_DEFAULT_CONSOLE_LOGGER; 00035 if (argc < 2) { 00036 LOG("This program requires a list of DLLs on the command line. Each of those"); 00037 LOG("dlls will be loaded and locked into memory. This will force them to"); 00038 LOG("be locked while the application is still running, and hence upgrades can"); 00039 LOG("be tested for how they behave when DLLs that are to be upgraded are"); 00040 LOG("inaccessible."); 00041 return 37; // error. 00042 } 00043 00044 string_array dll_list; 00045 for (int i = 1; i < argc; i++) { 00046 dll_list += argv[i]; 00047 } 00048 00049 library_plugins::dynamic_library_loader loaded("garbaloy.dll", false); 00050 // create the dll loader but don't actually try to load the bogus name 00051 // above. 00052 00053 amorph<byte_filer> simplistic_locks; 00054 for (int i = 0; i < dll_list.length(); i++) { 00055 LOG(istring("loading dll ") + dll_list[i]); 00056 /* this stuff is cool but doesn't lock the dll. 00057 void *handle = loaded.load_library(dll_list[i].s()); 00058 if (handle) { 00059 void *mainfunc = loaded.load_method(handle, MAKEINTRESOURCEA(1)); 00060 if (!mainfunc) { 00061 LOG(istring("failed to find first exported method in dll ") 00062 + dll_list[i]); 00063 } 00064 */ 00065 filename check_it(dll_list[i]); 00066 if (!check_it.good()) { 00067 LOG(istring("failed to find the dll ") + dll_list[i]); 00068 continue; 00069 } 00070 byte_filer *gubba = new byte_filer(dll_list[i], "a+b"); 00071 if (gubba->good()) { 00072 simplistic_locks.append(gubba); 00073 } else { 00074 LOG(istring("failed to load dll ") + dll_list[i]); 00075 } 00076 } 00077 00078 if (dll_list.length()) { 00079 LOG("now pausing forever. break the program to release the dlls."); 00080 while (true) { portable::sleep_ms(100); } 00081 } else { 00082 LOG("didn't find any dlls to load and lock. exiting."); 00083 } 00084 00085 return 0; 00086 } 00087
1.5.1