modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-09-29 16:07:28 +04:00
parent 4686fd07d4
commit bd10883740
2 changed files with 15 additions and 17 deletions

View File

@ -88,18 +88,20 @@ class BgLauncherApp extends Application {
} elseif (!$pid) { } elseif (!$pid) {
# child, fork ok # child, fork ok
$runfile->wfPrepare($pid); $runfile->wfPrepare($pid);
$logfile = $runfile->getLogfile() ?? "/tmp/NULIB_APP_app_console.log"; $outfile = $runfile->getOutfile() ?? "/tmp/NULIB_APP_app_console.out";
$exitcode = app2::EC_FORK_CHILD; $exitcode = app2::EC_FORK_CHILD;
try { try {
# rediriger STDOUT et STDERR # rediriger STDIN, STDOUT et STDERR
fclose(STDIN);
$in = fopen("/dev/null", "rb");
fclose(STDOUT); fclose(STDOUT);
$out = fopen($logfile, "a+b"); $out = fopen($outfile, "a+b");
fclose(STDERR); fclose(STDERR);
$err = fopen($logfile, "a+b"); $err = fopen($outfile, "a+b");
# puis lancer la commande # puis lancer la commande
$cmd = new Cmd($args); $cmd = new Cmd($args);
$cmd->addSource("/g/init.env"); $cmd->addSource("/g/init.env");
$cmd->addRedir("both", $logfile, true); $cmd->addRedir("both", $outfile, true);
$cmd->fork_exec($exitcode, false); $cmd->fork_exec($exitcode, false);
sh::_waitpid(-$pid, $exitcode); sh::_waitpid(-$pid, $exitcode);
} finally { } finally {

View File

@ -21,21 +21,21 @@ class RunFile {
const NAME = null; const NAME = null;
function __construct(?string $name, string $file, ?string $logfile=null) { function __construct(?string $name, string $file, ?string $outfile=null) {
$file = path::ensure_ext($file, self::RUN_EXT); $file = path::ensure_ext($file, self::RUN_EXT);
$this->name = $name ?? static::NAME; $this->name = $name ?? static::NAME;
$this->file = new SharedFile($file); $this->file = new SharedFile($file);
$this->logfile = $logfile; $this->outfile = $outfile;
} }
protected ?string $name; protected ?string $name;
protected SharedFile $file; protected SharedFile $file;
protected ?string $logfile; protected ?string $outfile;
function getLogfile(): ?string { function getOutfile(): ?string {
return $this->logfile; return $this->outfile;
} }
protected static function merge(array $data, array $merge): array { protected static function merge(array $data, array $merge): array {
@ -47,7 +47,6 @@ class RunFile {
protected function initData(): array { protected function initData(): array {
return [ return [
"name" => $this->name, "name" => $this->name,
"mode" => null,
"pgid" => null, "pgid" => null,
"pid" => null, "pid" => null,
"serial" => 0, "serial" => 0,
@ -56,7 +55,7 @@ class RunFile {
"date_lock" => null, "date_lock" => null,
"date_release" => null, "date_release" => null,
# run # run
"logfile" => $this->logfile, "logfile" => $this->outfile,
"date_start" => null, "date_start" => null,
"date_stop" => null, "date_stop" => null,
"exitcode" => null, "exitcode" => null,
@ -178,7 +177,6 @@ class RunFile {
posix_setsid(); posix_setsid();
$pgid = posix_getpid(); $pgid = posix_getpid();
return cl::merge($this->initData(), [ return cl::merge($this->initData(), [
"mode" => "session",
"pgid" => $pgid, "pgid" => $pgid,
"pid" => null, "pid" => null,
"date_start" => new DateTime(), "date_start" => new DateTime(),
@ -190,13 +188,12 @@ class RunFile {
function wfStart(): void { function wfStart(): void {
$this->update(function (array $data) { $this->update(function (array $data) {
$pid = posix_getpid(); $pid = posix_getpid();
if ($data["mode"] === "session") { if ($data["pgid"] !== null) {
A::merge($data, [ A::merge($data, [
"pid" => $pid, "pid" => $pid,
]); ]);
} else { } else {
$data = cl::merge($this->initData(), [ $data = cl::merge($this->initData(), [
"mode" => "standalone",
"pid" => $pid, "pid" => $pid,
"date_start" => new DateTime(), "date_start" => new DateTime(),
]); ]);
@ -218,7 +215,7 @@ class RunFile {
} }
function _getCid(array $data=null): int { function _getCid(array $data=null): int {
if ($data["mode"] === "session") return -$data["pgid"]; if ($data["pgid"] !== null) return -$data["pgid"];
else return $data["pid"]; else return $data["pid"];
} }
@ -276,7 +273,6 @@ class RunFile {
function wfReaped(int $exitcode): void { function wfReaped(int $exitcode): void {
$this->update(function (array $data) use ($exitcode) { $this->update(function (array $data) use ($exitcode) {
return [ return [
"mode" => null,
"pgid" => null, "pgid" => null,
"date_stop" => $data["date_stop"] ?? new DateTime(), "date_stop" => $data["date_stop"] ?? new DateTime(),
"exitcode" => $exitcode, "exitcode" => $exitcode,