sysupgrade: run only one instance at a time.
authorKenneth Johansson <kenneth.johansson@inteno.se>
Wed, 24 May 2017 11:45:37 +0000 (13:45 +0200)
committerJohn Crispin <john@phrozen.org>
Thu, 25 May 2017 07:22:43 +0000 (09:22 +0200)
Things do not work well if running multiple instances of
upgrade at the same time.

Signed-off-by: Kenneth Johansson <kenneth.johansson@inteno.se>
package/base-files/files/sbin/sysupgrade

index c095ca81c50c71021af2dc04a561ac22f6b7442b..1eede14b05d2409308d47bb9304219de84ec0808 100755 (executable)
@@ -47,6 +47,20 @@ while [ -n "$1" ]; do
        shift;
 done
 
+# just one instance
+if  ! lock -n /tmp/sysupgrade.lock
+then
+       echo "Another instance of sysupgrade already running"
+       echo "If you are sure this is wrong remove file /tmp/sysupgrade.lock"
+       exit 1
+fi
+
+# make sure the lock is removed when done even when killed
+finish() {
+       lock -u /var/sysupgrade.lock
+}
+trap finish EXIT INT TERM
+
 export CONFFILES=/tmp/sysupgrade.conffiles
 export CONF_TAR=/tmp/sysupgrade.tgz