Update of /cvsroot/ipcop/ipcop/src/rpc2 In directory usw-pr-cvs1:/tmp/cvs-serv27366/src/rpc2 Added Files: ipcopstatus.py ipcopsystem.py xmlrpcd.py Removed Files: Makefile functions.c rpc2.c rpc2.h status.c sysmodules.c sysreboot.c system.c Log Message: Major changes: lfs 3.2, python --- NEW FILE: ipcopstatus.py --- import os def uptime (): uptime = os.popen ('uptime').readline () return uptime def connection (): return def disk (): return _exec_array('df -k') def memory (): return _exec_array('free') def uname (): return _exec_scalar('uname -a') def users (): return _exec_array('who') def _exec_scalar (command): return os.popen (command).readline () def _exec_array (command): return os.popen(command).readlines() --- NEW FILE: ipcopsystem.py --- import os def reboot (): # no implementation for obvious reasons ;) return 'Rebooting' def shutdown (): # again, no implementation return 'Shutting down' def language (): # ? return 'English' def version (): return '0.0.1' --- NEW FILE: xmlrpcd.py --- #!/usr/bin/python -O import sys, os, string, signal, errno, SimpleXMLRPCServer class IPCOP: def __init__(self): # Make all of the Python string functions available through # python_string.func_name import ipcopsystem, ipcopstatus self.ipcopsystem = ipcopsystem self.status = ipcopstatus #============================================================================# # ----- Signal Handlers ---------------------------------------------------- # #----------------------------------------------------------------------------# #============================================================================# # terminate() - Signal handler that is called on SIGTERM # #----------------------------------------------------------------------------# def terminate(signal, param): try: # Remove the pid file os.remove('/var/run/xmlrpc.pid') except: pass # Ignore any errors sys.exit(0) #============================================================================# # Check to see if no old proccess exists # #----------------------------------------------------------------------------# # Check, if there is already a running instance if os.path.isfile('/var/run/xmlrpc.pid'): f = open('/var/run/xmlrpc.pid', 'r') pid = string.atoi(string.strip(f.readline())) f.close() try: os.kill(pid, 0) except os.error, args: if args[0] != errno.ESRCH: # NO SUCH PROCESS raise os.error, args else: sys.stderr.write("xmlrpc: there is already a running instance\n") sys.exit(1) #============================================================================# # Initialize a daemon process # #----------------------------------------------------------------------------# if os.getppid() != 1: # Ignore a terminal output signal signal.signal(signal.SIGTTOU, signal.SIG_IGN) # Ignore a terminal input signal signal.signal(signal.SIGTTIN, signal.SIG_IGN) # Ignore a terminal stop signal signal.signal(signal.SIGTSTP, signal.SIG_IGN) # Fork the first child pid = os.fork() # The parent ends here if pid > 0: sys.exit(0) # Make ourself a leader of the process group os.setpgrp() # Ignore a hangup signal signal.signal(signal.SIGHUP, signal.SIG_IGN) # Fork the second child pid = os.fork() # The parent ends here if pid > 0: sys.exit(0) # Close sys.stdin sys.stdin.close() # Close sys.stdout and redirect the message log to sys.stdout sys.stdout.close() # Close sys.stderr and redirect the error log to sys.stderr sys.stderr.close() # Reset the umask os.umask(022) # Ignore a dead of child signal signal.signal(signal.SIGCLD, signal.SIG_IGN) # Install a hander for ther terminate signal signal.signal(signal.SIGTERM, terminate) # Install a handler for the interrupt signal signal.signal(signal.SIGINT, terminate) # Install a handler for the quit signal signal.signal(signal.SIGQUIT, terminate) # Write our process id into the pid file f = open('/var/run/xmlrpc.pid', 'w') f.write("%d" % os.getpid()) f.close() #============================================================================# # Do the real work # #----------------------------------------------------------------------------# server = SimpleXMLRPCServer.SimpleXMLRPCServer(("IN_ADDR_ANY", 445)) server.register_instance(IPCOP()) while (1): server.handle_request() #============================================================================# # EOF # #----------------------------------------------------------------------------# --- Makefile DELETED --- --- functions.c DELETED --- --- rpc2.c DELETED --- --- rpc2.h DELETED --- --- status.c DELETED --- --- sysmodules.c DELETED --- --- sysreboot.c DELETED --- --- system.c DELETED --- |