.PHONY: all install uninstall local install-local clean
-all: e2generic_global.lc luafile_ll_global.so e2util_global.so e2-su-2.2
+all: e2generic_global.lc luafile_ll_global.so e2util_global.so e2-su-2.2 \
+ lock.lc
install: all
install -m 644 e2generic_global.lc $(DESTDIR)$(LIBDIR)
+ install -m 644 lock.lc $(DESTDIR)$(LIBDIR)
install -m 755 luafile_ll_global.so $(DESTDIR)$(LIBDIR)
install -m 755 e2util_global.so $(DESTDIR)$(LIBDIR)
install -m 4754 -o root -g $(E2_GROUP) e2-su-2.2 $(DESTDIR)$(BINDIR)/
uninstall:
rm -f $(DESTDIR)$(BINDIR)/e2-su-2.2
rm -f $(DESTDIR)$(LIBDIR)/e2generic_global.lc
+ rm -f $(DESTDIR)$(LIBDIR)/lock.lc
rm -f $(DESTDIR)$(LIBDIR)/luafile_ll_global.so
rm -f $(DESTDIR)$(LIBDIR)/e2util_global.so
-local: e2generic_local.lc luafile_ll_local.so e2util_local.so
+local: e2generic_local.lc luafile_ll_local.so e2util_local.so lock.lc
install-local: local
mkdir -p $(LOCALLIBDIR) $(LOCALMAKDIR)
install -m 644 e2generic_local.lc $(LOCALLIBDIR)
+ install -m 644 lock.lc $(LOCALLIBDIR)
install -m 755 luafile_ll_local.so $(LOCALLIBDIR)
install -m 755 e2util_local.so $(LOCALLIBDIR)
install -m 644 e2-su-2.2.c $(LOCALMAKDIR)
%: %.in
$(TOPLEVEL)/scripts/genscript.sh $< $@
+%.lc: %.lua
+ $(LUAC) -o $@ $<
+
e2-su-2.2: e2-su-2.2.c
$(CC) $(CFLAGS) $(E2_SU_CFLAGS) $(LDFLAGS) $< -o $@
]]
require("buildconfig")
+require("lock")
+
_version = "e2factory, the emlix embedded build system, version " ..
buildconfig.VERSION
buildnumber_server_url = nil,
template_path = string.format("%s/templates", buildconfig.SYSCONFDIR),
extension_config = ".e2/extensions",
+ lock = nil,
}
-- Interrupt handling
if not e2lib.hostname then
e2lib.abort("hostname ist not set")
end
+
+ e2lib.lock = lock.new()
end
function e2lib.init2()
end
e2lib.rmtempdirs()
e2lib.rmtempfiles()
+ e2lib.lock:cleanup()
os.exit(1)
end
end
e2lib.rmtempdirs()
e2lib.rmtempfiles()
+ e2lib.lock:cleanup()
os.exit(rc)
end
--- /dev/null
+module("lock",package.seeall)
+
+function new()
+ local lock = {
+
+ locks = {},
+
+ lock = function(l, dir)
+ local e = new_error("locking failed")
+ rc, re = e2lib.mkdir(dir)
+ if not rc then
+ return false, e:cat(re)
+ end
+ table.insert(l.locks, dir)
+ return true
+ end,
+
+ unlock = function(l, dir)
+ local e = new_error("unlocking failed")
+ for i,x in ipairs(l.locks) do
+ if dir == x then
+ table.remove(l.locks, i)
+ rc, re = e2lib.rmdir(dir)
+ if not rc then
+ return false, e:cat(re)
+ end
+ end
+ end
+ return true, nil
+ end,
+
+ cleanup = function(l)
+ while #l.locks > 0 do
+ l:unlock(l.locks[1])
+ end
+ end,
+ }
+
+ return lock
+end
+
+--[[
+local test=false
+if test then
+ -- some dummy functions to test without context...
+ function new_error(x)
+ return true
+ end
+ e2lib = {}
+ e2lib.mkdir = function(x)
+ print("mkdir " .. x)
+ return true
+ end
+ e2lib.rmdir = function(x)
+ print("rmdir " .. x)
+ return true
+ end
+
+ l = new()
+
+ l:lock("/tmp/foo1")
+ l:lock("/tmp/foo2")
+ l:lock("/tmp/foo3")
+ l:unlock("/tmp/foo2")
+ l:cleanup()
+end
+]]