Testing a Linux daemon on an embedded system - linux

I have written a daemon in linux for doing dhcp for an embedded system. This platform only has a linux kernel running on it and have no CLI support. What is the best way for me to test my daemon? How do I write a program that will call the main function in this daemon and verify if its working fine?
Appreciate the answers.

When I've been in a situation like this, I've written a second daemon (or had a second listener in the existing daemon) to take the place of a CLI, listening at a particular port and responding to a very limited command set of your own choosing.
In this case, all you really care about is triggering the function on demand, so you could even have it trigger when you connect to this second port, and then report results back to the socket.
I strongly recommend, by the way, making sure your embedded system has some more generic mechanism for logging information to persistent storage and retrieving that log. It doesn't have to be syslog or anything so complicated. But you will want that ability in the future to enable forensic analysis of problems in the field.

You will want to write and debug your daemon in a full featured environment first, then install it on the embedded system at the end when you are sure it works properly.
If you can build a dhcp server for the embedded system you can surely build a simple shell for it also. Try building BusyBox or ash or dash.
You could also try using GDB remote debugging. I found an article about it.

Related

Trigger file system events on Linux from bash

I'd like to trigger file system events on a Linux virtual machine (VirtualBox). I'm not sure how to approach this, but I can imagine there could be 2 ways of doing it:
with a built-in command in the guest system
or from the host system controlling the guest through VirtualBox commands
I did some research and found tools like guard/listen, but I could not manage to make them work. (Guard asking for plugins and the documentation is not clear to me...)
My goal is not a new thing, I'd like to forward file system events from the host to the guest. On the host side I'm using fswatch to hook up to file system events. Fswatch would run a script on the guest system via SSH - that script/command could trigger an fs event in the guest system based on the parameter from fswatch which was a path... It's not an efficient approach I guess but for development purposes when I modify some files in the IDE should be good enough.
This one solved my problem: vagrant-notify-forwarder

Linux process performance monitoring agent

Hi Stackoverflow community,
For our tool we're trying to build a agent to remotely monitor linux processes, the resources they use, i/o info and tcp/ip connectivity. This is to gather these metrics and send them over to the server using log4. We're doing this in windows use wmi and log4net and looking to do the same in linux.
In essence, doing what top, lsof -i and iostat do then sending it to the central server.
Have seen some initiatives at:
lttng
munin monitoring
systemtap
opennms
godrb.com
mcollective
http://bitbucket.org/chrismiles/psi/wiki/Home
Looking at the source code of top, it directly queries /proc whereas lttng needs to install kernel modules. Bearing in mind, the end use is for enterprise systems, we would like to keep it as close to the kernel as possible without needing to add new modules.
Our goal is to monitor what each process on the box uses (cpu/mem/io etc), any process info (eg version) and where it connects tcp source and destination and send this to the server using log4. Happy for it to be in any language C/php/python/ruby etc
Do you have any suggestions?
Bill
"In essence, doing what top, lsof -i and iostat do then sending it to the central server"
Try SeaLion. Its exactly what you want. It will also give you the flexibility to add more commands as and when your monitoring requirements change or increase. You wouldn't have to look for other tools. It is lesser known but works very easily; simple setup and a great timeline to view the past data in.
For true enterprise monitoring, I would look at Megamon (http://www.megamon.com)

Implementing a kernel debugging module for a Linux guest OS inside a VmWare VM

Sorry for the rather long post.
I need some input regarding a project that I am going to undertake.
I am trying to make an application that collects kernel debugging information from a guest Linux OS, located inside a VmWare Virtual Machine, and send them to a host OS efficiently.
So far, I have found a similar project, but written for Windows[1].
The author of the project wrote a DLL that is loaded into memory, and replaces the implementation of the KdSendPacket and KdReceivePacket functions, to use the VmWare GuestRpc[2] mechanism, instead of the slow serial port.
The data are then send to a debugging application on the host(Kd or WinDbg) trough a named pipe.
The author claims that there is a speed-up up to 45%, by avoiding the serial port transmission.
I am trying to achieve something similar ,but for Linux, and try to make the debugging process a little faster, than using the serial port.
My concrete questions are :
Do any similar applications exist?
I didn't manage to find any.
Would such an application be worth it ,comparing its functionality to netconsole[3], for example?
What method of intercepting printk messages would you suggest ?
Is there an equivalent of KdSendPacket/KdReceivePacket on Linux ?
[1]. http://virtualkd.sysprogs.org/dox/operation.html
[2]. http://articles.sysprogs.org/kdvmware/guestrpc.shtml
[3]. http://www.kernel.org/doc/Documentation/networking/netconsole.txt
Using the serial port is really suboptimal.. even the (virtual) network would be preferable to that, but getting back to host-guest IPC channels, VMware's VMCI comes to mind.
many approaches can use to achieve your goal, below methods can be applied if network is connected:
use syslog service and transfer log though network to your server:
syslogd, syslogng seems support sending log to a log server with some filter critiera.
directly call tcp/udp socket functions in your kernel module to sends your collected data back to server.
other approaches, you may write application on host machine that calls hypervisor's share memory access function to read the memory buffer of your kernel module. However, the xen/kvm hypervisor both support these apis and i am not sure about weather vmware have this kind of library.

Run .exe with daemon or better solutions to get something similar to windows service (mac and linux)?

I was wondering if i can run a exe with daemons in mac and linux or do you have any other solutions to do something similar to a windows service that is a scheduler ? I know i can use crontab but i was wondering if there was other way to do it.
Thx
On OS X, the preferred way of doing things like this is with launchd daemons. You create a .plist file with information about what program to run, parameters to pass it, and what conditions to start it under (i.e. at certain times, when a network connection is received on a certain port, or just run always), and various other options. Lingon provides a handy GUI for creating the .plist, or just read the Apple LAUNCHD docs and create it yourself. Put the .plist in /Library/LaunchDaemons, and either reboot or activate it with sudo launchctl load /Library/LaunchDaemons/whatever.plist.
A warning about using launchd: most daemon-type programs for unix will "daemonize" themselves -- they drop into the background, and generally detach themselves from the program that started them. Launchd doesn't like this. It wants to keep watch over its children, so that it can monitor their status, relaunch them if necessary, etc. So you may either need to tell the program not to daemonize, or add an option to the .plist to tell launchd not to freak out if the program appears to quit.
Linux alternative to windows NT services are daemons. You can read a little more about it
here.
You also start executables by scripts located in "/etc/init.d" Just look at one of those scripts for reference. If you want to make a task or executable start at a given time use a crontab. It is made for this purpose and I don't see why use something else.
If you have a mono executable probably the easiest way is just to make a script in "init.d" if you want to start when system starts or make a crontab entry. It is realy easy. Here you can find a simple reference.

Setting environment variables remotely?

How can I set Linux environment variables remotely from a Windows application?
You can't directly. Environment variables are just a table of values associated with the process, and inhereted when you fork(2) a process.
If you want to set them, you need some kind of code at the Linux side doing it. The simplest is probably to run your remote programs through a shell, and set them on the command line.
Otherwise, you need a way to get your Linux-side client to put them into the environment with setenv(3).
Taking your rather terse question at face-value, you could have your Windows application ftp to the linux system as the user who is going to run the linux app and modify their .cshrc or .bashrc, adding the desired environment variables to the shell script. This won't modify already-running shells, though.
At an abstract level, you're talking about inter-process communication. You have information in the Windows application you want to communicate to communicate to some Linux application. I'm not sure environment variables are the best way to communicate this data. Perhaps opening a socket between your Windows app and Linux app would be best.
Two ways I can think of - in probable order of simplicity:
Write a Linux program that listens on a network socket for commands. Your Windows app sends the appropriate command. The Linux program runs the command to set the environment variable - something like system(export MY_ENV_VAR=abc). This won't be secure over the network unless you make it so.
Use SSH to login to the Linux system, then run a script to set the variable. I don't know if there are SSH libraries around for Windows but I'd be surprised if there aren't. PuTTY is an excellent open-source Windows SSH client so you may be able to use code from there but you should check the license first - depending on how you plan to use your application. This option has the benefit that you can use PKI to secure the network connection, if necessary.

Resources