コード例 #1
0
ファイル: process.cpp プロジェクト: akostrikov/ATCD
static void
test_setenv (const ACE_TCHAR *argv0)
{
    ACE_Process_Options options;
    //  options.setenv ("ACE_PROCESS_TEST", "here's a really large number: %u", 0 - 1);
    options.setenv (ACE_TEXT ("ACE_PROCESS_TEST= here's a large number %u"),
                    0 - 1);
    options.setenv (ACE_TEXT ("ACE_PROCESS_TEST2"), ACE_TEXT ("ophilli"));
#if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR)
    options.command_line ("%s -g", argv0);
#else
    options.command_line ("%ls -g", argv0);
#endif
    ACE_Process process;
    if (process.spawn (options) == -1)
    {
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p.\n"),
                    ACE_TEXT ("test_setenv")));
        return;
    }

    ACE_exitcode status;
    process.wait (&status);
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Process exit with status %d\n"),
                status));
}
コード例 #2
0
ファイル: Process_Test.cpp プロジェクト: INMarkus/ATCD
int
test_setenv (void)
{
  int status = 0;
  ACE_Process_Options opts;
  ACE_TCHAR bigval[5010] = ACE_TEXT ("");
  for (int i = 0; i < 100; ++i)
    ACE_OS::strcat (bigval,
                    ACE_TEXT ("01234567890123456789012345678901234567890123456789"));
#ifndef ACE_LACKS_VA_FUNCTIONS
# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
  const ACE_TCHAR *fmt = ACE_TEXT ("%ls");
# else
  const ACE_TCHAR *fmt = ACE_TEXT ("%s");
# endif

  if (0 != opts.setenv (ACE_TEXT ("A"), fmt, bigval))
    {
      status = errno;
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv")));
    }
  else
    {
      size_t env_len = ACE_OS::strlen (opts.env_buf ());
      if (env_len != 5002)
        {
          status = 1;
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("setenv result should be 5002 chars, not %B\n"),
                      env_len));
        }
    }
#endif
  return status;
}
コード例 #3
0
int main(int argc, char *argv[])
{
    ACE_Process_Options options;
    FILE *fp = 0;
    char *n_env = 0;
    int n;

    if (argc == 1) {
        n_env = ACE_OS::getenv("FACTORIAL");
        n = n_env == 0 ? 10 : atoi(n_env);
        options.command_line("%s %d", argv[0], n - 1);
        const char *working_dir = ACE_OS::getenv("WORKING_DIR");
        if (working_dir) options.working_directory(working_dir);
        fp = fopen("factorial.log", "a");
        cout << "before setenv" << endl;
        options.setenv("PROGRAM=%s", ACE::basename(argv[0]));
        cout << "after setenv" << endl;
    } else {
        fp = fopen("factorial.log", "a");
        if (atoi(argv[1]) == 1) {
            fprintf(fp, "[%s|%d]: base case\n",
                    ACE_OS::getenv("PROGRAM"), ACE_OS::getpid());
            fclose(fp);
            return 1;
        } else {
            n = atoi(argv[1]);
            options.command_line("%s %d", argv[0], n - 1);
        }
    }

    ACE_Process child;
    child.spawn(options);
    child.wait();
    int factorial = n * child.return_value();
    fprintf(fp, "[%s|%d]: %d! == %d\n",
            ACE_OS::getenv("PROGRAM"), ACE_OS::getpid(),
            n, factorial);
    fclose(fp);
    return factorial;
}
コード例 #4
0
ファイル: Env_Value_Test.cpp プロジェクト: binghuo365/BaseLab
int
// This has been unconditionally turned on for the time being since I can't
// figure out an easy way to enable it and still keep ACE_TMAIN in a seperate
// cpp.
#if 1 || defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) || defined (ACE_LACKS_FORK)
// ACE_HAS_NONSTATIC_OBJECT_MANAGER only allows main to have two
// arguments.  And on platforms that lack fork (), we can't use spawn.
run_main (int argc, ACE_TCHAR* [])
{
  ACE_UNUSED_ARG (argc);

  // Only Win32 can set wide-char environment strings. So, for all
  // others, use char string literals regardless of ACE_USES_WCHAR.
#  if defined (ACE_WIN32)
  ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_POSITIVE=10.2"));
  ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_NEGATIVE=-10.2"));
#  else
  ACE_OS::putenv ("TEST_VALUE_POSITIVE=10.2");
  ACE_OS::putenv ("TEST_VALUE_NEGATIVE=-10.2");
#  endif /* ACE_WIN32 */
#else  /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER  &&  ! ACE_LACKS_FORK */
run_main (int argc, ACE_TCHAR * [], ACE_TCHAR *envp[])
{
  if (argc == 1)
    {
      int status;

      // No arguments means we're the initial test.
      ACE_Process_Options options (1);
      status = options.setenv (envp);
      if (status != 0)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("setenv(envp)")));

      options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR
                            ACE_TEXT ("Env_Value_Test run_as_test"));

      status = options.setenv (ACE_TEXT ("TEST_VALUE_POSITIVE"),
                               ACE_TEXT ("%s"),
                               ACE_TEXT ("10.2"));
      if (status != 0)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("setenv(TEST_VALUE_POSITIVE)")));

      status = options.setenv (ACE_TEXT ("TEST_VALUE_NEGATIVE"),
                               ACE_TEXT ("%s"),
                               ACE_TEXT ("-10.2"));
      if (status != 0)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("%p\n"),
                    ACE_TEXT ("setenv(TEST_VALUE_NEGATIVE)")));

      ACE_Process p;
      pid_t result = p.spawn (options);
      if (result == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")));
      else
        p.wait ();
    }
  else
#endif /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER  &&  ! ACE_LACKS_FORK */
    {
      // In this case we're the child

    ACE_START_TEST (ACE_TEXT ("Env_Value_Test"));

      TEST_THIS (int, ACE_TEXT ("TEST_VALUE_POSITIVE"), 4, 10);
      TEST_THIS (double, ACE_TEXT ("TEST_VALUE_POSITIVE"), -1.0, 10.2);
      TEST_THIS (long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);

      TEST_THIS (int, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 4, -10);
      TEST_THIS (double, ACE_TEXT ("TEST_VALUE_NEGATIVE"), -1.0, -10.2);
      TEST_THIS (long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10L);
      TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned long) -10);
      TEST_THIS (short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10);
      TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned short) -10);

      const ACE_TCHAR *defstr = ACE_TEXT ("Sarah Cleeland is Two!");
      ACE_Env_Value<const ACE_TCHAR *> sval (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"),
                                  defstr);
      if (ACE_OS::strcmp (sval, defstr) != 0)
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("Mismatch: %s should be %s\n"),
                    (const ACE_TCHAR *)sval, defstr));
      ACE_END_TEST;
    }
  return 0;
}
コード例 #5
0
int
#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) || defined (ACE_LACKS_FORK)
// ACE_HAS_NONSTATIC_OBJECT_MANAGER only allows main to have two
// arguments.  And on platforms that lack fork (), we can't use spawn.

main (int argc, ACE_TCHAR* [])
{
  ACE_UNUSED_ARG (argc);

  ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_POSITIVE=10.2"));
  ACE_OS::putenv (ACE_TEXT ("TEST_VALUE_NEGATIVE=-10.2"));
#else  /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER  &&  ! ACE_LACKS_FORK */
main (int argc, ACE_TCHAR * [], ACE_TCHAR *envp[])
{
  if (argc == 1)
    {
      int status;

      // No arguments means we're the initial test.
      ACE_Process_Options options (1);
      status = options.setenv (envp);
      ACE_ASSERT (status == 0);

      options.command_line (ACE_TEXT (".") ACE_DIRECTORY_SEPARATOR_STR
                            ACE_TEXT ("Env_Value_Test run_as_test"));

      status = options.setenv (ACE_TEXT ("TEST_VALUE_POSITIVE"),
                               ACE_TEXT ("%s"),
                               ACE_TEXT ("10.2"));
      ACE_ASSERT (status == 0);
      status = options.setenv (ACE_TEXT ("TEST_VALUE_NEGATIVE"),
                               ACE_TEXT ("%s"),
                               ACE_TEXT ("-10.2"));
      ACE_ASSERT (status == 0);

      ACE_Process p;
      pid_t result = p.spawn (options);
      ACE_ASSERT (result != -1);
      p.wait ();
    }
  else
#endif /* ! ACE_HAS_NONSTATIC_OBJECT_MANAGER  &&  ! ACE_LACKS_FORK */
    {
      // In this case we're the child

    ACE_START_TEST (ACE_TEXT ("Env_Value_Test"));

      TEST_THIS (int, ACE_TEXT ("TEST_VALUE_POSITIVE"), 4, 10);
#if !defined (ACE_LACKS_FLOATING_POINT)
      TEST_THIS (double, ACE_TEXT ("TEST_VALUE_POSITIVE"), -1.0, 10.2);
#endif /* ! ACE_LACKS_FLOATING_POINT */
      TEST_THIS (long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);
      TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_POSITIVE"), 0, 10);

      TEST_THIS (int, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 4, -10);
#if !defined (ACE_LACKS_FLOATING_POINT)
      TEST_THIS (double, ACE_TEXT ("TEST_VALUE_NEGATIVE"), -1.0, -10.2);
#endif /* ! ACE_LACKS_FLOATING_POINT */
      TEST_THIS (long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10L);
      TEST_THIS (unsigned long, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned long) -10);
      TEST_THIS (short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, -10);
      TEST_THIS (unsigned short, ACE_TEXT ("TEST_VALUE_NEGATIVE"), 0, (unsigned short) -10);

      const ACE_TCHAR *defstr = ACE_TEXT ("Sarah Cleeland is Two!");
      ACE_Env_Value<const ACE_TCHAR *> sval (ACE_TEXT ("This_Shouldnt_Be_Set_Hopefully"),
                                  defstr);
      ACE_ASSERT (ACE_OS::strcmp (sval, defstr) == 0);
      ACE_END_TEST;
    }
  return 0;
}
コード例 #6
0
ファイル: Spawn.cpp プロジェクト: azraelly/knetwork
 int setEnvVariable (ACE_Process_Options &options)
 {
   ACE_TRACE ("Manager::setEnvVariables");
   return options.setenv
     (ACE_TEXT ("PRIVATE_VAR=/that/seems/to/be/it"));
 }