diff options
author | makefu <github@syntax-fehler.de> | 2011-09-14 17:30:24 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2011-09-14 17:30:24 +0200 |
commit | e087646763cefc3dae49530fba866aa2bb713f46 (patch) | |
tree | d855810d7a9093adc05ca10f7c8955e81b9f8d74 | |
parent | bf985820deacbe49d7328b51c9df8aa02a57b03e (diff) | |
parent | 6cb808fa910cb32a9ec786616be7b821a500e8d8 (diff) |
Merge branch 'master' of github.com:krebscode/painload
-rwxr-xr-x | Reaktor/IRC/asybot.py | 37 | ||||
-rw-r--r-- | hyper/process/Makefile | 14 | ||||
-rw-r--r-- | hyper/process/main.go | 52 |
3 files changed, 89 insertions, 14 deletions
diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py index 1a84b9d4..9021d22f 100755 --- a/Reaktor/IRC/asybot.py +++ b/Reaktor/IRC/asybot.py @@ -3,8 +3,6 @@ # //Reaktor/IRC/asybot.py # -from __future__ import print_function - def is_executable(x): import os return os.path.exists(x) and os.access(x, os.X_OK) @@ -16,6 +14,10 @@ from signal import SIGALRM, signal, alarm from datetime import datetime as date, timedelta from sys import exit from re import split, search + +import logging +log = logging.getLogger() + class asybot(asychat): def __init__(self, server, port, nickname, targets, **kwargs): asychat.__init__(self) @@ -41,7 +43,6 @@ class asybot(asychat): signal(SIGALRM, lambda signum, frame: self.alarm_handler()) self.reset_alarm() - loop() def reset_alarm(self): self.last_activity = date.now() @@ -50,10 +51,10 @@ class asybot(asychat): def alarm_handler(self): delta = date.now() - self.last_activity if delta > timedelta(seconds=self.kill_timeout): - print('No data for %s. Giving up...' % delta) + log.error('No data for %s. Giving up...' % delta) exit(2) else: - print('No data for %s. PINGing server...' % delta) + log.error('No data for %s. PINGing server...' % delta) self.push('PING :%s' % self.nickname) alarm(self.hammer_interval) @@ -61,7 +62,7 @@ class asybot(asychat): self.data += data def found_terminator(self): - print('< %s' % self.data) + log.debug('<< %s' % self.data) message = self.data self.data = '' @@ -73,6 +74,7 @@ class asybot(asychat): if command == 'PING': self.push('PONG :%s' % rest) + log.info("Replying to servers PING with PONG :%s" %rest) elif command == 'PRIVMSG': self.on_privmsg(prefix, command, params, rest) @@ -88,7 +90,7 @@ class asybot(asychat): self.reset_alarm() def push(self, message): - print('> %s' % message) + log.debug('>> %s' % message) asychat.push(self, message + self.get_terminator()) def handle_connect(self): @@ -99,7 +101,8 @@ class asybot(asychat): def on_privmsg(self, prefix, command, params, rest): def PRIVMSG(text): - self.push('PRIVMSG %s :%s' % (','.join(params), text)) + msg = 'PRIVMSG %s :%s' % (','.join(params), text) + self.push(msg) def ME(text): PRIVMSG('ACTION ' + text + '') @@ -132,8 +135,8 @@ class asybot(asychat): try: p = popen([command], stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) except OSError, error: - ME('is made of stupid') - print('OSError@%s: %s' % (command, error)) + ME('brain damaged') + log.error('OSError@%s: %s' % (command, error)) return stdout, stderr = [ x[:len(x)-1] for x in @@ -141,9 +144,9 @@ class asybot(asychat): code = p.returncode pid = p.pid - print('command: %s -> %s' % (command, code)) - [print('%s stdout: %s' % (pid, x)) for x in stdout] - [print('%s stderr: %s' % (pid, x)) for x in stderr] + log.info('command: %s -> %s' % (command, code)) + [log.debug('%s stdout: %s' % (pid, x)) for x in stdout] + [log.debug('%s stderr: %s' % (pid, x)) for x in stderr] if code == 0: [PRIVMSG(x) for x in stdout] @@ -154,6 +157,7 @@ class asybot(asychat): else: if _handle != '*': PRIVMSG(_from + ': you are made of stupid') + # retrieve the value of a [singleton] variable from a tinc.conf(5)-like file def getconf1(x, path): @@ -170,15 +174,20 @@ def getconf1(x, path): if __name__ == "__main__": from os import environ as env + + lol = logging.DEBUG if env.get('debug',False) else logging.INFO + logging.basicConfig(level=lol) name = getconf1('Name', '/etc/tinc/retiolum/tinc.conf') hostname = '%s.retiolum' % name nick = str(env.get('nick', name)) host = str(env.get('host', 'supernode')) port = int(env.get('port', 6667)) target = str(env.get('target', '#retiolum')) - print('====> irc://%s@%s:%s/%s' % (nick, host, port, target)) + log.info('=> irc://%s@%s:%s/%s' % (nick, host, port, target)) from getpass import getuser asybot(host, port, nick, [target], username=getuser(), ircname='//Reaktor running at %s' % hostname, hostname=hostname) + + loop() diff --git a/hyper/process/Makefile b/hyper/process/Makefile new file mode 100644 index 00000000..7d61b28d --- /dev/null +++ b/hyper/process/Makefile @@ -0,0 +1,14 @@ + +A := 8 + +.PHONY: all clean +all: main + +clean: + rm -f main *.$A + +%.$A: %.go + $Ag $< + +%: %.$A + $Al -o $@ $< diff --git a/hyper/process/main.go b/hyper/process/main.go new file mode 100644 index 00000000..297be2cf --- /dev/null +++ b/hyper/process/main.go @@ -0,0 +1,52 @@ +package main + +import "fmt" +import "os" + + +func reader(file *os.File) { + var b []byte = make([]byte, 1024) + var err os.Error = nil + for err == nil { + var n int + n, err = file.Read(b) + fmt.Printf("data: %d, %s\n", n, b) + } +} + +func main() { + var name = "/usr/bin/bc" + var argv = []string{ "bc" } + var envv = []string{ "FOO=23" } + //var chroot = false + var dir = "/var/empty" + var files [3][2]*os.File + var err os.Error + + for i, _ := range files { + files[i][0], files[i][1], err = os.Pipe() + err = err + } + + var attr = &os.ProcAttr{ + Dir: dir, + Env: envv, + Files: []*os.File{ /*files[0][0] */ os.Stdin, files[1][1], files[2][1]}, + } + + var p *os.Process + + p, err = os.StartProcess(name, argv, attr) + + for _, file := range attr.Files { + file.Close() + } + + p=p + + go reader(files[1][0]) + reader(files[2][0]) + + fmt.Printf("hello, world\n") + +} |