OSDN Git Service

Limitation of number of jobs on queue
authorniwa-hideyuki <niwa.hideyuki@jp.fujitsu.com>
Thu, 15 May 2014 07:52:45 +0000 (16:52 +0900)
committerniwa-hideyuki <niwa.hideyuki@jp.fujitsu.com>
Thu, 15 May 2014 07:52:45 +0000 (16:52 +0900)
lxcf/lib/lxcf-submit

index 4bfaaa9..d56def0 100755 (executable)
@@ -30,17 +30,38 @@ import fcntl
 import uuid
 import time
 
+
 MAXBUF = 4096-1
 
 # LOGFILE
 LOGFILE = '/var/log/lxcf/lxcf-messages'
 
 # QUEUE FILE
+MAXQNUM = 100
 QDIR = '/var/tmp/lxcf'
 HQFILE = '/var/tmp/lxcf/hqueue'
 QQFILE = '/var/tmp/lxcf/qqueue'
 LQFILE = '/var/tmp/lxcf/lqueue'
 
+# word count
+def wc(filename):
+    try:
+        f = open(filename, "r")
+    except:
+        return 0
+
+    fcntl.flock(f.fileno(), fcntl.LOCK_EX)
+
+    Lines = f.readlines()
+    num = len(Lines)
+
+    # unlock hosts file
+    fcntl.flock(f.fileno(), fcntl.LOCK_UN)
+
+    f.close()
+
+    return num
+
 # check root
 if os.geteuid() != 0:
     print "error: Because you are not root, you cannot execute this command. "
@@ -74,6 +95,12 @@ if QCMD.find(";") >= 0 or QCMD.find("&") >= 0 or QCMD.find("`") >= 0 or \
     print "error: The character not permitted was used (;&`$|). "
     quit()
 
+qnum = wc(HQFILE) + wc(QQFILE) + wc(LQFILE)
+
+if qnum > MAXQNUM:
+    print "error: There are a lot of jobs on queue(>",MAXQNUM,")"
+    quit()
+
 t = time.asctime()
 
 UUID = str(uuid.uuid1())