开发者

Design principles as to how linux repository managers update themselves?

开发者 https://www.devze.com 2023-01-20 08:03 出处:网络
I know there are other applications also, but considering yum/apt-get/aptitude/pacman are you core package managers for linux distributions.

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开发者_如何学Go 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号