darwin: Don't leave stdin/stdout closed

<rdar://problem/15609419>

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit ad8111d7c971ce448905c733d65ba0cfc72bdca4)
XQuartz: Use asl_log_descriptor to log stdout/stderr of child processes

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit d7c9235ee261b0f780320985233e00dec5e2689c)
XQuartz: Silence some static analyzer warnings by annotating referencing counts

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 9da6c0918f40359f28fe8889d5b7cae7efcc8377)
XQuartz: Fix darwinfb.h header guard

./darwinfb.h:28:9: warning: '_DARWIN_FB_H' is used as a header guard here, followed by #define of a different macro
      [-Wheader-guard,Lexical or Preprocessor Issue]
        ^~~~~~~~~~~~
./darwinfb.h:29:9: note: '_DARWIN_DB_H' is defined here; did you mean '_DARWIN_FB_H'? [Lexical or Preprocessor Issue]
        ^~~~~~~~~~~~
        _DARWIN_FB_H

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 2e3ebec9520719a8e5c3c92390e83bcb5216f978)
XQuartz: Mark applicationWillTerminate: noreturn

X11Controller.m:938:1: warning: method 'applicationWillTerminate:' could be declared with attribute 'noreturn'
      [-Wmissing-noreturn,Semantic Issue]
{
^

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit f79af1941776fd6f1ec26c50603fcc35ca7d514b)
XQuartz: Simplify hook_run to quiet static analyzer

x-hook.c:96:9: warning: Called function pointer is an uninitalized pointer value
        (*fun[i])(arg, data[i]);
        ^~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 959e8f23af7850fcaf40d6c67f5228241a36a9ab)
XQuartz: Validate screen in AppleDRIQueryDirectRenderingCapable requests

Return an error to the caller rather than crashing the server on
invalid screens.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit b3572c0d1ab7888ac26d6b2b8be6d1d19ed9af3f)
XQuartz: Validate length in appledri before swapping

Avoids potential memory corruption from bad requests

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit a03f096a85537d9e881cedaa6cb71aca43a97086)
XQuartz: Silence a clang static analysis warning about a possible memory leak on exit

stub.c:356:9: warning: Potential leak of memory pointed to by 'newargv'
        asl_log(aslc, NULL, ASL_LEVEL_ERR,
        ^~~~~~~
stub.c:356:9: warning: Potential leak of memory pointed to by 'newenvp'
        asl_log(aslc, NULL, ASL_LEVEL_ERR,
        ^~~~~~~
2 warnings generated.

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit b2f6b3497c33a4897afae80a2cf69c596b9f81e8)
XQuartz: Silence a clang static analysis warning about a memory leak

It seems the alanyzer can't comprehend dixSetPrivate().

quartz.c:119:12: warning: Potential leak of memory pointed to by 'displayInfo'
    return quartzProcs->AddScreen(index, pScreen);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 64327226ddfba8f0653615cd678d2d4336fb993d)
XQuartz: Check for allocated memory before using it in AppleWMSetWindowMenu

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 3bc608a361a01043b226fb9aaebf88f6fd852925)
XQuartz: Avoid passing uninitialized pointers to X11ApplicationSetWindowMenu in AppleWMSetWindowMenu

Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 77df653ae3d8448be21221711851acde12c6bc1a)