views:

17

answers:

2

I know there are other applications also, but considering yum/apt-get/aptitude/pacman are you core package managers for linux distributions.

Today I saw on my fedora 13 box:

(7/7): yum-3.2.28-4.fc13_3.2.28-5.fc13.noarch.drpm       |  42 kB     00:00     

And I started to wonder how does such a package update itself? What design is needed to ensure a program can update itself?

Perhaps this question is too general but I felt SO was more appropriate than programmers.SE for such a question being that it is more technical in nature. If there is a more appropriate place for this question feel free to let me know and I can close or a moderator can move.

Thanks.

+1  A: 

I've no idea how those particular systems work, but...

  • Modern unix systems will generally tolerate overwriting a running executable without a hiccup, so in theory you could just do it.
  • You could do it in a chroot jail and then move or something similar to reduce the time during which the system is vulnerable. Add a journalling filesystem and this is a little safer still.

It occurs to me that the package-manager needs to hold the package access database in memory as well to insure against a race condition there. Again, the chroot jail and copy option is available as a lower risk alternative.

dmckee
Does the toleration of overwriting have to do with the file not being run but a copy of the file being run and thus overwriting the copy is fine because when the program exits, the next subsequent run will run an updated copy of it?
Chris
@Chris: Uhm...yes. I think that linux in particular uses a mark-and-copy-on-update strategy so that no actual copy is made unless and until one "version" or the other is altered. However, I'm not sure than my claim is good very far into the past. Shall edit.
dmckee
A: 

And I started to wonder how does such a package update itself? What design is needed to ensure a program can update itself?

It's like a lot of things, you don't need to "design" specifically to solve this problem ... but you do need to be aware of certain "gotchas".

For instance Unix helps by reference counting inodes so "you" can delete a file you are still using, and it's fine. However this implies a few things you have to do, for instance if you have plugins then you need to load them all before you run start a transaction ... even if the plugin would only run at the end of the transaction (because you might have a different version at the end).

There are also some things that you need to do to make sure that anything you are updating works, like: Put new files down before removing old files. And don't truncate old files, just unlink. But those also help you :).

Using external problems, which you communicate with, can be tricky (because you can't exec a new copy of the old version after it's been updated). But this isn't often done, and when it is it's for things like downloading ... which can somewhat easily be made to happen before any updates.

There are also things which aren't a concern in the cmd line clients like yum/apt, for instance if you have a program which is going to run 2+ "updates" then you can have problems if the first update was to the package manager. downgrades make this even more fun :). Also daemon like processes should basically never "load" the package manager, but as with other gotchas ... you tend to want to follow this anyway, for other reasons.

James Antill