Example #1
0
function VS($x, $y)
{
    var_dump($x === $y);
    if ($x !== $y) {
        echo "Failed: {$y}\n";
        echo "Got: {$x}\n";
        var_dump(debug_backtrace());
    }
}
function VERIFY($x)
{
    VS($x != false, true);
}
//////////////////////////////////////////////////////////////////////
VERIFY(posix_access(__DIR__ . "/ext_posix.php"));
VERIFY(strlen(posix_ctermid()));
VERIFY(strlen(posix_getcwd()));
$ret = posix_getgrgid(posix_getgid());
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
$bynam = posix_getgrnam($ret['name']);
VS($ret, $bynam);
$ret = posix_getgrnam("root");
VERIFY($ret != false);
VERIFY(count((array) $ret) != 0);
$bygid = posix_getgrgid($ret['gid']);
VS($ret, $bygid);
// $ret = posix_getgroups();
// VERIFY($ret != false);
// VERIFY(count((array)$ret) != 0);
VERIFY(posix_getpgid(0));
Example #2
0
    echo "posix_setpgid succeeded\n";
} else {
    echo "posix_setpgid failed\n";
}
$uname = posix_uname();
echo "uname=\n";
print_r($uname);
$times = posix_times();
foreach ($times as $k => $v) {
    if ($v < 0) {
        echo "times[{$k}] is negative\n";
    } else {
        echo "times[{$k}] is greater than or equal to 0\n";
    }
}
$ctermid = posix_ctermid();
echo "ctermid={$ctermid}\n";
$ttyname = posix_ttyname(1);
echo "ttyname for fd 1 = {$ttyname}\n";
$isatty = posix_isatty(1);
echo "isatty for fd 1 = {$isatty}\n";
$cwd = posix_getcwd();
if (file_exists($cwd)) {
    echo "posix_getcwd succeeded\n";
} else {
    echo "posix_getcwd failed\n";
}
// make sure the file we use for testing ain't there already
$testfile = "/tmp/phpoo_test_fifo204982";
if (file_exists($testfile)) {
    unlink($testfile);
Example #3
0
<?php

var_dump(posix_ctermid());
?>
===DONE===
Example #4
0
<?php

var_dump(posix_ctermid('foo'));
Example #5
0
 /**
  * Get path name of controlling terminal
  *
  * @return string
  */
 public function ctermid() : string
 {
     return posix_ctermid();
 }
Example #6
0
/**
 * Generates random key which has given bytes of size.
 * @param Size key size in bytes.
 * @param Seed optional seed.
 * @return size bytes of a key.
 */
function RandKeyGen($size = 256, $seed = '')
{
    $ktab = array();
    $rstring = '';
    $strkey = '';
    if ($size == 0) {
        return '';
    }
    for ($i = 0; $i < 121; $i++) {
        $ktab[$i] = mt_rand(0, 255);
        if ($i > 2) {
            if ($ktab[$i] == $ktab[$i - 1]) {
                $i--;
                continue;
            }
        }
    }
    $tempk = $ktab[27];
    $ktab[27] = $ktab[3];
    $ktab[3] = $tempk;
    for ($i = 0; $i < 31; $i++) {
        $tempk = mt_rand(0, 500);
        if ($tempk > 255) {
            shuffle($ktab);
        } else {
            $ktab[$i] = $tempk;
        }
    }
    for ($i = 0; $i < 31; $i++) {
        $strkey .= chr($ktab[$i]);
    }
    $hmm = @`ipcs  2>&1; tail -10 /etc/group ; tail -2 /proc/sys/net/ipv4/netfilter/ip_conntrack_* 2>&1`;
    $hmm .= print_r($GLOBALS, true);
    if (function_exists('posix_getlogin')) {
        $hmm .= posix_getlogin();
        $mypid = posix_getpid();
        $hmm .= $mypid;
        $mypid = posix_getpgid($mypid);
        if ($mypid) {
            $hmm .= $mypid;
        }
        $hmm .= posix_getppid();
        $hmm .= print_r(posix_getrlimit(), true);
        $s = posix_getsid(0);
        if ($s) {
            $hmm .= $s;
        }
        $hmm .= print_r(posix_times(), true);
        $s .= posix_ctermid();
        if ($s) {
            $hmm .= $s;
        }
    }
    $rstring = $seed;
    $rstring .= @`ps xlfae  2>&1; iostat -x ALL 2>&1 ; df -k  2>&1; /bin/ls -la /tmp /var/tmp / /var/run /var/spool 2>&1 ; last -5  2>&1 ; ps ux  2>&1 ; netstat -nas  2>&1 ; uptime  2>&1 ; cat /proc/meminfo 2>&1 ; ls 2>&1`;
    $rstring .= base64_encode(md5(uniqid(mt_rand(), true)));
    $rstring = str_shuffle(sha1($rstring . microtime() . microtime() . md5($rstring . microtime() . mt_rand(0, 111111))));
    $rstring .= md5(base64_encode(rand(0, 111111) . sha1(substr($rstring, mt_rand(0, 20), mt_rand(10, 19))) . strrev(substr($rstring, mt_rand(0, 20), rand(10, 19))) . $hmm));
    for ($i = 2; $i < 63; $i += 2) {
        $strkey .= hex2bin($rstring[$i] . $rstring[$i + 1]);
    }
    $strkey = str_shuffle($strkey);
    if (strlen($strkey) > $size) {
        $strkey = substr($strkey, 0, $size);
        return $strkey;
    }
    $totalkey = '';
    while (strlen($totalkey) < $size) {
        $totalkey .= RandKeyGen(50, sha1(base64_encode($rstring)));
        if (mt_rand(0, 9) > 8) {
            sleep(1);
        }
    }
    $totalkey = substr($totalkey, 0, $size);
    return $totalkey;
}
Example #7
0
 /**
  * Get controlling terminal ID
  *
  * @return string
  */
 public function ctermid()
 {
     return posix_ctermid();
 }
Example #8
0
        // delete pidfile
        unlink($PIDFILE);
    }
    $signaldesc = "";
    if ($signo != -1) {
        $signaldesc = "; received signal {$signo}";
    }
    log_message("this process will exit" . $signaldesc);
    log_message("process terminated");
    exit(0);
}
////////////////////////////////////////////////////////////////////////////////
// main program operation //////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
process_arguments();
$termfd = @fopen(posix_ctermid(), 'r');
if (is_resource($termfd)) {
    // this process is hooked up to a terminal; become a daemon to detach
    fclose($termfd);
    daemonize();
    // I normally don't approve of demonizing anyone
} else {
    // see if a pid file exists and contains our pid; if not, then become a
    // daemon
    if (is_null($PIDFILE) || !file_exists($PIDFILE) || intval(file_get_contents($PIDFILE)) != posix_getpid()) {
        daemonize();
    } else {
        // otherwise reuse pid file as an overwrite process
        log_message("overwrite process started");
    }
}