ruby-lsapi 5.2 → 5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd8cc4083ffaa583379211d191ec387ebf69929bc27100fc0e6793a43186842b
4
- data.tar.gz: d25c2dfd57b141aefedbe63d0c52c60c1bf634cf6b11876d191a8758368df4b0
3
+ metadata.gz: 0a220d3f4f42cb5d58212a8947a2650b1998d5dba3c8bddbd492dd5864be96bf
4
+ data.tar.gz: 42cd393c94027e4620c08d6d661bca16508036312099321c074ed6c788654d2c
5
5
  SHA512:
6
- metadata.gz: d67f5730c65b2b42185450ffcdcb03203f5ba7952467b46cd82a6e60d530a0071b9ba22f42eee92d13adbe95d27aa705589386f2b12843a8bf4acd65c5a1c5ec
7
- data.tar.gz: 418eef951b7d6c9880c1a7f89a64568d2073920e9edc6ba45c21c5d43278f23e8294a2062c22d28ac309f1e204924e722b32c722458991269b8ed3c192a65e4b
6
+ metadata.gz: b1af0f8254ac6a7c89077b89ee9176f9024f763c6102c20a5c3545127620fa06f05fb4fc4f4be3871721bf0d0bfd30ae2496b47d642f60c64cfb171f23aa6459
7
+ data.tar.gz: bf5f7cefabdbb163081d693a5dffc17a843b2764b1b3a7875fda53ae9c6cfe527c7a7a5eae52e9828a1ab9ffb3699cd7f0d2c8805710970dc63cee75fa75ae73
data/ext/lsapi/lsapilib.c CHANGED
@@ -133,7 +133,7 @@ static int s_ppid;
133
133
  static int s_restored_ppid = 0;
134
134
  static int s_pid = 0;
135
135
  static int s_slow_req_msecs = 0;
136
- static int s_keepListener = 0;
136
+ static int s_keep_listener = 1;
137
137
  static int s_dump_debug_info = 0;
138
138
  static int s_pid_dump_debug_info = 0;
139
139
  static int s_req_processed = 0;
@@ -152,7 +152,7 @@ static size_t s_total_pages = 1;
152
152
  static size_t s_min_avail_pages = 256 * 1024;
153
153
  static size_t *s_avail_pages = &s_total_pages;
154
154
 
155
- LSAPI_Request g_req =
155
+ LSAPI_Request g_req =
156
156
  { .m_fdListen = -1, .m_fd = -1 };
157
157
 
158
158
  static char s_secret[24];
@@ -215,7 +215,7 @@ static int HTTP_HEADER_LEN[H_TRANSFER_ENCODING+1] =
215
215
  };
216
216
 
217
217
 
218
- static const char *s_log_level_names[8] =
218
+ static const char *s_log_level_names[8] =
219
219
  {
220
220
  "", "DEBUG","INFO", "NOTICE", "WARN", "ERROR", "CRIT", "FATAL"
221
221
  };
@@ -229,7 +229,7 @@ void LSAPI_Log(int flag, const char * fmt, ...)
229
229
  && !(s_stderr_is_pipe))
230
230
  {
231
231
  struct timeval tv;
232
- struct tm tm;
232
+ struct tm tm;
233
233
  gettimeofday(&tv, NULL);
234
234
  localtime_r(&tv.tv_sec, &tm);
235
235
  if (flag & LSAPI_LOG_TIMESTAMP_FULL)
@@ -244,18 +244,18 @@ void LSAPI_Log(int flag, const char * fmt, ...)
244
244
  tm.tm_hour, tm.tm_min, tm.tm_sec);
245
245
  }
246
246
  }
247
-
247
+
248
248
  int level = flag & LSAPI_LOG_LEVEL_BITS;
249
249
  if (level && level <= LSAPI_LOG_FLAG_FATAL)
250
250
  {
251
251
  p += snprintf(p, 100, "[%s] ", s_log_level_names[level]);
252
252
  }
253
-
253
+
254
254
  if (flag & LSAPI_LOG_PID)
255
255
  {
256
256
  p += snprintf(p, 100, "[UID:%d][%d] ", getuid(), s_pid);
257
257
  }
258
-
258
+
259
259
  if (p > buf)
260
260
  fprintf(stderr, "%.*s", (int)(p - buf), buf);
261
261
  va_list ap;
@@ -342,6 +342,7 @@ static void lsapi_enable_core_dump(void)
342
342
  int mib[2];
343
343
  size_t len;
344
344
 
345
+ #if !defined(__OpenBSD__)
345
346
  len = 2;
346
347
  if ( sysctlnametomib("kern.sugid_coredump", mib, &len) == 0 )
347
348
  {
@@ -350,6 +351,15 @@ static void lsapi_enable_core_dump(void)
350
351
  perror( "sysctl: Failed to set 'kern.sugid_coredump', "
351
352
  "core dump may not be available!");
352
353
  }
354
+ #else
355
+ int set = 3;
356
+ len = sizeof(set);
357
+ mib[0] = CTL_KERN;
358
+ mib[1] = KERN_NOSUIDCOREDUMP;
359
+ if (sysctl(mib, 2, NULL, 0, &set, len) == 0) {
360
+ s_enable_core_dump = 1;
361
+ }
362
+ #endif
353
363
 
354
364
 
355
365
  #endif
@@ -414,9 +424,10 @@ static void lsapi_close_connection(LSAPI_Request *pReq)
414
424
  lsapi_close(pReq->m_fd);
415
425
  pReq->m_fd = -1;
416
426
  if (s_busy_workers)
417
- __sync_fetch_and_sub(s_busy_workers, 1);
427
+ __atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
418
428
  if (s_worker_status)
419
- __sync_lock_test_and_set(&s_worker_status->m_state, LSAPI_STATE_IDLE);
429
+ __atomic_store_n(&s_worker_status->m_state, LSAPI_STATE_IDLE,
430
+ __ATOMIC_SEQ_CST);
420
431
  }
421
432
 
422
433
 
@@ -720,8 +731,8 @@ static int validateHeaders( LSAPI_Request * pReq )
720
731
  {
721
732
  if ( pReq->m_pHeaderIndex->m_headerOff[i] )
722
733
  {
723
- if (pReq->m_pHeaderIndex->m_headerOff[i] > totalLen
724
- || pReq->m_pHeaderIndex->m_headerLen[i]
734
+ if (pReq->m_pHeaderIndex->m_headerOff[i] > totalLen
735
+ || pReq->m_pHeaderIndex->m_headerLen[i]
725
736
  + pReq->m_pHeaderIndex->m_headerOff[i] > totalLen)
726
737
  return -1;
727
738
  }
@@ -733,8 +744,8 @@ static int validateHeaders( LSAPI_Request * pReq )
733
744
  pEnd = pCur + pReq->m_pHeader->m_cntUnknownHeaders;
734
745
  while( pCur < pEnd )
735
746
  {
736
- if (pCur->nameOff > totalLen
737
- || pCur->nameOff + pCur->nameLen > totalLen
747
+ if (pCur->nameOff > totalLen
748
+ || pCur->nameOff + pCur->nameLen > totalLen
738
749
  || pCur->valueOff > totalLen
739
750
  || pCur->valueOff + pCur->valueLen > totalLen)
740
751
  return -1;
@@ -893,6 +904,7 @@ static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char
893
904
  }
894
905
 
895
906
 
907
+ #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
896
908
  static int lsapi_lve_error( LSAPI_Request * pReq )
897
909
  {
898
910
  static const char * headers[] =
@@ -916,10 +928,8 @@ static int lsapi_lve_error( LSAPI_Request * pReq )
916
928
  return 0;
917
929
  }
918
930
 
919
-
920
931
  static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
921
932
  {
922
- #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
923
933
  if ( s_lve && uid ) //root user should not do that
924
934
  {
925
935
  uint32_t cookie;
@@ -927,37 +937,32 @@ static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
927
937
  ret = (*fp_lve_enter)(s_lve, uid, -1, -1, &cookie);
928
938
  if ( ret < 0 )
929
939
  {
930
- //lsapi_log("enter LVE (%d) : ressult: %d !\n", uid, ret );
940
+ //lsapi_log("enter LVE (%d) : result: %d !\n", uid, ret );
931
941
  LSAPI_perror_r(pReq, "LSAPI: lve_enter() failure, reached resource limit.", NULL );
932
942
  lsapi_lve_error( pReq );
933
943
  return -1;
934
944
  }
935
945
  }
936
- #endif
937
946
 
938
947
  return 0;
939
948
  }
940
949
 
941
-
942
950
  static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw )
943
951
  {
944
952
  int ret = 0;
945
- #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
946
953
  char error_msg[1024] = "";
947
954
  ret = (*fp_lve_jail)( pw, error_msg );
948
955
  if ( ret < 0 )
949
956
  {
950
- lsapi_log("LSAPI: LVE jail(%d) ressult: %d, error: %s !\n",
957
+ lsapi_log("LSAPI: LVE jail(%d) result: %d, error: %s !\n",
951
958
  uid, ret, error_msg );
952
959
  LSAPI_perror_r( pReq, "LSAPI: jail() failure.", NULL );
953
960
  return -1;
954
961
  }
955
- #endif
956
962
  return ret;
957
963
  }
958
964
 
959
965
 
960
- #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
961
966
  static int lsapi_initLVE(void)
962
967
  {
963
968
  const char * pEnv;
@@ -1207,13 +1212,13 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
1207
1212
  if ( parseEnv( pReq->m_pEnvList, pReq->m_pHeader->m_cntEnv,
1208
1213
  &pBegin, pEnd ) == -1 )
1209
1214
  return -1;
1210
- if (pReq->m_pHeader->m_scriptFileOff < 0
1211
- || pReq->m_pHeader->m_scriptFileOff >= totalLen
1215
+ if (pReq->m_pHeader->m_scriptFileOff < 0
1216
+ || pReq->m_pHeader->m_scriptFileOff >= totalLen
1212
1217
  || pReq->m_pHeader->m_scriptNameOff < 0
1213
1218
  || pReq->m_pHeader->m_scriptNameOff >= totalLen
1214
1219
  || pReq->m_pHeader->m_queryStringOff < 0
1215
1220
  || pReq->m_pHeader->m_queryStringOff >= totalLen
1216
- || pReq->m_pHeader->m_requestMethodOff < 0
1221
+ || pReq->m_pHeader->m_requestMethodOff < 0
1217
1222
  || pReq->m_pHeader->m_requestMethodOff >= totalLen)
1218
1223
  {
1219
1224
  lsapi_log("Bad request header - ERROR#1\n");
@@ -1244,13 +1249,13 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
1244
1249
  {
1245
1250
  fixHeaderIndexEndian( pReq );
1246
1251
  }
1247
-
1252
+
1248
1253
  if (validateHeaders(pReq) == -1)
1249
1254
  {
1250
1255
  lsapi_log("Bad request header - ERROR#2\n");
1251
1256
  return -1;
1252
1257
  }
1253
-
1258
+
1254
1259
  pReq->m_reqBodyLen = pReq->m_pHeader->m_reqBodyLen;
1255
1260
  if ( pReq->m_reqBodyLen == -2 )
1256
1261
  {
@@ -1271,7 +1276,7 @@ static struct lsapi_packet_header s_ack = {'L', 'S',
1271
1276
  LSAPI_REQ_RECEIVED, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
1272
1277
  static struct lsapi_packet_header s_conn_close_pkt = {'L', 'S',
1273
1278
  LSAPI_CONN_CLOSE, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
1274
-
1279
+
1275
1280
 
1276
1281
  static inline int send_notification_pkt( int fd, struct lsapi_packet_header *pkt )
1277
1282
  {
@@ -1337,30 +1342,6 @@ static inline int lsapi_notify_pid( int fd )
1337
1342
  return 0;
1338
1343
  }
1339
1344
 
1340
-
1341
- static char s_conn_key_packet[16];
1342
- static inline int init_conn_key( int fd )
1343
- {
1344
- struct lsapi_packet_header * pHeader = (struct lsapi_packet_header *)s_conn_key_packet;
1345
- struct timeval tv;
1346
- int i;
1347
- gettimeofday( &tv, NULL );
1348
- srand( (tv.tv_sec % 0x1000 + tv.tv_usec) ^ rand() );
1349
- for( i = 8; i < 16; ++i )
1350
- {
1351
- s_conn_key_packet[i]=(int) (256.0*rand()/(RAND_MAX+1.0));
1352
- }
1353
- lsapi_buildPacketHeader( pHeader, LSAPI_REQ_RECEIVED,
1354
- 8 + LSAPI_PACKET_HEADER_LEN );
1355
- if ( write( fd, s_conn_key_packet, LSAPI_PACKET_HEADER_LEN+8 )
1356
- < LSAPI_PACKET_HEADER_LEN+8 )
1357
- return -1;
1358
- return 0;
1359
-
1360
-
1361
- }
1362
-
1363
-
1364
1345
  static int readReq( LSAPI_Request * pReq )
1365
1346
  {
1366
1347
  int len;
@@ -1560,10 +1541,10 @@ int LSAPI_Accept_r( LSAPI_Request * pReq )
1560
1541
  else
1561
1542
  {
1562
1543
  if (s_worker_status)
1563
- __sync_lock_test_and_set(&s_worker_status->m_state,
1564
- LSAPI_STATE_CONNECTED);
1544
+ __atomic_store_n(&s_worker_status->m_state,
1545
+ LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
1565
1546
  if (s_busy_workers)
1566
- __sync_fetch_and_add(s_busy_workers, 1);
1547
+ __atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
1567
1548
  lsapi_set_nblock( pReq->m_fd , 0 );
1568
1549
  if (((struct sockaddr *)&achPeer)->sa_family == AF_INET )
1569
1550
  {
@@ -1695,10 +1676,10 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex )
1695
1676
  off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ];
1696
1677
  if ( !off )
1697
1678
  return NULL;
1698
- if ( *(pReq->m_pHttpHeader + off
1679
+ if ( *(pReq->m_pHttpHeader + off
1699
1680
  + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) )
1700
1681
  {
1701
- *( pReq->m_pHttpHeader + off
1682
+ *( pReq->m_pHttpHeader + off
1702
1683
  + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
1703
1684
  }
1704
1685
  return pReq->m_pHttpHeader + off;
@@ -1927,7 +1908,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len )
1927
1908
  }
1928
1909
 
1929
1910
 
1930
- #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__)
1911
+ #if defined(__FreeBSD__ )
1931
1912
  ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
1932
1913
  {
1933
1914
  ssize_t ret;
@@ -1942,6 +1923,41 @@ ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
1942
1923
  }
1943
1924
  #endif
1944
1925
 
1926
+ #if defined(__OpenBSD__) || defined(__NetBSD__)
1927
+ ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
1928
+ {
1929
+ ssize_t ret;
1930
+ off_t written = 0;
1931
+ const size_t bufsiz = 16384;
1932
+ unsigned char in[bufsiz] = {0};
1933
+
1934
+ if (lseek(fdIn, *off, SEEK_SET) == -1) {
1935
+ return -1;
1936
+ }
1937
+
1938
+ while (size > 0) {
1939
+ size_t tor = size > sizeof(in) ? sizeof(in) : size;
1940
+ ssize_t c = read(fdIn, in, tor);
1941
+ if (c <= 0) {
1942
+ goto end;
1943
+ }
1944
+
1945
+ ssize_t w = write(fdOut, in, c);
1946
+ if (w > 0)
1947
+ written += w;
1948
+
1949
+ if (w != c) {
1950
+ goto end;
1951
+ }
1952
+ size -= c;
1953
+ }
1954
+
1955
+ end:
1956
+ *off += written;
1957
+ return 0;
1958
+ }
1959
+ #endif
1960
+
1945
1961
 
1946
1962
  #if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
1947
1963
  ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size )
@@ -2152,7 +2168,7 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
2152
2168
  {
2153
2169
  if ( strcmp( name, CGI_HEADERS[i] ) == 0 )
2154
2170
  {
2155
- pValue = pReq->m_pHttpHeader
2171
+ pValue = pReq->m_pHttpHeader
2156
2172
  + pReq->m_pHeaderIndex->m_headerOff[i];
2157
2173
  if ( *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) != '\0')
2158
2174
  {
@@ -2188,7 +2204,7 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
2188
2204
  if (( pKey == pKeyEnd )&& (!*p ))
2189
2205
  {
2190
2206
  pValue = pReq->m_pHttpHeader + pCur->valueOff;
2191
-
2207
+
2192
2208
  if ( *(pValue + pCur->valueLen) != '\0')
2193
2209
  {
2194
2210
  *(pValue + pCur->valueLen) = '\0';
@@ -2655,8 +2671,12 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr )
2655
2671
  ((struct sockaddr_in *)pAddr)->sin_addr.s_addr = htonl( INADDR_LOOPBACK );
2656
2672
  else
2657
2673
  {
2674
+ #ifdef HAVE_INET_PTON
2675
+ if (!inet_pton(AF_INET, p, &((struct sockaddr_in *)pAddr)->sin_addr))
2676
+ #else
2658
2677
  ((struct sockaddr_in *)pAddr)->sin_addr.s_addr = inet_addr( p );
2659
2678
  if ( ((struct sockaddr_in *)pAddr)->sin_addr.s_addr == INADDR_BROADCAST)
2679
+ #endif
2660
2680
  {
2661
2681
  doAddrInfo = 1;
2662
2682
  }
@@ -2853,9 +2873,9 @@ void LSAPI_reset_server_state( void )
2853
2873
  ++pStatus;
2854
2874
  }
2855
2875
  if (s_busy_workers)
2856
- __sync_lock_release(s_busy_workers);
2876
+ __atomic_store_n(s_busy_workers, 0, __ATOMIC_SEQ_CST);
2857
2877
  if (s_accepting_workers)
2858
- __sync_lock_release(s_accepting_workers);
2878
+ __atomic_store_n(s_accepting_workers, 0, __ATOMIC_SEQ_CST);
2859
2879
 
2860
2880
  }
2861
2881
 
@@ -2863,8 +2883,10 @@ void LSAPI_reset_server_state( void )
2863
2883
  static void lsapi_sigchild( int signal )
2864
2884
  {
2865
2885
  int status, pid;
2886
+ char expect_connected = LSAPI_STATE_CONNECTED;
2887
+ char expect_accepting = LSAPI_STATE_ACCEPTING;
2866
2888
  lsapi_child_status * child_status;
2867
- if (g_prefork_server == NULL)
2889
+ if (g_prefork_server == NULL)
2868
2890
  return;
2869
2891
  while( 1 )
2870
2892
  {
@@ -2876,9 +2898,13 @@ static void lsapi_sigchild( int signal )
2876
2898
  if ( WIFSIGNALED( status ))
2877
2899
  {
2878
2900
  int sig_num = WTERMSIG( status );
2879
- int dump = WCOREDUMP( status );
2901
+ #ifdef WCOREDUMP
2902
+ const char * dump = WCOREDUMP( status ) ? "yes" : "no";
2903
+ #else
2904
+ const char * dump = "unknown";
2905
+ #endif
2880
2906
  lsapi_log("Child process with pid: %d was killed by signal: "
2881
- "%d, core dump: %d\n", pid, sig_num, dump );
2907
+ "%d, core dumped: %s\n", pid, sig_num, dump );
2882
2908
  }
2883
2909
  if ( pid == s_pid_dump_debug_info )
2884
2910
  {
@@ -2894,19 +2920,23 @@ static void lsapi_sigchild( int signal )
2894
2920
  child_status = find_child_status( pid );
2895
2921
  if ( child_status )
2896
2922
  {
2897
- if (__sync_bool_compare_and_swap(&child_status->m_state,
2898
- LSAPI_STATE_CONNECTED,
2899
- LSAPI_STATE_IDLE))
2923
+ if (__atomic_compare_exchange_n(&child_status->m_state,
2924
+ &expect_connected,
2925
+ LSAPI_STATE_IDLE, 1,
2926
+ __ATOMIC_SEQ_CST,
2927
+ __ATOMIC_SEQ_CST))
2900
2928
  {
2901
2929
  if (s_busy_workers)
2902
- __sync_fetch_and_sub(s_busy_workers, 1);
2930
+ __atomic_fetch_sub(s_busy_workers, 1, __ATOMIC_SEQ_CST);
2903
2931
  }
2904
- else if (__sync_bool_compare_and_swap(&child_status->m_state,
2905
- LSAPI_STATE_ACCEPTING,
2906
- LSAPI_STATE_IDLE))
2932
+ else if (__atomic_compare_exchange_n(&child_status->m_state,
2933
+ &expect_accepting,
2934
+ LSAPI_STATE_IDLE, 1,
2935
+ __ATOMIC_SEQ_CST,
2936
+ __ATOMIC_SEQ_CST))
2907
2937
  {
2908
2938
  if (s_accepting_workers)
2909
- __sync_fetch_and_sub(s_accepting_workers, 1);
2939
+ __atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
2910
2940
  }
2911
2941
  child_status->m_pid = 0;
2912
2942
  --g_prefork_server->m_iCurChildren;
@@ -2928,7 +2958,7 @@ static int lsapi_init_children_status(void)
2928
2958
  return 0;
2929
2959
  max_children = g_prefork_server->m_iMaxChildren
2930
2960
  + g_prefork_server->m_iExtraChildren;
2931
-
2961
+
2932
2962
  size = max_children * sizeof( lsapi_child_status ) * 2 + 3 * sizeof(int);
2933
2963
  size = (size + 4095) / 4096 * 4096;
2934
2964
  pBuf =( char*) mmap( NULL, size, PROT_READ | PROT_WRITE,
@@ -2964,7 +2994,7 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur )
2964
2994
  lsapi_log("Possible runaway process, UID: %d, PPID: %d, PID: %d, "
2965
2995
  "reqCount: %d, process time: %ld, checkpoint time: %ld, start "
2966
2996
  "time: %ld\n", getuid(), getppid(), pStatus->m_pid,
2967
- pStatus->m_iReqCounter, tmCur - pStatus->m_tmReqBegin,
2997
+ pStatus->m_iReqCounter, tmCur - pStatus->m_tmReqBegin,
2968
2998
  tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
2969
2999
 
2970
3000
  s_pid_dump_debug_info = fork();
@@ -2996,9 +3026,8 @@ static void lsapi_check_child_status( long tmCur )
2996
3026
  ++count;
2997
3027
  if ( !pStatus->m_inProcess )
2998
3028
  {
2999
-
3000
- if (g_prefork_server->m_iCurChildren - dying
3001
- > g_prefork_server->m_iMaxChildren
3029
+ if (g_prefork_server->m_iCurChildren - dying
3030
+ > g_prefork_server->m_iMaxChildren
3002
3031
  || idle > g_prefork_server->m_iMaxIdleChildren)
3003
3032
  {
3004
3033
  ++pStatus->m_iKillSent;
@@ -3006,14 +3035,14 @@ static void lsapi_check_child_status( long tmCur )
3006
3035
  }
3007
3036
  else
3008
3037
  {
3009
- if (s_max_idle_secs> 0
3038
+ if (s_max_idle_secs> 0
3010
3039
  && tmCur - pStatus->m_tmWaitBegin > s_max_idle_secs + 5)
3011
3040
  {
3012
3041
  ++pStatus->m_iKillSent;
3013
3042
  //tobekilled = SIGUSR1;
3014
3043
  }
3015
3044
  }
3016
- if ( !tobekilled )
3045
+ if (!pStatus->m_iKillSent)
3017
3046
  ++idle;
3018
3047
  }
3019
3048
  else
@@ -3039,7 +3068,7 @@ static void lsapi_check_child_status( long tmCur )
3039
3068
  }
3040
3069
  if ( tobekilled )
3041
3070
  {
3042
- if (( kill( pStatus->m_pid, tobekilled ) == -1 ) &&
3071
+ if (( kill( pStatus->m_pid, tobekilled ) == -1 ) &&
3043
3072
  ( errno == ESRCH ))
3044
3073
  {
3045
3074
  pStatus->m_pid = 0;
@@ -3083,11 +3112,11 @@ static void lsapi_check_child_status( long tmCur )
3083
3112
  //}
3084
3113
 
3085
3114
 
3086
- void set_skip_write()
3115
+ void set_skip_write(void)
3087
3116
  { s_skip_write = 1; }
3088
3117
 
3089
3118
 
3090
- int is_enough_free_mem()
3119
+ int is_enough_free_mem(void)
3091
3120
  {
3092
3121
  #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
3093
3122
  //minimum 1GB or 10% available free memory
@@ -3098,7 +3127,7 @@ int is_enough_free_mem()
3098
3127
  }
3099
3128
 
3100
3129
 
3101
- static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
3130
+ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
3102
3131
  LSAPI_Request * pReq )
3103
3132
  {
3104
3133
  struct sigaction act, old_term, old_quit, old_int,
@@ -3173,19 +3202,19 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
3173
3202
  #endif
3174
3203
  FD_ZERO( &readfds );
3175
3204
  FD_SET( pServer->m_fd, &readfds );
3176
- timeout.tv_sec = 1;
3205
+ timeout.tv_sec = 1;
3177
3206
  timeout.tv_usec = 0;
3178
3207
  ret = (*g_fnSelect)(pServer->m_fd+1, &readfds, NULL, NULL, &timeout);
3179
3208
  if (ret == 1 )
3180
3209
  {
3181
3210
  int accepting = 0;
3182
3211
  if (s_accepting_workers)
3183
- accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3212
+ accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
3184
3213
 
3185
3214
  if (pServer->m_iCurChildren > 0
3186
3215
  && accepting > 0)
3187
3216
  {
3188
- usleep( 400);
3217
+ usleep(400);
3189
3218
  while(accepting-- > 0)
3190
3219
  sched_yield();
3191
3220
  continue;
@@ -3203,13 +3232,13 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
3203
3232
  continue;
3204
3233
  }
3205
3234
 
3206
- if (pServer->m_iCurChildren >=
3235
+ if (pServer->m_iCurChildren >=
3207
3236
  pServer->m_iMaxChildren + pServer->m_iExtraChildren)
3208
3237
  {
3209
3238
  lsapi_log("Reached max children process limit: %d, extra: %d,"
3210
3239
  " current: %d, busy: %d, please increase LSAPI_CHILDREN.\n",
3211
- pServer->m_iMaxChildren, pServer->m_iExtraChildren,
3212
- pServer->m_iCurChildren,
3240
+ pServer->m_iMaxChildren, pServer->m_iExtraChildren,
3241
+ pServer->m_iCurChildren,
3213
3242
  s_busy_workers ? *s_busy_workers : -1 );
3214
3243
  usleep( 100000 );
3215
3244
  continue;
@@ -3246,16 +3275,16 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
3246
3275
  if (pthread_atfork_func)
3247
3276
  (*pthread_atfork_func)(NULL, NULL, set_skip_write);
3248
3277
 
3249
- __sync_lock_test_and_set(&s_worker_status->m_state,
3250
- LSAPI_STATE_CONNECTED);
3278
+ __atomic_store_n(&s_worker_status->m_state,
3279
+ LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
3251
3280
  if (s_busy_workers)
3252
- __sync_add_and_fetch(s_busy_workers, 1);
3281
+ __atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
3253
3282
  lsapi_set_nblock( pReq->m_fd, 0 );
3254
3283
  //keep it open if busy_count is used.
3255
- if (s_busy_workers
3284
+ if (!s_keep_listener && s_busy_workers
3256
3285
  && *s_busy_workers > (pServer->m_iMaxChildren >> 1))
3257
- s_keepListener = 1;
3258
- if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
3286
+ s_keep_listener = 1;
3287
+ if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
3259
3288
  && pReq->m_fdListen != -1 )
3260
3289
  {
3261
3290
  close( pReq->m_fdListen );
@@ -3321,7 +3350,7 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
3321
3350
  {
3322
3351
  int max_children = g_prefork_server->m_iMaxChildren;
3323
3352
  s_pid = getpid();
3324
- __sync_lock_test_and_set(&pReq->child_status->m_pid, s_pid);
3353
+ __atomic_store_n(&pReq->child_status->m_pid, s_pid, __ATOMIC_SEQ_CST);
3325
3354
  s_worker_status = pReq->child_status;
3326
3355
 
3327
3356
  setsid();
@@ -3333,16 +3362,16 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
3333
3362
  if (pthread_atfork_func)
3334
3363
  (*pthread_atfork_func)(NULL, NULL, set_skip_write);
3335
3364
 
3336
- __sync_lock_test_and_set(&s_worker_status->m_state,
3337
- LSAPI_STATE_CONNECTED);
3365
+ __atomic_store_n(&s_worker_status->m_state,
3366
+ LSAPI_STATE_CONNECTED, __ATOMIC_SEQ_CST);
3338
3367
  if (s_busy_workers)
3339
- __sync_add_and_fetch(s_busy_workers, 1);
3368
+ __atomic_add_fetch(s_busy_workers, 1, __ATOMIC_SEQ_CST);
3340
3369
  lsapi_set_nblock( pReq->m_fd, 0 );
3341
3370
  //keep it open if busy_count is used.
3342
- if (s_busy_workers
3371
+ if (!s_keep_listener && s_busy_workers
3343
3372
  && *s_busy_workers > (max_children >> 1))
3344
- s_keepListener = 1;
3345
- if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
3373
+ s_keep_listener = 1;
3374
+ if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
3346
3375
  && pReq->m_fdListen != -1 )
3347
3376
  {
3348
3377
  close(pReq->m_fdListen);
@@ -3453,7 +3482,7 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
3453
3482
  {
3454
3483
  int accepting = 0;
3455
3484
  if (s_accepting_workers)
3456
- accepting = __sync_add_and_fetch(s_accepting_workers, 0);
3485
+ accepting = __atomic_load_n(s_accepting_workers, __ATOMIC_SEQ_CST);
3457
3486
 
3458
3487
  if (pServer->m_iCurChildren > 0
3459
3488
  && accepting > 0)
@@ -3538,14 +3567,14 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3538
3567
  }
3539
3568
  else if (s_req_processed > 0 && s_max_busy_workers > 0 && s_busy_workers)
3540
3569
  {
3541
- ret = __sync_fetch_and_add(s_busy_workers, 0);
3570
+ ret = __atomic_load_n(s_busy_workers, __ATOMIC_SEQ_CST);
3542
3571
  if (ret >= s_max_busy_workers)
3543
3572
  {
3544
3573
  send_conn_close_notification(pReq->m_fd);
3545
3574
  lsapi_close_connection(pReq);
3546
3575
  }
3547
3576
  }
3548
-
3577
+
3549
3578
  if ( (unsigned int)s_req_processed > s_max_reqs )
3550
3579
  return -1;
3551
3580
 
@@ -3572,7 +3601,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3572
3601
  {
3573
3602
  if ( !g_running )
3574
3603
  return -1;
3575
- if (s_req_processed && s_worker_status
3604
+ if (s_req_processed && s_worker_status
3576
3605
  && s_worker_status->m_iKillSent)
3577
3606
  return -1;
3578
3607
  FD_ZERO( &readfds );
@@ -3582,29 +3611,41 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3582
3611
  if (fd == pReq->m_fdListen)
3583
3612
  {
3584
3613
  if (s_worker_status)
3585
- __sync_lock_test_and_set(&s_worker_status->m_state,
3586
- LSAPI_STATE_ACCEPTING);
3614
+ __atomic_store_n(&s_worker_status->m_state,
3615
+ LSAPI_STATE_ACCEPTING, __ATOMIC_SEQ_CST);
3587
3616
  if (s_accepting_workers)
3588
- __sync_fetch_and_add(s_accepting_workers, 1);
3617
+ __atomic_fetch_add(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
3589
3618
  }
3590
3619
  ret = (*g_fnSelect)(fd+1, &readfds, NULL, NULL, &timeout);
3591
3620
  if (fd == pReq->m_fdListen)
3592
3621
  {
3593
3622
  if (s_accepting_workers)
3594
- __sync_fetch_and_sub(s_accepting_workers, 1);
3623
+ __atomic_fetch_sub(s_accepting_workers, 1, __ATOMIC_SEQ_CST);
3595
3624
  if (s_worker_status)
3596
- __sync_lock_test_and_set(&s_worker_status->m_state,
3597
- LSAPI_STATE_IDLE);
3625
+ __atomic_store_n(&s_worker_status->m_state,
3626
+ LSAPI_STATE_IDLE, __ATOMIC_SEQ_CST);
3598
3627
  }
3599
-
3628
+
3600
3629
  if ( ret == 0 )
3601
3630
  {
3602
3631
  if ( s_worker_status )
3603
3632
  {
3604
3633
  s_worker_status->m_inProcess = 0;
3605
- if (fd == pReq->m_fdListen
3606
- && (s_keepListener != 2 || !is_enough_free_mem()))
3607
- return -1;
3634
+ if (fd == pReq->m_fdListen)
3635
+ {
3636
+ if (s_keep_listener == 0 || !is_enough_free_mem())
3637
+ return -1;
3638
+ if (s_keep_listener == 1)
3639
+ {
3640
+ int wait_time = 10;
3641
+ if (s_busy_workers)
3642
+ wait_time += *s_busy_workers * 10;
3643
+ if (s_accepting_workers)
3644
+ wait_time >>= (*s_accepting_workers);
3645
+ if (wait_secs >= wait_time)
3646
+ return -1;
3647
+ }
3648
+ }
3608
3649
  }
3609
3650
  ++wait_secs;
3610
3651
  if (( s_max_idle_secs > 0 )&&(wait_secs >= s_max_idle_secs ))
@@ -3621,7 +3662,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3621
3662
  }
3622
3663
  else if ( ret >= 1 )
3623
3664
  {
3624
- if (s_req_processed && s_worker_status
3665
+ if (s_req_processed && s_worker_status
3625
3666
  && s_worker_status->m_iKillSent)
3626
3667
  return -1;
3627
3668
  if ( fd == pReq->m_fdListen )
@@ -3630,16 +3671,17 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3630
3671
  if ( pReq->m_fd != -1 )
3631
3672
  {
3632
3673
  if (s_worker_status)
3633
- __sync_lock_test_and_set(&s_worker_status->m_state,
3634
- LSAPI_STATE_CONNECTED);
3674
+ __atomic_store_n(&s_worker_status->m_state,
3675
+ LSAPI_STATE_CONNECTED,
3676
+ __ATOMIC_SEQ_CST);
3635
3677
  if (s_busy_workers)
3636
- __sync_fetch_and_add(s_busy_workers, 1);
3678
+ __atomic_fetch_add(s_busy_workers, 1, __ATOMIC_SEQ_CST);
3637
3679
 
3638
3680
  fd = pReq->m_fd;
3639
-
3681
+
3640
3682
  lsapi_set_nblock( fd, 0 );
3641
3683
  //init_conn_key( pReq->m_fd );
3642
- if (!s_keepListener)
3684
+ if (!s_keep_listener)
3643
3685
  {
3644
3686
  close( pReq->m_fdListen );
3645
3687
  pReq->m_fdListen = -1;
@@ -3668,7 +3710,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
3668
3710
  s_worker_status->m_iKillSent = 0;
3669
3711
  s_worker_status->m_inProcess = 1;
3670
3712
  ++s_worker_status->m_iReqCounter;
3671
- s_worker_status->m_tmReqBegin =
3713
+ s_worker_status->m_tmReqBegin =
3672
3714
  s_worker_status->m_tmLastCheckPoint = time(NULL);
3673
3715
  }
3674
3716
  ++s_req_processed;
@@ -3742,7 +3784,7 @@ void LSAPI_No_Check_ppid(void)
3742
3784
  }
3743
3785
 
3744
3786
 
3745
- int LSAPI_Get_ppid()
3787
+ int LSAPI_Get_ppid(void)
3746
3788
  {
3747
3789
  return(s_ppid);
3748
3790
  }
@@ -3852,7 +3894,7 @@ static int lsapi_check_path(const char *p, char *final, int max_len)
3852
3894
  return -1;
3853
3895
  }
3854
3896
  p = final;
3855
- if (realpath(p, resolved_path) == NULL
3897
+ if (realpath(p, resolved_path) == NULL
3856
3898
  && errno != ENOENT && errno != EACCES)
3857
3899
  return -1;
3858
3900
  if (strncmp(resolved_path, "/etc/", 5) == 0)
@@ -3908,7 +3950,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3908
3950
  char ch;
3909
3951
  int n;
3910
3952
  int avoidFork = 0;
3911
-
3953
+
3912
3954
  p = getenv("LSAPI_STDERR_LOG");
3913
3955
  if (p)
3914
3956
  {
@@ -3931,7 +3973,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3931
3973
  if ( p )
3932
3974
  {
3933
3975
  n = atoi( p );
3934
- s_keepListener = n;
3976
+ s_keep_listener = n;
3935
3977
  }
3936
3978
 
3937
3979
  p = getenv( "LSAPI_AVOID_FORK" );
@@ -3940,7 +3982,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3940
3982
  avoidFork = atoi( p );
3941
3983
  if (avoidFork)
3942
3984
  {
3943
- s_keepListener = 2;
3985
+ s_keep_listener = 2;
3944
3986
  ch = *(p + strlen(p) - 1);
3945
3987
  if ( ch == 'G' || ch == 'g' )
3946
3988
  avoidFork *= 1024 * 1024 * 1024;
@@ -4019,7 +4061,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
4019
4061
  {
4020
4062
  LSAPI_No_Check_ppid();
4021
4063
  }
4022
-
4064
+
4023
4065
  p = getenv("LSAPI_MAX_BUSY_WORKER");
4024
4066
  if (p)
4025
4067
  {
@@ -4028,7 +4070,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
4028
4070
  if (n >= 0)
4029
4071
  LSAPI_No_Check_ppid();
4030
4072
  }
4031
-
4073
+
4032
4074
 
4033
4075
  p = getenv( "LSAPI_DUMP_DEBUG_INFO" );
4034
4076
  if ( p )
@@ -4148,7 +4190,7 @@ void lsapi_MD5Update(struct lsapi_MD5Context *ctx, unsigned char const *buf, uns
4148
4190
 
4149
4191
 
4150
4192
  /*
4151
- * Final wrapup - pad to 64-byte boundary with the bit pattern
4193
+ * Final wrap-up - pad to 64-byte boundary with the bit pattern
4152
4194
  * 1 0* (64-bit count of bits processed, MSB-first)
4153
4195
  */
4154
4196
  void lsapi_MD5Final(unsigned char digest[16], struct lsapi_MD5Context *ctx)
@@ -4294,7 +4336,7 @@ static void lsapi_MD5Transform(uint32 buf[4], uint32 const in[16])
4294
4336
  }
4295
4337
 
4296
4338
 
4297
- int LSAPI_Set_Restored_Parent_Pid(int pid)
4339
+ int LSAPI_Set_Restored_Parent_Pid(int pid)
4298
4340
  {
4299
4341
  int old_ppid = s_ppid;
4300
4342
  s_restored_ppid = pid;
@@ -4304,7 +4346,7 @@ int LSAPI_Set_Restored_Parent_Pid(int pid)
4304
4346
 
4305
4347
  int LSAPI_Inc_Req_Processed(int cnt)
4306
4348
  {
4307
- return __sync_add_and_fetch(s_global_counter, cnt);
4349
+ return __atomic_add_fetch(s_global_counter, cnt, __ATOMIC_SEQ_CST);
4308
4350
  }
4309
4351
 
4310
4352
 
data/ext/lsapi/lsruby.c CHANGED
@@ -1,10 +1,11 @@
1
1
 
2
2
  #include "ruby.h"
3
3
 
4
- #if defined( RUBY_19 ) || defined( RUBY_2 )
5
- #include <ruby/util.h>
6
- #else
4
+ #if defined( RUBY_VERSION_CODE ) && RUBY_VERSION_CODE < 180
7
5
  #include "util.h"
6
+ #else
7
+ #include <ruby/util.h>
8
+ #include <ruby/version.h>
8
9
  #endif
9
10
 
10
11
  #include "lsapilib.h"
@@ -18,20 +19,24 @@
18
19
  #include <sys/mman.h>
19
20
  #include <fcntl.h>
20
21
 
22
+
23
+ #ifndef RUBY_API_VERSION_CODE
24
+ #define RUBY_API_VERSION_CODE (RUBY_API_VERSION_MAJOR*10000+RUBY_API_VERSION_MINOR*100+RUBY_API_VERSION_TEENY)
25
+ #endif
26
+
21
27
  /* RUBY_EXTERN VALUE ruby_errinfo; */
22
28
  RUBY_EXTERN VALUE rb_stdin;
23
29
  RUBY_EXTERN VALUE rb_stdout;
24
- #if RUBY_VERSION_CODE < 180
30
+ #if defined( RUBY_VERSION_CODE ) && RUBY_VERSION_CODE < 180
25
31
  RUBY_EXTERN VALUE rb_defout;
26
32
  #endif
27
33
 
28
34
  static VALUE orig_stdin;
29
35
  static VALUE orig_stdout;
30
36
  static VALUE orig_stderr;
31
- #if RUBY_VERSION_CODE < 180
37
+ #if defined( RUBY_VERSION_CODE ) && RUBY_VERSION_CODE < 180
32
38
  static VALUE orig_defout;
33
39
  #endif
34
-
35
40
  static VALUE orig_env;
36
41
 
37
42
  static VALUE env_copy;
@@ -249,11 +254,13 @@ static VALUE lsapi_s_postfork_parent(VALUE self)
249
254
 
250
255
  static VALUE lsapi_eval_string_wrap(VALUE self, VALUE str)
251
256
  {
257
+ #if RUBY_API_VERSION_CODE < 20700
252
258
  if (rb_safe_level() >= 4)
253
259
  {
254
260
  Check_Type(str, T_STRING);
255
261
  }
256
262
  else
263
+ #endif
257
264
  {
258
265
  SafeStringValue(str);
259
266
  }
@@ -449,10 +456,12 @@ static VALUE lsapi_getc( VALUE self )
449
456
  * lsapi_data *data;
450
457
  * Data_Get_Struct(self,lsapi_data, data);
451
458
  */
459
+ #if RUBY_API_VERSION_CODE < 20700
452
460
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
453
461
  {
454
462
  rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
455
463
  }
464
+ #endif
456
465
  ch = LSAPI_ReqBodyGetChar_r( &g_req );
457
466
  if ( ch == EOF )
458
467
  return Qnil;
@@ -574,11 +583,12 @@ static VALUE lsapi_gets( VALUE self )
574
583
  int n;
575
584
  char *p = NULL;
576
585
 
586
+ #if RUBY_API_VERSION_CODE < 20700
577
587
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
578
588
  {
579
589
  rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
580
590
  }
581
-
591
+ #endif
582
592
  if (createBodyBuf() == 1)
583
593
  {
584
594
  return Qnil;
@@ -600,7 +610,9 @@ static VALUE lsapi_gets( VALUE self )
600
610
  n = s_body.bodyCurrentLen - s_body.curPos;
601
611
 
602
612
  str = rb_str_buf_new( n );
613
+ #if RUBY_API_VERSION_CODE < 20700
603
614
  OBJ_TAINT(str);
615
+ #endif
604
616
 
605
617
  if (n > 0)
606
618
  {
@@ -618,11 +630,12 @@ static VALUE lsapi_read(int argc, VALUE *argv, VALUE self)
618
630
  int needRead;
619
631
  int nRead;
620
632
 
633
+ #if RUBY_API_VERSION_CODE < 20700
621
634
  if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
622
635
  {
623
636
  rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
624
637
  }
625
-
638
+ #endif
626
639
  if (createBodyBuf() == 1)
627
640
  {
628
641
  return Qnil;
@@ -646,7 +659,9 @@ static VALUE lsapi_read(int argc, VALUE *argv, VALUE self)
646
659
  needRead = 0;
647
660
 
648
661
  str = rb_str_buf_new( n );
662
+ #if RUBY_API_VERSION_CODE < 20700
649
663
  OBJ_TAINT(str);
664
+ #endif
650
665
  if (n == 0)
651
666
  return str;
652
667
 
@@ -678,7 +693,7 @@ static VALUE lsapi_rewind(VALUE self)
678
693
  return self;
679
694
  }
680
695
 
681
- static VALUE lsapi_each(int argc, VALUE *argv, VALUE self)
696
+ static VALUE lsapi_each(VALUE self)
682
697
  {
683
698
  VALUE str;
684
699
  lsapi_rewind(self);
@@ -694,15 +709,6 @@ static VALUE lsapi_each(int argc, VALUE *argv, VALUE self)
694
709
 
695
710
  static VALUE lsapi_eof(VALUE self)
696
711
  {
697
- /*
698
- * lsapi_data *data;
699
- *
700
- * if (rb_safe_level() >= 4 && !OBJ_TAINTED(self))
701
- * {
702
- * rb_raise(rb_eSecurityError, "Insecure: operation on untainted IO");
703
- }
704
- Data_Get_Struct(self, lsapi_data, data);
705
- */
706
712
  return (LSAPI_GetReqBodyRemain_r( &g_req ) <= 0) ? Qtrue : Qfalse;
707
713
  }
708
714
 
@@ -839,7 +845,7 @@ void Init_lsapi()
839
845
  orig_stdin = rb_stdin;
840
846
  orig_stdout = rb_stdout;
841
847
  orig_stderr = rb_stderr;
842
- #if RUBY_VERSION_CODE < 180
848
+ #if defined( RUBY_VERSION_CODE ) && RUBY_VERSION_CODE < 180
843
849
  orig_defout = rb_defout;
844
850
  #endif
845
851
  orig_env = rb_const_get( rb_cObject, rb_intern("ENV") );
@@ -899,9 +905,10 @@ void Init_lsapi()
899
905
  s_req_data->fn_write = LSAPI_Write_r;
900
906
  rb_stdin = rb_stdout = s_req;
901
907
 
902
- #if RUBY_VERSION_CODE < 180
908
+ #if defined( RUBY_VERSION_CODE ) && RUBY_VERSION_CODE < 180
903
909
  rb_defout = s_req;
904
910
  #endif
911
+
905
912
  rb_global_variable(&s_req );
906
913
 
907
914
  s_req_stderr = Data_Make_Struct( cLSAPI, lsapi_data, lsapi_mark, free, s_stderr_data );
data/lsapi.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{ruby-lsapi}
3
- s.version = "5.2"
4
- s.date = %q{2021-01-30}
3
+ s.version = "5.4"
4
+ s.date = %q{2022-01-17}
5
5
  s.description = "This is a ruby extension for fast communication with LiteSpeed Web Server."
6
6
  s.summary = %q{A ruby extension for fast communication with LiteSpeed Web Server.}
7
7
  s.has_rdoc = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsapi
3
3
  version: !ruby/object:Gem::Version
4
- version: '5.2'
4
+ version: '5.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - LiteSpeed Technologies Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-30 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This is a ruby extension for fast communication with LiteSpeed Web Server.
14
14
  email: info@litespeedtech.com
@@ -33,7 +33,7 @@ files:
33
33
  homepage: http://www.litespeedtech.com/
34
34
  licenses: []
35
35
  metadata: {}
36
- post_install_message:
36
+ post_install_message:
37
37
  rdoc_options: []
38
38
  require_paths:
39
39
  - lib
@@ -48,9 +48,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
- rubyforge_project: ruby-lsapi
52
- rubygems_version: 2.7.6.2
53
- signing_key:
51
+ rubygems_version: 3.3.3
52
+ signing_key:
54
53
  specification_version: 4
55
54
  summary: A ruby extension for fast communication with LiteSpeed Web Server.
56
55
  test_files: []