forked from kohler/hotcrp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
* upstream/master: (78 commits) Don't hashtarget new comments. Linked-to review is highlighted. Linked-to comment is highlighted. Fix links to comments from action log. Hotcrp-daemonize forks. An active matching job token can't be invalid. Oops Add `hotcrp-daemonize` command to close unwanted file descriptors. Add Job_Capability::canonical_token. api/job not found is not mistaken for OK. Introduce BatchProcess class. Update country listing Invalidate review-accept capabilities after 45 days, not 30. Nits. Fix prior commit for truncated s=1 graphs and flip. Limit size of image generated by scorechart.php. Canonicalize response names in document requests. Internal: PaperStatus::_execute_tags to save tag changes. Improve spacing on assign page. Remove references to PaperInfo::$paperTags. ...
- Loading branch information
Showing
82 changed files
with
1,957 additions
and
1,318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <dirent.h> | ||
#include <sys/types.h> | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
|
||
int main(int argc, char** argv) { | ||
DIR* dir = opendir("/dev/fd"); | ||
struct dirent* de; | ||
while (dir && (de = readdir(dir))) { | ||
if (!isdigit((unsigned char) de->d_name[0])) { | ||
continue; | ||
} | ||
char* ends; | ||
unsigned long u = strtoul(de->d_name, &ends, 10); | ||
if (*ends == 0 && (int) u != dirfd(dir) && (int) u > 2) { | ||
close((int) u); | ||
} | ||
} | ||
closedir(dir); | ||
if (fork() > 0) { | ||
exit(0); | ||
} | ||
setsid(); | ||
execvp(argv[1], argv + 1); | ||
exit(127); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
// batchprocess.php -- HotCRP code for running batch processes | ||
// Copyright (c) 2006-2024 Eddie Kohler; see LICENSE. | ||
|
||
class BatchProcess { | ||
/** @param Throwable $ex | ||
* @suppress PhanUndeclaredProperty */ | ||
static function exception_handler($ex) { | ||
global $argv; | ||
$s = $ex->getMessage(); | ||
if (defined("HOTCRP_TESTHARNESS") || $ex instanceof Error) { | ||
$s = $ex->getFile() . ":" . $ex->getLine() . ": " . $s; | ||
} | ||
if ($s !== "" && strpos($s, ":") === false) { | ||
$script = $argv[0] ?? ""; | ||
if (($slash = strrpos($script, "/")) !== false) { | ||
if (($slash === 5 && str_starts_with($script, "batch")) | ||
|| ($slash > 5 && substr_compare($script, "/batch", $slash - 6, 6) === 0)) { | ||
$slash -= 6; | ||
} | ||
$script = substr($script, $slash + 1); | ||
} | ||
if ($script !== "") { | ||
$s = "{$script}: {$s}"; | ||
} | ||
} | ||
if ($s !== "" && substr($s, -1) !== "\n") { | ||
$s = "{$s}\n"; | ||
} | ||
$exitStatus = 3; | ||
if (property_exists($ex, "exitStatus") && is_int($ex->exitStatus)) { | ||
$exitStatus = $ex->exitStatus; | ||
} | ||
if (property_exists($ex, "getopt") | ||
&& $ex->getopt instanceof Getopt | ||
&& $exitStatus !== 0) { | ||
$s .= $ex->getopt->short_usage(); | ||
} | ||
if (property_exists($ex, "context") && is_array($ex->context)) { | ||
foreach ($ex->context as $c) { | ||
$i = 0; | ||
while ($i !== strlen($c) && $c[$i] === " ") { | ||
++$i; | ||
} | ||
$s .= prefix_word_wrap(str_repeat(" ", $i + 2), trim($c), 2); | ||
} | ||
} | ||
if (defined("HOTCRP_TESTHARNESS") || $ex instanceof Error) { | ||
$s .= debug_string_backtrace($ex) . "\n"; | ||
} | ||
fwrite(STDERR, $s); | ||
exit($exitStatus); | ||
} | ||
|
||
/** @return bool */ | ||
static function daemonize() { | ||
if (!function_exists("pcntl_fork")) { | ||
return false; | ||
} | ||
if (($f = pcntl_fork()) < 0) { | ||
return false; | ||
} else if ($f > 0) { | ||
exit(0); | ||
} | ||
if (function_exists("posix_setsid")) { | ||
if (posix_setsid() < 0) { | ||
error_log("posix_setsid error: " . posix_strerror(posix_get_last_error())); | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.