brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 1a66a61 Raw
58 lines · c
1// RUN: %clang %s -o %t && %run %t 2>&1 | FileCheck %s2//3// Older versions of Android do not have certain posix_spawn* functions.4// UNSUPPORTED: android5 6#include <assert.h>7#include <spawn.h>8#include <stdio.h>9#include <stdlib.h>10#include <string.h>11#include <sys/wait.h>12 13extern char **environ;14 15int main(int argc, char **argv) {16  if (argc > 1) {17    // CHECK: SPAWNED18    // CHECK: SPAWNED19    printf("SPAWNED\n");20    return 0;21  }22 23  posix_spawnattr_t attr = {0};24  posix_spawn_file_actions_t file_actions = {0};25 26  char *const args[] = {27      argv[0], "2", "3", "4", "2", "3", "4", "2", "3", "4",28      "2",     "3", "4", "2", "3", "4", "2", "3", "4", NULL,29  };30  char *env[] = {31      "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B",32      "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", "A=B", NULL,33  };34 35  // When this test runs with a runtime (e.g. ASAN), the spawned process needs36  // to use the same runtime search path as the parent. Otherwise, it might37  // try to load a runtime that doesn't work and crash before hitting main(),38  // failing the test. We technically should forward the variable for the39  // current platform, but some platforms have multiple such variables and40  // it's quite difficult to plumb this through the lit config.41  for (char **e = environ; *e; e++)42    if (strncmp(*e, "DYLD_LIBRARY_PATH=", sizeof("DYLD_LIBRARY_PATH=") - 1) ==43        0)44      env[0] = *e;45 46  pid_t pid;47  int s = posix_spawn(&pid, argv[0], &file_actions, &attr, args, env);48  assert(!s);49 50  waitpid(pid, &s, WUNTRACED | WCONTINUED);51 52  s = posix_spawnp(&pid, argv[0], &file_actions, &attr, args, env);53  assert(!s);54 55  waitpid(pid, &s, WUNTRACED | WCONTINUED);56  return 0;57}58