Take the 2-minute tour ×

I am writing a program in C on Linux environment (Debian-Lenny) and would like the program to be updated when an update is available (the program gets notified when a new update is available). I am looking for a way that the program can update itself.

What I am thinking is that the main program invokes a new program to handle the update. The updater program will have(access to) the source code and receive the update information about the changes on the source code, something like that:

edit1: line 20, remove column 5 to 20;
edit2: line25, remove column 4-7 then add "if(x>3){" from the column4
edit3: line 26, enter a new line and insert "x++;"

then kill the main process, recompile the source code, and then replace the new binary with the old one.

or is there a better (easier) and standard way to implement the ability that a program can update itself?

I use the program to control a system with a Linux embedded board. Therefore, I don't want the source code to be accessible to another person (if the system is hacked or something). If the best way to update a program by using the source code, how do you suggest me to secure the source code? If you suggest me to encrypt the source code, what function (Linux C) can the program use to encrypt and decrypt the source file?

share|improve this question
How about checking for an update on a remote server? Is that an option? –  Jeff Jun 21 '13 at 8:19
might be easiest to update a svn, git etc trunk and then recompile the code, and have the svn or git etc do the dirty work. –  hetepeperfan Jun 21 '13 at 8:19
I'm not sure I'm reading this correctly, but if you care about the source code, you should compile the new version of the program on a secure box, and just send the binary (or let the client fetch it). –  Will Jun 21 '13 at 8:21
The nodes are connected each other via ad-hoc wlan, it will be a closed network but there will be gateway nodes that have Internet access, the GW nodes will notify clients that there is available update, but I wonder how I should implement the update procedure on the client side –  angs Jun 21 '13 at 8:27

2 Answers 2

up vote 8 down vote accepted

If your target system is Debian, then you should just take advantage of the Debian packaging system to provide updates. Package your compiled application in a .deb package, distribute it on an APT archive which is included in your system's sources.list, and just use cron to schedule a regular update check with apt. The .deb package can include a post-installation script that restarts your application.

You could run an apt-proxy caching proxy on your "gateway" nodes that have internet access, and have the other nodes use that as their apt source.

Distributing source code in this case is probably not appropriate, because then you would need to include a full compiler toolchain on your target system.

By the way, Debian Lenny is no longer supported; you should upgrade to the current stable release; at time of writing, that is Wheezy.

share|improve this answer

What you're describing is very similar to the 80s-style of delivering Unix source code, popularized by the development of PERL. You use diff to get a record of changes between different versions of the source-code, then distribute this "patch" file, and use patch to perform the necessary modifications at the client-end. This doesn't address the network-communication or version-control issues.

A possible downside is that a first-time download may need to apply many patches to bring the version up. This is often the case when investigating old source from nntp:comp.sources.unix.

share|improve this answer
80s-90s Unix history: catb.org/esr/writings/taoup/html/ch02s01.html#id2880014 –  luser droog Jun 21 '13 at 8:45

Your Answer


