~semi-hallikas/sspamm/3.0-devel

« back to all changes in this revision

Viewing changes to sspamm.py

  • Committer: Sami-Pekka Hallikas
  • Date: 2010-12-10 22:29:14 UTC
  • Revision ID: semi@hallikas.com-20101210222914-f2k7nn69n5spmrgy
Some bugs in last revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
462
462
def mkdir(path, id=None):
463
463
        debug("mkdir(\"%s\")" % (path), LOG_DEBUG, id=id)
464
464
        try:
465
 
                os.mkdir(path)
 
465
                os.makedirs(path, 0770)
466
466
        except OSError, (errno, strerror):
467
467
                if errno != 17: debug("%s" % sys.exc_value, LOG_ERR)
468
468
        except:
2166
2166
        logfile = None
2167
2167
 
2168
2168
        if childname: debug("Tlogger loop started", LOG_INFO)
2169
 
        while conf["runtime"]["endtime"] == 0 or len(loglines) > 0:
2170
 
                needflush = None
2171
 
                while len(loglines) > 0:
2172
 
                        line = loglines.pop(0)
2173
 
                        if line == "sighup":
2174
 
                                if logfile: logfile.close()
2175
 
                                if conf["main"]["logfile"]:
2176
 
                                        logpath=conf["main"]["logfile"][0:conf["main"]["logfile"].rfind("/")+1]
2177
 
                                        if not os.path.exists(logpath):
2178
 
                                                mkdir(logpath)
2179
 
                                        logfile = open(conf["main"]["logfile"], "a")
2180
 
                                        conf["runtime"]["logtime"] = os.stat(conf["main"]["logfile"])[8]
2181
 
                                continue
2182
 
                        if logfile: logfile.write(line+"\n")
2183
 
                        if conf["main"]["verbose"] == 7:
2184
 
                                print line
2185
 
                        needflush = True
2186
 
                if needflush:
2187
 
                        if logfile: logfile.flush()
2188
 
                        sys.stdout.flush()
2189
 
                if not childname: break
2190
 
                time.sleep(1)
2191
 
                try:
2192
 
                        if conf["runtime"]["logtime"] != os.stat(conf["main"]["logfile"])[8] and "sighup" not in loglines:
2193
 
                                loglines.append("sighup")
2194
 
                        if conf["main"]["logfile"]: conf["runtime"]["logtime"] = os.stat(conf["main"]["logfile"])[8]
2195
 
                except:
2196
 
                        if "sighup" not in loglines: loglines.append("sighup")
 
2169
        try:
 
2170
                while conf["runtime"]["endtime"] == 0 or len(loglines) > 0:
 
2171
                        needflush = None
 
2172
                        while len(loglines) > 0:
 
2173
                                line = loglines.pop(0)
 
2174
                                if line == "sighup":
 
2175
                                        if logfile: logfile.close()
 
2176
                                        if conf["main"]["logfile"]:
 
2177
                                                logpath=conf["main"]["logfile"][0:conf["main"]["logfile"].rfind("/")+1]
 
2178
                                                if not os.path.exists(logpath):
 
2179
                                                        mkdir(logpath)
 
2180
                                                logfile = open(conf["main"]["logfile"], "a")
 
2181
                                                conf["runtime"]["logtime"] = os.stat(conf["main"]["logfile"])[8]
 
2182
                                        continue
 
2183
                                if logfile: logfile.write(line+"\n")
 
2184
                                if conf["main"]["verbose"] == 7:
 
2185
                                        print line
 
2186
                                needflush = True
 
2187
                        if needflush:
 
2188
                                if logfile: logfile.flush()
 
2189
                                sys.stdout.flush()
 
2190
                        if not childname: break
 
2191
                        time.sleep(1)
 
2192
                        try:
 
2193
                                if conf["runtime"]["logtime"] != os.stat(conf["main"]["logfile"])[8] and "sighup" not in loglines:
 
2194
                                        loglines.append("sighup")
 
2195
                                if conf["main"]["logfile"]: conf["runtime"]["logtime"] = os.stat(conf["main"]["logfile"])[8]
 
2196
                        except:
 
2197
                                if "sighup" not in loglines: loglines.append("sighup")
2197
2198
 
2198
 
        if logfile: logfile.close()
2199
 
        if childname: debug("Logger thread quited", LOG_INFO)
 
2199
                if logfile: logfile.close()
 
2200
                if childname: debug("Logger thread quited", LOG_INFO)
 
2201
                return
 
2202
        except:
 
2203
                pass
 
2204
        debug("Logger thread quited", LOG_INFO)
2200
2205
        return
2201
2206
 
2202
2207
## Thread to keep CRC database clean