List of commits:
Subject Hash Author Date (UTC)
rg_exec function permits stdout streaming 37e9c670be82c66970a3972aee87af34553eec98 Catalin(ux) M. BOIE 2016-08-28 05:15:26
Added tutorials infrastructure and the first tutorial about CI 3fe5fc6d3dafa859e4e20c853f355dec279630b0 Catalin(ux) M. BOIE 2016-08-28 05:12:09
Spell checking c5c8cbc69ec8e33b623f49e5417ef85073d5aebe Catalin(ux) M. BOIE 2016-08-28 05:07:13
Fix a bug that prevented the log function to log invalid UTF-8 chars 3a5d9efe50b391c4b5f64a879e64d3203ba66ef0 Catalin(ux) M. BOIE 2016-07-31 04:40:12
rg_exec accepts a second para: data to be sent as stdin 71d2b273ae592e3c6e6a77e7b19df3f94aa1e9e9 Catalin(ux) M. BOIE 2016-07-31 03:05:23
Simplify event processing by passing full 'ui'; fixed 'confirmed' filed usage cbb6f8877db547d55b7b86e0fe5c41519d6c8b65 Catalin(ux) M. BOIE 2016-07-14 05:08:51
Fixed the unit tests (minor) 0e9cfc3911aba7119bb57140ecfa51ad6e3983bf Catalin(ux) M. BOIE 2016-07-14 05:05:37
Fixed e-mail confirmation logic. dd5b4be2e8e49aa612ddf7557e8ef0b1e0268822 Catalin(ux) M. BOIE 2016-07-11 21:09:19
Do more tests and resync some with the reality db9bb136ff176006cbb8f8848309b8adbf98d630 Catalin(ux) M. BOIE 2016-07-11 04:07:38
Improved user cache to not have null elements in JSON d6b75a2cc4830cfb8dfb92e911f1e5a41c2023bc Catalin(ux) M. BOIE 2016-07-11 04:06:25
Allow rights to have numbers and _ in name 4f5c38389bc98e2dcb60d36359917c33820e5779 Catalin(ux) M. BOIE 2016-07-11 04:05:40
Allow strange chars in cache names 00b05d99d3d3cf0229249718d2482af40f063972 Catalin(ux) M. BOIE 2016-07-11 04:04:08
Small improvements to builder and worker 08f9bc668f7f192af61868bebd644bea64b6aedd Catalin(ux) M. BOIE 2016-07-11 04:01:47
SELinux improvements to support the builder a2b52360b43be53786ee5d68c9fcb2db14f29c0c Catalin(ux) M. BOIE 2016-07-11 04:00:57
Document docker on Download web section 5d4ece50d6b4dc3d4902afd9264a45834ceb3592 Catalin(ux) M. BOIE 2016-07-11 03:54:31
Doc: restore context for rc.local eb5fa1cab84737e3440cfbca147d50859b8f9a53 Catalin(ux) M. BOIE 2016-07-07 04:09:23
Fixed small bug preventing e-mail to show in report 26d884b3a332f3c3b241c194912b9653749a9427 Catalin(ux) M. BOIE 2016-07-07 03:37:23
Do not clobber the cron file 5c68384676d9b8087255dda3b62e3588fc50e6c7 Catalin(ux) M. BOIE 2016-07-06 22:03:58
When using rg_json_encode, no quotes needed. c4b7693a81e593918f8c06408f16b4884a92773b Catalin(ux) M. BOIE 2016-07-06 05:21:00
Remove summary from tables because violates HTML5 specs. :( 11865f18e979f3849dbb265e5c5350f4a638088b Catalin(ux) M. BOIE 2016-07-06 05:00:11
Commit 37e9c670be82c66970a3972aee87af34553eec98 - rg_exec function permits stdout streaming
Author: Catalin(ux) M. BOIE
Author date (UTC): 2016-08-28 05:15
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2016-08-28 05:15
Parent(s): 3fe5fc6d3dafa859e4e20c853f355dec279630b0
Signer:
Signing key:
Signing status: N
Tree: 25068a0f4c61db069ca396eb6332000ee0d74145
File Lines added Lines deleted
inc/builder.inc.php 1 1
inc/git.inc.php 18 18
inc/totp.inc.php 2 2
inc/util.inc.php 48 31
scripts/worker.php 16 16
tests/export.php 1 1
tests/git2.php 2 2
tests/pr_anon.php 7 7
tests/repo.php 1 1
tests/user.php 1 1
tests/util.php 3 3
tests/wh_cloud.php 1 1
File inc/builder.inc.php changed (mode: 100644) (index b38750f..f55d480)
... ... function rg_builder_add($db, $repo_id, $d)
84 84 function rg_builder_vm_list() function rg_builder_vm_list()
85 85 { {
86 86 $cmd = 'virsh list --name'; $cmd = 'virsh list --name';
87 $r = rg_exec($cmd, '');
87 $r = rg_exec($cmd, '', FALSE);
88 88 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
89 89 rg_log('Cannot find out virtual machines: ' . $r['errmsg']); rg_log('Cannot find out virtual machines: ' . $r['errmsg']);
90 90 return FALSE; return FALSE;
File inc/git.inc.php changed (mode: 100644) (index af45be2..421394a)
... ... function rg_git_init($dst)
134 134 if (!is_dir($dst . "/rocketgit")) { if (!is_dir($dst . "/rocketgit")) {
135 135 $dst2 = $dst . '.tmp'; $dst2 = $dst . '.tmp';
136 136 $cmd = 'git init --bare ' . escapeshellarg($dst2); $cmd = 'git init --bare ' . escapeshellarg($dst2);
137 $a = rg_exec($cmd, '');
137 $a = rg_exec($cmd, '', FALSE);
138 138 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
139 139 rg_git_set_error("error on init " . $a['errmsg'] . ")"); rg_git_set_error("error on init " . $a['errmsg'] . ")");
140 140 break; break;
 
... ... function rg_git_clone($src, $dst)
185 185 if (!file_exists($dst . "/rocketgit")) { if (!file_exists($dst . "/rocketgit")) {
186 186 $cmd = "git clone --bare " . escapeshellarg($src) $cmd = "git clone --bare " . escapeshellarg($src)
187 187 . " " . escapeshellarg($dst); . " " . escapeshellarg($dst);
188 $a = rg_exec($cmd, '');
188 $a = rg_exec($cmd, '', FALSE);
189 189 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
190 190 rg_git_set_error("error on clone (" . $a['errmsg'] . ")"); rg_git_set_error("error on clone (" . $a['errmsg'] . ")");
191 191 break; break;
 
... ... function rg_git_type($obj)
227 227 } }
228 228
229 229 $cmd = "git cat-file -t '" . escapeshellarg($obj) . "'"; $cmd = "git cat-file -t '" . escapeshellarg($obj) . "'";
230 $a = rg_exec($cmd, '');
230 $a = rg_exec($cmd, '', FALSE);
231 231 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
232 232 rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")"); rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")");
233 233 break; break;
 
... ... function rg_git_content($obj)
253 253 $ret = FALSE; $ret = FALSE;
254 254 while (1) { while (1) {
255 255 $cmd = "git cat-file -p '" . escapeshellarg($obj) . "'"; $cmd = "git cat-file -p '" . escapeshellarg($obj) . "'";
256 $a = rg_exec($cmd, '');
256 $a = rg_exec($cmd, '', FALSE);
257 257 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
258 258 rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")"); rg_git_set_error("error on cat-file (" . $a['errmsg'] . ")");
259 259 break; break;
 
... ... function rg_git_rev_ok($rev)
330 330 $ret = FALSE; $ret = FALSE;
331 331 while (1) { while (1) {
332 332 $cmd = 'git rev-parse --verify ' . escapeshellarg($rev); $cmd = 'git rev-parse --verify ' . escapeshellarg($rev);
333 $a = rg_exec($cmd, '');
333 $a = rg_exec($cmd, '', FALSE);
334 334 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
335 335 rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")"); rg_git_set_error("error on rev-parse (" . $a['errmsg'] . ")");
336 336 break; break;
 
... ... function rg_git_whitespace_ok($old, $new)
365 365 $cmd = "git diff --check" $cmd = "git diff --check"
366 366 . " " . escapeshellarg($old) . " " . escapeshellarg($old)
367 367 . " " . escapeshellarg($new); . " " . escapeshellarg($new);
368 $a = rg_exec($cmd, '');
368 $a = rg_exec($cmd, '', FALSE);
369 369 rg_log("a:" . rg_array2string($a)); rg_log("a:" . rg_array2string($a));
370 370 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
371 371 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)
446 446 . ' merge-base' . ' merge-base'
447 447 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
448 448 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
449 $a = rg_exec($cmd, '');
449 $a = rg_exec($cmd, '', FALSE);
450 450 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
451 451 rg_git_set_error('error on git merge_base (' rg_git_set_error('error on git merge_base ('
452 452 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_update_ref($repo_path, $ref, $old, $new, $reason)
493 493 if (!empty($old)) if (!empty($old))
494 494 $cmd .= " " . escapeshellarg($old); $cmd .= " " . escapeshellarg($old);
495 495
496 $a = rg_exec($cmd, '');
496 $a = rg_exec($cmd, '', FALSE);
497 497 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
498 498 rg_git_set_error("error on update-ref (" . $a['errmsg'] . ")"); rg_git_set_error("error on update-ref (" . $a['errmsg'] . ")");
499 499 break; break;
 
... ... function rg_git_shortlog($repo_path, $a, $b)
522 522 . ' --git-dir=' . escapeshellarg($repo_path) . ' --git-dir=' . escapeshellarg($repo_path)
523 523 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
524 524 . '..' . escapeshellarg($b); . '..' . escapeshellarg($b);
525 $r = rg_exec($cmd, '');
525 $r = rg_exec($cmd, '', FALSE);
526 526 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
527 527 rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')'); rg_git_set_error('error on shortlog (' . $r['errmsg'] . ')');
528 528 break; break;
 
... ... function rg_git_ls_tree($repo_path, $tree, $path)
559 559 . escapeshellarg($tree); . escapeshellarg($tree);
560 560 if (!empty($path)) if (!empty($path))
561 561 $cmd .= ' ' . escapeshellarg($path); $cmd .= ' ' . escapeshellarg($path);
562 $a = rg_exec($cmd, '');
562 $a = rg_exec($cmd, '', FALSE);
563 563 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
564 564 rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on ls-tree (" . $a['errmsg'] . ")");
565 565 break; break;
 
... ... function rg_git_log($path, $max, $from, $to, $also_patch)
868 868 . "%x00ROCKETGIT_END_OF_VARS%x00\""; . "%x00ROCKETGIT_END_OF_VARS%x00\"";
869 869 if (!empty($from_to)) if (!empty($from_to))
870 870 $cmd .= ' ' . escapeshellarg($from_to); $cmd .= ' ' . escapeshellarg($from_to);
871 $a = rg_exec($cmd, '');
871 $a = rg_exec($cmd, '', FALSE);
872 872 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
873 873 rg_internal_error("error on log (" . $a['errmsg'] . ")"); rg_internal_error("error on log (" . $a['errmsg'] . ")");
874 874 rg_git_set_error("could not generate log; try again later"); rg_git_set_error("could not generate log; try again later");
 
... ... function rg_git_files($old, $new)
1044 1044
1045 1045 $cmd = 'git diff --name-only ' . escapeshellarg($old) $cmd = 'git diff --name-only ' . escapeshellarg($old)
1046 1046 . ' ' . escapeshellarg($new); . ' ' . escapeshellarg($new);
1047 $a = rg_exec($cmd, '');
1047 $a = rg_exec($cmd, '', FALSE);
1048 1048 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1049 1049 rg_git_set_error("error on git diff (" . $a['errmsg'] . ")"); rg_git_set_error("error on git diff (" . $a['errmsg'] . ")");
1050 1050 break; break;
 
... ... function rg_git_diff_tree($tree1, $tree2)
1645 1645 while (1) { while (1) {
1646 1646 $cmd = "git diff-tree -r " . escapeshellarg($tree1) $cmd = "git diff-tree -r " . escapeshellarg($tree1)
1647 1647 . " " . escapeshellarg($tree2); . " " . escapeshellarg($tree2);
1648 $a = rg_exec($cmd, '');
1648 $a = rg_exec($cmd, '', FALSE);
1649 1649 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1650 1650 rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")"); rg_git_set_error("error on diff-tree (" . $a['errmsg'] . ")");
1651 1651 break; break;
 
... ... function rg_git_content_by_file($treeish, $file)
1689 1689 while (1) { while (1) {
1690 1690 $cmd = 'git show ' . escapeshellarg($treeish) . ':' $cmd = 'git show ' . escapeshellarg($treeish) . ':'
1691 1691 . escapeshellarg($file); . escapeshellarg($file);
1692 $a = rg_exec($cmd, '');
1692 $a = rg_exec($cmd, '', FALSE);
1693 1693 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1694 1694 rg_git_set_error("error on show (" . $a['errmsg'] . ")"); rg_git_set_error("error on show (" . $a['errmsg'] . ")");
1695 1695 break; break;
 
... ... function rg_git_archive($repo_path, $treeish, $archive_name, $format)
1802 1802 . ' archive --format=' . escapeshellarg($format) . ' archive --format=' . escapeshellarg($format)
1803 1803 . ' --output=' . escapeshellarg($archive_name) . ' --output=' . escapeshellarg($archive_name)
1804 1804 . ' ' . escapeshellarg($treeish); . ' ' . escapeshellarg($treeish);
1805 $a = rg_exec($cmd, '');
1805 $a = rg_exec($cmd, '', FALSE);
1806 1806 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1807 1807 rg_git_set_error('error on git archive' rg_git_set_error('error on git archive'
1808 1808 . ' (' . $a['errmsg'] . ')'); . ' (' . $a['errmsg'] . ')');
 
... ... function rg_git_merge_tree($repo_path, $base, $a, $b)
1871 1871 . ' ' . escapeshellarg($base) . ' ' . escapeshellarg($base)
1872 1872 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
1873 1873 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
1874 $a = rg_exec($cmd, '');
1874 $a = rg_exec($cmd, '', FALSE);
1875 1875 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1876 1876 rg_git_set_error('error on git merge-tree (' rg_git_set_error('error on git merge-tree ('
1877 1877 . $a['errmsg'] . ')'); . $a['errmsg'] . ')');
 
... ... function rg_git_merge($repo_path, $a, $b, $ff, $msg)
1973 1973 . ' -m ' . escapeshellarg($msg) . ' -m ' . escapeshellarg($msg)
1974 1974 . ' ' . escapeshellarg($a) . ' ' . escapeshellarg($a)
1975 1975 . ' ' . escapeshellarg($b); . ' ' . escapeshellarg($b);
1976 $a = rg_exec($cmd, '');
1976 $a = rg_exec($cmd, '', FALSE);
1977 1977 rg_rmdir($work_tree); rg_rmdir($work_tree);
1978 1978 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
1979 1979 rg_git_set_error('error on git merge (' rg_git_set_error('error on git merge ('
 
... ... function rg_git_request_pull($repo_path, $start, $url, $end, $patch)
2022 2022 if ($patch) if ($patch)
2023 2023 $cmd .= ' --patch'; $cmd .= ' --patch';
2024 2024 $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end); $cmd .= escapeshellarg($start) . '..' . escapeshellarg($end);
2025 $r = rg_exec($cmd, '');
2025 $r = rg_exec($cmd, '', FALSE);
2026 2026 if ($a['ok'] != 1) { if ($a['ok'] != 1) {
2027 2027 rg_git_set_error('error on git diff: ' . $a['errmsg']); rg_git_set_error('error on git diff: ' . $a['errmsg']);
2028 2028 break; break;
File inc/totp.inc.php changed (mode: 100644) (index 4d1cd73..16b1368)
... ... function rg_totp_png($secret)
155 155 $extra = gmdate('Y-m-d H:i'); $extra = gmdate('Y-m-d H:i');
156 156 $issuer = $rg_ssh_host; $issuer = $rg_ssh_host;
157 157 $cmd = "qrencode -o - --level=H --type=PNG 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'"; $cmd = "qrencode -o - --level=H --type=PNG 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'";
158 $a = rg_exec($cmd, '');
158 $a = rg_exec($cmd, '', FALSE);
159 159 if ($a['ok'] != 1) if ($a['ok'] != 1)
160 160 return FALSE; return FALSE;
161 161
 
... ... function rg_totp_text($secret)
172 172 $extra = gmdate('Y-m-d H:i'); $extra = gmdate('Y-m-d H:i');
173 173 $issuer = $rg_ssh_host; $issuer = $rg_ssh_host;
174 174 $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'"; $cmd = "qrencode -o - --level=M --margin=2 --type=UTF8 'otpauth://totp/$extra?secret=$secret&issuer=$issuer'";
175 $a = rg_exec($cmd, '');
175 $a = rg_exec($cmd, '', FALSE);
176 176 if ($a['ok'] != 1) if ($a['ok'] != 1)
177 177 return FALSE; return FALSE;
178 178
File inc/util.inc.php changed (mode: 100644) (index ec32a85..22c7f3f)
... ... function rg_ok($msg)
959 959 /* /*
960 960 * Execute $cmd and returns the output as a string, binary safe * Execute $cmd and returns the output as a string, binary safe
961 961 * @input: some data to be sent to the process and received as stdin * @input: some data to be sent to the process and received as stdin
962 * @stream_stdout - TRUE => will output to stdout, FALSE => store in ret
962 963 */ */
963 function rg_exec($cmd, $input)
964 function rg_exec($cmd, $input, $stream_stdout)
964 965 { {
965 966 rg_prof_start("exec"); rg_prof_start("exec");
966 967 rg_log_enter("Executing [$cmd]..."); rg_log_enter("Executing [$cmd]...");
 
... ... function rg_exec($cmd, $input)
972 973 while (1) { while (1) {
973 974 $desc = array( $desc = array(
974 975 0 => array("pipe", "r"), 0 => array("pipe", "r"),
975 1 => array("pipe", "w"),
976 1 => array('pipe', 'w'),
976 977 2 => array("pipe", "w") 2 => array("pipe", "w")
977 978 ); );
979 //rg_log_ml('DEBUG: desc: ' . print_r($desc, TRUE));
980
978 981 $a = proc_open($cmd, $desc, $pipes); $a = proc_open($cmd, $desc, $pipes);
979 982 if ($a === FALSE) { if ($a === FALSE) {
980 983 $ret['errmsg'] = "cannot call proc_open"; $ret['errmsg'] = "cannot call proc_open";
981 984 break; break;
982 985 } }
983 986
987 //rg_log_ml('DEBUG: proc_open pipes: ' . print_r($pipes, TRUE));
988
984 989 $stderr = ""; $stderr = "";
985 990 $ret['data'] = ""; $ret['data'] = "";
986 991 $rx = array($pipes[1], $pipes[2]); $rx = array($pipes[1], $pipes[2]);
 
... ... function rg_exec($cmd, $input)
996 1001 $ret['errmsg'] = "cannot select"; $ret['errmsg'] = "cannot select";
997 1002 break; break;
998 1003 } }
999 rg_log('DEBUG: stream_select returned ' . $r
1000 . ', revents: ' . rg_array2string($revents)
1001 . ', wevents: ' . rg_array2string($wevents));
1004 //rg_log('DEBUG: stream_select returned ' . $r
1005 // . ', revents: ' . rg_array2string($revents)
1006 // . ', wevents: ' . rg_array2string($wevents));
1002 1007
1003 foreach ($revents as $fd) {
1008 foreach ($wevents as $fd) {
1004 1009 if (!empty($ret['errmsg'])) if (!empty($ret['errmsg']))
1005 1010 break; break;
1006 1011
1007 rg_log('DEBUG: Event on fd ' . $fd . '!');
1008 if ($fd === $pipes[0]) {
1009 rg_log('We can write!');
1010 $r = @fwrite($fd, $input);
1011 if ($r === FALSE) {
1012 $ret['ermsg'] = 'cannot write';
1013 break;
1014 }
1015 rg_log('fwrite returned ' . $r . '.');
1016 $input = substr($input, $r);
1017 if (empty($input))
1018 unset($wx[$fd]);
1019 continue;
1020 }
1012 //rg_log('DEBUG: write event on fd ' . $fd . '!');
1021 1013
1022 if (feof($fd)) {
1023 //rg_log("eof on fd $fd!");
1024 foreach ($rx as $_key => $_fd)
1025 if ($_fd == $fd)
1026 unset($rx[$_key]);
1027 continue;
1014 //rg_log('DEBUG: Writing [' . $input . ']...');
1015 $r = @fwrite($fd, $input);
1016 if ($r === FALSE) {
1017 $ret['ermsg'] = 'cannot write';
1018 break;
1028 1019 } }
1020 //rg_log('DEBUG: fwrite returned ' . $r . '.');
1021 $input = substr($input, $r);
1022 if (empty($input))
1023 $wx = array();
1024 }
1025
1026 foreach ($revents as $fd) {
1027 if (!empty($ret['errmsg']))
1028 break;
1029 1029
1030 //rg_log('DEBUG: read event on fd ' . $fd . '!');
1030 1031 $_d = fread($fd, 32 * 4096); $_d = fread($fd, 32 * 4096);
1031 1032 if ($_d === FALSE) { if ($_d === FALSE) {
1032 1033 $ret['errmsg'] = "cannot read"; $ret['errmsg'] = "cannot read";
1033 1034 break; break;
1034 1035 } }
1035 1036
1036 //rg_log("DEBUG: got data from fd $fd [$_d]");
1037 if (empty($_d)) {
1038 //rg_log('DEBUG: stream ' . $fd . ' returned no data.');
1039 foreach ($rx as $_k => $_fd) {
1040 if ($_fd === $fd) {
1041 unset($rx[$_k]);
1042 break;
1043 }
1044 }
1045 continue;
1046 }
1037 1047
1038 if ($fd === $pipes[2])
1048 //rg_log('DEBUG: got data from fd ' . $fd
1049 // . ': ' . bin2hex($_d));
1050 if ($fd === $pipes[2]) {
1039 1051 $stderr .= $_d; $stderr .= $_d;
1040 else if ($fd === $pipes[1])
1041 $ret['data'] .= $_d;
1052 } else if ($fd === $pipes[1]) {
1053 if ($stream_stdout)
1054 echo $_d;
1055 else
1056 $ret['data'] .= $_d;
1057 }
1042 1058 } }
1043 1059
1044 1060 if (!empty($ret['errmsg'])) if (!empty($ret['errmsg']))
 
... ... function rg_exec($cmd, $input)
1048 1064 $ret['data'] = trim($ret['data']); $ret['data'] = trim($ret['data']);
1049 1065
1050 1066 for ($i = 0; $i < 3; $i++) for ($i = 0; $i < 3; $i++)
1051 fclose($pipes[$i]);
1067 if (isset($pipes[$i]))
1068 fclose($pipes[$i]);
1052 1069
1053 1070 $err = proc_close($a); $err = proc_close($a);
1054 1071 if ($err != 0) { if ($err != 0) {
File scripts/worker.php changed (mode: 100644) (index d78b2a7..6fe3575)
... ... function reload_config()
95 95 $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\'' $cmd = 'ssh-keygen -t rsa -b 4096 -N \'\''
96 96 . ' -C \'Key to connect to builder\'' . ' -C \'Key to connect to builder\''
97 97 . ' -f ' . escapeshellarg($conf['state'] . '/key'); . ' -f ' . escapeshellarg($conf['state'] . '/key');
98 $r = rg_exec($cmd, '');
98 $r = rg_exec($cmd, '', FALSE);
99 99 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
100 100 rg_log('Cannot create key: ' . $r['data'] . '!'); rg_log('Cannot create key: ' . $r['data'] . '!');
101 101 sleep(60); sleep(60);
 
... ... function start_worker($job)
135 135 $do_umount = FALSE; $do_umount = FALSE;
136 136 $err = TRUE; $err = TRUE;
137 137 while (1) { while (1) {
138 rg_exec('virsh destroy ' . $ename, '');
139 rg_exec('virsh undefine ' . $ename, '');
138 rg_exec('virsh destroy ' . $ename, '', FALSE);
139 rg_exec('virsh undefine ' . $ename, '', FALSE);
140 140
141 141 $r = rg_del_tree($job['main']); $r = rg_del_tree($job['main']);
142 142 if ($r === FALSE) { if ($r === FALSE) {
 
... ... function start_worker($job)
161 161 } }
162 162
163 163 $r = rg_exec('qemu-img create -b ' . $master $r = rg_exec('qemu-img create -b ' . $master
164 . ' -f qcow2 ' . $img, '');
164 . ' -f qcow2 ' . $img, '', FALSE);
165 165 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
166 166 $reason = 'cannot create image: ' . $r['errmsg']; $reason = 'cannot create image: ' . $r['errmsg'];
167 167 break; break;
168 168 } }
169 169
170 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '');
170 $r = rg_exec('qemu-img create -f raw ' . $img2 . ' 1G', '', FALSE);
171 171 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
172 172 $reason = 'cannot create image2: ' . $r['errmsg']; $reason = 'cannot create image2: ' . $r['errmsg'];
173 173 break; break;
 
... ... function start_worker($job)
177 177 $path = getenv('PATH'); $path = getenv('PATH');
178 178 putenv('PATH=' . $path . ':/usr/sbin'); putenv('PATH=' . $path . ':/usr/sbin');
179 179
180 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '');
180 $r = rg_exec('mkfs.ext4 -L RG ' . $img2, '', FALSE);
181 181 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
182 182 $reason = 'cannot create fs: ' . $r['errmsg']; $reason = 'cannot create fs: ' . $r['errmsg'];
183 183 break; break;
 
... ... function start_worker($job)
189 189 break; break;
190 190 } }
191 191
192 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '');
192 $r = rg_exec('mount ' . $img2 . ' ' . $emain . '/root', '', FALSE);
193 193 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
194 194 $reason = 'cannot mount fs: ' . $r['errmsg']; $reason = 'cannot mount fs: ' . $r['errmsg'];
195 195 break; break;
 
... ... function start_worker($job)
204 204 $cmd = 'git clone --depth 1' $cmd = 'git clone --depth 1'
205 205 . ' ' . escapeshellarg($job['url']) . ' ' . escapeshellarg($job['url'])
206 206 . ' ' . $emain . '/root/git'; . ' ' . $emain . '/root/git';
207 $r = rg_exec($cmd, '');
207 $r = rg_exec($cmd, '', FALSE);
208 208 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
209 209 $reason = 'cannot clone: ' . $r['errmsg']; $reason = 'cannot clone: ' . $r['errmsg'];
210 210 break; break;
 
... ... function start_worker($job)
300 300 break; break;
301 301 } }
302 302
303 $r = rg_exec('umount ' . $emain . '/root', '');
303 $r = rg_exec('umount ' . $emain . '/root', '', FALSE);
304 304 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
305 305 $reason = 'cannot umount fs: ' . $r['errmsg']; $reason = 'cannot umount fs: ' . $r['errmsg'];
306 306 break; break;
 
... ... function start_worker($job)
328 328 . ' --rng /dev/random' . ' --rng /dev/random'
329 329 . ' --memballoon virtio' . ' --memballoon virtio'
330 330 . ' --console pty,target_type=virtio' . ' --console pty,target_type=virtio'
331 . ' ' . $env['paras'], '');
331 . ' ' . $env['paras'], '', FALSE);
332 332 if ($r['ok'] !== 1) { if ($r['ok'] !== 1) {
333 333 $reason = 'cannot define and start virtual machine: ' . $r['errmsg']; $reason = 'cannot define and start virtual machine: ' . $r['errmsg'];
334 334 break; break;
 
... ... function start_worker($job)
338 338 break; break;
339 339 } }
340 340 if ($do_umount) if ($do_umount)
341 rg_exec('umount ' . $emain . '/root', '');
341 rg_exec('umount ' . $emain . '/root', '', FALSE);
342 342
343 343 // Seems that any error above must retrigger the build on other worker // Seems that any error above must retrigger the build on other worker
344 344 if ($err) if ($err)
 
... ... function rg_job_extract_info(&$job)
447 447 } }
448 448
449 449 $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root'; $cmd = 'mount ' . $emain . '/image2.raw ' . $emain . '/root';
450 $r = rg_exec($cmd, '');
450 $r = rg_exec($cmd, '', FALSE);
451 451 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
452 452 $job['error'] = 'Could not mount image: ' . $r['data']; $job['error'] = 'Could not mount image: ' . $r['data'];
453 453 break; break;
 
... ... function rg_job_extract_info(&$job)
489 489 unset($job['env']); unset($job['env']);
490 490
491 491 $cmd = 'umount ' . $emain . '/root'; $cmd = 'umount ' . $emain . '/root';
492 $r = rg_exec($cmd, '');
492 $r = rg_exec($cmd, '', FALSE);
493 493 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
494 494 rg_log('Cannot unmount!'); rg_log('Cannot unmount!');
495 495 break; break;
 
... ... while(1) {
600 600
601 601 // TODO: do we destroy the pool in case of crash? // TODO: do we destroy the pool in case of crash?
602 602 $cmd = 'virsh pool-destroy rocketgit-j-' . $jid; $cmd = 'virsh pool-destroy rocketgit-j-' . $jid;
603 $r = rg_exec($cmd, '');
603 $r = rg_exec($cmd, '', FALSE);
604 604 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
605 605 $job['error'] = 'Could not destroy pool: ' . $r['data']; $job['error'] = 'Could not destroy pool: ' . $r['data'];
606 606 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
 
... ... while(1) {
609 609
610 610 // TODO: do we clean the pool in case of crash? // TODO: do we clean the pool in case of crash?
611 611 $cmd = 'virsh pool-undefine rocketgit-j-' . $jid; $cmd = 'virsh pool-undefine rocketgit-j-' . $jid;
612 $r = rg_exec($cmd, '');
612 $r = rg_exec($cmd, '', FALSE);
613 613 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
614 614 $job['error'] = 'Could not undefine pool: ' . $r['data']; $job['error'] = 'Could not undefine pool: ' . $r['data'];
615 615 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
 
... ... while(1) {
618 618
619 619 // TODO: do we clean the machine in case of crash? // TODO: do we clean the machine in case of crash?
620 620 $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid); $cmd = 'virsh undefine rg-worker-' . escapeshellarg($jid);
621 $r = rg_exec($cmd, '');
621 $r = rg_exec($cmd, '', FALSE);
622 622 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
623 623 $job['error'] = 'Could not undefine machine: ' . $r['data']; $job['error'] = 'Could not undefine machine: ' . $r['data'];
624 624 rg_log('Error: ' . $job['error']); rg_log('Error: ' . $job['error']);
File tests/export.php changed (mode: 100644) (index 429604f..02263f3)
... ... if ($r === FALSE) {
45 45 } }
46 46
47 47 $cmd = 'cat export.json | json_verify'; $cmd = 'cat export.json | json_verify';
48 $a = rg_exec($cmd, '');
48 $a = rg_exec($cmd, '', FALSE);
49 49 if ($a['ok'] !== 1) { if ($a['ok'] !== 1) {
50 50 rg_log_ml(print_r($a, TRUE)); rg_log_ml(print_r($a, TRUE));
51 51 rg_log('Seems the JSON is not valid!'); rg_log('Seems the JSON is not valid!');
File tests/git2.php changed (mode: 100644) (index f1ee122..1e41756)
... ... $remote = 'ssh://rocketgit@' . $rg_ssh_host . ':' .$rg_ssh_port
66 66 . '/' . escapeshellarg($repo['name']); . '/' . escapeshellarg($repo['name']);
67 67 $r = rg_exec("cd git2 && git remote add origin $remote" $r = rg_exec("cd git2 && git remote add origin $remote"
68 68 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\""
69 . " && git push origin master", '');
69 . " && git push origin master", '', FALSE);
70 70 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
71 71 rg_log_ml('out: ' . $r['errmsg']); rg_log_ml('out: ' . $r['errmsg']);
72 72 rg_log("Seems I cannot push master! err=$err"); rg_log("Seems I cannot push master! err=$err");
 
... ... rg_log('');
79 79 rg_log_enter('Trying to push tags...'); rg_log_enter('Trying to push tags...');
80 80 $r = rg_exec("cd git2" $r = rg_exec("cd git2"
81 81 . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\"" . " && export GIT_SSH_COMMAND=\"ssh -v -o IdentityFile=../keys/git2\""
82 . " && git push --tags origin", '');
82 . " && git push --tags origin", '', FALSE);
83 83 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
84 84 rg_log_ml('error: ' . $r['errmsg']); rg_log_ml('error: ' . $r['errmsg']);
85 85 rg_log("Seems I cannot push tags!"); rg_log("Seems I cannot push tags!");
File tests/pr_anon.php changed (mode: 100644) (index 0cd7e2d..65379b5)
... ... rg_log_exit();
82 82 rg_log(''); rg_log('');
83 83 rg_log_enter('Preparing repo...'); rg_log_enter('Preparing repo...');
84 84 system('rm -rf _pr_anon.git 2>/dev/null'); system('rm -rf _pr_anon.git 2>/dev/null');
85 $r = rg_exec('git init _pr_anon.git', '');
85 $r = rg_exec('git init _pr_anon.git', '', FALSE);
86 86 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
87 87 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
88 88 rg_log('Could not init repo!'); rg_log('Could not init repo!');
 
... ... if ($r['ok'] != 1) {
91 91 $r = rg_exec('cd _pr_anon.git; git remote add origin_ssh ' $r = rg_exec('cd _pr_anon.git; git remote add origin_ssh '
92 92 . ' ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port . ' ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
93 93 . '/user/' . escapeshellarg($rg_ui['username']) . '/' . '/user/' . escapeshellarg($rg_ui['username']) . '/'
94 . escapeshellarg($repo['name']), '');
94 . escapeshellarg($repo['name']), '', FALSE);
95 95 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
96 96 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
97 97 rg_log('Could not add ssh remote!'); rg_log('Could not add ssh remote!');
 
... ... if ($r['ok'] != 1) {
100 100 $r = rg_exec('cd _pr_anon.git; git remote add origin_git ' $r = rg_exec('cd _pr_anon.git; git remote add origin_git '
101 101 . ' git://' . $rg_git_host . ':' . $rg_git_port . ' git://' . $rg_git_host . ':' . $rg_git_port
102 102 . '/user/' . escapeshellarg($rg_ui['username']) . '/' . '/user/' . escapeshellarg($rg_ui['username']) . '/'
103 . escapeshellarg($repo['name']), '');
103 . escapeshellarg($repo['name']), '', FALSE);
104 104 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
105 105 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
106 106 rg_log('Could not add git remote!'); rg_log('Could not add git remote!');
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../keys/pr_anon";'
115 115 . 'cd _pr_anon.git; echo "change1" > a;' . 'cd _pr_anon.git; echo "change1" > a;'
116 116 . 'git add a; git commit -m "change1 desc";' . 'git add a; git commit -m "change1 desc";'
117 117 . 'echo "change2" > a; git commit -a -m "change2 desc";' . 'echo "change2" > a; git commit -a -m "change2 desc";'
118 . 'git push origin_ssh master', '');
118 . 'git push origin_ssh master', '', FALSE);
119 119 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
120 120 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
121 121 rg_log('Non-anonymous push was rejected!'); rg_log('Non-anonymous push was rejected!');
 
... ... rg_log_enter('Do an anonymous push...');
129 129 $r = rg_exec('cd _pr_anon.git; echo "change3" >> a;' $r = rg_exec('cd _pr_anon.git; echo "change3" >> a;'
130 130 . 'git add a; git commit -m "anon change1 desc";' . 'git add a; git commit -m "anon change1 desc";'
131 131 . 'echo "change4" >> a; git commit -a -m "anon change2 desc";' . 'echo "change4" >> a; git commit -a -m "anon change2 desc";'
132 . 'git push origin_git master', '');
132 . 'git push origin_git master', '', FALSE);
133 133 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
134 134 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
135 135 rg_log('Anonymous push was rejected!'); rg_log('Anonymous push was rejected!');
 
... ... $r = rg_exec('cd _pr_anon.git;'
212 212 . 'git pull origin_git master;' . 'git pull origin_git master;'
213 213 . 'echo "change2" > a;' . 'echo "change2" > a;'
214 214 . 'git commit -a -m "conflict1b";' . 'git commit -a -m "conflict1b";'
215 . 'git push origin_git master', '');
215 . 'git push origin_git master', '', FALSE);
216 216 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
217 217 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
218 218 rg_log('Could not pull/commit/push by git proto!'); rg_log('Could not pull/commit/push by git proto!');
 
... ... $r = rg_exec('export GIT_SSH_COMMAND="ssh -o IdentityFile=../keys/pr_anon";'
223 223 . 'git reset --hard HEAD^1;' . 'git reset --hard HEAD^1;'
224 224 . ' echo "change1" > a;' . ' echo "change1" > a;'
225 225 . 'git commit -a -m "conflict1a";' . 'git commit -a -m "conflict1a";'
226 . 'git push origin_ssh master', '');
226 . 'git push origin_ssh master', '', FALSE);
227 227 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
228 228 rg_log_ml('r: ' . print_r($r, TRUE)); rg_log_ml('r: ' . print_r($r, TRUE));
229 229 rg_log('Could not reset/commit/push by ssh proto!'); rg_log('Could not reset/commit/push by ssh proto!');
File tests/repo.php changed (mode: 100644) (index 0fdba41..52a3cec)
... ... if ($ri['exists'] != 1) {
192 192
193 193 rg_log(''); rg_log('');
194 194 rg_log_enter('Cleaning repos folder...'); rg_log_enter('Cleaning repos folder...');
195 $r = rg_exec("rm -rf base/*", '');
195 $r = rg_exec("rm -rf base/*", '', FALSE);
196 196 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
197 197 rg_log("Failed to clean base folder."); rg_log("Failed to clean base folder.");
198 198 exit(1); exit(1);
File tests/user.php changed (mode: 100644) (index cacb722..d5e6d5d)
... ... $rg_admin_name = "RocketGit Admin";
27 27 $_SERVER['HTTP_HOST'] = "fake.tld"; $_SERVER['HTTP_HOST'] = "fake.tld";
28 28
29 29
30 $r = rg_exec("rm -rf ubase", '');
30 $r = rg_exec("rm -rf ubase", '', FALSE);
31 31 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
32 32 rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!"); rg_log("Cannot remove ubase dir (" . $r['errmsg'] . ")!");
33 33 exit(1); exit(1);
File tests/util.php changed (mode: 100644) (index 9b45304..9cf02c7)
... ... if ($r !== TRUE) {
264 264 } }
265 265
266 266
267 $r = rg_exec("/xxxx", '');
267 $r = rg_exec("/xxxx", '', FALSE);
268 268 if ($r['ok'] == 1) { if ($r['ok'] == 1) {
269 269 rg_log("util.php: running non existing command does not return 0!"); rg_log("util.php: running non existing command does not return 0!");
270 270 print_r($r); print_r($r);
271 271 exit(1); exit(1);
272 272 } }
273 273
274 $r = rg_exec("ls", '');
274 $r = rg_exec("ls", '', FALSE);
275 275 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
276 276 rg_log("util.php: cannot run a command!"); rg_log("util.php: cannot run a command!");
277 277 print_r($r); print_r($r);
278 278 exit(1); exit(1);
279 279 } }
280 280
281 $r = rg_exec("./util_exit_code.sh 5", '');
281 $r = rg_exec("./util_exit_code.sh 5", '', FALSE);
282 282 if ($r['code'] != 5) { if ($r['code'] != 5) {
283 283 rg_log("util.php: error code seems to not be propageted!"); rg_log("util.php: error code seems to not be propageted!");
284 284 print_r($r); print_r($r);
File tests/wh_cloud.php changed (mode: 100644) (index cf746ea..7e172ea)
... ... rg_test_create_repo($db, $rg_ui, $repo);
103 103 $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port $repo_url = 'ssh://rocketgit@' . $rg_ssh_host . ':' . $rg_ssh_port
104 104 . '/user/' . $rg_ui['username'] . '/' . $repo['name']; . '/user/' . $rg_ui['username'] . '/' . $repo['name'];
105 105 rg_log('repo_url=' . escapeshellarg($repo_url)); rg_log('repo_url=' . escapeshellarg($repo_url));
106 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '');
106 $r = rg_exec('./wh_cloud.git.sh ' . escapeshellarg($repo_url), '', FALSE);
107 107 if ($r['ok'] != 1) { if ($r['ok'] != 1) {
108 108 rg_log('Could not create local git repo: ' . $r['errmsg'] . '!'); rg_log('Could not create local git repo: ' . $r['errmsg'] . '!');
109 109 exit(1); exit(1);
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/catalinux/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/catalinux/rocketgit

Clone this repository using git:
git clone git://git.rocketgit.com/user/catalinux/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main