Linux C - implementing the ability that a program can update itself
Asked Answered
H

2

7

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?

Hintz answered 21/6, 2013 at 8:14 Comment(4)
How about checking for an update on a remote server? Is that an option?Carboxylate
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.Ibnrushd
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).Alpestrine
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 sideHintz
T
9

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.

Testimony answered 21/6, 2013 at 8:42 Comment(0)
J
1

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.

Janaye answered 21/6, 2013 at 8:25 Comment(1)
80s-90s Unix history: catb.org/esr/writings/taoup/html/ch02s01.html#id2880014Janaye

© 2022 - 2024 — McMap. All rights reserved.