Cannot Get LXC Container to Start - c++

I am using LXC via the C API, and have simply copied and pasted the example code (as shown in that link, but replacing the main function name with my own). Then calling this from within another block of code in my program, I cannot get the container to start properly.
The call to start simply returns false. If I change the second parameter to start to 0 (implying that lxcinit should be used instead of /sbin/init), then start "succeeds", but the container state is immediately set to STOPPED, and so I cannot attach to the container.
Attempting to get logs by setting:
c->set_config_item(c, "lxc.logfile", "/home/user/lxc-log.log");
c->set_config_item(c, "lxc.logpriority", "TRACE");
c->set_config_item(c, "lxc.console.logfile", "/home/user/lxc-log2.log");
c->set_config_item(c, "lxc.console.logpriority", "TRACE");
Just produces empty files.
Thinking that this may be related to another issue I saw, I also tried setting:
c->set_config_item(c, "lxc.aa_allow_incomplete", "1");
Creating a separate C++ program, and compiling it works like a charm, but when I attempt to call it from within another program, by simply adding a function and calling it (specifically a uni project), I cannot get it to run properly at all.

As it turned out, I was able to solve this issue by disabling two packages that were included as part of the larger project tcmalloc, and asan.

Related

Is there a way to stop RGui from crashing when an RCPP program fails to work correctly?

I'm using Rcpp to run C++ code using RGui (version 3.4.1) as a user interface. Quite often I make changes to the C++ code which compile correctly but cause errors (e.g. searching beyond the end of an array) when I run the relevant program in RGui, causing RGui to crash. This is aggravating because I have to re-open RGui, re-open my R script (sometimes with unsaved changes lost), set the working directory again, etc. before I can re-compile the C++ code and run the program in such a way as to find the problem or test amendments. Sometimes it promptly crashes again because I haven't fixed or bypassed the problem.
Is there some way to change the way Rcpp runs such that RGui returns an error message instead of crashing in these sorts of situations?
Briefly:
It is spelled Rcpp. Capital R, lowercase cpp.
Yes, don't have bugs :)
In general, 2. is the only viable answer. If you need a managed language, use R.
If the code takes your environment down, test outside the environment. Seriously. That is for example why I (co-)wrote littler and test "raw code" on the command-line: it can only take the command-line app down.
We do have a feature in eg RcppArmadillo to test for "out of bounds" vector access: use x.at(i,j) which will warn. See http://arma.sourceforge.net/docs.html#element_access
I don't actually know of a way to prevent this apart from more careful programming, and saving before execution. But having done this a few times I have discovered a way to get back at unsaved changes, (at least in windows).
When you get the pop-up that tells you to restart R, you don't do it. You open up task manager and right-click on the process and select 'Create Dump File'. Find this file in explorer and open it with some text editor.
They are very big, and full of all sorts of stuff, but if you use find function to search for some string you know to be in your script, then you can find all the unsaved work. You can then copy and paste this into another file to save.
If you use R-studio instead of R-GUI, it usually manages to look after your unsaved work better.

Executing code during runtime that cannot be included in the main program

I'm coding a web server for fun and I'm now trying to make it dynamic.
I need to do the part usually PHP would do in regular web development, be inside the page code and be executed server side while the server runs.
Now, I've been thinking, and reading a bit on this. I could separate it and then invoke the compiler to make that code run, but I've also read that's not a good way to go about it, so I'd like to avoid it.
I thought maybe if I compiled a program that would go with the specific page it was meant to and made it change the page based on arguments and return the page in buffers, it could work, but that just seems cumbersome.
One wouldn't want to include the code for every single page on the webserver because it just doesn't scale well.
I don't believe C++ can do a "CALL" as in batch when the program is running, it would though, I believe, be the ideal solution besides including a file mid program which isn't possible.
I would like to know whether or not there's a way of executing a program or non-included code during runtime and if so how.
You could try dlopen, dlsym, dlerror and dlclose. These allow you to, at runtime, load libraries. Your server could use it to load code which should execute inside a page.
Howto, by Aaron Isotton
Documentation on man7.org

NS-3 with DCE: How to get input at runtime working with my binaries

I'm using ns-3 with direct code execution, working on Ubuntu, and after a while, I got everything to work, but the thing is: I have four nodes with each one binary to run, and some of the binaries take input from me at runtime, via std::cin. (They will then send messages to the other nodes based on the input). I need to get this working inside the ns-3-environment and I couldn't figure out how.
So far, if I start my simulation and it gets to the point where a node with an application starts that is waiting for input (in an endless loop), the whole thing blocks, it doesn't start other applications, it never even stops the simulation. If I just curiously type something and hit enter, it says "relocation error: elf-cache/0/libgcc_s.so.1: symbol dl_iterate_phdr, version GLIBC_2.2.5 not defined in file 0001.so.6 with link time reference" and gives me an exit code 127.
So, naturally I would just find out how to do runtime input in ns3, but I can't find any material on this.
So, I found the solution for file input finally. Maybe it's useful for someone.
std::ifstream config_doc("path/here/file.txt", std::ifstream::binary);
worked for me - if you make sure that your path starts at the designated folder for the ns3-node. For example, if it's the 0th (1st) node, it has to be placed inside the folder files-0, like this:
(...) /source/ns-3-dce/files-0/path/here/file.txt (if you use path/here/file.txt like above). The node always has its home directory in its files-x directory.

Emscripten application not executing

When running my asmjs\emscripten application, compiled from C++, it has suddenly started to log: "run() called, but dependencies remain, so not running" to the web console, and nothing more happens.
I've added some cout's at the absolute start of my main, but even they aren't reached.
The application executed successfully before, but suddenly this started to happen and I don't know what change triggered this.
Does anyone know how to debug this?
Update
After removing as much source code as I could, this happens as soon as I #include , even due my main simply consists of a single cout.
Ideally you would have the entire environment when it was running in version control, and build every version since to see where it broke.
You might have your code in version control, but perhaps not Emscripten itself. If you've updated Emscripten, this could lead to differences in behaviour. I would try going back to whatever version you used when it was running. Note that sometimes various cache directories survive an Emscripten version change, and might need to be cleared manually (I forgot which exactly).
The dependencies remaining could mean that you are trying to do something before Emscripten has loaded any other files it needs to, say files requested by --preload-file or --memory-init-file. Note that according to https://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html#faq-when-safe-to-call-compiled-functions you should not try to run any Emscripten functions, until the C++ main function has run. To detect this, you can, for example, call your own Javascript function from main (there are other ways).
The fact this wasn't causing a problem before could have been something that seems quite unrelated: a change or update in the web browser, changing limits of concurrent downloads, or a change in the web server this is running from. You could look in the Network tab in the browser to see if anything leaps out at you as being different or suspicious.
However, as main isn't even reached, then it might not be that. I would try commenting out virtually all of your code, and make it so you have practically nothing but a hello-world program. Perhaps you don't have a correct setting in the Module object, or maybe the request for the memory initialization file is failing (you can check in the Network tab in the browser for that one). If your basic hello world program still isn't working, then you could post again, with its code, in a separate question.
This can also happens when the browser runs out of memory. Unfortunately, the browser's memory handling is not in our control so there isn't much you can do beside reducing your payload. This includes code size, preload content size, etc. Basically anything that can reduce the total memory consumption of your program will help fixing this. Browser vendors are constantly working to improve this, but it's going to take a while still.
I think you haven't given enough information to really know for sure. But it might be for instance that your js suddenly crossed some memory threshold which exceeds what the browser wants to allocate to it. You could try reducing the amount of memory used / streaming some assets instead of preloading them / ship less code / use -Os optimization level?

CreateInstance Returns "The specified module could not be found."

I've been trying to get a program that worked on Windows 2000 to work on Windows 2003. Everything I've had to do so far to get the program to work on Windows 2003 has had to do with incorrect configuration. Right now, this piece of code:
chr = pAdapterEnvPtr.CreateInstance(__uuidof(PFADAPTERMNGLib::PFAdapterEnv));
is returning:
0x8007007E
or in other words:
The specified module could not be found.
I have two other programs and another .dll and I can successfully create instances of those classes. But this seems to fail.
I have used Procmon to try to figure out what the program can't find, but Procmon did not display anything that could indicate that the program could not find something.
In OleView, if I try to create an instance of the class, I see the following image:
If you look on the left side of the image, trying to create an instance of PFComgMng gives me the same error. (PFAdapterEnv and PFCompMng use the same process, PFAdapterMng.exe.) However, PFMQMonitor, PFSend, and PFTrace all work correctly. (Which use PFMQListen.exe, PFSend.dll, and PFTraceService.exe.)
Another thing that I wanted to note is that the following piece of code:
hr = pPFCompMng.CreateInstance(__uuidof(PFADAPTERMNGLib::PFCompMng));
works perfectly fine when it gets called earlier from PFAdapterMng.exe. So it seems like PFAdapterMng.exe can successfully find the module and create the instance, but any other processes that try to create either of the instances of the classes within PFAdapterMng.exe can't find the module, resulting in this error.
Since Procmon isn't helping with this specific case, does anyone know what I could do to figure out what's keeping other processes from finding the module?
UPDATE:
I can't run Dependency Walker with profiling because PFAdapterMng.exe and PFTraceService.exe must be run as services. I tried to run Dependency Walker while profiling OleView and tried to create instances of PFAdapterEnv and PFCompMng to try to find out why I was getting the Module not found message box. Unfortunately, Dependency Walker didn't show that anything was missing.
UPDATE2:
Maybe I missed something in the Procmon log, so I created a new log by capturing events right before I stepped over the call to CreateInstance and right after the call. Maybe someone else could take a look and tell me if i missed it? I simply can't find any indications that PFMQListen.exe could not find something..
Here's a link to a zipped folder with a Procmon file, a .csv file, and a .xml file.
http://www.mediafire.com/?07jq8zj7emmpsvd
UPDATE3:
So, I managed to get Dependency Walker running under Profile mode to create an instance of PFAdapterEnv. Dependency Walker did not find any missing .dll's.
So, Procmon doesn't show anything, and neither does Dependency Walker. I was stepping through the code at the assembly level with ollydbg, and I noticed that the error was created in the function NdrClientCall2. I don't know if this means anything.
Any ideas as to what else I can try? Do people need more information to help me solve this problem? If so, please ask.
UPDATE4:
I tried using /RegServer to register the applications, and it worked. I tried using /RegServer previously, where I just unregistered everything using /UnregServer. This time, I also deleted the component from Component Services which I needed to have because I wanted to run PFAdapterMng under another identity.
So, it seems like everything works when running on /RegServer and double-clicking the applications. However, I would like everything to run under a different configuration.
How do I configure everything to get the applications to work as follows:
PFAdapterMng.exe - Register as /Service and run under another identity through services.msc
PFTraceServer.exe - Register as /Service and run under another identity through services.msc
PFMQListen.exe - Register as /RegServer which will be started by PFAdapterMng
PFMQSend.dll - Registered with Regsvr32 and loaded by PFAdapterMng
Thanks,
Krzys
My guess is that it is related to the search path of some DLL dependencies of the executable.
You can try the "Dependency Walker" on every module to see if all DLL are available: http://www.dependencywalker.com/
And update the search PATH if needed.