View | Details | Raw Unified | Return to bug 41335 | Differences between
and this patch

Collapse All | Expand All

(-)a/services/univention-ad-connector/modules/univention/connector/ad/main.py (-3 / +20 lines)
 Lines 34-39    Link Here 
34
34
35
import sys
35
import sys
36
import string
36
import string
37
import fcntl
37
import os
38
import os
38
import time
39
import time
39
import signal
40
import signal
 Lines 66-72   sys.path = ['/etc/univention/%s/ad/' % CONFIGBASENAME] + sys.path Link Here 
66
import mapping
67
import mapping
67
68
68
69
69
def daemon():
70
def daemon(lock_file):
70
	try:
71
	try:
71
		pid = os.fork()
72
		pid = os.fork()
72
	except OSError, e:
73
	except OSError, e:
 Lines 96-101   def daemon(): Link Here 
96
		maxfd = 256       # default maximum
97
		maxfd = 256       # default maximum
97
98
98
	for fd in range(0, maxfd):
99
	for fd in range(0, maxfd):
100
		if fd == lock_file.fileno():
101
			continue
99
		try:
102
		try:
100
			os.close(fd)
103
			os.close(fd)
101
		except OSError:   # ERROR (ignore)
104
		except OSError:   # ERROR (ignore)
 Lines 284-297   def connect(): Link Here 
284
	ad.close_debug()
287
	ad.close_debug()
285
288
286
289
290
def lock(filename):
291
	lock_file = open(filename, "a+")
292
	fcntl.flock(lock_file.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
293
	return lock_file
294
295
287
def main():
296
def main():
288
297
289
	daemon()
298
	try:
299
		lock_file = lock('/var/lock/univention-ad-%s' % CONFIGBASENAME)
300
	except IOError:
301
		print >> sys.stderr, 'Error: Another AD connector process is already running.'
302
		sys.exit(1)
303
304
	daemon(lock_file)
290
305
291
	while True:
306
	while True:
292
		try:
307
		try:
293
			connect()
308
			connect()
294
		except SystemExit:
309
		except SystemExit:
310
			lock_file.close()
295
			raise
311
			raise
296
		except:
312
		except:
297
			f = open(STATUSLOGFILE, 'w+')
313
			f = open(STATUSLOGFILE, 'w+')
 Lines 312-317   def main(): Link Here 
312
328
313
			f.close()
329
			f.close()
314
330
331
	lock_file.close()
332
315
333
316
if __name__ == "__main__":
334
if __name__ == "__main__":
317
	main()
335
	main()
318
- 

Return to bug 41335