]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.8.x' of jill@xmpp001.controlezvous.ca:/opt/local/share/laconica into...
authorEvan Prodromou <evan@controlyourself.ca>
Sun, 28 Jun 2009 20:20:58 +0000 (16:20 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Sun, 28 Jun 2009 20:20:58 +0000 (16:20 -0400)
lib/daemon.php
lib/queuehandler.php
scripts/commandline.inc
scripts/xmppdaemon.php

index a0df00bdcc852cc434f025ed6f062aa4496a653d..72e8bc20286a7a97ebe62f03088a4912a957082c 100644 (file)
@@ -23,6 +23,13 @@ if (!defined('LACONICA')) {
 
 class Daemon
 {
+    var $daemonize = true;
+
+    function __construct($daemonize = true)
+    {
+        $this->daemonize = $daemonize;
+    }
+
     function name()
     {
         return null;
@@ -129,12 +136,15 @@ class Daemon
             common_log(LOG_INFO, $this->name() . ' already running. Exiting.');
             exit(0);
         }
-        if ($this->background()) {
-            $this->writePidFile();
-            $this->changeUser();
-            $this->run();
-            $this->clearPidFile();
+
+        if ($this->daemonize) {
+            $this->background();
         }
+
+        $this->writePidFile();
+        $this->changeUser();
+        $this->run();
+        $this->clearPidFile();
     }
 
     function run()
index ae403c65e24f815f4f38b56b9ec081e760092074..c1c4f3309a24011b60e72de070a5fcef0267ad56 100644 (file)
@@ -27,11 +27,12 @@ require_once(INSTALLDIR.'/classes/Notice.php');
 
 class QueueHandler extends Daemon
 {
-
     var $_id = 'generic';
 
-    function QueueHandler($id=null)
+    function __construct($id=null, $daemonize=true)
     {
+        parent::__construct($daemonize);
+
         if ($id) {
             $this->set_id($id);
         }
index 53b9a490bc1cc89ca9348e1133eb273d1b37394e..9c6787cb7a299e03c9aac6fbec035e661184c5d2 100644 (file)
@@ -122,24 +122,60 @@ require_once INSTALLDIR . '/lib/common.php';
 
 set_error_handler('common_error_handler');
 
-function have_option($str)
+function have_option($opt, $alt=null)
 {
    global $options;
+
+   $matches = array($opt);
+
+   if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
+      $matches[] = '--'.$opt;
+   } else {
+      $matches[] = $opt;
+   }
+
+   if (!empty($alt)) {
+       if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
+           $matches[] = '--'.$alt;
+       } else {
+           $matches[] = $alt;
+       }
+   }
+
    foreach ($options as $option) {
-       if ($option[0] == $str) {
+       if (in_array($option[0], $matches)) {
           return true;
        }
    }
+
    return false;
 }
 
-function get_option_value($str)
+function get_option_value($str, $alt=null)
 {
    global $options;
+
+   $matches = array();
+
+   if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
+      $matches[] = '--'.$opt;
+   } else {
+      $matches[] = $opt;
+   }
+
+   if (!empty($alt)) {
+       if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
+           $matches[] = '--'.$alt;
+       } else {
+           $matches[] = $alt;
+       }
+   }
+
    foreach ($options as $option) {
-       if ($option[0] == $str) {
+       if (in_array($option[0], $matches)) {
           return $option[1];
        }
    }
+
    return null;
 }
\ No newline at end of file
index 3eecfec29a13725aa46684428b30dc1d301b3052..38d739e680053f728c2b65a5c9b5b594eb525178 100755 (executable)
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
-$shortoptions = 'i::';
-$longoptions = array('id::');
+$shortoptions = 'fi::';
+$longoptions = array('id::', 'foreground');
 
 $helptext = <<<END_OF_XMPP_HELP
 Daemon script for receiving new notices from Jabber users.
 
     -i --id           Identity (default none)
+    -f --foreground   Stay in the foreground (default background)
 
 END_OF_XMPP_HELP;
 
@@ -42,8 +43,10 @@ require_once INSTALLDIR . '/lib/daemon.php';
 
 class XMPPDaemon extends Daemon
 {
-    function XMPPDaemon($resource=null)
+    function XMPPDaemon($resource=null, $daemonize=true)
     {
+        parent::__construct($daemonize);
+
         static $attrs = array('server', 'port', 'user', 'password', 'host');
 
         foreach ($attrs as $attr)
@@ -62,7 +65,6 @@ class XMPPDaemon extends Daemon
 
     function connect()
     {
-
         $connect_to = ($this->host) ? $this->host : $this->server;
 
         $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port");
@@ -323,16 +325,16 @@ if (common_config('xmpp','enabled')==false) {
     exit();
 }
 
-if (have_option('i')) {
-    $id = get_option_value('i');
-} else if (have_option('--id')) {
-    $id = get_option_value('--id');
+if (have_option('i', 'id')) {
+    $id = get_option_value('i', 'id');
 } else if (count($args) > 0) {
     $id = $args[0];
 } else {
     $id = null;
 }
 
-$daemon = new XMPPDaemon($id);
+$foreground = have_option('f', 'foreground');
+
+$daemon = new XMPPDaemon($id, $foreground);
 
 $daemon->runOnce();