File inc/git.inc.php changed (mode: 100644) (index 9b4fe90..4053b28) |
... |
... |
$rg_git_debug = 0; |
11 |
11 |
$rg_git_zero = "0000000000000000000000000000000000000000"; |
$rg_git_zero = "0000000000000000000000000000000000000000"; |
12 |
12 |
$rg_git_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
$rg_git_empty = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"; |
13 |
13 |
define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10))); |
define('GIT_LINK_MASK', intval(base_convert('160000', 8, 10))); |
|
14 |
|
define('RG_GIT_HASH_LEN', 10); |
14 |
15 |
|
|
15 |
16 |
define ('RG_GIT_CMD', 'git -c gc.auto=0'); |
define ('RG_GIT_CMD', 'git -c gc.auto=0'); |
16 |
17 |
|
|
|
... |
... |
function rg_git_lock($repo_path, $timeout) |
52 |
53 |
|
|
53 |
54 |
$ret = FALSE; |
$ret = FALSE; |
54 |
55 |
while (1) { |
while (1) { |
55 |
|
$f = @fopen($repo_path . '/rg_lock', 'w'); |
|
|
56 |
|
$f = @fopen($repo_path . '/rocketgit/rg_lock', 'w'); |
56 |
57 |
if ($f === FALSE) { |
if ($f === FALSE) { |
57 |
58 |
rg_git_set_error('cannot lock repo (open)'); |
rg_git_set_error('cannot lock repo (open)'); |
58 |
59 |
break; |
break; |
|
... |
... |
function rg_git_init($dst) |
309 |
310 |
if (!is_dir($dst . "/rocketgit")) { |
if (!is_dir($dst . "/rocketgit")) { |
310 |
311 |
$dst2 = $dst . '.tmp'; |
$dst2 = $dst . '.tmp'; |
311 |
312 |
$cmd = RG_GIT_CMD . ' init --bare ' . escapeshellarg($dst2); |
$cmd = RG_GIT_CMD . ' init --bare ' . escapeshellarg($dst2); |
312 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
313 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
313 |
314 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
314 |
315 |
rg_git_set_error("error on init " . $a['errmsg'] . ")"); |
rg_git_set_error("error on init " . $a['errmsg'] . ")"); |
315 |
316 |
break; |
break; |
|
... |
... |
function rg_git_clone($src, $dst) |
360 |
361 |
if (!file_exists($dst . "/rocketgit")) { |
if (!file_exists($dst . "/rocketgit")) { |
361 |
362 |
$cmd = RG_GIT_CMD . "clone --bare " . escapeshellarg($src) |
$cmd = RG_GIT_CMD . "clone --bare " . escapeshellarg($src) |
362 |
363 |
. " " . escapeshellarg($dst); |
. " " . escapeshellarg($dst); |
363 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
364 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
364 |
365 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
365 |
366 |
rg_git_set_error("error on clone (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on clone (" . $a['errmsg'] . ")"); |
366 |
367 |
break; |
break; |
|
... |
... |
function rg_git_type($obj) |
402 |
403 |
} |
} |
403 |
404 |
|
|
404 |
405 |
$cmd = RG_GIT_CMD . ' cat-file -t ' . escapeshellarg($obj); |
$cmd = RG_GIT_CMD . ' cat-file -t ' . escapeshellarg($obj); |
405 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
406 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
406 |
407 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
407 |
408 |
rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); |
rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); |
408 |
409 |
break; |
break; |
|
... |
... |
function rg_git_content($obj) |
428 |
429 |
$ret = FALSE; |
$ret = FALSE; |
429 |
430 |
while (1) { |
while (1) { |
430 |
431 |
$cmd = RG_GIT_CMD . ' cat-file -p ' . escapeshellarg($obj); |
$cmd = RG_GIT_CMD . ' cat-file -p ' . escapeshellarg($obj); |
431 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
432 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
432 |
433 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
433 |
434 |
rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); |
rg_git_set_error('error on cat-file (' . $a['errmsg'] . ')'); |
434 |
435 |
break; |
break; |
|
... |
... |
function rg_git_rev_ok($rev) |
505 |
506 |
$ret = FALSE; |
$ret = FALSE; |
506 |
507 |
while (1) { |
while (1) { |
507 |
508 |
$cmd = RG_GIT_CMD . ' rev-parse --verify ' . escapeshellarg($rev); |
$cmd = RG_GIT_CMD . ' rev-parse --verify ' . escapeshellarg($rev); |
508 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
509 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
509 |
510 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
510 |
511 |
rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")"); |
511 |
512 |
break; |
break; |
|
... |
... |
function rg_git_whitespace_ok($old, $new) |
540 |
541 |
$cmd = RG_GIT_CMD . " diff --check" |
$cmd = RG_GIT_CMD . " diff --check" |
541 |
542 |
. " " . escapeshellarg($old) |
. " " . escapeshellarg($old) |
542 |
543 |
. " " . escapeshellarg($new); |
. " " . escapeshellarg($new); |
543 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
544 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
544 |
545 |
rg_log("a:" . rg_array2string($a)); |
rg_log("a:" . rg_array2string($a)); |
545 |
546 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
546 |
547 |
rg_git_set_error("error on diff (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on diff (" . $a['errmsg'] . ")"); |
|
... |
... |
function rg_git_merge_base($repo_path, $a, $b) |
604 |
605 |
if ($head === FALSE) |
if ($head === FALSE) |
605 |
606 |
break; |
break; |
606 |
607 |
|
|
|
608 |
|
// TODO: why do we use escape here?! |
607 |
609 |
$key = 'git' |
$key = 'git' |
608 |
610 |
. '::' . sha1($repo_path) |
. '::' . sha1($repo_path) |
609 |
611 |
. '::' . 'merge-base' |
. '::' . 'merge-base' |
|
... |
... |
function rg_git_merge_base($repo_path, $a, $b) |
621 |
623 |
. ' merge-base' |
. ' merge-base' |
622 |
624 |
. ' ' . escapeshellarg($a) |
. ' ' . escapeshellarg($a) |
623 |
625 |
. ' ' . escapeshellarg($b); |
. ' ' . escapeshellarg($b); |
624 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
626 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
625 |
627 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
626 |
628 |
rg_git_set_error('error on git merge_base (' |
rg_git_set_error('error on git merge_base (' |
627 |
629 |
. $a['errmsg'] . ')'); |
. $a['errmsg'] . ')'); |
|
... |
... |
function rg_git_update_ref($repo_path, $ref, $old, $new, $reason) |
672 |
674 |
if (!empty($old)) |
if (!empty($old)) |
673 |
675 |
$cmd .= " " . escapeshellarg($old); |
$cmd .= " " . escapeshellarg($old); |
674 |
676 |
|
|
675 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
677 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
676 |
678 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
677 |
679 |
rg_git_set_error( |
rg_git_set_error( |
678 |
680 |
'error on update-ref (' . $r['errmsg'] . ')'); |
'error on update-ref (' . $r['errmsg'] . ')'); |
|
... |
... |
function rg_git_shortlog($repo_path, $a, $b) |
702 |
704 |
. ' --git-dir=' . escapeshellarg($repo_path) |
. ' --git-dir=' . escapeshellarg($repo_path) |
703 |
705 |
. ' ' . escapeshellarg($a) |
. ' ' . escapeshellarg($a) |
704 |
706 |
. '..' . escapeshellarg($b); |
. '..' . escapeshellarg($b); |
705 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
707 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
706 |
708 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
707 |
709 |
rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')'); |
rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')'); |
708 |
710 |
break; |
break; |
|
... |
... |
function rg_git_ls_tree($repo_path, $tree, $path) |
739 |
741 |
. escapeshellarg($tree); |
. escapeshellarg($tree); |
740 |
742 |
if (!empty($path)) |
if (!empty($path)) |
741 |
743 |
$cmd .= ' ' . escapeshellarg($path); |
$cmd .= ' ' . escapeshellarg($path); |
742 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
744 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
743 |
745 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
744 |
746 |
rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")"); |
745 |
747 |
break; |
break; |
|
... |
... |
function rg_git_log_simple($repo_path, $max, $from, $to, $also_patch, $files, |
1186 |
1188 |
foreach ($files as $f) |
foreach ($files as $f) |
1187 |
1189 |
$cmd .= ' ' . escapeshellarg($f); |
$cmd .= ' ' . escapeshellarg($f); |
1188 |
1190 |
} |
} |
1189 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
1191 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
1190 |
1192 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
1191 |
1193 |
rg_internal_error("error on log (" . $a['errmsg'] . ")" |
rg_internal_error("error on log (" . $a['errmsg'] . ")" |
1192 |
1194 |
. " cmd=" . $cmd); |
. " cmd=" . $cmd); |
|
... |
... |
function rg_git_files($old, $new) |
1633 |
1635 |
|
|
1634 |
1636 |
$cmd = RG_GIT_CMD . ' diff --name-only ' . escapeshellarg($old) |
$cmd = RG_GIT_CMD . ' diff --name-only ' . escapeshellarg($old) |
1635 |
1637 |
. ' ' . escapeshellarg($new); |
. ' ' . escapeshellarg($new); |
1636 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
1638 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
1637 |
1639 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
1638 |
1640 |
rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); |
1639 |
1641 |
break; |
break; |
|
... |
... |
function rg_git_diff_tree($tree1, $tree2) |
2229 |
2231 |
while (1) { |
while (1) { |
2230 |
2232 |
$cmd = RG_GIT_CMD . " diff-tree -r " . escapeshellarg($tree1) |
$cmd = RG_GIT_CMD . " diff-tree -r " . escapeshellarg($tree1) |
2231 |
2233 |
. " " . escapeshellarg($tree2); |
. " " . escapeshellarg($tree2); |
2232 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
2234 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2233 |
2235 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
2234 |
2236 |
rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); |
2235 |
2237 |
break; |
break; |
|
... |
... |
function rg_git_content_by_file($treeish, $file) |
2274 |
2276 |
while (1) { |
while (1) { |
2275 |
2277 |
$cmd = RG_GIT_CMD . ' show ' . escapeshellarg($treeish) . ':' |
$cmd = RG_GIT_CMD . ' show ' . escapeshellarg($treeish) . ':' |
2276 |
2278 |
. escapeshellarg($file); |
. escapeshellarg($file); |
2277 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
2279 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2278 |
2280 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
2279 |
2281 |
rg_git_set_error("error on show (" . $a['errmsg'] . ")"); |
rg_git_set_error("error on show (" . $a['errmsg'] . ")"); |
2280 |
2282 |
break; |
break; |
|
... |
... |
function rg_git_archive($repo_path, $treeish, $archive_name, $format) |
2400 |
2402 |
. ' archive --format=' . escapeshellarg($format) |
. ' archive --format=' . escapeshellarg($format) |
2401 |
2403 |
. ' --output=' . escapeshellarg($archive_name) |
. ' --output=' . escapeshellarg($archive_name) |
2402 |
2404 |
. ' ' . escapeshellarg($treeish); |
. ' ' . escapeshellarg($treeish); |
2403 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
2405 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2404 |
2406 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
2405 |
2407 |
rg_git_set_error('error on git archive' |
rg_git_set_error('error on git archive' |
2406 |
2408 |
. ' (' . $a['errmsg'] . ')'); |
. ' (' . $a['errmsg'] . ')'); |
|
... |
... |
function rg_git_merge_tree($repo_path, $base, $a, $b) |
2469 |
2471 |
. ' ' . escapeshellarg($base) |
. ' ' . escapeshellarg($base) |
2470 |
2472 |
. ' ' . escapeshellarg($a) |
. ' ' . escapeshellarg($a) |
2471 |
2473 |
. ' ' . escapeshellarg($b); |
. ' ' . escapeshellarg($b); |
2472 |
|
$a = rg_exec($cmd, '', FALSE, FALSE); |
|
|
2474 |
|
$a = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2473 |
2475 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
2474 |
2476 |
rg_git_set_error('error on git merge-tree (' |
rg_git_set_error('error on git merge-tree (' |
2475 |
2477 |
. $a['errmsg'] . ')'); |
. $a['errmsg'] . ')'); |
|
... |
... |
function rg_git_request_pull($repo_path, $start, $url, $end, $patch) |
2657 |
2659 |
if ($patch) |
if ($patch) |
2658 |
2660 |
$cmd .= ' --patch'; |
$cmd .= ' --patch'; |
2659 |
2661 |
$cmd .= escapeshellarg($start) . '..' . escapeshellarg($end); |
$cmd .= escapeshellarg($start) . '..' . escapeshellarg($end); |
2660 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
2662 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
2661 |
2663 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
2662 |
2664 |
rg_git_set_error('error on git diff: ' . $a['errmsg']); |
rg_git_set_error('error on git diff: ' . $a['errmsg']); |
2663 |
2665 |
break; |
break; |
File inc/util.inc.php changed (mode: 100644) (index e4a7bf8..9cbf1fe) |
... |
... |
function rg_util_error() |
30 |
30 |
*/ |
*/ |
31 |
31 |
$rg_template_functions = array(); |
$rg_template_functions = array(); |
32 |
32 |
|
|
|
33 |
|
/* |
|
34 |
|
* |
|
35 |
|
*/ |
|
36 |
|
function rg_php_err() |
|
37 |
|
{ |
|
38 |
|
$a = error_get_last(); |
|
39 |
|
if ($a === NULL) |
|
40 |
|
return 'no error'; |
|
41 |
|
|
|
42 |
|
return $a['message']; |
|
43 |
|
} |
|
44 |
|
|
33 |
45 |
/* |
/* |
34 |
46 |
* Register a function to be called when a @@func:func_name:var@@ construction |
* Register a function to be called when a @@func:func_name:var@@ construction |
35 |
47 |
* is found in a template. |
* is found in a template. |
|
... |
... |
function rg_ok($msg) |
1031 |
1043 |
} |
} |
1032 |
1044 |
|
|
1033 |
1045 |
/* |
/* |
1034 |
|
* Execute $cmd and returns the output as a string, binary safe |
|
1035 |
|
* @input: some data to be sent to the process and received as stdin |
|
1036 |
|
* @cb_stdout - call back called when there is something to be send to stdout |
|
1037 |
|
* if @cb_stdout is FALSE, stdout output will be returned in $ret['data'] |
|
1038 |
|
* cb_stderr - call back called when there is something to be send to stderr |
|
1039 |
|
* if @cb_stderr is FALSE, stderr output will be returned in $ret['stderr'] |
|
|
1046 |
|
* Helper for rg_exec to init the structure |
1040 |
1047 |
*/ |
*/ |
1041 |
|
function rg_exec($cmd, $input, $cb_stdout, $cb_stderr) |
|
|
1048 |
|
function rg_exec2_helper_init(&$info) |
1042 |
1049 |
{ |
{ |
1043 |
|
rg_prof_start('exec'); |
|
1044 |
|
rg_log_enter('Executing [' . $cmd . ']'); |
|
1045 |
|
|
|
1046 |
|
// DEBUG |
|
1047 |
|
$d = FALSE; |
|
1048 |
|
|
|
1049 |
|
$ret = array(); |
|
1050 |
|
$ret['ok'] = 0; |
|
1051 |
|
$ret['errmsg'] = ''; |
|
1052 |
|
$ret['code'] = 65000; // fake code |
|
1053 |
|
$ret['data'] = ''; |
|
1054 |
|
$ret['stderr'] = ''; |
|
1055 |
|
while (1) { |
|
1056 |
|
$desc = array( |
|
1057 |
|
0 => array("pipe", "r"), |
|
1058 |
|
1 => array('pipe', 'w'), |
|
1059 |
|
2 => array("pipe", "w") |
|
1060 |
|
); |
|
1061 |
|
$d && rg_log_ml('DEBUG: desc: ' . print_r($desc, TRUE)); |
|
1062 |
|
|
|
1063 |
|
$a = proc_open($cmd, $desc, $pipes); |
|
1064 |
|
if ($a === FALSE) { |
|
1065 |
|
$ret['errmsg'] = "cannot call proc_open"; |
|
1066 |
|
break; |
|
1067 |
|
} |
|
1068 |
|
|
|
1069 |
|
$d && rg_log_ml('DEBUG: proc_open pipes: ' . print_r($pipes, TRUE)); |
|
1070 |
|
|
|
1071 |
|
$rx = array($pipes[1], $pipes[2]); |
|
1072 |
|
$wx = array(); |
|
1073 |
|
if (!empty($input)) |
|
1074 |
|
$wx[] = $pipes[0]; |
|
1075 |
|
while (!empty($rx)) { |
|
1076 |
|
$revents = $rx; |
|
1077 |
|
$wevents = $wx; |
|
1078 |
|
$ex = NULL; |
|
1079 |
|
$d && rg_log('DEBUG: before stream_select:' |
|
1080 |
|
. ' revents: ' . rg_array2string($revents) |
|
1081 |
|
. ' wevents: ' . rg_array2string($wevents)); |
|
1082 |
|
$r = stream_select($revents, $wevents, $ex, 5, 0); |
|
1083 |
|
if ($r === FALSE) { |
|
1084 |
|
$ret['errmsg'] = "cannot select"; |
|
1085 |
|
break; |
|
1086 |
|
} |
|
1087 |
|
|
|
1088 |
|
if ($r === 0) { |
|
1089 |
|
$ps = proc_get_status($a); |
|
1090 |
|
rg_log_ml('ps: ' . print_r($ps, TRUE)); |
|
1091 |
|
//rg_log('DEBUG: No activity (conn status=' . connection_status() . ')!'); |
|
1092 |
|
if (connection_aborted()) { |
|
1093 |
|
$d && rg_log('connection aborted'); |
|
1094 |
|
$ret['errmsg'] = 'connection aborted'; |
|
1095 |
|
break; |
|
1096 |
|
} |
|
1097 |
|
continue; |
|
1098 |
|
} |
|
1099 |
|
|
|
1100 |
|
$d && rg_log('DEBUG: stream_select returned ' . $r |
|
1101 |
|
. ' revents: ' . rg_array2string($revents) |
|
1102 |
|
. ' wevents: ' . rg_array2string($wevents) |
|
1103 |
|
. ' ex: ' . rg_array2string($ex)); |
|
1104 |
|
|
|
1105 |
|
foreach ($wevents as $fd) { |
|
1106 |
|
if (!empty($ret['errmsg'])) |
|
1107 |
|
break; |
|
1108 |
|
|
|
1109 |
|
$d && rg_log('DEBUG: write event on fd ' . $fd . '!'); |
|
1110 |
|
|
|
1111 |
|
$d && rg_log('DEBUG: Writing to fd ' . $fd |
|
1112 |
|
. ' [' . $input . ']...'); |
|
1113 |
|
$r = @fwrite($fd, $input); |
|
1114 |
|
if ($r === FALSE) { |
|
1115 |
|
$ret['ermsg'] = 'cannot write'; |
|
1116 |
|
break; |
|
1117 |
|
} |
|
1118 |
|
$d && rg_log('DEBUG: fwrite returned ' . $r . '.'); |
|
1119 |
|
$input = substr($input, $r); |
|
1120 |
|
if (empty($input)) |
|
1121 |
|
$wx = array(); |
|
1122 |
|
} |
|
|
1050 |
|
$info['last_activity'] = 0; |
|
1051 |
|
$info['last_errmsg'] = ''; |
|
1052 |
|
$info['closed'] = array(0 => 0, 1 => 0, 2 => 0); |
|
1053 |
|
$info['start_ts'] = time(); |
|
1054 |
|
$info['last_failure'] = 0; |
|
1055 |
|
if (!isset($info['out_buf'])) |
|
1056 |
|
$info['out_buf'] = ''; |
|
1057 |
|
$info['in_buf'] = ''; |
|
1058 |
|
$info['err_buf'] = ''; |
|
1059 |
|
$info['done'] = FALSE; |
1123 |
1060 |
|
|
1124 |
|
$do_break = FALSE; |
|
1125 |
|
foreach ($revents as $fd) { |
|
1126 |
|
if (!empty($ret['errmsg'])) |
|
1127 |
|
break; |
|
|
1061 |
|
if (!isset($info['idle_time'])) |
|
1062 |
|
$info['idle_time'] = 5; |
1128 |
1063 |
|
|
1129 |
|
$d && rg_log('DEBUG: read event on fd ' . $fd . '!'); |
|
1130 |
|
$_d = fread($fd, 32 * 4096); |
|
1131 |
|
if ($_d === FALSE) { |
|
1132 |
|
$ret['errmsg'] = "cannot read"; |
|
1133 |
|
break; |
|
1134 |
|
} |
|
|
1064 |
|
if (!isset($info['output_done'])) { |
|
1065 |
|
if (isset($info['input_fd'])) |
|
1066 |
|
$info['output_done'] = 0; |
|
1067 |
|
else |
|
1068 |
|
$info['output_done'] = 1; |
|
1069 |
|
} |
|
1070 |
|
} |
1135 |
1071 |
|
|
1136 |
|
if (empty($_d)) { |
|
1137 |
|
$d && rg_log('DEBUG: stream ' . $fd . ' returned no data.'); |
|
1138 |
|
// We exit only if we get EOF in stdout not on stderr |
|
1139 |
|
if ($fd === $pipes[1]) |
|
1140 |
|
$do_break = TRUE; |
|
1141 |
|
continue; |
|
1142 |
|
} |
|
|
1072 |
|
/* |
|
1073 |
|
* Helper for rg_exec to close a stream |
|
1074 |
|
*/ |
|
1075 |
|
function rg_exec2_helper_close_stream($fd, $index, &$info, $stream) |
|
1076 |
|
{ |
|
1077 |
|
global $rg_util_debug; |
1143 |
1078 |
|
|
1144 |
|
if ($fd === $pipes[2]) { |
|
1145 |
|
if ($cb_stderr === FALSE) { |
|
1146 |
|
$d && rg_log('DEBUG: fd is pipes[2], append to stderr var: ' . $_d); |
|
1147 |
|
$ret['stderr'] .= $_d; |
|
1148 |
|
} else { |
|
1149 |
|
$d && rg_log('DEBUG: fd is pipes[2], call stdout cb:' . $_d); |
|
1150 |
|
$cb_stderr($_d); |
|
1151 |
|
// We want the last error message to be able to log something |
|
1152 |
|
$ret['stderr'] = $_d; |
|
1153 |
|
} |
|
1154 |
|
} else if ($fd === $pipes[1]) { |
|
1155 |
|
if ($cb_stdout === FALSE) { |
|
1156 |
|
$d && rg_log('DEBUG: fd is pipes[1], append to stdout var: ' . $_d); |
|
1157 |
|
$ret['data'] .= $_d; |
|
1158 |
|
} else { |
|
1159 |
|
$d && rg_log('DEBUG: fd is pipes[1], call stdout cb: ' . $_d); |
|
1160 |
|
$cb_stdout($_d); |
|
1161 |
|
} |
|
1162 |
|
} else { |
|
1163 |
|
rg_internal_error('invalid fd'); |
|
1164 |
|
} |
|
1165 |
|
} |
|
|
1079 |
|
$rg_util_debug && |
|
1080 |
|
rg_log_enter($index . ' DEBUG: exec2_helper_close_stream: stream ' . $stream); |
1166 |
1081 |
|
|
1167 |
|
if ($do_break || !empty($ret['errmsg'])) |
|
1168 |
|
break; |
|
1169 |
|
} |
|
1170 |
|
$ret['stderr'] = trim($ret['stderr']); |
|
1171 |
|
$ret['data'] = trim($ret['data']); |
|
1172 |
|
|
|
1173 |
|
for ($i = 0; $i < 3; $i++) |
|
1174 |
|
if (isset($pipes[$i])) |
|
1175 |
|
fclose($pipes[$i]); |
|
1176 |
|
|
|
1177 |
|
$err = proc_close($a); |
|
1178 |
|
if ($err != 0) { |
|
1179 |
|
rg_log('DEBUG: exec returned ' . $err); |
|
1180 |
|
$ret['code'] = $err; |
|
1181 |
|
$ret['errmsg'] = 'task returned code ' . $err |
|
1182 |
|
. ' (' . $ret['stderr'] . ')'; |
|
1183 |
|
break; |
|
1184 |
|
} |
|
|
1082 |
|
if ($stream == -1) { |
|
1083 |
|
$info['output_done'] = 1; |
|
1084 |
|
unset($info['input_fd']); |
|
1085 |
|
} else { |
|
1086 |
|
$info['closed'][$stream] = 1; |
|
1087 |
|
unset($info['pipes'][$stream]); |
|
1088 |
|
} |
1185 |
1089 |
|
|
1186 |
|
//rg_log('DEBUG: exec returned ok'); |
|
1187 |
|
$ret['code'] = 0; |
|
1188 |
|
$ret['ok'] = 1; |
|
1189 |
|
break; |
|
|
1090 |
|
$r = @fclose($fd); |
|
1091 |
|
if ($r === FALSE) |
|
1092 |
|
rg_log($index . ' Error closing stream ' . $stream |
|
1093 |
|
. ' (' . rg_php_err() . ')'); |
|
1094 |
|
|
|
1095 |
|
if (($stream == 0) && isset($info['input_fd'])) { |
|
1096 |
|
$rg_util_debug && |
|
1097 |
|
rg_log($index . ' DEBUG: closing stream 0 =>' |
|
1098 |
|
. ' closing input_fd ' . $info['input_fd']); |
|
1099 |
|
rg_exec2_helper_close_stream($info['input_fd'], $index, $info, -1); |
1190 |
1100 |
} |
} |
1191 |
1101 |
|
|
|
1102 |
|
$rg_util_debug && |
1192 |
1103 |
rg_log_exit(); |
rg_log_exit(); |
1193 |
|
rg_prof_end("exec"); |
|
1194 |
|
return $ret; |
|
1195 |
1104 |
} |
} |
1196 |
1105 |
|
|
1197 |
1106 |
/* |
/* |
1198 |
1107 |
* This will replace rg_exec function |
* This will replace rg_exec function |
|
1108 |
|
* Returns the array of the commands with the last status. |
1199 |
1109 |
*/ |
*/ |
1200 |
|
function rg_exec2(&$a) |
|
|
1110 |
|
function rg_exec2($a) |
1201 |
1111 |
{ |
{ |
1202 |
1112 |
global $rg_util_debug; |
global $rg_util_debug; |
1203 |
1113 |
|
|
|
... |
... |
function rg_exec2(&$a) |
1207 |
1117 |
$rg_util_debug && |
$rg_util_debug && |
1208 |
1118 |
rg_log_ml('DEBUG: a: ' . print_r($a, TRUE)); |
rg_log_ml('DEBUG: a: ' . print_r($a, TRUE)); |
1209 |
1119 |
|
|
|
1120 |
|
$ret = array(); |
|
1121 |
|
$ret['ok'] = 0; |
|
1122 |
|
$ret['cmds'] = $a['cmds']; |
|
1123 |
|
|
1210 |
1124 |
// some status initialization |
// some status initialization |
1211 |
1125 |
$s = array(); |
$s = array(); |
1212 |
|
foreach ($a['cmds'] as $cmd => &$info) { |
|
1213 |
|
if (!isset($info['restart_delay'])) |
|
1214 |
|
$info['restart_delay'] = 0; |
|
1215 |
|
if (!isset($info['idle_time'])) |
|
1216 |
|
$info['idle_time'] = 5; |
|
1217 |
|
|
|
|
1126 |
|
foreach ($ret['cmds'] as $cmd => &$info) { |
1218 |
1127 |
$info['needs_start'] = TRUE; |
$info['needs_start'] = TRUE; |
1219 |
|
$info['needs_stop'] = FALSE; |
|
1220 |
|
$info['last_failure'] = 0; |
|
1221 |
|
if (!isset($info['out_buf'])) |
|
1222 |
|
$info['out_buf'] = ''; |
|
1223 |
|
$info['in_buf'] = ''; |
|
1224 |
|
$info['err_buf'] = ''; |
|
1225 |
|
$info['done'] = FALSE; |
|
1226 |
|
$info['last_activity'] = 0; |
|
1227 |
1128 |
$info['stopped'] = TRUE; |
$info['stopped'] = TRUE; |
1228 |
|
$info['closed'] = array(1 => 0, 2 => 0); |
|
|
1129 |
|
$info['needs_stop'] = FALSE; |
|
1130 |
|
rg_exec2_helper_init($info); |
1229 |
1131 |
} |
} |
1230 |
1132 |
|
|
1231 |
|
$ret = array(); |
|
1232 |
|
$ret['ok'] = 0; |
|
1233 |
1133 |
while (1) { |
while (1) { |
1234 |
1134 |
// check if all commands are started |
// check if all commands are started |
1235 |
1135 |
$now = time(); |
$now = time(); |
1236 |
1136 |
$rx = array(); $wx = array(); |
$rx = array(); $wx = array(); |
1237 |
1137 |
$lut = array(); |
$lut = array(); |
1238 |
1138 |
$done = TRUE; |
$done = TRUE; |
1239 |
|
foreach ($a['cmds'] as $index => &$info) { |
|
1240 |
|
if (($info['closed'][1] == 1) && ($info['closed'][2] == 1)) { |
|
1241 |
|
$rg_util_debug && rg_log('DEBUG: Both in streams are closed.'); |
|
|
1139 |
|
foreach ($ret['cmds'] as $index => &$info) { |
|
1140 |
|
if ($info['closed'][0] + $info['closed'][1] + $info['closed'][2] == 3) { |
|
1141 |
|
$rg_util_debug && |
|
1142 |
|
rg_log($index . ' DEBUG: All streams are closed.' |
|
1143 |
|
. ' Set needs_stop to TRUE'); |
1242 |
1144 |
$info['needs_stop'] = TRUE; |
$info['needs_stop'] = TRUE; |
1243 |
1145 |
} |
} |
1244 |
1146 |
|
|
1245 |
1147 |
if ($info['needs_stop'] == TRUE) { |
if ($info['needs_stop'] == TRUE) { |
1246 |
1148 |
$rg_util_debug && |
$rg_util_debug && |
1247 |
|
rg_log('DEBUG: index ' . $index . ' needs stop!'); |
|
|
1149 |
|
rg_log($index . ' DEBUG: needs stop is TRUE!'); |
1248 |
1150 |
|
|
1249 |
1151 |
$info['ps'] = @proc_get_status($info['a']); |
$info['ps'] = @proc_get_status($info['a']); |
1250 |
1152 |
$rg_util_debug && |
$rg_util_debug && |
1251 |
|
rg_log_ml('DEBUG: info[ps][' . $index . ']: ' |
|
|
1153 |
|
rg_log_ml($index . ' DEBUG: info[ps]: ' |
1252 |
1154 |
. print_r($info['ps'], TRUE)); |
. print_r($info['ps'], TRUE)); |
1253 |
1155 |
|
|
1254 |
1156 |
if ($info['ps']['running'] === FALSE) { |
if ($info['ps']['running'] === FALSE) { |
|
... |
... |
function rg_exec2(&$a) |
1258 |
1160 |
if (isset($info['pipes'][$i])) |
if (isset($info['pipes'][$i])) |
1259 |
1161 |
fclose($info['pipes'][$i]); |
fclose($info['pipes'][$i]); |
1260 |
1162 |
|
|
|
1163 |
|
if (isset($info['input_fd'])) { |
|
1164 |
|
@fclose($info['input_fd']); |
|
1165 |
|
unset($info['input_fd']); |
|
1166 |
|
} |
|
1167 |
|
|
1261 |
1168 |
$err = @proc_close($info['a']); |
$err = @proc_close($info['a']); |
1262 |
|
if ($err != 0) |
|
|
1169 |
|
if ($err != 0) { |
1263 |
1170 |
$rg_util_debug && |
$rg_util_debug && |
1264 |
|
rg_log('DEBUG: proc_close returned ' . $err); |
|
|
1171 |
|
rg_log($index . ' DEBUG: proc_close returned ' . $err); |
|
1172 |
|
} |
|
1173 |
|
// TODO: where should we use it? |
1265 |
1174 |
$ec = 0; /* we are force closing program */ |
$ec = 0; /* we are force closing program */ |
1266 |
1175 |
} |
} |
1267 |
1176 |
|
|
|
1177 |
|
if (($info['ps']['exitcode'] != 0) && empty($info['last_errmsg'])) |
|
1178 |
|
$info['last_errmsg'] = 'child exited with an error code'; |
|
1179 |
|
|
1268 |
1180 |
if (isset($info['cb_finish'])) |
if (isset($info['cb_finish'])) |
1269 |
1181 |
$info['cb_finish']($index, $info, $ec); |
$info['cb_finish']($index, $info, $ec); |
1270 |
1182 |
|
|
|
... |
... |
function rg_exec2(&$a) |
1274 |
1186 |
$info['needs_stop'] = FALSE; |
$info['needs_stop'] = FALSE; |
1275 |
1187 |
$info['stopped'] = TRUE; |
$info['stopped'] = TRUE; |
1276 |
1188 |
|
|
1277 |
|
if (isset($info['restart_delay'])) { |
|
|
1189 |
|
if (!isset($info['restart_delay'])) { |
1278 |
1190 |
$rg_util_debug && |
$rg_util_debug && |
1279 |
|
rg_log('DEBUG: index ' . $index . ' has no restart flag => done = TRUE'); |
|
|
1191 |
|
rg_log($index . ' DEBUG: no restart flag => done = TRUE'); |
1280 |
1192 |
$info['done'] = TRUE; |
$info['done'] = TRUE; |
|
1193 |
|
} else { |
|
1194 |
|
rg_exec2_helper_init($info); |
1281 |
1195 |
} |
} |
1282 |
1196 |
} |
} |
1283 |
1197 |
|
|
1284 |
1198 |
$rg_util_debug && |
$rg_util_debug && |
1285 |
|
rg_log('DEBUG: index=' . $index |
|
1286 |
|
. ' done=' . ($info['done'] === TRUE ? 'true' : 'false')); |
|
|
1199 |
|
rg_log($index . ' DEBUG:' |
|
1200 |
|
. ' info[done]=' . ($info['done'] === TRUE ? 'true' : 'false')); |
1287 |
1201 |
if ($info['done']) |
if ($info['done']) |
1288 |
1202 |
continue; |
continue; |
1289 |
1203 |
|
|
|
1204 |
|
$rg_util_debug && |
|
1205 |
|
rg_log($index . ' DEBUG: set done to FALSE'); |
1290 |
1206 |
$done = FALSE; |
$done = FALSE; |
1291 |
1207 |
|
|
1292 |
1208 |
if ($info['needs_start'] == TRUE) { |
if ($info['needs_start'] == TRUE) { |
1293 |
|
$done = FALSE; |
|
|
1209 |
|
$restart_delay = isset($info['restart_delay']) ? $info['restart_delay'] : 0; |
1294 |
1210 |
|
|
1295 |
|
if ($info['last_failure'] + $info['restart_delay'] > $now) |
|
|
1211 |
|
if ($info['last_failure'] + $restart_delay > $now) |
1296 |
1212 |
continue; |
continue; |
1297 |
1213 |
|
|
1298 |
1214 |
$rg_util_debug && |
$rg_util_debug && |
1299 |
|
rg_log('DEBUG: Running [' . $info['cmd'] . ']'); |
|
|
1215 |
|
rg_log($index . ' DEBUG: Running [' . $info['cmd'] . ']'); |
1300 |
1216 |
$desc = array( |
$desc = array( |
1301 |
|
0 => array("pipe", "r"), |
|
|
1217 |
|
0 => array('pipe', 'r'), |
1302 |
1218 |
1 => array('pipe', 'w'), |
1 => array('pipe', 'w'), |
1303 |
1219 |
2 => array("pipe", "w") |
2 => array("pipe", "w") |
1304 |
1220 |
); |
); |
|
... |
... |
function rg_exec2(&$a) |
1313 |
1229 |
} |
} |
1314 |
1230 |
|
|
1315 |
1231 |
$rg_util_debug && |
$rg_util_debug && |
1316 |
|
rg_log_ml('DEBUG: proc_open pipes: ' |
|
1317 |
|
. print_r($info['pipes'], TRUE)); |
|
1318 |
|
$info['needs_start'] = FALSE; |
|
1319 |
|
$info['start_ts'] = time(); |
|
|
1232 |
|
rg_log($index . ' DEBUG: proc_open pipes: ' |
|
1233 |
|
. rg_array2string($info['pipes'])); |
|
1234 |
|
|
1320 |
1235 |
$info['stopped'] = FALSE; |
$info['stopped'] = FALSE; |
1321 |
|
$info['last_errmsg'] = ''; |
|
1322 |
|
$info['closed'][1] = 0; |
|
1323 |
|
$info['closed'][2] = 0; |
|
|
1236 |
|
$info['needs_start'] = FALSE; |
|
1237 |
|
|
|
1238 |
|
// cb_output can populate $info['out_buf'] |
|
1239 |
|
if (isset($info['cb_output'])) { |
|
1240 |
|
$rg_util_debug && |
|
1241 |
|
rg_log($index . ' DEBUG: calling cb_output (first)...'); |
|
1242 |
|
$info['cb_output']($index, $info); |
|
1243 |
|
} |
1324 |
1244 |
} |
} |
1325 |
1245 |
|
|
1326 |
1246 |
if ($info['stopped']) { |
if ($info['stopped']) { |
1327 |
1247 |
$rg_util_debug && |
$rg_util_debug && |
1328 |
|
rg_log('DEBUG: index ' . $index. ' is stopped'); |
|
|
1248 |
|
rg_log($index . ' DEBUG: stopped is TRUE'); |
1329 |
1249 |
continue; |
continue; |
1330 |
1250 |
} |
} |
1331 |
1251 |
|
|
|
... |
... |
function rg_exec2(&$a) |
1335 |
1255 |
&& ($info['last_activity'] > 0) |
&& ($info['last_activity'] > 0) |
1336 |
1256 |
&& ($info['last_activity'] + $info['idle_time'] <= time())) { |
&& ($info['last_activity'] + $info['idle_time'] <= time())) { |
1337 |
1257 |
$rg_util_debug && |
$rg_util_debug && |
1338 |
|
rg_log('DEBUG: IDLE: ' . $index |
|
|
1258 |
|
rg_log($index . ' DEBUG: IDLE:' |
1339 |
1259 |
. ' last_activity=' . $info['last_activity'] |
. ' last_activity=' . $info['last_activity'] |
1340 |
1260 |
. ' now=' . time()); |
. ' now=' . time()); |
1341 |
1261 |
$info['cb_idle']($index, $info); |
$info['cb_idle']($index, $info); |
1342 |
1262 |
} |
} |
1343 |
1263 |
|
|
1344 |
|
if ($info['closed'][1] == 0) $rx[] = $info['pipes'][1]; |
|
1345 |
|
if ($info['closed'][2] == 0) $rx[] = $info['pipes'][2]; |
|
1346 |
|
|
|
1347 |
|
if (isset($info['cb_output']) || !empty($info['out_buf'])) { |
|
|
1264 |
|
if (!empty($info['out_buf'])) { |
1348 |
1265 |
$rg_util_debug && |
$rg_util_debug && |
1349 |
|
rg_log('DEBUG: We have cb_output or data in out_buf, enable write notification!'); |
|
|
1266 |
|
rg_log($index . ' DEBUG: enable write notification!'); |
|
1267 |
|
|
1350 |
1268 |
$wx[] = $info['pipes'][0]; |
$wx[] = $info['pipes'][0]; |
|
1269 |
|
} else if (($info['output_done'] == 1) && ($info['closed'][0] == 0)) { |
|
1270 |
|
$rg_util_debug && |
|
1271 |
|
rg_log($index . ' DEBUG: No output available' |
|
1272 |
|
. ', close output ' . $info['pipes'][0]); |
|
1273 |
|
rg_exec2_helper_close_stream($info['pipes'][0], $index, $info, 0); |
1351 |
1274 |
} |
} |
1352 |
1275 |
|
|
|
1276 |
|
if ($info['closed'][1] == 0) $rx[] = $info['pipes'][1]; |
|
1277 |
|
if ($info['closed'][2] == 0) $rx[] = $info['pipes'][2]; |
|
1278 |
|
if (isset($info['input_fd'])) |
|
1279 |
|
$rx[] = $info['input_fd']; |
|
1280 |
|
|
1353 |
1281 |
for ($i = 0; $i <= 2; $i++) { |
for ($i = 0; $i <= 2; $i++) { |
|
1282 |
|
if (!isset($info['pipes'][$i])) |
|
1283 |
|
continue; |
|
1284 |
|
|
1354 |
1285 |
$k = intval($info['pipes'][$i]); |
$k = intval($info['pipes'][$i]); |
1355 |
|
$lut[$k] = array('index' => $index, 'stream' => $i); |
|
|
1286 |
|
$lut[$k] = array('index' => $index, |
|
1287 |
|
'stream' => $i); |
|
1288 |
|
} |
|
1289 |
|
|
|
1290 |
|
if (isset($info['input_fd'])) { |
|
1291 |
|
$k = intval($info['input_fd']); |
|
1292 |
|
$lut[$k] = array('index' => $index, |
|
1293 |
|
'stream' => -1); |
1356 |
1294 |
} |
} |
1357 |
1295 |
} |
} |
1358 |
1296 |
if ($done) { |
if ($done) { |
|
... |
... |
function rg_exec2(&$a) |
1364 |
1302 |
|
|
1365 |
1303 |
if (empty($rx) && empty($wx)) { |
if (empty($rx) && empty($wx)) { |
1366 |
1304 |
$rg_util_debug && |
$rg_util_debug && |
1367 |
|
rg_log('DEBUG: No events... sleeping'); |
|
|
1305 |
|
rg_log('DEBUG: No r/w events; sleeping...'); |
1368 |
1306 |
sleep(1); |
sleep(1); |
1369 |
1307 |
continue; |
continue; |
1370 |
1308 |
} |
} |
|
... |
... |
function rg_exec2(&$a) |
1372 |
1310 |
$revents = $rx; |
$revents = $rx; |
1373 |
1311 |
$wevents = $wx; |
$wevents = $wx; |
1374 |
1312 |
$ex = NULL; |
$ex = NULL; |
1375 |
|
$rg_util_debug && rg_log('DEBUG: before stream_select:'); |
|
1376 |
|
$rg_util_debug && !empty($revents) && rg_log_ml('revents: ' . trim(print_r($revents, TRUE))); |
|
1377 |
|
$rg_util_debug && !empty($wevents) && rg_log_ml('wevents: ' . trim(print_r($wevents, TRUE))); |
|
|
1313 |
|
$rg_util_debug && rg_log('DEBUG: before stream_select:' |
|
1314 |
|
. (empty($revents) ? '' : ' revents:' . rg_array2string($revents)) |
|
1315 |
|
. (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents))); |
1378 |
1316 |
$r = stream_select($revents, $wevents, $ex, 1, 0); |
$r = stream_select($revents, $wevents, $ex, 1, 0); |
1379 |
1317 |
if ($r === FALSE) { |
if ($r === FALSE) { |
1380 |
1318 |
$ret['errmsg'] = "cannot select"; |
$ret['errmsg'] = "cannot select"; |
1381 |
1319 |
break; |
break; |
1382 |
1320 |
} |
} |
1383 |
1321 |
|
|
1384 |
|
if (isset($a['cb_tick'])) |
|
1385 |
|
$a['cb_tick']($a); |
|
|
1322 |
|
$rg_util_debug && (!empty($revents) || !empty($wevents) || !empty($ex)) && |
|
1323 |
|
rg_log('DEBUG: after stream_select:' |
|
1324 |
|
. (empty($revents) ? '' : ' revents:' . rg_array2string($revents)) |
|
1325 |
|
. (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents)) |
|
1326 |
|
. (empty($ex) ? '' : ' ex:' . rg_array2string($ex))); |
1386 |
1327 |
|
|
1387 |
1328 |
if ($r === 0) |
if ($r === 0) |
1388 |
1329 |
continue; |
continue; |
1389 |
1330 |
|
|
1390 |
|
$rg_util_debug && rg_log('DEBUG: stream_select returned ' . $r . ' events.'); |
|
1391 |
|
$rg_util_debug && !empty($revents) && rg_log_ml('revents: ' . trim(print_r($revents, TRUE))); |
|
1392 |
|
$rg_util_debug && !empty($wevents) && rg_log_ml('wevents: ' . trim(print_r($wevents, TRUE))); |
|
1393 |
|
$rg_util_debug && !empty($ex) && rg_log_ml('ex: ' . trim(print_r($ex, TRUE))); |
|
1394 |
|
|
|
1395 |
1331 |
foreach ($wevents as $fd) { |
foreach ($wevents as $fd) { |
1396 |
1332 |
$ifd = intval($fd); |
$ifd = intval($fd); |
1397 |
1333 |
$index = $lut[$ifd]['index']; |
$index = $lut[$ifd]['index']; |
1398 |
1334 |
$rg_util_debug && |
$rg_util_debug && |
1399 |
|
rg_log('DEBUG: write event on ifd ' . $ifd |
|
1400 |
|
. ' index=' . $index . '!'); |
|
|
1335 |
|
rg_log($index . ' DEBUG: write event on ifd ' . $ifd); |
1401 |
1336 |
|
|
1402 |
|
$info = &$a['cmds'][$index]; |
|
|
1337 |
|
$info = &$ret['cmds'][$index]; |
1403 |
1338 |
|
|
1404 |
1339 |
$rg_util_debug && |
$rg_util_debug && |
1405 |
|
rg_log('DEBUG: out_buf before cb: ' . $info['out_buf']); |
|
|
1340 |
|
rg_log($index . ' DEBUG: out_buf before cb: ' . $info['out_buf']); |
1406 |
1341 |
|
|
1407 |
|
// cb_output will populate $info['out_buf'] |
|
1408 |
|
if (isset($info['cb_output'])) |
|
|
1342 |
|
// cb_output can populate $info['out_buf'] |
|
1343 |
|
if (isset($info['cb_output'])) { |
|
1344 |
|
$rg_util_debug && |
|
1345 |
|
rg_log($index . ' DEBUG: calling cb_output...'); |
1409 |
1346 |
$info['cb_output']($index, $info); |
$info['cb_output']($index, $info); |
|
1347 |
|
} |
1410 |
1348 |
|
|
1411 |
1349 |
if (empty($info['out_buf'])) { |
if (empty($info['out_buf'])) { |
1412 |
1350 |
$rg_util_debug && |
$rg_util_debug && |
1413 |
|
rg_log_ml('DEBUG: out_buf is empty!' . print_r($info, TRUE)); |
|
|
1351 |
|
rg_log_ml($index . ' DEBUG: out_buf is empty!' |
|
1352 |
|
. ' info: ' . print_r($info, TRUE)); |
1414 |
1353 |
continue; |
continue; |
1415 |
1354 |
} |
} |
1416 |
1355 |
|
|
1417 |
1356 |
$rg_util_debug && |
$rg_util_debug && |
1418 |
|
rg_log('DEBUG: SENDING: [' . $info['out_buf'] . ']'); |
|
|
1357 |
|
rg_log($index . ' DEBUG: send: [' . $info['out_buf'] . ']'); |
1419 |
1358 |
$r = @fwrite($fd, $info['out_buf']); |
$r = @fwrite($fd, $info['out_buf']); |
1420 |
1359 |
if ($r === FALSE) { |
if ($r === FALSE) { |
1421 |
1360 |
$info['last_errmsg'] = 'cannot write'; |
$info['last_errmsg'] = 'cannot write'; |
1422 |
1361 |
if (isset($info['cb_error'])) |
if (isset($info['cb_error'])) |
1423 |
1362 |
$info['cb_error']($index, $info, $info['last_errmsg']); |
$info['cb_error']($index, $info, $info['last_errmsg']); |
|
1363 |
|
else |
|
1364 |
|
rg_log($index . ' fwrite returned FALSE'); |
1424 |
1365 |
$info['needs_stop'] = TRUE; |
$info['needs_stop'] = TRUE; |
1425 |
1366 |
continue; |
continue; |
1426 |
1367 |
} |
} |
1427 |
1368 |
$rg_util_debug && |
$rg_util_debug && |
1428 |
|
rg_log('DEBUG: fwrite returned ' . $r . '.'); |
|
|
1369 |
|
rg_log($index . ' DEBUG: fwrite returned ' . $r . '.'); |
1429 |
1370 |
$info['out_buf'] = substr($info['out_buf'], $r); |
$info['out_buf'] = substr($info['out_buf'], $r); |
1430 |
1371 |
} |
} |
1431 |
1372 |
|
|
|
... |
... |
function rg_exec2(&$a) |
1434 |
1375 |
$index = $lut[$ifd]['index']; |
$index = $lut[$ifd]['index']; |
1435 |
1376 |
$stream = $lut[$ifd]['stream']; |
$stream = $lut[$ifd]['stream']; |
1436 |
1377 |
$rg_util_debug && |
$rg_util_debug && |
1437 |
|
rg_log('DEBUG: read event on ifd ' . $ifd |
|
1438 |
|
. ' index=' . $index . ', stream=' . $stream . '!'); |
|
|
1378 |
|
rg_log($index . ' DEBUG: read event on ifd ' . $ifd |
|
1379 |
|
. ', stream=' . $stream . '!'); |
1439 |
1380 |
|
|
1440 |
|
$info = &$a['cmds'][$index]; |
|
|
1381 |
|
$info = &$ret['cmds'][$index]; |
1441 |
1382 |
|
|
1442 |
1383 |
$_d = @fread($fd, 32 * 4096); |
$_d = @fread($fd, 32 * 4096); |
1443 |
1384 |
if ($_d === FALSE) { |
if ($_d === FALSE) { |
1444 |
1385 |
$rg_util_debug && |
$rg_util_debug && |
1445 |
|
rg_log('DEBUG: ifd ' . $ifd . ' fread returned FALSE'); |
|
|
1386 |
|
rg_log($index . ' DEBUG: ifd ' . $ifd . ' fread returned FALSE'); |
1446 |
1387 |
$info['last_errmsg'] = 'cannot read'; |
$info['last_errmsg'] = 'cannot read'; |
1447 |
1388 |
if (isset($info['cb_error'])) |
if (isset($info['cb_error'])) |
1448 |
1389 |
$info['cb_error']($index, $info, $info['last_errmsg']); |
$info['cb_error']($index, $info, $info['last_errmsg']); |
|
... |
... |
function rg_exec2(&$a) |
1452 |
1393 |
|
|
1453 |
1394 |
if (empty($_d)) { |
if (empty($_d)) { |
1454 |
1395 |
$rg_util_debug && |
$rg_util_debug && |
1455 |
|
rg_log('DEBUG: ifd ' . $ifd . ' returned no data.'); |
|
1456 |
|
$info['closed'][$stream] = 1; |
|
|
1396 |
|
rg_log($index . ' DEBUG: ifd ' . $ifd . ' returned no data.'); |
|
1397 |
|
rg_exec2_helper_close_stream($fd, $index, $info, $stream); |
1457 |
1398 |
continue; |
continue; |
1458 |
1399 |
} |
} |
1459 |
1400 |
|
|
1460 |
|
$info['last_activity'] = time(); |
|
1461 |
1401 |
$rg_util_debug && |
$rg_util_debug && |
1462 |
|
rg_log('DEBUG: index ' . $index . ': set last_activity to ' . $info['last_activity']); |
|
|
1402 |
|
rg_log($index . ' DEBUG: fread [stream ' . $stream . '] returned [' |
|
1403 |
|
. $_d . ']'); |
|
1404 |
|
|
|
1405 |
|
$info['last_activity'] = time(); |
1463 |
1406 |
|
|
1464 |
1407 |
switch ($stream) { |
switch ($stream) { |
|
1408 |
|
case -1: $info['out_buf'] .= $_d; break; |
1465 |
1409 |
case 1: $info['in_buf'] .= $_d; break; |
case 1: $info['in_buf'] .= $_d; break; |
1466 |
1410 |
case 2: $info['err_buf'] .= $_d; break; |
case 2: $info['err_buf'] .= $_d; break; |
1467 |
1411 |
} |
} |
|
... |
... |
function rg_exec2(&$a) |
1469 |
1413 |
if (isset($info['cb_input'])) |
if (isset($info['cb_input'])) |
1470 |
1414 |
$info['cb_input']($index, $info, $stream); |
$info['cb_input']($index, $info, $stream); |
1471 |
1415 |
} |
} |
|
1416 |
|
|
|
1417 |
|
foreach ($ret['cmds'] as $index => &$info) |
|
1418 |
|
if (isset($info['cb_tick'])) |
|
1419 |
|
$info['cb_tick']($index, $info); |
1472 |
1420 |
} |
} |
1473 |
1421 |
|
|
1474 |
1422 |
rg_log_exit(); |
rg_log_exit(); |
|
... |
... |
function rg_exec2(&$a) |
1476 |
1424 |
return $ret; |
return $ret; |
1477 |
1425 |
} |
} |
1478 |
1426 |
|
|
|
1427 |
|
/* |
|
1428 |
|
* Helper for rg_exec |
|
1429 |
|
*/ |
|
1430 |
|
function rg_exec_helper_data($index, &$a, $stream) |
|
1431 |
|
{ |
|
1432 |
|
rg_log('DEBUG: rg_exec_helper_data[' . $index . '] stream=' . $stream); |
|
1433 |
|
switch ($stream) { |
|
1434 |
|
case 1: $a['my_data_out']($a['in_buf']); $a['in_buf'] = ''; break; |
|
1435 |
|
case 1: $a['my_err_out']($a['err_buf']); $a['err_buf'] = ''; break; |
|
1436 |
|
} |
|
1437 |
|
} |
|
1438 |
|
|
|
1439 |
|
/* |
|
1440 |
|
* Helper for rg_exec |
|
1441 |
|
*/ |
|
1442 |
|
function rg_exec_helper_output($index, &$a) |
|
1443 |
|
{ |
|
1444 |
|
return $a['my_data_in'](); |
|
1445 |
|
} |
|
1446 |
|
|
|
1447 |
|
/* |
|
1448 |
|
* Execute $cmd and returns the output as a string, binary safe |
|
1449 |
|
* @input: some data to be sent to the process and received as stdin |
|
1450 |
|
* @cb_stdin - call back used to pass data frou our stdin to the process |
|
1451 |
|
* ifa @cb_stdin is false, it is not called; if is 0, STDIN will be used. |
|
1452 |
|
* @cb_stdout - call back called when there is something to be send to our stdout |
|
1453 |
|
* if @cb_stdout is FALSE, stdout output will be returned in $ret['data'] |
|
1454 |
|
* cb_stderr - call back called when there is something to be sent to our stderr |
|
1455 |
|
* if @cb_stderr is FALSE, stderr output will be returned in $ret['stderr'] |
|
1456 |
|
*/ |
|
1457 |
|
function rg_exec($cmd, $input, $cb_stdin, $cb_stdout, $cb_stderr) |
|
1458 |
|
{ |
|
1459 |
|
$ret = array(); |
|
1460 |
|
$ret['ok'] = 0; |
|
1461 |
|
while(1) { |
|
1462 |
|
$ret['errmsg'] = ''; |
|
1463 |
|
$ret['code'] = 65000; // fake code |
|
1464 |
|
$ret['data'] = ''; |
|
1465 |
|
$ret['stderr'] = ''; |
|
1466 |
|
|
|
1467 |
|
$a = array('cmds' => array( |
|
1468 |
|
'cmd1' => array( |
|
1469 |
|
'cmd' => $cmd, |
|
1470 |
|
'out_buf' => $input |
|
1471 |
|
) |
|
1472 |
|
) |
|
1473 |
|
); |
|
1474 |
|
|
|
1475 |
|
if ($cb_stdin === 0) { |
|
1476 |
|
$a['cmds']['cmd1']['input_fd'] = @fopen('php://stdin', 'rb'); |
|
1477 |
|
if ($a['cmds']['cmd1']['input_fd'] === FALSE) { |
|
1478 |
|
$ret['errmsg'] = 'cannot open stdin'; |
|
1479 |
|
break; |
|
1480 |
|
} |
|
1481 |
|
} else if ($cb_stdin !== FALSE) { |
|
1482 |
|
$a['cmds']['cmd1']['my_data_in'] = $cb_stdin; |
|
1483 |
|
$a['cmds']['cmd1']['cb_output'] = 'rg_exec_helper_output'; |
|
1484 |
|
} |
|
1485 |
|
|
|
1486 |
|
if ($cb_stdout !== FALSE) { |
|
1487 |
|
$a['cmds']['cmd1']['my_data_out'] = $cb_stdout; |
|
1488 |
|
$a['cmds']['cmd1']['cb_input'] = 'rg_exec_helper_data'; |
|
1489 |
|
} |
|
1490 |
|
|
|
1491 |
|
if ($cb_stderr !== FALSE) { |
|
1492 |
|
$a['cmds']['cmd1']['my_err_out'] = $cb_stderr; |
|
1493 |
|
$a['cmds']['cmd1']['cb_input'] = 'rg_exec_helper_data'; |
|
1494 |
|
} |
|
1495 |
|
|
|
1496 |
|
$r = rg_exec2($a); |
|
1497 |
|
if ($r['ok'] != 1) { |
|
1498 |
|
$ret['errmsg'] = $r['errmsg']; |
|
1499 |
|
break; |
|
1500 |
|
} |
|
1501 |
|
|
|
1502 |
|
$ret['code'] = $r['cmds']['cmd1']['ps']['exitcode']; |
|
1503 |
|
$ret['data'] = $r['cmds']['cmd1']['in_buf']; |
|
1504 |
|
$ret['stderr'] = $r['cmds']['cmd1']['err_buf']; |
|
1505 |
|
$ret['errmsg'] = $r['cmds']['cmd1']['last_errmsg']; |
|
1506 |
|
|
|
1507 |
|
if ($ret['code'] == 0) |
|
1508 |
|
$ret['ok'] = 1; |
|
1509 |
|
break; |
|
1510 |
|
} |
|
1511 |
|
|
|
1512 |
|
return $ret; |
|
1513 |
|
} |
|
1514 |
|
|
1479 |
1515 |
/* |
/* |
1480 |
1516 |
* Force browser to redirect to another page |
* Force browser to redirect to another page |
1481 |
1517 |
*/ |
*/ |
File scripts/worker.php changed (mode: 100644) (index c0172c2..046554f) |
... |
... |
function reload_config() |
101 |
101 |
$cmd = 'ssh-keygen -t rsa -b 4096 -N \'\'' |
$cmd = 'ssh-keygen -t rsa -b 4096 -N \'\'' |
102 |
102 |
. ' -C \'Key to connect to builder\'' |
. ' -C \'Key to connect to builder\'' |
103 |
103 |
. ' -f ' . escapeshellarg($conf['state'] . '/key'); |
. ' -f ' . escapeshellarg($conf['state'] . '/key'); |
104 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
104 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
105 |
105 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
106 |
106 |
rg_log('Cannot create key: ' . $r['errmsg'] . '!'); |
rg_log('Cannot create key: ' . $r['errmsg'] . '!'); |
107 |
107 |
sleep(60); |
sleep(60); |
|
... |
... |
function start_worker($job) |
141 |
141 |
$do_umount = FALSE; |
$do_umount = FALSE; |
142 |
142 |
$err = TRUE; |
$err = TRUE; |
143 |
143 |
while (1) { |
while (1) { |
144 |
|
rg_exec('virsh destroy ' . $ename, '', FALSE, FALSE); |
|
145 |
|
rg_exec('virsh undefine ' . $ename, '', FALSE, FALSE); |
|
|
144 |
|
rg_exec('virsh destroy ' . $ename, '', FALSE, FALSE, FALSE); |
|
145 |
|
rg_exec('virsh undefine ' . $ename, '', FALSE, FALSE, FALSE); |
146 |
146 |
|
|
147 |
147 |
$r = rg_del_tree($job['main']); |
$r = rg_del_tree($job['main']); |
148 |
148 |
if ($r === FALSE) { |
if ($r === FALSE) { |
|
... |
... |
function start_worker($job) |
159 |
159 |
|
|
160 |
160 |
// We need to allow libvirt access to the image |
// We need to allow libvirt access to the image |
161 |
161 |
$r = rg_exec('chown qemu:qemu ' |
$r = rg_exec('chown qemu:qemu ' |
162 |
|
. escapeshellarg($job['main']), '', FALSE, FALSE); |
|
|
162 |
|
. escapeshellarg($job['main']), '', FALSE, FALSE, FALSE); |
163 |
163 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
164 |
164 |
$reason = 'cannot chown build dir to qemu user: ' . $r['errmsg']; |
$reason = 'cannot chown build dir to qemu user: ' . $r['errmsg']; |
165 |
165 |
break; |
break; |
|
... |
... |
function start_worker($job) |
175 |
175 |
} |
} |
176 |
176 |
|
|
177 |
177 |
$r = rg_exec('qemu-img create -b ' . $master |
$r = rg_exec('qemu-img create -b ' . $master |
178 |
|
. ' -f qcow2 ' . $img, '', FALSE, FALSE); |
|
|
178 |
|
. ' -f qcow2 ' . $img, '', FALSE, FALSE, FALSE); |
179 |
179 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
180 |
180 |
$reason = 'cannot create image: ' . $r['errmsg']; |
$reason = 'cannot create image: ' . $r['errmsg']; |
181 |
181 |
break; |
break; |
182 |
182 |
} |
} |
183 |
183 |
|
|
184 |
|
$r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '', |
|
185 |
|
FALSE, FALSE); |
|
|
184 |
|
$r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', |
|
185 |
|
'', FALSE, FALSE, FALSE); |
186 |
186 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
187 |
187 |
$reason = 'cannot create image2: ' . $r['errmsg']; |
$reason = 'cannot create image2: ' . $r['errmsg']; |
188 |
188 |
break; |
break; |
|
... |
... |
function start_worker($job) |
192 |
192 |
$path = getenv('PATH'); |
$path = getenv('PATH'); |
193 |
193 |
putenv('PATH=' . $path . ':/usr/sbin'); |
putenv('PATH=' . $path . ':/usr/sbin'); |
194 |
194 |
|
|
195 |
|
$r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE, FALSE); |
|
|
195 |
|
$r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE, FALSE, FALSE); |
196 |
196 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
197 |
197 |
$reason = 'cannot create fs: ' . $r['errmsg']; |
$reason = 'cannot create fs: ' . $r['errmsg']; |
198 |
198 |
break; |
break; |
|
... |
... |
function start_worker($job) |
204 |
204 |
break; |
break; |
205 |
205 |
} |
} |
206 |
206 |
|
|
207 |
|
$r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '', |
|
208 |
|
FALSE, FALSE); |
|
|
207 |
|
$r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', |
|
208 |
|
'', FALSE, FALSE, FALSE); |
209 |
209 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
210 |
210 |
$reason = 'cannot mount fs: ' . $r['errmsg']; |
$reason = 'cannot mount fs: ' . $r['errmsg']; |
211 |
211 |
break; |
break; |
|
... |
... |
function start_worker($job) |
224 |
224 |
$cmd = ' git clone --depth 1' |
$cmd = ' git clone --depth 1' |
225 |
225 |
. ' ' . escapeshellarg($job['url']) |
. ' ' . escapeshellarg($job['url']) |
226 |
226 |
. ' ' . $emain . '/root/git'; |
. ' ' . $emain . '/root/git'; |
227 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
227 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
228 |
228 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
229 |
229 |
$reason = 'cannot clone: ' . $r['errmsg']; |
$reason = 'cannot clone: ' . $r['errmsg']; |
230 |
230 |
break; |
break; |
|
... |
... |
function start_worker($job) |
324 |
324 |
break; |
break; |
325 |
325 |
} |
} |
326 |
326 |
|
|
327 |
|
$r = rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE); |
|
|
327 |
|
$r = rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE, FALSE); |
328 |
328 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
329 |
329 |
$reason = 'cannot umount fs: ' . $r['errmsg']; |
$reason = 'cannot umount fs: ' . $r['errmsg']; |
330 |
330 |
break; |
break; |
|
... |
... |
function start_worker($job) |
332 |
332 |
$do_umount = FALSE; |
$do_umount = FALSE; |
333 |
333 |
|
|
334 |
334 |
// We need to allow libvirt access to the image |
// We need to allow libvirt access to the image |
335 |
|
$r = rg_exec('chown qemu:qemu ' . $img2, '', FALSE, FALSE); |
|
|
335 |
|
$r = rg_exec('chown qemu:qemu ' . $img2, '', FALSE, FALSE, FALSE); |
336 |
336 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
337 |
337 |
$reason = 'cannot chown image to qemu user: ' . $r['errmsg']; |
$reason = 'cannot chown image to qemu user: ' . $r['errmsg']; |
338 |
338 |
break; |
break; |
|
... |
... |
function start_worker($job) |
358 |
358 |
. ' --rng /dev/random' |
. ' --rng /dev/random' |
359 |
359 |
. ' --memballoon virtio' |
. ' --memballoon virtio' |
360 |
360 |
. ' --console pty,target_type=virtio' |
. ' --console pty,target_type=virtio' |
361 |
|
. ' ' . $env['paras'], '', FALSE, FALSE); |
|
|
361 |
|
. ' ' . $env['paras'], '', FALSE, FALSE, FALSE); |
362 |
362 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
363 |
363 |
$reason = 'cannot define and start virtual machine: ' |
$reason = 'cannot define and start virtual machine: ' |
364 |
364 |
. $r['errmsg']; |
. $r['errmsg']; |
|
... |
... |
function start_worker($job) |
369 |
369 |
break; |
break; |
370 |
370 |
} |
} |
371 |
371 |
if ($do_umount) |
if ($do_umount) |
372 |
|
rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE); |
|
|
372 |
|
rg_exec('umount ' . $emain . '/root', '', FALSE, FALSE, FALSE); |
373 |
373 |
|
|
374 |
374 |
// Seems that any error above must retrigger the build on other worker |
// Seems that any error above must retrigger the build on other worker |
375 |
375 |
if ($err) |
if ($err) |
|
... |
... |
function rg_job_extract_info(&$job) |
478 |
478 |
} |
} |
479 |
479 |
|
|
480 |
480 |
$cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root'; |
$cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root'; |
481 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
481 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
482 |
482 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
483 |
483 |
$job['error'] = 'Could not mount image: ' . $r['errmsg']; |
$job['error'] = 'Could not mount image: ' . $r['errmsg']; |
484 |
484 |
break; |
break; |
|
... |
... |
function rg_job_extract_info(&$job) |
520 |
520 |
unset($job['env']); |
unset($job['env']); |
521 |
521 |
|
|
522 |
522 |
$cmd = 'umount ' . $emain . '/root'; |
$cmd = 'umount ' . $emain . '/root'; |
523 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
523 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
524 |
524 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
525 |
525 |
rg_log('Cannot unmount: ' . $r['errmsg'] . '!'); |
rg_log('Cannot unmount: ' . $r['errmsg'] . '!'); |
526 |
526 |
break; |
break; |
|
... |
... |
while(1) { |
630 |
630 |
|
|
631 |
631 |
// TODO: do we destroy the pool in case of crash? |
// TODO: do we destroy the pool in case of crash? |
632 |
632 |
$cmd = 'virsh pool-destroy rocketgit-j-' . $jid; |
$cmd = 'virsh pool-destroy rocketgit-j-' . $jid; |
633 |
|
$r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
633 |
|
$r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
634 |
634 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
635 |
635 |
$job['error'] = 'Could not destroy pool: ' . $r['errmsg']; |
$job['error'] = 'Could not destroy pool: ' . $r['errmsg']; |
636 |
636 |
rg_log('Error: ' . $job['error']); |
rg_log('Error: ' . $job['error']); |
|
... |
... |
while(1) { |
639 |
639 |
|
|
640 |
640 |
// TODO: do we clean the pool in case of crash? |
// TODO: do we clean the pool in case of crash? |
641 |
641 |
// $cmd = 'virsh pool-undefine rocketgit-j-' . $jid; |
// $cmd = 'virsh pool-undefine rocketgit-j-' . $jid; |
642 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
642 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
643 |
643 |
// if ($r['ok'] != 1) { |
// if ($r['ok'] != 1) { |
644 |
644 |
// $job['error'] = 'Could not undefine pool: ' . $r['errmsg']; |
// $job['error'] = 'Could not undefine pool: ' . $r['errmsg']; |
645 |
645 |
// rg_log('Error: ' . $job['error']); |
// rg_log('Error: ' . $job['error']); |
|
... |
... |
while(1) { |
648 |
648 |
|
|
649 |
649 |
// // TODO: do we clean the machine in case of crash? |
// // TODO: do we clean the machine in case of crash? |
650 |
650 |
// $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid); |
// $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid); |
651 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
651 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
652 |
652 |
// if ($r['ok'] != 1) { |
// if ($r['ok'] != 1) { |
653 |
653 |
// $job['error'] = 'Could not undefine machine: ' . $r['errmsg']; |
// $job['error'] = 'Could not undefine machine: ' . $r['errmsg']; |
654 |
654 |
// rg_log('Error: ' . $job['error']); |
// rg_log('Error: ' . $job['error']); |
|
... |
... |
while(1) { |
656 |
656 |
// } |
// } |
657 |
657 |
|
|
658 |
658 |
// $cmd = 'virsh destroy rocketgit-j-' . $jid; |
// $cmd = 'virsh destroy rocketgit-j-' . $jid; |
659 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE); |
|
|
659 |
|
// $r = rg_exec($cmd, '', FALSE, FALSE, FALSE); |
660 |
660 |
// if ($r['ok'] != 1) { |
// if ($r['ok'] != 1) { |
661 |
661 |
// $job['error'] = 'Could not destroy: ' . $r['errmsg']; |
// $job['error'] = 'Could not destroy: ' . $r['errmsg']; |
662 |
662 |
// rg_log('Error: ' . $job['error']); |
// rg_log('Error: ' . $job['error']); |
File tests/by_http.php changed (mode: 100644) (index 3536aa2..12fdd6c) |
... |
... |
$a = rg_exec('rm -rf .by_http' |
52 |
52 |
. ' && git remote add private_repo_git ' . escapeshellarg($repo2['clone_url_git']) |
. ' && git remote add private_repo_git ' . escapeshellarg($repo2['clone_url_git']) |
53 |
53 |
. ' && echo "a signature" > a' |
. ' && echo "a signature" > a' |
54 |
54 |
. ' && git add a' |
. ' && git add a' |
55 |
|
. ' && git commit -a -m "' . $commit_body . '"', '', FALSE, FALSE); |
|
|
55 |
|
. ' && git commit -a -m "' . $commit_body . '"', |
|
56 |
|
'', FALSE, FALSE, FALSE); |
56 |
57 |
if ($a['ok'] != 1) { |
if ($a['ok'] != 1) { |
57 |
58 |
rg_log("Something wrong generating the git repo: " . $a['stderr']); |
rg_log("Something wrong generating the git repo: " . $a['stderr']); |
58 |
59 |
exit(1); |
exit(1); |
|
... |
... |
if ($a['ok'] != 1) { |
60 |
61 |
|
|
61 |
62 |
|
|
62 |
63 |
rg_log(''); |
rg_log(''); |
63 |
|
rg_log_enter('Trying to push to public (without user/pass)...'); |
|
|
64 |
|
rg_log_enter('Trying to push to public (empty user)...'); |
|
65 |
|
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_empty'); |
|
66 |
|
$r = rg_exec('cd .by_http && git push public_repo master', |
|
67 |
|
'', FALSE, FALSE, FALSE); |
|
68 |
|
if ($r['ok'] == 1) { |
|
69 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
70 |
|
rg_log('Seems I can push with empty user!'); |
|
71 |
|
exit(1); |
|
72 |
|
} |
|
73 |
|
if (!strstr($r['stderr'], 'Authentication failed')) { |
|
74 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
75 |
|
rg_log('The stderr does not contain \'Authentication failed\'!'); |
|
76 |
|
exit(1); |
|
77 |
|
} |
|
78 |
|
rg_log_exit(); |
|
79 |
|
|
|
80 |
|
|
|
81 |
|
rg_log(''); |
|
82 |
|
rg_log_enter('Trying to push to public (with guest)...'); |
64 |
83 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); |
65 |
|
$r = rg_exec('cd .by_http && git push public_repo master', '', FALSE, FALSE); |
|
|
84 |
|
$r = rg_exec('cd .by_http && git push public_repo master', |
|
85 |
|
'', FALSE, FALSE, FALSE); |
66 |
86 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
67 |
87 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
68 |
88 |
rg_log('Seems I cannot push without authentication (anonymous push)!'); |
rg_log('Seems I cannot push without authentication (anonymous push)!'); |
|
... |
... |
rg_log_exit(); |
79 |
99 |
rg_log(''); |
rg_log(''); |
80 |
100 |
rg_log_enter('Trying to push to public (with user/pass)...'); |
rg_log_enter('Trying to push to public (with user/pass)...'); |
81 |
101 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
82 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE); |
|
|
102 |
|
$r = rg_exec('cd .by_http && git push --verbose public_repo master', |
|
103 |
|
'', FALSE, FALSE, FALSE); |
83 |
104 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
84 |
105 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
85 |
106 |
rg_log('Seems I cannot push with authentication!'); |
rg_log('Seems I cannot push with authentication!'); |
|
... |
... |
rg_log_exit(); |
91 |
112 |
rg_log(''); |
rg_log(''); |
92 |
113 |
rg_log_enter('Trying to fetch from public (with user/pass)...'); |
rg_log_enter('Trying to fetch from public (with user/pass)...'); |
93 |
114 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
94 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE); |
|
|
115 |
|
$r = rg_exec('cd .by_http && git fetch --verbose public_repo master', |
|
116 |
|
'', FALSE, FALSE, FALSE); |
95 |
117 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
96 |
118 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
97 |
119 |
rg_log('Seems I cannot fetch with authentication!'); |
rg_log('Seems I cannot fetch with authentication!'); |
|
... |
... |
rg_log_exit(); |
102 |
124 |
|
|
103 |
125 |
rg_log(''); |
rg_log(''); |
104 |
126 |
rg_log_enter('Trying to fetch from private (by git://)...'); |
rg_log_enter('Trying to fetch from private (by git://)...'); |
105 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o fetch_by_git.strace' |
|
106 |
|
. ' git fetch --verbose private_repo_git master', '', FALSE, FALSE); |
|
|
127 |
|
$r = rg_exec('cd .by_http && git fetch --verbose private_repo_git master', |
|
128 |
|
'', FALSE, FALSE, FALSE); |
107 |
129 |
if ($r['ok'] == 1) { |
if ($r['ok'] == 1) { |
108 |
130 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
109 |
131 |
rg_log('Seems I can fetch by git://!'); |
rg_log('Seems I can fetch by git://!'); |
|
... |
... |
rg_log_exit(); |
113 |
135 |
|
|
114 |
136 |
|
|
115 |
137 |
rg_log(''); |
rg_log(''); |
116 |
|
rg_log_enter('Trying to push to private (without user/pass)...'); |
|
|
138 |
|
rg_log_enter('Trying to push to private (guest user)...'); |
117 |
139 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass_guest'); |
118 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o push_no_user.strace' |
|
119 |
|
. ' git push --verbose private_repo master', '', FALSE, FALSE); |
|
|
140 |
|
$r = rg_exec('cd .by_http && git push --verbose private_repo master', |
|
141 |
|
'', FALSE, FALSE, FALSE); |
120 |
142 |
if ($r['ok'] == 1) { |
if ($r['ok'] == 1) { |
121 |
143 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
122 |
144 |
rg_log('Seems I can push without authentication (anonymous push)!'); |
rg_log('Seems I can push without authentication (anonymous push)!'); |
|
... |
... |
rg_log_exit(); |
134 |
156 |
rg_log(''); |
rg_log(''); |
135 |
157 |
rg_log_enter('Trying to push to private (with user/pass)...'); |
rg_log_enter('Trying to push to private (with user/pass)...'); |
136 |
158 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
137 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o push_with_user.strace' |
|
138 |
|
. ' git push --verbose private_repo master', '', FALSE, FALSE); |
|
|
159 |
|
$r = rg_exec('cd .by_http && git push --verbose private_repo master', |
|
160 |
|
'', FALSE, FALSE, FALSE); |
139 |
161 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
140 |
162 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
141 |
163 |
rg_log('Seems I cannot push with authentication!'); |
rg_log('Seems I cannot push with authentication!'); |
|
... |
... |
rg_log_exit(); |
147 |
169 |
rg_log(''); |
rg_log(''); |
148 |
170 |
rg_log_enter('Trying to fetch from private (with user/pass)...'); |
rg_log_enter('Trying to fetch from private (with user/pass)...'); |
149 |
171 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
150 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o x2.strace git fetch --verbose private_repo', '', FALSE, FALSE); |
|
|
172 |
|
$r = rg_exec('cd .by_http && git fetch --verbose private_repo', |
|
173 |
|
'', FALSE, FALSE, FALSE); |
151 |
174 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
152 |
175 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
153 |
176 |
rg_log('Seems I cannot fetch with authentication!'); |
rg_log('Seems I cannot fetch with authentication!'); |
|
... |
... |
rg_log('key: ' . $key); |
166 |
189 |
rg_log(''); |
rg_log(''); |
167 |
190 |
rg_log_enter('Trying to push to public (with user/pass/login_token_missing)...'); |
rg_log_enter('Trying to push to public (with user/pass/login_token_missing)...'); |
168 |
191 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
169 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE); |
|
|
192 |
|
$r = rg_exec('cd .by_http && git push --verbose public_repo master', |
|
193 |
|
'', FALSE, FALSE, FALSE); |
170 |
194 |
if ($r['ok'] !== 0) { |
if ($r['ok'] !== 0) { |
171 |
195 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
172 |
196 |
rg_log('Seems I can push without passing login_token!'); |
rg_log('Seems I can push without passing login_token!'); |
|
... |
... |
rg_log_exit(); |
178 |
202 |
rg_log(''); |
rg_log(''); |
179 |
203 |
rg_log_enter('Trying to fetch from public (with user/pass/login_token_missing)...'); |
rg_log_enter('Trying to fetch from public (with user/pass/login_token_missing)...'); |
180 |
204 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
181 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE); |
|
|
205 |
|
$r = rg_exec('cd .by_http && git fetch --verbose public_repo master', |
|
206 |
|
'', FALSE, FALSE, FALSE); |
182 |
207 |
if ($r['ok'] !== 1) { |
if ($r['ok'] !== 1) { |
183 |
208 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
184 |
209 |
rg_log('Seems I cannot fetch without passing login_token!'); |
rg_log('Seems I cannot fetch without passing login_token!'); |
|
... |
... |
rg_log(''); |
191 |
216 |
rg_log_enter('Trying to push to public (with user/pass/login_token_ok)...'); |
rg_log_enter('Trying to push to public (with user/pass/login_token_ok)...'); |
192 |
217 |
putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 30) / 30, 6)); |
putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 30) / 30, 6)); |
193 |
218 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
194 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git push --verbose public_repo master', '', FALSE, FALSE); |
|
|
219 |
|
$r = rg_exec('cd .by_http && git push --verbose public_repo master', |
|
220 |
|
'', FALSE, FALSE, FALSE); |
195 |
221 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
196 |
222 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
197 |
223 |
rg_log('Seems I cannot push with authentication!'); |
rg_log('Seems I cannot push with authentication!'); |
|
... |
... |
rg_log(''); |
204 |
230 |
rg_log_enter('Trying to fetch from public (with user/pass/login_token_ok)...'); |
rg_log_enter('Trying to fetch from public (with user/pass/login_token_ok)...'); |
205 |
231 |
putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 0) / 30, 6)); |
putenv('RG_LOGIN_TOKEN=' . rg_totp_compute($key, (time() - 0) / 30, 6)); |
206 |
232 |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
putenv('GIT_ASKPASS=' . dirname(__FILE__) . '/ask_pass'); |
207 |
|
$r = rg_exec('cd .by_http && strace -s2000 -f -tt -o by_http.strace git fetch --verbose public_repo master', '', FALSE, FALSE); |
|
|
233 |
|
$r = rg_exec('cd .by_http && git fetch --verbose public_repo master', |
|
234 |
|
'', FALSE, FALSE, FALSE); |
208 |
235 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
209 |
236 |
rg_log_ml('r: ' . print_r($r, TRUE)); |
rg_log_ml('r: ' . print_r($r, TRUE)); |
210 |
237 |
rg_log('Seems I cannot fetch with authentication!'); |
rg_log('Seems I cannot fetch with authentication!'); |
File tests/pr_anon.php changed (mode: 100644) (index 5dcac32..2f4fa79) |
... |
... |
$r = rg_exec('mkdir -p temp_repos && cd temp_repos' |
97 |
97 |
. ' && git remote add origin_git ' |
. ' && git remote add origin_git ' |
98 |
98 |
. ' git://' . $rg_git_host . ':' . $rg_git_port |
. ' git://' . $rg_git_host . ':' . $rg_git_port |
99 |
99 |
. '/user/' . escapeshellarg($rg_ui['username']) . '/' |
. '/user/' . escapeshellarg($rg_ui['username']) . '/' |
100 |
|
. escapeshellarg($repo['name']), '', FALSE, FALSE); |
|
|
100 |
|
. escapeshellarg($repo['name']), |
|
101 |
|
'', FALSE, FALSE, FALSE); |
101 |
102 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
102 |
103 |
rg_log('Could not prepare git repo: ' . $r['errmsg'] . '!'); |
rg_log('Could not prepare git repo: ' . $r['errmsg'] . '!'); |
103 |
104 |
exit(1); |
exit(1); |
|
... |
... |
$r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"' |
112 |
113 |
. ' && echo "change1" > a && git add a && git commit -m "change1 desc"' |
. ' && echo "change1" > a && git add a && git commit -m "change1 desc"' |
113 |
114 |
. ' && echo "change2" > a && git commit -a -m "change2 desc"' |
. ' && echo "change2" > a && git commit -a -m "change2 desc"' |
114 |
115 |
. ' && git push origin_ssh master', |
. ' && git push origin_ssh master', |
115 |
|
'', FALSE, FALSE); |
|
|
116 |
|
'', FALSE, FALSE, FALSE); |
116 |
117 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
117 |
118 |
rg_log('Non-anonymous push was rejected: ' . $r['errmsg'] . '!'); |
rg_log('Non-anonymous push was rejected: ' . $r['errmsg'] . '!'); |
118 |
119 |
exit(1); |
exit(1); |
|
... |
... |
$r = rg_exec('cd temp_repos/pr_anon' |
127 |
128 |
. ' && git commit -m "anon change1 desc"' |
. ' && git commit -m "anon change1 desc"' |
128 |
129 |
. ' && echo "change4" >> a; git commit -a -m "anon change2 desc"' |
. ' && echo "change4" >> a; git commit -a -m "anon change2 desc"' |
129 |
130 |
. ' && git push origin_git master', |
. ' && git push origin_git master', |
130 |
|
'', FALSE, FALSE); |
|
|
131 |
|
'', FALSE, FALSE, FALSE); |
131 |
132 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
132 |
133 |
rg_log('Anonymous push was rejected: ' . $r['errmsg'] . '!'); |
rg_log('Anonymous push was rejected: ' . $r['errmsg'] . '!'); |
133 |
134 |
exit(1); |
exit(1); |
|
... |
... |
rg_log_exit(); |
175 |
176 |
|
|
176 |
177 |
rg_log(''); |
rg_log(''); |
177 |
178 |
rg_log_enter('Merging merge request...'); |
rg_log_enter('Merging merge request...'); |
|
179 |
|
$mm1 = 'This is the merge message <xss>'; |
178 |
180 |
$data = array('token' => $r['tokens']['mr_merge'], |
$data = array('token' => $r['tokens']['mr_merge'], |
179 |
|
'merge_ff' => 0, 'merge_msg' => 'This is the merge message <xss>'); |
|
|
181 |
|
'merge_ff' => 0, 'merge_msg' => $mm1); |
180 |
182 |
$r = do_req($test_url . $url . $mri['id'] . '/merge', $data, $headers); |
$r = do_req($test_url . $url . $mri['id'] . '/merge', $data, $headers); |
181 |
183 |
if ($r === FALSE) { |
if ($r === FALSE) { |
182 |
184 |
rg_log('Cannot post merge form'); |
rg_log('Cannot post merge form'); |
|
... |
... |
while (1) { |
200 |
202 |
$tries++; |
$tries++; |
201 |
203 |
sleep(1); |
sleep(1); |
202 |
204 |
} |
} |
|
205 |
|
$r = rg_exec('cd temp_repos/pr_anon' |
|
206 |
|
. ' && git pull origin_git master' |
|
207 |
|
. ' && git log --oneline -n1', |
|
208 |
|
'', FALSE, FALSE, FALSE); |
|
209 |
|
if ($r['ok'] != 1) { |
|
210 |
|
rg_log('Could not pull: ' . $r['errmsg'] . '!'); |
|
211 |
|
exit(1); |
|
212 |
|
} |
|
213 |
|
if (!strstr($r['data'], $mm1)) { |
|
214 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
215 |
|
rg_log('Cannot find the merge message!'); |
|
216 |
|
exit(1); |
|
217 |
|
} |
203 |
218 |
rg_log_exit(); |
rg_log_exit(); |
204 |
219 |
|
|
205 |
220 |
|
|
206 |
221 |
rg_log(''); |
rg_log(''); |
207 |
222 |
rg_log_enter('Now, try to see what happens when a merge is with conflicts...'); |
rg_log_enter('Now, try to see what happens when a merge is with conflicts...'); |
208 |
223 |
$r = rg_exec('cd temp_repos/pr_anon' |
$r = rg_exec('cd temp_repos/pr_anon' |
209 |
|
. ' && git pull origin_git master' |
|
210 |
224 |
. ' && echo "change2" > a' |
. ' && echo "change2" > a' |
211 |
225 |
. ' && git commit -a -m "conflict1b"' |
. ' && git commit -a -m "conflict1b"' |
212 |
226 |
. ' && git push origin_git master', |
. ' && git push origin_git master', |
213 |
|
'', FALSE, FALSE); |
|
|
227 |
|
'', FALSE, FALSE, FALSE); |
214 |
228 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
215 |
229 |
rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!'); |
rg_log('Could not pull/commit/push by git proto: ' . $r['errmsg'] . '!'); |
216 |
230 |
exit(1); |
exit(1); |
|
... |
... |
$r = rg_exec('export GIT_SSH_COMMAND="' . $ssh . '"' |
221 |
235 |
. ' && echo "change1" > a' |
. ' && echo "change1" > a' |
222 |
236 |
. ' && git commit -a -m "conflict1a"' |
. ' && git commit -a -m "conflict1a"' |
223 |
237 |
. ' && git push origin_ssh master', |
. ' && git push origin_ssh master', |
224 |
|
'', FALSE, FALSE); |
|
|
238 |
|
'', FALSE, FALSE, FALSE); |
225 |
239 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
226 |
240 |
rg_log('Could not reset/commit/push by ssh proto: ' . $r['errmsg'] . '!'); |
rg_log('Could not reset/commit/push by ssh proto: ' . $r['errmsg'] . '!'); |
227 |
241 |
exit(1); |
exit(1); |
File tests/util.php changed (mode: 100644) (index abf6055..f1da20c) |
... |
... |
if ($r !== TRUE) { |
295 |
295 |
} |
} |
296 |
296 |
|
|
297 |
297 |
|
|
298 |
|
$r = rg_exec("/xxxx", '', FALSE, FALSE); |
|
|
298 |
|
rg_log(''); |
|
299 |
|
rg_log_enter('exec a non existing command'); |
|
300 |
|
$r = rg_exec("/xxxx", '', FALSE, FALSE, FALSE); |
299 |
301 |
if ($r['ok'] == 1) { |
if ($r['ok'] == 1) { |
300 |
|
rg_log("util.php: running non existing command does not return 0!"); |
|
301 |
|
print_r($r); |
|
|
302 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
303 |
|
rg_log("running non existing command does not return 0!"); |
|
304 |
|
exit(1); |
|
305 |
|
} |
|
306 |
|
if (strcmp($r['stderr'], "sh: /xxxx: No such file or directory\n") != 0) { |
|
307 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
308 |
|
rg_log('stderr is not correct!'); |
302 |
309 |
exit(1); |
exit(1); |
303 |
310 |
} |
} |
|
311 |
|
if ($r['code'] != 127) { |
|
312 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
313 |
|
rg_log('error code must be 127!'); |
|
314 |
|
exit(1); |
|
315 |
|
} |
|
316 |
|
rg_log_exit(); |
304 |
317 |
|
|
305 |
|
$r = rg_exec("ls", '', FALSE, FALSE); |
|
|
318 |
|
rg_log(''); |
|
319 |
|
rg_log_enter('exec a normal \'ls\' command'); |
|
320 |
|
$r = rg_exec("ls", '', FALSE, FALSE, FALSE); |
306 |
321 |
if ($r['ok'] != 1) { |
if ($r['ok'] != 1) { |
307 |
|
rg_log("util.php: cannot run a command!"); |
|
308 |
|
print_r($r); |
|
|
322 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
323 |
|
rg_log("cannot run a command!"); |
309 |
324 |
exit(1); |
exit(1); |
310 |
325 |
} |
} |
|
326 |
|
rg_log_exit(); |
|
327 |
|
|
311 |
328 |
|
|
312 |
|
$r = rg_exec("./util_exit_code.sh 5", '', FALSE, FALSE); |
|
313 |
|
if ($r['code'] != 5) { |
|
314 |
|
rg_log("util.php: error code seems to not be propageted!"); |
|
315 |
|
print_r($r); |
|
|
329 |
|
rg_log(''); |
|
330 |
|
rg_log_enter('force exit code 5'); |
|
331 |
|
$r = rg_exec("./util_exit_code.sh 5", '', FALSE, FALSE, FALSE); |
|
332 |
|
if (($r['ok'] == 1) || ($r['code'] != 5)) { |
|
333 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
334 |
|
rg_log("error code seems to not be propageted!"); |
316 |
335 |
exit(1); |
exit(1); |
317 |
336 |
} |
} |
|
337 |
|
rg_log_exit(); |
|
338 |
|
|
|
339 |
|
|
|
340 |
|
rg_log(''); |
|
341 |
|
rg_log_enter('stdout closes first'); |
|
342 |
|
$r = rg_exec("./util_stdout_closes_first.sh", '', FALSE, FALSE, FALSE); |
|
343 |
|
if (($r['ok'] != 1) || ($r['code'] != 0)) { |
|
344 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
345 |
|
rg_log("stdout_closes_first should return ok/code0!"); |
|
346 |
|
exit(1); |
|
347 |
|
} |
|
348 |
|
if (strcmp($r['data'], "stdout\n") != 0) { |
|
349 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
350 |
|
rg_log("stdout returned value is not correct!"); |
|
351 |
|
exit(1); |
|
352 |
|
} |
|
353 |
|
if (strcmp($r['stderr'], "stderr1\nstderr2\n") != 0) { |
|
354 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
355 |
|
rg_log("stderr returned value is not correct!"); |
|
356 |
|
exit(1); |
|
357 |
|
} |
|
358 |
|
rg_log_exit(); |
|
359 |
|
|
|
360 |
|
|
|
361 |
|
rg_log(''); |
|
362 |
|
rg_log_enter('exec2 - complex'); |
|
363 |
|
// Define helpers |
|
364 |
|
function cb_input($index, &$a, $stream) |
|
365 |
|
{ |
|
366 |
|
if (isset($a['cb_input_called'])) |
|
367 |
|
return; |
|
368 |
|
|
|
369 |
|
rg_log('cb_input[' . $index . '] stream=' . $stream); |
|
370 |
|
switch ($stream) { |
|
371 |
|
case 1: rg_log(' stdout: ' . $a['in_buf']); break; |
|
372 |
|
case 2: rg_log(' stderr: ' . $a['err_buf']); break; |
|
373 |
|
} |
|
374 |
|
|
|
375 |
|
$a['out_buf'] .= ' send_something_from_cb_input_' . $index . "\n"; |
|
376 |
|
$a['cb_input_called'] = 1; |
|
377 |
|
} |
|
378 |
|
function cb_output($index, &$a) |
|
379 |
|
{ |
|
380 |
|
if (isset($a['cb_output_called'])) |
|
381 |
|
return; |
|
382 |
|
|
|
383 |
|
rg_log('cb_output[' . $index . ']'); |
|
384 |
|
|
|
385 |
|
$a['out_buf'] .= ' generated_output_' . $index . "\n"; |
|
386 |
|
$a['cb_output_called'] = 1; |
|
387 |
|
} |
|
388 |
|
function cb_error($index, &$a, $msg) |
|
389 |
|
{ |
|
390 |
|
rg_log('cb_error[' . $index . ']: ' . $msg); |
|
391 |
|
// If we need to restart the command, use this: |
|
392 |
|
//$a['restart_delay'] = 0; // in seconds |
|
393 |
|
} |
|
394 |
|
function cb_idle($index, &$a) |
|
395 |
|
{ |
|
396 |
|
rg_log('cb_idle[' . $index . ']'); |
|
397 |
|
} |
|
398 |
|
function cb_finish($index, &$a, $exitcode) |
|
399 |
|
{ |
|
400 |
|
rg_log('cb_finish[' . $index . ']: exitcode=' . $exitcode); |
|
401 |
|
} |
|
402 |
|
function cb_tick($index, &$a) |
|
403 |
|
{ |
|
404 |
|
rg_log('cb_tick[' . $index . ']'); |
|
405 |
|
$a['my'] = 'tick_was_here'; |
318 |
406 |
|
|
|
407 |
|
if (!isset($a['cb_input_called']) || !isset($a['cb_output_called'])) |
|
408 |
|
return; |
|
409 |
|
|
|
410 |
|
// We do not want to output something anymore |
|
411 |
|
// This can be set from any callback. |
|
412 |
|
rg_log('cb_tick: now we can set output_done to 1'); |
|
413 |
|
$a['output_done'] = 1; |
|
414 |
|
} |
|
415 |
|
|
|
416 |
|
$a = array( |
|
417 |
|
'cmds' => array( |
|
418 |
|
'cmd1' => array( |
|
419 |
|
'cmd' => 'echo first1; read a; sleep .2; echo last1; echo "err1-[${a}]" 1>&2', |
|
420 |
|
'cb_input' => 'cb_input', |
|
421 |
|
'cb_output' => 'cb_output', |
|
422 |
|
'cb_error' => 'cb_error', |
|
423 |
|
'cb_idle' => 'cb_idle', |
|
424 |
|
'cb_finish' => 'cb_finish', |
|
425 |
|
'cb_tick' => 'cb_tick', |
|
426 |
|
'out_buf' => 'aaa1', |
|
427 |
|
'output_done' => 0 |
|
428 |
|
), |
|
429 |
|
'cmd2' => array( |
|
430 |
|
'cmd' => 'echo first2; read a; sleep .2; echo last2; echo "err2-[${a}]" 1>&2', |
|
431 |
|
'cb_input' => 'cb_input', |
|
432 |
|
'cb_output' => 'cb_output', |
|
433 |
|
'cb_error' => 'cb_error', |
|
434 |
|
'cb_idle' => 'cb_idle', |
|
435 |
|
'cb_finish' => 'cb_finish', |
|
436 |
|
'cb_tick' => 'cb_tick', |
|
437 |
|
'out_buf' => 'aaa2', |
|
438 |
|
'output_done' => 0 |
|
439 |
|
) |
|
440 |
|
) |
|
441 |
|
); |
|
442 |
|
$r = rg_exec2($a); |
|
443 |
|
if ($r['ok'] != 1) { |
|
444 |
|
rg_log('rg_exec2 failed: ' . $r['errmsg'] . '!'); |
|
445 |
|
exit(1); |
|
446 |
|
} |
|
447 |
|
$e = "first1\nlast1\n"; |
|
448 |
|
if (strcmp($r['cmds']['cmd1']['in_buf'], $e) != 0) { |
|
449 |
|
rg_log('cmd1 in_buf is not ok: [' |
|
450 |
|
. $r['cmds']['cmd1']['in_buf'] . '] != [' . $e . ']!'); |
|
451 |
|
exit(1); |
|
452 |
|
} |
|
453 |
|
$e = "first2\nlast2\n"; |
|
454 |
|
if (strcmp($r['cmds']['cmd2']['in_buf'], $e) != 0) { |
|
455 |
|
rg_log('cmd2 in_buf is not ok: [' |
|
456 |
|
. $r['cmds']['cmd2']['in_buf'] . '] != [' . $e . ']!'); |
|
457 |
|
exit(1); |
|
458 |
|
} |
|
459 |
|
$e = "err2-[aaa2 generated_output_cmd2]\n"; |
|
460 |
|
if (strcmp($r['cmds']['cmd2']['err_buf'], $e) != 0) { |
|
461 |
|
rg_log('cmd2 err_buf is not ok: [' |
|
462 |
|
. $r['cmds']['cmd2']['err_buf'] . '] != [' . $e . ']!'); |
|
463 |
|
exit(1); |
|
464 |
|
} |
|
465 |
|
$e = 'tick_was_here'; |
|
466 |
|
if (!isset($r['cmds']['cmd2']['my']) || (strcmp($r['cmds']['cmd2']['my'], $e) != 0)) { |
|
467 |
|
rg_log_ml('r: ' . print_r($r, TRUE)); |
|
468 |
|
rg_log('my is not ok (cb_tick was not called?)!'); |
|
469 |
|
exit(1); |
|
470 |
|
} |
|
471 |
|
rg_log_exit(); |
|
472 |
|
|
|
473 |
|
|
|
474 |
|
rg_log(''); |
319 |
475 |
$t = "test rg_template_table(dir, data, more) with no data"; |
$t = "test rg_template_table(dir, data, more) with no data"; |
320 |
|
rg_log($t); |
|
|
476 |
|
rg_log_enter($t); |
321 |
477 |
$data = array(); |
$data = array(); |
322 |
478 |
$r = rg_template_table("t1", $data, array("a" => "A")); |
$r = rg_template_table("t1", $data, array("a" => "A")); |
323 |
479 |
$e = "XAX"; |
$e = "XAX"; |
324 |
480 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
325 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
481 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
326 |
482 |
exit(1); |
exit(1); |
327 |
483 |
} |
} |
|
484 |
|
rg_log_exit(); |
328 |
485 |
|
|
329 |
486 |
$t = "test rg_template_table(dir, data, more) with data"; |
$t = "test rg_template_table(dir, data, more) with data"; |
330 |
487 |
rg_log($t); |
rg_log($t); |
|
... |
... |
$data = array(array("a" => "A", "b" => "B"), array("a" => "A2", "b" => "B2")); |
332 |
489 |
$r = rg_template_table("t2", $data, array("c" => "C")); |
$r = rg_template_table("t2", $data, array("c" => "C")); |
333 |
490 |
$e = "HEADCABCA2B2CFOOTC"; |
$e = "HEADCABCA2B2CFOOTC"; |
334 |
491 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
335 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
492 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
336 |
493 |
exit(1); |
exit(1); |
337 |
494 |
} |
} |
338 |
495 |
|
|
|
... |
... |
$data = array("X" => "0", "A" => "Avalue", "B" => "Bvalue"); |
342 |
499 |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
343 |
500 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
344 |
501 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
345 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
502 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
346 |
503 |
exit(1); |
exit(1); |
347 |
504 |
} |
} |
348 |
505 |
|
|
|
... |
... |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
352 |
509 |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
353 |
510 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
354 |
511 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
355 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
512 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
356 |
513 |
exit(1); |
exit(1); |
357 |
514 |
} |
} |
358 |
515 |
|
|
|
... |
... |
$data = array("X" => "1", "A" => "Avalue", "B" => "Bvalue"); |
362 |
519 |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
$r = rg_template("t3/c1", $data, TRUE /*xss*/); |
363 |
520 |
$e = "XXAvalueYY"; |
$e = "XXAvalueYY"; |
364 |
521 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
365 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
522 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
366 |
523 |
exit(1); |
exit(1); |
367 |
524 |
} |
} |
368 |
525 |
|
|
|
... |
... |
$data = array("X" => "1", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
373 |
530 |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
374 |
531 |
$e = "XXRvalueZZYY"; |
$e = "XXRvalueZZYY"; |
375 |
532 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
376 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
533 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
377 |
534 |
exit(1); |
exit(1); |
378 |
535 |
} |
} |
379 |
536 |
|
|
|
... |
... |
$data = array("X" => "1", "Y" => "0", "A" => "Avalue", "B" => "Bvalue", |
384 |
541 |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
385 |
542 |
$e = "XXTvalueZZYY"; |
$e = "XXTvalueZZYY"; |
386 |
543 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
387 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
544 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
388 |
545 |
exit(1); |
exit(1); |
389 |
546 |
} |
} |
390 |
547 |
|
|
|
... |
... |
$data = array("X" => "0", "Y" => "1", "A" => "Avalue", "B" => "Bvalue", |
395 |
552 |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
$r = rg_template("t3/c3", $data, TRUE /*xss*/); |
396 |
553 |
$e = "XXBvalueYY"; |
$e = "XXBvalueYY"; |
397 |
554 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
398 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
555 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
399 |
556 |
exit(1); |
exit(1); |
400 |
557 |
} |
} |
401 |
558 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
406 |
563 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
407 |
564 |
$e = "XXTRUE_LEVEL_2YY"; |
$e = "XXTRUE_LEVEL_2YY"; |
408 |
565 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
409 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
566 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
410 |
567 |
exit(1); |
exit(1); |
411 |
568 |
} |
} |
412 |
569 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
417 |
574 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
418 |
575 |
$e = "XXFALSE_LEVEL_1YY"; |
$e = "XXFALSE_LEVEL_1YY"; |
419 |
576 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
420 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
577 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
421 |
578 |
exit(1); |
exit(1); |
422 |
579 |
} |
} |
423 |
580 |
|
|
|
... |
... |
$r = rg_template("t3/c4", $data, TRUE /*xss*/); |
428 |
585 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
429 |
586 |
$e = "XXFALSE_LEVEL_0YY"; |
$e = "XXFALSE_LEVEL_0YY"; |
430 |
587 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
431 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
588 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
432 |
589 |
exit(1); |
exit(1); |
433 |
590 |
} |
} |
434 |
591 |
|
|
|
... |
... |
$r = rg_template("t3/c5", $data, TRUE /*xss*/); |
439 |
596 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
440 |
597 |
$e = "XX-X0Y0Z0-YY"; |
$e = "XX-X0Y0Z0-YY"; |
441 |
598 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
442 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
599 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
443 |
600 |
exit(1); |
exit(1); |
444 |
601 |
} |
} |
445 |
602 |
|
|
|
... |
... |
$r = rg_template("t3/c5", $data, TRUE /*xss*/); |
450 |
607 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
451 |
608 |
$e = "XX-X0Y1Z0-YY"; |
$e = "XX-X0Y1Z0-YY"; |
452 |
609 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
453 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
610 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
454 |
611 |
exit(1); |
exit(1); |
455 |
612 |
} |
} |
456 |
613 |
|
|
|
... |
... |
$r = rg_template("t3/c6", $data, TRUE /*xss*/); |
461 |
618 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
462 |
619 |
$e = "A"; |
$e = "A"; |
463 |
620 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
464 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
621 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
465 |
622 |
exit(1); |
exit(1); |
466 |
623 |
} |
} |
467 |
624 |
|
|
|
... |
... |
$r = rg_template("t3/c6b", $data, TRUE /*xss*/); |
472 |
629 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
473 |
630 |
$e = "AY"; |
$e = "AY"; |
474 |
631 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
475 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
632 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
476 |
633 |
exit(1); |
exit(1); |
477 |
634 |
} |
} |
478 |
635 |
|
|
|
... |
... |
$r = rg_template("t3/c7", $data, TRUE /*xss*/); |
483 |
640 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
484 |
641 |
$e = "B"; |
$e = "B"; |
485 |
642 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
486 |
|
rg_log("util.php: $t: not working (r=$r e=$e)!"); |
|
|
643 |
|
rg_log("$t: not working (r=$r e=$e)!"); |
487 |
644 |
exit(1); |
exit(1); |
488 |
645 |
} |
} |
489 |
646 |
|
|
|
... |
... |
$r = rg_template("t3/c8", $data, TRUE /*xss*/); |
494 |
651 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
495 |
652 |
$e = "}}"; |
$e = "}}"; |
496 |
653 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
497 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
|
|
654 |
|
rg_log("$t: not working (r=[$r] e=[$e])!"); |
498 |
655 |
exit(1); |
exit(1); |
499 |
656 |
} |
} |
500 |
657 |
|
|
|
... |
... |
$r = rg_template("t3/c9", $data, TRUE /*xss*/); |
505 |
662 |
$r = preg_replace('/\s/', '', $r); |
$r = preg_replace('/\s/', '', $r); |
506 |
663 |
$e = "XXBLABLABLAabcYYabc"; |
$e = "XXBLABLABLAabcYYabc"; |
507 |
664 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
508 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
|
|
665 |
|
rg_log("$t: not working (r=[$r] e=[$e])!"); |
509 |
666 |
exit(1); |
exit(1); |
510 |
667 |
} |
} |
511 |
668 |
|
|
|
... |
... |
$data = array("X" => "abc"); |
515 |
672 |
$r = rg_template("t3/c9", $data, TRUE /*xss protection*/); |
$r = rg_template("t3/c9", $data, TRUE /*xss protection*/); |
516 |
673 |
$e = "XX\n\tBLA\n\tBLA\n\tBLA\n\tabc\nYY\nabc\n"; |
$e = "XX\n\tBLA\n\tBLA\n\tBLA\n\tabc\nYY\nabc\n"; |
517 |
674 |
if (strcmp($r, $e) != 0) { |
if (strcmp($r, $e) != 0) { |
518 |
|
rg_log("util.php: $t: not working (r=[$r] e=[$e])!"); |
|
|
675 |
|
rg_log("$t: not working (r=[$r] e=[$e])!"); |
519 |
676 |
exit(1); |
exit(1); |
520 |
677 |
} |
} |
521 |
678 |
|
|
|
... |
... |
$t = "test rg_copy_tree"; |
537 |
694 |
rg_log($t); |
rg_log($t); |
538 |
695 |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
$r = rg_copy_tree("tree1", "tree1.copy", 0755); |
539 |
696 |
if ($r !== TRUE) { |
if ($r !== TRUE) { |
540 |
|
rg_log("util.php: $t: not working!"); |
|
|
697 |
|
rg_log("$t: not working!"); |
541 |
698 |
exit(1); |
exit(1); |
542 |
699 |
} |
} |
543 |
700 |
if (!file_exists("tree1.copy/a/f2")) { |
if (!file_exists("tree1.copy/a/f2")) { |
544 |
|
rg_log("util.php: $t(2): not working!"); |
|
|
701 |
|
rg_log("$t(2): not working!"); |
545 |
702 |
exit(1); |
exit(1); |
546 |
703 |
} |
} |
547 |
704 |
|
|
|
... |
... |
if (strcmp($r, $e) != 0) { |
587 |
744 |
} |
} |
588 |
745 |
|
|
589 |
746 |
|
|
590 |
|
rg_log(''); |
|
591 |
|
rg_log_enter('rg_exec2'); |
|
592 |
|
// Define helpers |
|
593 |
|
function cb_input($index, &$a, $stream) |
|
594 |
|
{ |
|
595 |
|
rg_log('cb_input[' . $index . '] stream=' . $stream); |
|
596 |
|
switch ($stream) { |
|
597 |
|
case 1: rg_log(' stdout: ' . $a['in_buf']); break; |
|
598 |
|
case 1: rg_log(' stderr: ' . $a['err_buf']); break; |
|
599 |
|
} |
|
600 |
|
|
|
601 |
|
$a['out_buf'] .= ' send_something_from_cb_input_' . $index . "\n"; |
|
602 |
|
} |
|
603 |
|
function cb_output($index, &$a) |
|
604 |
|
{ |
|
605 |
|
rg_log('cb_output[' . $index . ']'); |
|
606 |
|
|
|
607 |
|
$a['out_buf'] .= ' generated_output_' . $index . "\n"; |
|
608 |
|
|
|
609 |
|
// we do not want anymore to be called |
|
610 |
|
rg_log('Unsetting cb_output'); |
|
611 |
|
unset($a['cb_output']); |
|
612 |
|
} |
|
613 |
|
function cb_error($index, &$a, $msg) |
|
614 |
|
{ |
|
615 |
|
rg_log('cb_error[' . $index . ']: ' . $msg); |
|
616 |
|
// If we need to restart the command, use this: |
|
617 |
|
//$a['needs_restart'] = TRUE; |
|
618 |
|
} |
|
619 |
|
function cb_idle($index, &$a) |
|
620 |
|
{ |
|
621 |
|
rg_log('cb_idle[' . $index . ']'); |
|
622 |
|
$a['done'] = TRUE; |
|
623 |
|
} |
|
624 |
|
function cb_finish($index, &$a, $exitcode) |
|
625 |
|
{ |
|
626 |
|
rg_log('cb_finish[' . $index . ']: exitcode=' . $exitcode); |
|
627 |
|
} |
|
628 |
|
function cb_tick(&$a) |
|
629 |
|
{ |
|
630 |
|
rg_log('cb_tick'); |
|
631 |
|
$a['my'] = 'tick_was_here'; |
|
632 |
|
} |
|
633 |
|
|
|
634 |
|
$a = array( |
|
635 |
|
'cmds' => array( |
|
636 |
|
'cmd1' => array( |
|
637 |
|
'cmd' => 'echo first1; read a; sleep 2; echo last1; echo "err1-[${a}]" 1>&2', |
|
638 |
|
'cb_input' => 'cb_input', |
|
639 |
|
'cb_output' => 'cb_output', |
|
640 |
|
'cb_error' => 'cb_error', |
|
641 |
|
'cb_idle' => 'cb_idle', |
|
642 |
|
'cb_finish' => 'cb_finish', |
|
643 |
|
'out_buf' => 'aaa1' |
|
644 |
|
), |
|
645 |
|
'cmd2' => array( |
|
646 |
|
'cmd' => 'echo first2; read a; sleep 2; echo last2; echo "err2-[${a}]" 1>&2', |
|
647 |
|
'cb_input' => 'cb_input', |
|
648 |
|
'cb_output' => 'cb_output', |
|
649 |
|
'cb_error' => 'cb_error', |
|
650 |
|
'cb_idle' => 'cb_idle', |
|
651 |
|
'cb_finish' => 'cb_finish', |
|
652 |
|
'out_buf' => 'aaa2' |
|
653 |
|
) |
|
654 |
|
), |
|
655 |
|
'cb_tick' => 'cb_tick' |
|
656 |
|
); |
|
657 |
|
$r = rg_exec2($a); |
|
658 |
|
if ($r['ok'] != 1) { |
|
659 |
|
rg_log('rg_exec2 failed: ' . $r['errmsg'] . '!'); |
|
660 |
|
exit(1); |
|
661 |
|
} |
|
662 |
|
$e = "first1\nlast1\n"; |
|
663 |
|
if (strcmp($a['cmds']['cmd1']['in_buf'], $e) != 0) { |
|
664 |
|
rg_log('cmd1 in_buf is not ok: [' |
|
665 |
|
. $a['cmds']['cmd1']['in_buf'] . '] != [' . $e . ']!'); |
|
666 |
|
exit(1); |
|
667 |
|
} |
|
668 |
|
$e = "first2\nlast2\n"; |
|
669 |
|
if (strcmp($a['cmds']['cmd2']['in_buf'], $e) != 0) { |
|
670 |
|
rg_log('cmd2 in_buf is not ok: [' |
|
671 |
|
. $a['cmds']['cmd2']['in_buf'] . '] != [' . $e . ']!'); |
|
672 |
|
exit(1); |
|
673 |
|
} |
|
674 |
|
$e = "err2-[aaa2 generated_output_cmd2]\n"; |
|
675 |
|
if (strcmp($a['cmds']['cmd2']['err_buf'], $e) != 0) { |
|
676 |
|
rg_log('cmd2 err_buf is not ok: [' |
|
677 |
|
. $a['cmds']['cmd2']['err_buf'] . '] != [' . $e . ']!'); |
|
678 |
|
exit(1); |
|
679 |
|
} |
|
680 |
|
$e = 'tick_was_here'; |
|
681 |
|
if (!isset($a['my']) || (strcmp($a['my'], $e) != 0)) { |
|
682 |
|
rg_log('my is not ok (cb_tick was not called?): [' |
|
683 |
|
. (isset($a['my']) ? $a['my'] : '') . '] != [' . $e . ']!'); |
|
684 |
|
exit(1); |
|
685 |
|
} |
|
686 |
|
rg_log_exit(); |
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
|
690 |
747 |
rg_log(''); |
rg_log(''); |
691 |
748 |
$s = 'șțaaș'; |
$s = 'șțaaș'; |
692 |
749 |
rg_log_enter('visible_string [' . $s . ']'); |
rg_log_enter('visible_string [' . $s . ']'); |