testprocess.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. * This component and the accompanying materials are made available
  5. * under the terms of the License "Eclipse Public License v1.0"
  6. * which accompanies this distribution, and is available
  7. * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. *
  9. * Initial Contributors:
  10. * Nokia Corporation - initial contribution.
  11. *
  12. * Contributors:
  13. *
  14. * Description:
  15. * This programs tests the process execution functions in talon.
  16. * it executes it's first argument with the following arguments
  17. * as parameters to it. Output is buffered and finally printed.
  18. * Should be run from within valgrind if possible to detect memory
  19. * corruption errors.
  20. */
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <stdio.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <fcntl.h>
  27. #include "process.h"
  28. int main(int argc, char *argv[])
  29. {
  30. char *shell = getenv("TALON_SHELL");
  31. char **args = malloc((argc+2)*sizeof(char *));
  32. int i;
  33. proc *p;
  34. for (i=1; i < argc; i++)
  35. {
  36. args[i] = argv[i];
  37. printf("arg: %s\n", args[i]);
  38. }
  39. args[argc] = NULL;
  40. if (! shell)
  41. {
  42. fprintf(stderr, "error: %s", "TALONSHELL not set in environment\n");
  43. return 1;
  44. }
  45. args[0] = shell;
  46. p = process_run(shell, args, 4000);
  47. if (p)
  48. {
  49. buffer_prepend(p->output, "<recipe>\n<!CDATA<[[\n", 20);
  50. buffer_append(p->output, "\n]]></recipe>\n", 13);
  51. unsigned int iterator = 0;
  52. byteblock *bb;
  53. while ((bb = buffer_getbytes(p->output, &iterator)))
  54. {
  55. write(STDOUT_FILENO, &bb->byte0, bb->fill);
  56. }
  57. process_free(&p);
  58. } else {
  59. fprintf(stderr, "error: %s", "failed to run process\n");
  60. return 1;
  61. }
  62. free(args);
  63. return 0;
  64. }