Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Self Recompiling Daemon
#1
In a strictly technical sense, a Unix-like system process is a daemon when its parent process terminates and the daemon is assigned init process as its parent and has no controlling terminal. However, more commonly, a daemon may be any background process, whether a child of the init process or not.

How to daemonize a process?

When you start process from command line then close the shell, your process dies with it. However, when you start it in the background via '&' suffix and close the shell, the process continues and becomes child of process 1 just like the definition above requires. Your program has been daemonized by shell.

If you want System V init daemon, check this init script template.

Self Rebuilding

Need a daemon that runs with root privileges but is started by a webpage running with user privileges. This can be accomplished by sticky bit, which causes process to run with user id of file's owner. However, if the source file changes, the webpage cannot set owner and mode due to access privileges. One of the options is to have the daemon detect modification of its' source code, then rebuild and restart itself. This code watches the modification time of its own source code and when it detects a change, it rebuilds and restarts via auto-generated shell script.

Btw. this is a security hazard and mere convenience for development. Normally if web app requires a daemon like this, it should have no way to arbitrarily inject the code and rebuild. So when you are done developing, change the ALLOW_SELF_REBUILD at the top of file to 0.


Attached Files
.zip   daemon.zip (Size: 1.88 KB / Downloads: 30)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)