🐛 Keep the bundle's log lines off the process's stderr
Every line of the Metal bundle's (rgfxLogLine) went to the unified log and also to the process's stderr wherever NSLog writes there. So a command-line program in a guest that joins its stderr to its output printed the bundle's lines among its own: a user's script showed "RGFX: feature profile 10002: ..." in its output. A Mac's Metal writes nothing there of its own. rgfxLogLine now logs to the unified log alone. The words of a death, which the process ends at next and which Metal writes on stderr at the same calls, go through rgfxLogDeathLine, which still writes them there; the death checks read them. shell_tests runs itself again with --log-line, its stderr a pipe, and checks that a logged line writes nothing there. It fails with the old rgfxLogLine. What changes for the guest: a program's stderr carries none of the bundle's lines except a death's words; the unified log keeps them all, as before.
This commit is contained in:
1 parent
cf3c32173d
commit
70088b78b1
7 files changed
+63
-13
No files matched your search
@@ -3496,7 +3496,7 @@ static NSError *rgfxInvalidInputError()
|
||||
- (void)encodeSignalEventScheduled:(id<MTLEvent>)event value:(uint64_t)value
|
||||
{
|
||||
if ([(id)event isKindOfClass:[RgfxEvent class]]) {
|
||||
rgfxLogLine(@"MTLEvent passed to API expecting MTLSharedEvent");
|
||||
rgfxLogDeathLine(@"MTLEvent passed to API expecting MTLSharedEvent");
|
||||
abort();
|
||||
}
|
||||
if (event == nil && _retained)
|
||||
|
||||
@@ -670,7 +670,7 @@ bool isRendererPluginData(NSData *data)
|
||||
- (void)setPluginData:(id)pluginData
|
||||
{
|
||||
(void)pluginData;
|
||||
rgfxLogLine(@"RGFX: -[%s setPluginData:] ends the process, as Metal's function does",
|
||||
rgfxLogDeathLine(@"RGFX: -[%s setPluginData:] ends the process, as Metal's function does",
|
||||
class_getName([self class]));
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// identifier, so `log config --subsystem ai.aneesiqbal.reims-graphics` sets the level those lines
|
||||
// are kept at and persisted to, on every release: a line on OS_LOG_DEFAULT has no subsystem, and
|
||||
// no mode persists its debug lines (docs/lessons.md). Its Objective-C sources log through
|
||||
// rgfxLogLine, at the default level, which the log store keeps, with their text public.
|
||||
// rgfxLogLine, at the default level, which the log store keeps, with their text public, and the
|
||||
// words of a death through rgfxLogDeathLine, which also go to the process's stderr.
|
||||
// tests/bundle_log_check.sh keeps the subsystem equal to Info.plist's CFBundleIdentifier and the
|
||||
// bundle off OS_LOG_DEFAULT and NSLog.
|
||||
|
||||
@@ -18,7 +19,7 @@
|
||||
// The bundle's log object, made at the first call in a process and never released.
|
||||
os_log_t rgfxLog();
|
||||
|
||||
// Whether a line also goes to the process's stderr, as NSLog's does: where it is a file, a
|
||||
// Whether a death's line also goes to the process's stderr, as NSLog's does: where it is a file, a
|
||||
// socket, a pipe or a terminal, not /dev/null or nothing.
|
||||
bool rgfxLogToStderr();
|
||||
|
||||
@@ -35,13 +36,26 @@ void rgfxNoteNil(const char *creator, const char *cause, const char *asked);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// A line of the bundle's at the default level, on its subsystem, with all of its text public:
|
||||
// it is formatted here, as NSLog formats, and logged as one public string, and written to stderr
|
||||
// where NSLog writes there too (a death's words among them, which tests/shell_tests.mm's death
|
||||
// checks read). An NSLog argument the unified log takes for private (an object, or a string made
|
||||
// at run time) reads `<private>` on macOS 26, so a line naming what a guest's framework asked for
|
||||
// named nothing there.
|
||||
// A line of the bundle's at the default level, on its subsystem, with all of its text public: it
|
||||
// is formatted here, as NSLog formats, and logged as one public string. An NSLog argument the
|
||||
// unified log takes for private (an object, or a string made at run time) reads `<private>` on
|
||||
// macOS 26, so a line naming what a guest's framework asked for named nothing there. It goes to
|
||||
// the unified log alone, never to the process's stderr, where a Mac's Metal writes nothing of
|
||||
// its own: a command-line program whose stderr joins its output shows none of the bundle's lines.
|
||||
NS_FORMAT_FUNCTION(1, 2) static inline void rgfxLogLine(NSString *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
NSString *line = [[NSString alloc] initWithFormat:format arguments:args];
|
||||
va_end(args);
|
||||
os_log(rgfxLog(), "%{public}@", line);
|
||||
}
|
||||
|
||||
// The words of a death, logged as rgfxLogLine logs a line and written to the process's stderr
|
||||
// where NSLog writes there too, as Metal writes its words at the deaths whose calls end the
|
||||
// process here (tests/shell_tests.mm's death checks read them there). Its caller ends the
|
||||
// process next.
|
||||
NS_FORMAT_FUNCTION(1, 2) static inline void rgfxLogDeathLine(NSString *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
@@ -47,7 +47,7 @@ float floatOf(uint64_t bits)
|
||||
// creation, and compiles a Mutable map at its creation, so no answer of its is the host's.
|
||||
[[noreturn]] void endsTheProcess(const char *call)
|
||||
{
|
||||
rgfxLogLine(@"RGFX: -[RgfxRasterizationRateMap %s] ends the process, as Metal's map does", call);
|
||||
rgfxLogDeathLine(@"RGFX: -[RgfxRasterizationRateMap %s] ends the process, as Metal's map does", call);
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace {
|
||||
// removes-nil).
|
||||
[[noreturn]] void endsTheProcess(const char *call)
|
||||
{
|
||||
rgfxLogLine(@"RGFX: -[RgfxResidencySet %s] of a nil allocation ends the process, as Metal's set does",
|
||||
rgfxLogDeathLine(@"RGFX: -[RgfxResidencySet %s] of a nil allocation ends the process, as Metal's set does",
|
||||
call);
|
||||
abort();
|
||||
}
|
||||
|
||||
@@ -825,7 +825,7 @@ void rgfxEndAtInvalidTextureDescriptor(MTLTextureDescriptor *descriptor, id<MTLD
|
||||
// A type past MTLTextureTypeTextureBuffer ends the process with no words, at each creator of
|
||||
// both x86 Macs (oracle_texdesc type10).
|
||||
if (type > MTLTextureTypeTextureBuffer) {
|
||||
rgfxLogLine(@"RGFX: texture type %llu ends the process, as Metal's creators do", ull(type));
|
||||
rgfxLogDeathLine(@"RGFX: texture type %llu ends the process, as Metal's creators do", ull(type));
|
||||
abort();
|
||||
}
|
||||
NSString *typeName = rgfxTextureTypeName(type);
|
||||
|
||||
@@ -1771,6 +1771,37 @@ static void checkDies(const char *name, const char *words)
|
||||
CHECK(err.find(words) != std::string::npos);
|
||||
}
|
||||
|
||||
// A line of the bundle's (rgfxLogLine) goes to the unified log alone: run again with --log-line,
|
||||
// this binary logs one with its stderr a pipe, where NSLog would write, and writes nothing there.
|
||||
// So a command-line program whose stderr joins its output prints none of the bundle's lines, as
|
||||
// on a Mac. A death's words (rgfxLogDeathLine) still reach stderr: the death checks read them.
|
||||
static void test_log_lines_stay_off_stderr()
|
||||
{
|
||||
int fds[2];
|
||||
CHECK(pipe(fds) == 0);
|
||||
posix_spawn_file_actions_t fa;
|
||||
posix_spawn_file_actions_init(&fa);
|
||||
posix_spawn_file_actions_adddup2(&fa, fds[1], 2);
|
||||
posix_spawn_file_actions_addclose(&fa, fds[0]);
|
||||
char *args[] = {const_cast<char *>(g_self), const_cast<char *>("--log-line"), nullptr};
|
||||
pid_t pid = 0;
|
||||
CHECK(posix_spawn(&pid, g_self, &fa, nullptr, args, *_NSGetEnviron()) == 0);
|
||||
posix_spawn_file_actions_destroy(&fa);
|
||||
close(fds[1]);
|
||||
std::string err;
|
||||
char chunk[512];
|
||||
ssize_t n;
|
||||
while ((n = read(fds[0], chunk, sizeof chunk)) > 0)
|
||||
err.append(chunk, static_cast<size_t>(n));
|
||||
close(fds[0]);
|
||||
int status = 0;
|
||||
CHECK(waitpid(pid, &status, 0) == pid);
|
||||
CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 0);
|
||||
if (err.find("RGFX:") != std::string::npos)
|
||||
std::fprintf(stderr, "--log-line wrote on its stderr:\n%s\n", err.c_str());
|
||||
CHECK(err.find("RGFX:") == std::string::npos);
|
||||
}
|
||||
|
||||
// A .metallib of one function, `rgfx_exported`, of the TYPE a dynamic library's exported function
|
||||
// has (3), in metallibOf's layout.
|
||||
static std::vector<uint8_t> exportedFunctionMetallib();
|
||||
@@ -22741,6 +22772,10 @@ int main(int argc, char **argv)
|
||||
g_self = argv[0];
|
||||
if (argc == 3 && std::strcmp(argv[1], "--dies") == 0)
|
||||
return dies_case(argv[2]);
|
||||
if (argc == 2 && std::strcmp(argv[1], "--log-line") == 0) {
|
||||
rgfxLogLine(@"RGFX: a line of the unified log alone");
|
||||
return 0;
|
||||
}
|
||||
if (argc == 3 && std::strcmp(argv[1], "--queue-dies") == 0)
|
||||
return rgfxQueueDiesCase(argv[2]);
|
||||
if (argc == 3 && std::strcmp(argv[1], "--queue-lock") == 0)
|
||||
@@ -22961,6 +22996,7 @@ int main(int argc, char **argv)
|
||||
test_no_copy_shadows_lie_in_slabs();
|
||||
test_binds_note_shadow_writes();
|
||||
test_block_call();
|
||||
test_log_lines_stay_off_stderr();
|
||||
rgfxProtocolTests(argv[0]); // tests/protocol_tests.mm
|
||||
rgfxArchiveTests(); // tests/archive_tests.mm
|
||||
rgfxResourceTests(); // tests/resource_tests.mm
|
||||
|
||||
Reference in new issue
Block a user