IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Explorar el Código

Locking for entire focker by default.

master
Stanislaw Adaszewski hace 4 años
padre
commit
d6e85d675b
Se han modificado 3 ficheros con 24 adiciones y 14 borrados
  1. +2
    -0
      focker/focker.py
  2. +3
    -14
      focker/jail.py
  3. +19
    -0
      focker/misc.py

+ 2
- 0
focker/focker.py Ver fichero

@@ -38,6 +38,7 @@ from .compose import \
command_compose_build, \
command_compose_run
from .bootstrap import command_bootstrap
from .misc import focker_lock
class ListForwarderFunctor(object):
@@ -203,6 +204,7 @@ def create_parser():
def main():
focker_lock()
zfs_init()
parser = create_parser()
args = parser.parse_args()


+ 3
- 14
focker/jail.py Ver fichero

@@ -15,8 +15,6 @@ import os
import jailconf
from .mount import getmntinfo
import shlex
import fcntl
# import pdb
import stat
@@ -38,18 +36,9 @@ def backup_file(fname, nbackups=10):
def jail_conf_write(conf):
os.makedirs('/var/lock', exist_ok=True)
with open('/var/lock/focker.lock', 'a+') as f:
print('Waiting for /var/lock/focker.lock ...')
fcntl.flock(f, fcntl.LOCK_EX)
print('Lock acquired')
try:
bakname = backup_file('/etc/jail.conf')
os.chmod(bakname, 0o600)
conf.write('/etc/jail.conf')
finally:
fcntl.flock(f, fcntl.LOCK_UN)
print('Lock released')
bakname = backup_file('/etc/jail.conf')
os.chmod(bakname, 0o600)
conf.write('/etc/jail.conf')
def jail_fs_create(image=None):


+ 19
- 0
focker/misc.py Ver fichero

@@ -7,6 +7,8 @@
import random
from .zfs import zfs_exists
import os
import fcntl
def random_sha256_hexdigest():
@@ -19,3 +21,20 @@ def find_prefix(head, tail):
if not zfs_exists(name):
break
return name
def focker_lock():
os.makedirs('/var/lock', exist_ok=True)
if focker_lock.fd is None:
focker_lock.fd = open('/var/lock/focker.lock', 'a+')
print('Waiting for /var/lock/focker.lock ...')
fcntl.flock(focker_lock.fd, fcntl.LOCK_EX)
print('Lock acquired.')
focker_lock.fd = None
def focker_unlock():
if focker_lock.fd is None:
return
fcntl.flock(focker_lock.fd, fcntl.LOCK_UN)
print('Lock released')

Cargando…
Cancelar
Guardar