List of commits:
Subject Hash Author Date (UTC)
More rg_exec2 fixes 808297884e42942c83762040c4247c7cf9a593e8 Catalin(ux) M. BOIE 2019-11-06 16:31:09
Always set rg[hostname] - used also for ssh connections for TOTP 1a7a693617ac521967b8df73245cd704004b76b5 Catalin(ux) M. BOIE 2019-11-06 04:10:59
White space corrections 92a1b944842439b9476a954daa2a65c5acfca85c Catalin(ux) M. BOIE 2019-11-05 18:52:08
README updates b57e3765de34c5e4ed7afa8384f24b6337352b17 Catalin(ux) M. BOIE 2019-11-01 03:18:48
download page updates 0185da40f7b2779c886b9c3e67b10fe69b1b112c Catalin(ux) M. BOIE 2019-11-01 03:13:14
css: small updates 59ae919c798d64f74ed8bdeb08241e4e76840afe Catalin(ux) M. BOIE 2019-10-30 21:33:37
comparison: updated pagespeed and other changes 3f423b7b0a98c0342e5d855c254812d37a03a5b8 Catalin(ux) M. BOIE 2019-10-30 21:27:20
html: specify logo size to avoid re-render b2ce82a59029e93438e9e6792f6aa6f7e44741c7 Catalin(ux) M. BOIE 2019-10-30 21:15:10
git(rocketgit_t) needs to map rocketgit_var_t files 2b10062807dd4f478e136aea1c239e117b46caed Catalin(ux) M. BOIE 2019-10-30 21:02:18
css: gravatar is displayed as block to get rid of below extra space b02dc575be2ccd8b99eff7509f8a7e62c57654a6 Catalin(ux) M. BOIE 2019-10-30 20:58:03
SELinux: more rights added 2e71284e917886f9ef2b0dcb005f63ff8153df1f Catalin(ux) M. BOIE 2019-10-30 17:30:08
We need also php-json for API f53e706bea1f29bb678ca39c2295ac8354af76d8 Catalin(ux) M. BOIE 2019-10-30 17:26:35
Small changes in several places 357571a8a8821b82f072bf83808342693e9a649c Catalin(ux) M. BOIE 2019-10-30 17:13:29
SELinux: php tries to map the config file 3e2115c88e7b424171060f14aa2cf4c856bf5e58 Catalin(ux) M. BOIE 2019-10-30 15:09:12
Removed comments from php-fpm.conf 46f4a76b3d0a37b3f6f2bdef8b749eca84246cce Catalin(ux) M. BOIE 2019-10-29 15:14:18
pool sample: removed comments 53364f40abda9cdab63a961e230bedb3c2dfcb67 Catalin(ux) M. BOIE 2019-10-29 15:12:01
Adapt spec file to Fedora 31 599df94445a9396fdc1cc0cc43df50838db973ae Catalin(ux) M. BOIE 2019-10-29 13:59:05
Cosmetic 69abfb69054c86d3b8136a83f3929831b2f75afe Catalin(ux) M. BOIE 2019-10-29 13:56:48
selinux: we need also map for httpd_t -> rocketgit_usr_t 6f4161abd283b4b83e5f3655d47187d9daf37a6f Catalin(ux) M. BOIE 2019-10-29 03:44:20
.spec update f5b7c9777f6e0f9e5b669c45abf5420bf0da80b8 Catalin(ux) M. BOIE 2019-10-26 05:35:45
Commit 808297884e42942c83762040c4247c7cf9a593e8 - More rg_exec2 fixes
Author: Catalin(ux) M. BOIE
Author date (UTC): 2019-11-06 16:31
Committer name: Catalin(ux) M. BOIE
Committer date (UTC): 2019-11-06 16:31
Parent(s): 1a7a693617ac521967b8df73245cd704004b76b5
Signing key:
Tree: 157e7c8886626691d9d8f68052aaa8bbf702e47d
File Lines added Lines deleted
inc/util.inc.php 80 63
samples/config.php 1 1
tests/_run_tests.sh 0 1
tests/util.php 15 7
tests/util_sleep_after_closing_fds.sh 2 3
File inc/util.inc.php changed (mode: 100644) (index 90d0a0b..c0cf795)
... ... function rg_exec2_helper_init(&$info)
1047 1047 { {
1048 1048 $info['last_activity'] = 0; $info['last_activity'] = 0;
1049 1049 $info['last_errmsg'] = ''; $info['last_errmsg'] = '';
1050 $info['closed'] = array(0 => 0, 1 => 0, 2 => 0);
1051 1050 $info['start_ts'] = time(); $info['start_ts'] = time();
1052 1051 $info['last_failure'] = 0; $info['last_failure'] = 0;
1053 1052 if (!isset($info['out_buf'])) if (!isset($info['out_buf']))
 
... ... function rg_exec2_helper_init(&$info)
1055 1054 $info['in_buf'] = ''; $info['in_buf'] = '';
1056 1055 $info['err_buf'] = ''; $info['err_buf'] = '';
1057 1056 $info['done'] = FALSE; $info['done'] = FALSE;
1057 $info['started'] = 0;
1058 1058
1059 1059 if (!isset($info['idle_time'])) if (!isset($info['idle_time']))
1060 1060 $info['idle_time'] = 5; $info['idle_time'] = 5;
1061 1061
1062 if (!isset($info['output_done'])) {
1063 if (isset($info['input_fd']))
1064 $info['output_done'] = 0;
1065 else
1066 $info['output_done'] = 1;
1067 }
1062 if (isset($info['input_fd']))
1063 $info['input_fd_done'] = 0;
1064 else
1065 $info['input_fd_done'] = 1;
1066
1067 if (!isset($info['output_done']))
1068 $info['output_done'] = 1;
1068 1069 } }
1069 1070
1070 1071 /* /*
1071 1072 * Helper for rg_exec to close a stream * Helper for rg_exec to close a stream
1072 1073 */ */
1073 function rg_exec2_helper_close_stream($fd, $index, &$info, $stream)
1074 function rg_exec2_helper_close_stream($index, $fd, &$info, $stream)
1074 1075 { {
1075 1076 global $rg_util_debug; global $rg_util_debug;
1076 1077
 
... ... function rg_exec2_helper_close_stream($fd, $index, &$info, $stream)
1078 1079 rg_log_enter($index . ' DEBUG: exec2_helper_close_stream: stream ' . $stream); rg_log_enter($index . ' DEBUG: exec2_helper_close_stream: stream ' . $stream);
1079 1080
1080 1081 if ($stream == -1) { if ($stream == -1) {
1081 $info['output_done'] = 1;
1082 $info['input_fd_done'] = 1;
1082 1083 unset($info['input_fd']); unset($info['input_fd']);
1083 1084 } else { } else {
1084 $info['closed'][$stream] = 1;
1085 1085 unset($info['pipes'][$stream]); unset($info['pipes'][$stream]);
1086 1086 } }
1087 1087
 
... ... function rg_exec2_helper_close_stream($fd, $index, &$info, $stream)
1094 1094 $rg_util_debug && $rg_util_debug &&
1095 1095 rg_log($index . ' DEBUG: closing stream 0 =>' rg_log($index . ' DEBUG: closing stream 0 =>'
1096 1096 . ' closing input_fd ' . $info['input_fd']); . ' closing input_fd ' . $info['input_fd']);
1097 rg_exec2_helper_close_stream($info['input_fd'], $index, $info, -1);
1097 rg_exec2_helper_close_stream($index, $info['input_fd'], $info, -1);
1098 1098 } }
1099 1099
1100 1100 $rg_util_debug && $rg_util_debug &&
 
... ... function rg_exec2($a)
1122 1122 // some status initialization // some status initialization
1123 1123 $s = array(); $s = array();
1124 1124 foreach ($ret['cmds'] as $cmd => &$info) { foreach ($ret['cmds'] as $cmd => &$info) {
1125 $info['needs_start'] = TRUE;
1126 1125 $info['stopped'] = TRUE; $info['stopped'] = TRUE;
1127 $info['needs_stop'] = FALSE;
1126 $info['wait_for_stop'] = FALSE;
1128 1127 rg_exec2_helper_init($info); rg_exec2_helper_init($info);
1129 1128 } }
1130 1129
 
... ... function rg_exec2($a)
1135 1134 $lut = array(); $lut = array();
1136 1135 $done = TRUE; $done = TRUE;
1137 1136 foreach ($ret['cmds'] as $index => &$info) { foreach ($ret['cmds'] as $index => &$info) {
1138 if ($info['closed'][0] + $info['closed'][1] + $info['closed'][2] == 3) {
1137 if ($info['done'])
1138 continue;
1139
1140 if ($info['started'] == 0) {
1141 // nothing
1142 } else if (empty($info['pipes'])) {
1139 1143 $rg_util_debug && $rg_util_debug &&
1140 1144 rg_log($index . ' DEBUG: All streams are closed.' rg_log($index . ' DEBUG: All streams are closed.'
1141 . ' Set needs_stop to TRUE');
1142 $info['needs_stop'] = TRUE;
1145 . ' Set wait_for_stop to TRUE');
1146 $info['wait_for_stop'] = TRUE;
1147 } else {
1148 $rg_util_debug &&
1149 rg_log_ml($index . ' DEBUG: Cannot set wait_for_stop to'
1150 . ' true because something is not closed; pipes:'
1151 . ' ' . rg_array2string($info['pipes']));
1143 1152 } }
1144 1153
1145 if ($info['needs_stop'] == TRUE) {
1154 if ($info['wait_for_stop'] == TRUE) {
1146 1155 $rg_util_debug && $rg_util_debug &&
1147 1156 rg_log($index . ' DEBUG: needs stop is TRUE!'); rg_log($index . ' DEBUG: needs stop is TRUE!');
1148 1157
1149 $info['ps'] = @proc_get_status($info['a']);
1158 for ($i = 0; $i <= 2; $i++)
1159 if (isset($info['pipes'][$i]))
1160 fclose($info['pipes'][$i]);
1161
1162 if (isset($info['input_fd'])) {
1163 @fclose($info['input_fd']);
1164 unset($info['input_fd']);
1165 }
1166
1167 $info['ps'] = proc_get_status($info['a']);
1150 1168 $rg_util_debug && $rg_util_debug &&
1151 1169 rg_log_ml($index . ' DEBUG: info[ps]: ' rg_log_ml($index . ' DEBUG: info[ps]: '
1152 1170 . print_r($info['ps'], TRUE)); . print_r($info['ps'], TRUE));
1153 1171
1154 if ($info['ps']['running'] === FALSE) {
1155 $ec = $info['ps']['exitcode'];
1156 } else {
1157 for ($i = 0; $i < 3; $i++)
1158 if (isset($info['pipes'][$i]))
1159 fclose($info['pipes'][$i]);
1160
1161 if (isset($info['input_fd'])) {
1162 @fclose($info['input_fd']);
1163 unset($info['input_fd']);
1164 }
1165
1166 $err = @proc_close($info['a']);
1167 if ($err != 0) {
1168 $rg_util_debug &&
1169 rg_log($index . ' DEBUG: proc_close returned ' . $err);
1170 }
1171 // TODO: where should we use it?
1172 $ec = 0; /* we are force closing program */
1172 if ($info['ps']['running'] !== FALSE) {
1173 $done = FALSE;
1174 continue;
1173 1175 } }
1174 1176
1175 if (($info['ps']['exitcode'] != 0) && empty($info['last_errmsg']))
1176 $info['last_errmsg'] = 'child exited with an error code';
1177 @proc_close($info['a']);
1178 $info['exitcode'] = $info['ps']['exitcode'];
1179
1180 if (($info['exitcode'] != 0) && empty($info['last_errmsg']))
1181 $info['last_errmsg'] = 'child exited with'
1182 . ' error code ' . $info['exitcode'];
1177 1183
1178 1184 if (isset($info['cb_finish'])) if (isset($info['cb_finish']))
1179 $info['cb_finish']($index, $info, $ec);
1185 $info['cb_finish']($index, $info, $info['exitcode']);
1180 1186
1181 1187 unset($info['pipes']); unset($info['pipes']);
1182 1188 unset($info['a']); unset($info['a']);
1183 1189
1184 $info['needs_stop'] = FALSE;
1190 $info['wait_for_stop'] = FALSE;
1185 1191 $info['stopped'] = TRUE; $info['stopped'] = TRUE;
1186 1192
1187 if (!isset($info['restart_delay'])) {
1193 if (isset($info['restart_delay'])) {
1194 rg_exec2_helper_init($info);
1195 } else {
1188 1196 $rg_util_debug && $rg_util_debug &&
1189 1197 rg_log($index . ' DEBUG: no restart flag => done = TRUE'); rg_log($index . ' DEBUG: no restart flag => done = TRUE');
1190 1198 $info['done'] = TRUE; $info['done'] = TRUE;
1191 } else {
1192 rg_exec2_helper_init($info);
1193 1199 } }
1194 1200 } }
1195 1201
 
... ... function rg_exec2($a)
1203 1209 rg_log($index . ' DEBUG: set done to FALSE'); rg_log($index . ' DEBUG: set done to FALSE');
1204 1210 $done = FALSE; $done = FALSE;
1205 1211
1206 if ($info['needs_start'] == TRUE) {
1212 if ($info['started'] == 0) {
1207 1213 $restart_delay = isset($info['restart_delay']) ? $info['restart_delay'] : 0; $restart_delay = isset($info['restart_delay']) ? $info['restart_delay'] : 0;
1208 1214
1209 1215 if ($info['last_failure'] + $restart_delay > $now) if ($info['last_failure'] + $restart_delay > $now)
 
... ... function rg_exec2($a)
1231 1237 . rg_array2string($info['pipes'])); . rg_array2string($info['pipes']));
1232 1238
1233 1239 $info['stopped'] = FALSE; $info['stopped'] = FALSE;
1234 $info['needs_start'] = FALSE;
1240 $info['started'] = time();
1235 1241
1236 1242 // cb_output can populate $info['out_buf'] // cb_output can populate $info['out_buf']
1237 1243 if (isset($info['cb_output'])) { if (isset($info['cb_output'])) {
 
... ... function rg_exec2($a)
1261 1267
1262 1268 if (!empty($info['out_buf'])) { if (!empty($info['out_buf'])) {
1263 1269 $rg_util_debug && $rg_util_debug &&
1264 rg_log($index . ' DEBUG: enable write notification!');
1270 rg_log($index . ' DEBUG: out_buf not empty =>'
1271 . ' enable write notification!');
1265 1272
1266 1273 $wx[] = $info['pipes'][0]; $wx[] = $info['pipes'][0];
1267 } else if (($info['output_done'] == 1) && ($info['closed'][0] == 0)) {
1274 } else if (($info['input_fd_done'] == 1)
1275 && ($info['output_done'] == 1)
1276 && (isset($info['pipes'][0]))) {
1268 1277 $rg_util_debug && $rg_util_debug &&
1269 rg_log($index . ' DEBUG: No output available'
1270 . ', close output ' . $info['pipes'][0]);
1271 rg_exec2_helper_close_stream($info['pipes'][0], $index, $info, 0);
1278 rg_log($index . ' DEBUG: empty(out_buf)'
1279 . ' && input_fd_done == 1'
1280 . ' && output_done == 1'
1281 . ': close output ' . $info['pipes'][0]);
1282 rg_exec2_helper_close_stream($index,
1283 $info['pipes'][0], $info, 0);
1272 1284 } }
1273 1285
1274 if ($info['closed'][1] == 0) $rx[] = $info['pipes'][1];
1275 if ($info['closed'][2] == 0) $rx[] = $info['pipes'][2];
1276 if (isset($info['input_fd']))
1277 $rx[] = $info['input_fd'];
1286 if (isset($info['pipes'][1])) $rx[] = $info['pipes'][1];
1287 if (isset($info['pipes'][2])) $rx[] = $info['pipes'][2];
1288 if (isset($info['input_fd'])) $rx[] = $info['input_fd'];
1278 1289
1279 1290 for ($i = 0; $i <= 2; $i++) { for ($i = 0; $i <= 2; $i++) {
1280 1291 if (!isset($info['pipes'][$i])) if (!isset($info['pipes'][$i]))
 
... ... function rg_exec2($a)
1311 1322 $rg_util_debug && rg_log('DEBUG: before stream_select:' $rg_util_debug && rg_log('DEBUG: before stream_select:'
1312 1323 . (empty($revents) ? '' : ' revents:' . rg_array2string($revents)) . (empty($revents) ? '' : ' revents:' . rg_array2string($revents))
1313 1324 . (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents))); . (empty($wevents) ? '' : ' wevents:' . rg_array2string($wevents)));
1314 $r = stream_select($revents, $wevents, $ex, 1, 0);
1325 $r = stream_select($revents, $wevents, $ex, 0, 100 * 1000);
1315 1326 if ($r === FALSE) { if ($r === FALSE) {
1316 1327 $ret['errmsg'] = "cannot select"; $ret['errmsg'] = "cannot select";
1317 1328 break; break;
 
... ... function rg_exec2($a)
1360 1371 $info['cb_error']($index, $info, $info['last_errmsg']); $info['cb_error']($index, $info, $info['last_errmsg']);
1361 1372 else else
1362 1373 rg_log($index . ' fwrite returned FALSE'); rg_log($index . ' fwrite returned FALSE');
1363 $info['needs_stop'] = TRUE;
1374 $info['wait_for_stop'] = TRUE;
1364 1375 continue; continue;
1365 1376 } }
1366 1377 $rg_util_debug && $rg_util_debug &&
 
... ... function rg_exec2($a)
1385 1396 $info['last_errmsg'] = 'cannot read'; $info['last_errmsg'] = 'cannot read';
1386 1397 if (isset($info['cb_error'])) if (isset($info['cb_error']))
1387 1398 $info['cb_error']($index, $info, $info['last_errmsg']); $info['cb_error']($index, $info, $info['last_errmsg']);
1388 $info['needs_stop'] = TRUE;
1399 $info['wait_for_stop'] = TRUE;
1389 1400 continue; continue;
1390 1401 } }
1391 1402
1392 1403 if (empty($_d)) { if (empty($_d)) {
1393 1404 $rg_util_debug && $rg_util_debug &&
1394 1405 rg_log($index . ' DEBUG: ifd ' . $ifd . ' returned no data.'); rg_log($index . ' DEBUG: ifd ' . $ifd . ' returned no data.');
1395 rg_exec2_helper_close_stream($fd, $index, $info, $stream);
1406 rg_exec2_helper_close_stream($index, $fd, $info, $stream);
1396 1407 continue; continue;
1397 1408 } }
1398 1409
 
... ... function rg_exec2($a)
1412 1423 $info['cb_input']($index, $info, $stream); $info['cb_input']($index, $info, $stream);
1413 1424 } }
1414 1425
1415 foreach ($ret['cmds'] as $index => &$info)
1416 if (isset($info['cb_tick']))
1417 $info['cb_tick']($index, $info);
1426 foreach ($ret['cmds'] as $index => &$info) {
1427 if (!isset($info['cb_tick']))
1428 continue;
1429
1430 if ($info['done'])
1431 continue;
1432
1433 $info['cb_tick']($index, $info);
1434 }
1418 1435 } }
1419 1436
1420 1437 rg_log_exit(); rg_log_exit();
 
... ... function rg_exec($cmd, $input, $cb_stdin, $cb_stdout, $cb_stderr)
1497 1514 break; break;
1498 1515 } }
1499 1516
1500 $ret['code'] = $r['cmds']['cmd1']['ps']['exitcode'];
1517 $ret['code'] = $r['cmds']['cmd1']['exitcode'];
1501 1518 $ret['data'] = $r['cmds']['cmd1']['in_buf']; $ret['data'] = $r['cmds']['cmd1']['in_buf'];
1502 1519 $ret['stderr'] = $r['cmds']['cmd1']['err_buf']; $ret['stderr'] = $r['cmds']['cmd1']['err_buf'];
1503 1520 $ret['errmsg'] = $r['cmds']['cmd1']['last_errmsg']; $ret['errmsg'] = $r['cmds']['cmd1']['last_errmsg'];
File samples/config.php changed (mode: 100644) (index 9828b21..1edf447)
... ... $rg_scripts = "/usr/share/rocketgit";
21 21 // M = Mark, L = Letter, N = Number // M = Mark, L = Letter, N = Number
22 22 $rg_repo_allow = '-\p{L}\p{N}._+=*&'; $rg_repo_allow = '-\p{L}\p{N}._+=*&';
23 23
24 // Allowed repo name length
24 // Allowed repo name length (chars, not bytes)
25 25 $rg_repo_min_len = 1; $rg_repo_min_len = 1;
26 26 $rg_repo_max_len = 64; $rg_repo_max_len = 64;
27 27
File tests/_run_tests.sh changed (mode: 100755) (index 4df0439..f60da2f)
... ... for t in ${tests}; do
16 16 continue continue
17 17 fi fi
18 18
19 echo
20 19 echo "${t}: Running..." echo "${t}: Running..."
21 20 if [ -r "${t}.sh" ]; then if [ -r "${t}.sh" ]; then
22 21 ./${t}.sh ./${t}.sh
File tests/util.php changed (mode: 100644) (index f1da20c..777a935)
... ... if (strcmp($r['stderr'], "stderr1\nstderr2\n") != 0) {
358 358 rg_log_exit(); rg_log_exit();
359 359
360 360
361 rg_log('');
362 rg_log_enter('sleep after closing fds');
363 $r = rg_exec("./util_sleep_after_closing_fds.sh", '', FALSE, FALSE, FALSE);
364 if (($r['ok'] != 1) || ($r['code'] != 0)) {
365 rg_log_ml('r: ' . print_r($r, TRUE));
366 rg_log("We need code 0 here!");
367 exit(1);
368 }
369 rg_log_exit();
370
371
361 372 rg_log(''); rg_log('');
362 373 rg_log_enter('exec2 - complex'); rg_log_enter('exec2 - complex');
363 374 // Define helpers // Define helpers
 
... ... function cb_tick($index, &$a)
404 415 rg_log('cb_tick[' . $index . ']'); rg_log('cb_tick[' . $index . ']');
405 416 $a['my'] = 'tick_was_here'; $a['my'] = 'tick_was_here';
406 417
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;
418 if (isset($a['cb_output_called']) && isset($a['cb_input_called'])) {
419 rg_log('cb_tick[' . $index . ']: set output_done to 1');
420 $a['output_done'] = 1;
421 }
414 422 } }
415 423
416 424 $a = array( $a = array(
File tests/util_sleep_after_closing_fds.sh copied from file tests/util_stdout_closes_first.sh (similarity 66%) (mode: 100755) (index 18283ef..d9b0710)
... ... echo "stdout"
4 4 echo "stderr1" 1>&2 echo "stderr1" 1>&2
5 5
6 6 exec 1<&- exec 1<&-
7 exec 2<&-
7 8
8 sleep .2
9
10 echo "stderr2" 1>&2
9 sleep .5
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