lock.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) 2009 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. * Test program for grabbing and releasing the talon output semaphore.
  16. */
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <stdio.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <fcntl.h>
  24. #include <stdarg.h>
  25. #include "sema.h"
  26. #include "buffer.h"
  27. #include "../config.h"
  28. /* The output semaphore. */
  29. sbs_semaphore talon_sem;
  30. #define TALON_ATTEMPT_STRMAX 32
  31. #define RECIPETAG_STRMAX 2048
  32. #define STATUS_STRMAX 100
  33. #define TALONDELIMITER '|'
  34. #define VARNAMEMAX 100
  35. #define VARVALMAX 1024
  36. #include "log.h"
  37. #ifdef HAS_MSVCRT
  38. /* Make all output handling binary */
  39. unsigned int _CRT_fmode = _O_BINARY;
  40. #endif
  41. double getseconds(void)
  42. {
  43. struct timeval tp;
  44. gettimeofday(&tp, NULL);
  45. return (double)tp.tv_sec + ((double)tp.tv_usec)/1000000.0L;
  46. }
  47. void talon_setenv(char name[], char val[])
  48. {
  49. #if defined(HAS_GETENVIRONMENTVARIABLE)
  50. SetEnvironmentVariableA(name,val);
  51. #elif defined(HAS_GETENV)
  52. setenv(name,val, 1);
  53. #else
  54. # error "Need a function for setting environment variables"
  55. #endif
  56. }
  57. #define TALON_MAXENV 4096
  58. char * talon_getenv(char name[])
  59. {
  60. #if defined(HAS_SETENV)
  61. char *val = getenv(name);
  62. char *dest = NULL;
  63. if (val)
  64. {
  65. dest = malloc(strlen(val) + 1);
  66. if (dest)
  67. {
  68. strcpy(dest,val);
  69. }
  70. }
  71. return dest;
  72. #elif defined(HAS_SETENVIRONMENTVARIABLE)
  73. char *val = malloc(TALON_MAXENV);
  74. if (0 != GetEnvironmentVariableA(name,val,TALON_MAXENV-1))
  75. return val;
  76. else
  77. return NULL;
  78. #else
  79. # error "Need a function for setting environment variables"
  80. #endif
  81. }
  82. int main(int argc, char *argv[])
  83. {
  84. /* find the argument to -c then strip the talon related front section */
  85. char *recipe = NULL;
  86. int talon_returncode = 0;
  87. /* Now take settings from the environment (having potentially modified it) */
  88. if (talon_getenv("TALON_DEBUG"))
  89. loglevel=LOGDEBUG;
  90. int enverrors = 0;
  91. char *buildid = talon_getenv("TALON_BUILDID");
  92. if (!buildid)
  93. {
  94. error("error: %s", "TALON_BUILDID not set in environment\n");
  95. enverrors++;
  96. }
  97. talon_sem.name = buildid;
  98. talon_sem.timeout = 999999990;
  99. int x;
  100. debug("debug: %s", "WAITING ON SEMAPHORE\n");
  101. x = sema_wait(&talon_sem);
  102. if (x == 0)
  103. {
  104. debug("debug: %s", "SEMAPHORE OBTAINED\n");
  105. getchar();
  106. sema_release(&talon_sem);
  107. debug("debug: %s", "SEMAPHORE RELEASED\n");
  108. }
  109. }