Perl lock file while updating mxr distortion dating vintage
I am writing a script to do some apt commands, but I am running into potential issues of the apt/dpkg databases being locked so my script bails. /var/lib/dpkg/lock) before doing anything just like apt does when it runs it's command, but I can't figure out how apt is performing the lock.The lock file is always there, and apt-get is not doing a flock on the file.We as programmers are used to putting ourselves in the shoes of our program, and relating to it as an individual: What file should I open now? What do I do if that other program went and deleted that file? But this handy metaphor breaks down when we need to imagine other simultaneous instances of our program following the same set of instructions.And thats just how the above counter program was getting into trouble.What about just doing a check of the process list when your script runs, and exiting if apt is running at the same time? Looks like this person went down the same path as you did, without much success. Since I am using Ruby for the scripting language, I had to create my own function to look for lock.The reason for this, is because Ruby does not implement the fcntl function entirely. The ability to build flock structs and how to pass them is left out or not documented. Here is the function I ended up writing: def flocked?In testing, I never had two instances of the program running at once; but once the counter was on a publicly visible Web page, there were eventually two instances of the counter running at once, with various unfortunate results.Problems with Simultaneous Instances Imagine that two people, at about the same instant, are accessing the Web page with the counter discussed above.
From an strace I see that apt-get opens the file, but that is it. Brain Eno and Peter Schmidt, Oblique Strategies The worst kinds of bugs are the ones that dont appear during development, but then randomly appear only in real use.It was a simple SSI counter for a Web page, and it looked like this: I tested it in an .shtml Web page and, in the browser, it merrily displayed Hits on this page: 4, then on reloading displayed Hits on this page: 5, and so on.It then tells the user Hits on this page: 1, and updates the with a new value: 1. Each program was perfectly following its own instructions, but together they managed to be wrong.I had tacitly assumed that this case, where two instances coincide, would never happen; but I never actually put anything in place to stop it from happening.
Or maybe Id assumed it could happen, but that the chances were astronomical.