ruby-lsapi 4.1 → 4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTBmYTY2NTdiZDk3NjAxNTViYmExOTc4ZDU5ZjJhYjk1MmFmNjhiZA==
5
- data.tar.gz: !binary |-
6
- YmRkNDNhMGZiMmI5Y2I2YjQ0M2Q4OTkzZWVhMjRkMmFmZjA4ZDFlYQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NTg2NGQ5Zjc1NWUyYTExNDUzMTYzN2VhODAyMDI4N2Y0MDFhMTBiMThkMWNm
10
- MWU3NDY0Njg4MzcxZDUyYmYzYjJjMjIyYTUxNGU4YTUyOGQ1ZDIxZDg1YWJh
11
- YjZlNDJlNTJhMWJkMzZiOWVjMmE2ODQ2ZGNmMTkzMzk1MDRhMDg=
12
- data.tar.gz: !binary |-
13
- MzBmZDNhMmY5NGQ3NWY0NmJmMDIyMTgzNTUyMDBhZDczMzM2Y2MwY2I5YzAx
14
- NGYxN2M0OWEyYTQ1YjYzNTEwNzlmNGQ3ZGY4ZDU1MGM3MTQ2NThlZDkwODBi
15
- MjExZWRkOWIxZTI1NGVjMWEwMDNmYzBkNTBjMTBhNmFlZTc5ZTM=
2
+ SHA1:
3
+ metadata.gz: 7071cdbea2aaa5b5e3e15d81cb659dbcdd4f0ec2
4
+ data.tar.gz: c224835bd8b574e1a697cbe1754a21f01bec9a5f
5
+ SHA512:
6
+ metadata.gz: b00c35195f8785e6196f1b2ab97d3bac71ad795b7290015e5bb2f419d1a2477d44b27088d019f329d4c13ba11b672417bf78c4189a43ecb9b1465c58c60c7046
7
+ data.tar.gz: a623cc9fcd25ab6ce7e6c41d50ddc8d19c5b020d23fff9ad5890483346a89ae01ab4ab466f85bef896745f74faddf7581f4a9b01c7ca8ef42122a69a36fa84cf
@@ -6,4 +6,7 @@ end
6
6
  if RUBY_VERSION =~ /1.9/ then
7
7
  $CPPFLAGS += " -DRUBY_19"
8
8
  end
9
+ if RUBY_VERSION =~ /2/ then
10
+ $CPPFLAGS += " -DRUBY_2"
11
+ end
9
12
  create_makefile( "lsapi" )
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2005, Lite Speed Technologies Inc.
2
+ Copyright (c) 2002-2014, Lite Speed Technologies Inc.
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -30,14 +30,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
30
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  */
32
32
 
33
- /***************************************************************************
34
- $Id: lsapidef.h,v 1.17 2012/12/01 19:23:31 gwang Exp $
35
- -------------------
36
- begin : Thu Feb 10 2005
37
- author : George Wang
38
- email : gwang@litespeedtech.com
39
- ***************************************************************************/
40
-
41
33
  #ifndef _LSAPIDEF_H_
42
34
  #define _LSAPIDEF_H_
43
35
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2005, Lite Speed Technologies Inc.
2
+ Copyright (c) 2002-2015, Lite Speed Technologies Inc.
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -30,14 +30,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
30
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  */
32
32
 
33
- /***************************************************************************
34
- lsapilib.c - description
35
- -------------------
36
- begin : Mon Feb 21 2005
37
- copyright : (C) 2005 by George Wang
38
- email : gwang@litespeedtech.com
39
- ***************************************************************************/
40
-
41
33
 
42
34
  #include <ctype.h>
43
35
  #include <dlfcn.h>
@@ -114,6 +106,7 @@ static int s_ppid;
114
106
  static int s_slow_req_msecs = 0;
115
107
  static int s_keepListener = 0;
116
108
  static int s_dump_debug_info = 0;
109
+ static int s_pid_dump_debug_info = 0;
117
110
 
118
111
  LSAPI_Request g_req = { -1, -1 };
119
112
 
@@ -230,7 +223,6 @@ static void lsapi_enable_core_dump()
230
223
  }
231
224
 
232
225
 
233
-
234
226
  static inline void lsapi_buildPacketHeader( struct lsapi_packet_header * pHeader,
235
227
  char type, int len )
236
228
  {
@@ -670,36 +662,6 @@ static int readSecret( const char * pSecretFile )
670
662
  return 0;
671
663
  }
672
664
 
673
- static int lsapi_initSuEXEC()
674
- {
675
- int i;
676
- struct passwd * pw;
677
- pw = getpwnam( "nobody" );
678
- s_defaultUid = pw->pw_uid;
679
- s_defaultGid = pw->pw_gid;
680
- if ( s_uid == 0 )
681
- {
682
- const char * p = getenv( "LSAPI_DEFAULT_UID" );
683
- if ( p )
684
- {
685
- i = atoi( p );
686
- if ( i > 0 )
687
- s_defaultUid = i;
688
- }
689
- p = getenv( "LSAPI_DEFAULT_GID" );
690
- if ( p )
691
- {
692
- i = atoi( p );
693
- if ( i > 0 )
694
- s_defaultGid = i;
695
- }
696
- p = getenv( "LSAPI_SECRET" );
697
- if (( !p )||( readSecret(p) == -1 ))
698
- return -1;
699
- }
700
- return 0;
701
- }
702
-
703
665
  int LSAPI_is_suEXEC_Daemon()
704
666
  {
705
667
  if (( !s_uid )&&( s_pSecret[0] ))
@@ -719,6 +681,29 @@ static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char
719
681
  return 0;
720
682
  }
721
683
 
684
+ static int lsapi_lve_error( LSAPI_Request * pReq )
685
+ {
686
+ static const char * headers[] =
687
+ {
688
+ "Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0",
689
+ "Pragma: no-cache",
690
+ "Retry-After: 60",
691
+ "Content-Type: text/html",
692
+ NULL
693
+ };
694
+ static const char achBody[] =
695
+ "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
696
+ "<HTML><HEAD>\n<TITLE>508 Resource Limit Is Reached</TITLE>\n"
697
+ "</HEAD><BODY>\n" "<H1>Resource Limit Is Reached</H1>\n"
698
+ "The website is temporarily unable to service your request as it exceeded resource limit.\n"
699
+ "Please try again later.\n"
700
+ "<HR>\n"
701
+ "</BODY></HTML>\n";
702
+
703
+ LSAPI_ErrResponse_r( pReq, 508, headers, achBody, sizeof( achBody ) - 1 );
704
+ return 0;
705
+ }
706
+
722
707
  static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
723
708
  {
724
709
  #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
@@ -731,6 +716,7 @@ static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
731
716
  {
732
717
  fprintf( stderr, "Pid (%d): enter LVE (%d) : ressult: %d !\n", getpid(), uid, ret );
733
718
  LSAPI_perror_r(pReq, "LSAPI: lve_enter() failure, reached resource limit.", NULL );
719
+ lsapi_lve_error( pReq );
734
720
  return -1;
735
721
  }
736
722
  }
@@ -1031,18 +1017,52 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen )
1031
1017
  }
1032
1018
 
1033
1019
  //OPTIMIZATION
1034
- static int s_accept_notify = 0;
1020
+ static char s_accept_notify = 0;
1021
+ static char s_schedule_notify = 0;
1022
+ static char s_notify_scheduled = 0;
1023
+ static char s_notified_pid = 0;
1035
1024
 
1036
- static struct lsapi_packet_header ack = {'L', 'S',
1025
+ static struct lsapi_packet_header s_ack = {'L', 'S',
1037
1026
  LSAPI_REQ_RECEIVED, LSAPI_ENDIAN, {LSAPI_PACKET_HEADER_LEN} };
1038
- static inline int notify_req_received( int fd )
1027
+
1028
+
1029
+ static inline int write_req_received_notification( int fd )
1039
1030
  {
1040
- if ( write( fd, &ack, LSAPI_PACKET_HEADER_LEN )
1031
+ if ( write( fd, &s_ack, LSAPI_PACKET_HEADER_LEN )
1041
1032
  < LSAPI_PACKET_HEADER_LEN )
1042
1033
  return -1;
1043
1034
  return 0;
1044
1035
  }
1045
1036
 
1037
+ static void lsapi_sigalarm( int sig )
1038
+ {
1039
+ if ( s_notify_scheduled )
1040
+ {
1041
+ s_notify_scheduled = 0;
1042
+ if ( g_req.m_fd != -1 )
1043
+ write_req_received_notification( g_req.m_fd );
1044
+ }
1045
+ }
1046
+
1047
+ static inline int lsapi_schedule_notify()
1048
+ {
1049
+ if ( !s_notify_scheduled )
1050
+ {
1051
+ alarm( 2 );
1052
+ s_notify_scheduled = 1;
1053
+ }
1054
+ return 0;
1055
+ }
1056
+
1057
+ static inline int notify_req_received( int fd )
1058
+ {
1059
+ if ( s_schedule_notify )
1060
+ return lsapi_schedule_notify();
1061
+ return write_req_received_notification( fd );
1062
+
1063
+ }
1064
+
1065
+
1046
1066
  static inline int lsapi_notify_pid( int fd )
1047
1067
  {
1048
1068
  char achBuf[16];
@@ -1128,17 +1148,22 @@ static int readReq( LSAPI_Request * pReq )
1128
1148
  fprintf( stderr, "%d: parseRequest error\n", getpid() );
1129
1149
  return -1;
1130
1150
  }
1151
+
1152
+ pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER;
1153
+
1131
1154
  if ( !s_uid )
1132
1155
  if ( lsapi_changeUGid( pReq ) )
1133
1156
  return -1;
1134
1157
  pReq->m_bufProcessed = packetLen;
1135
- pReq->m_reqState = LSAPI_ST_REQ_BODY | LSAPI_ST_RESP_HEADER;
1136
1158
 
1137
1159
  //OPTIMIZATION
1138
- if ( !s_accept_notify )
1160
+ if ( !s_accept_notify && !s_notified_pid )
1139
1161
  return notify_req_received( pReq->m_fd );
1140
1162
  else
1163
+ {
1164
+ s_notified_pid = 0;
1141
1165
  return 0;
1166
+ }
1142
1167
  }
1143
1168
 
1144
1169
 
@@ -1178,6 +1203,7 @@ int LSAPI_IsRunning(void)
1178
1203
 
1179
1204
  int LSAPI_InitRequest( LSAPI_Request * pReq, int fd )
1180
1205
  {
1206
+ int newfd;
1181
1207
  if ( !pReq )
1182
1208
  return -1;
1183
1209
  memset( pReq, 0, sizeof( LSAPI_Request ) );
@@ -1191,7 +1217,14 @@ int LSAPI_InitRequest( LSAPI_Request * pReq, int fd )
1191
1217
  pReq->m_respPktHeaderEnd = &pReq->m_respPktHeader[5];
1192
1218
  if ( allocateRespHeaderBuf( pReq, LSAPI_INIT_RESP_HEADER_LEN ) == -1 )
1193
1219
  return -1;
1194
-
1220
+
1221
+ if ( fd == STDIN_FILENO )
1222
+ {
1223
+ fd = dup( fd );
1224
+ newfd = open( "/dev/null", O_RDWR );
1225
+ dup2( newfd, STDIN_FILENO );
1226
+ }
1227
+
1195
1228
  if ( isPipe( fd ) )
1196
1229
  {
1197
1230
  pReq->m_fdListen = -1;
@@ -1339,10 +1372,12 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex )
1339
1372
  off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ];
1340
1373
  if ( !off )
1341
1374
  return NULL;
1342
- if ( *(pReq->m_pHttpHeader + off +
1343
- pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) )
1344
- *( pReq->m_pHttpHeader + off +
1345
- pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
1375
+ if ( *(pReq->m_pHttpHeader + off
1376
+ + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) )
1377
+ {
1378
+ *( pReq->m_pHttpHeader + off
1379
+ + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0;
1380
+ }
1346
1381
  return pReq->m_pHttpHeader + off;
1347
1382
  }
1348
1383
 
@@ -1608,7 +1643,7 @@ ssize_t gsendfile( int fdOut, int fdIn, off_t *off, size_t size )
1608
1643
  ++n;
1609
1644
 
1610
1645
  size_t written;
1611
- ssize_t ret = ::sendfilev( fdOut, vec, n, &written );
1646
+ ssize_t ret = sendfilev( fdOut, vec, n, &written );
1612
1647
  if (( !ret )||( errno == EAGAIN ))
1613
1648
  ret = written;
1614
1649
  if ( ret > 0 )
@@ -1779,12 +1814,21 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le
1779
1814
  static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
1780
1815
  {
1781
1816
  int i;
1817
+ char * pValue;
1782
1818
  for( i = 0; i < H_TRANSFER_ENCODING; ++i )
1783
1819
  {
1784
1820
  if ( pReq->m_pHeaderIndex->m_headerOff[i] )
1785
1821
  {
1786
1822
  if ( strcmp( name, CGI_HEADERS[i] ) == 0 )
1787
- return pReq->m_pHttpHeader + pReq->m_pHeaderIndex->m_headerOff[i];
1823
+ {
1824
+ pValue = pReq->m_pHttpHeader
1825
+ + pReq->m_pHeaderIndex->m_headerOff[i];
1826
+ if ( *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) != '\0')
1827
+ {
1828
+ *(pValue + pReq->m_pHeaderIndex->m_headerLen[i]) = '\0';
1829
+ }
1830
+ return pValue;
1831
+ }
1788
1832
  }
1789
1833
  }
1790
1834
  if ( pReq->m_pHeader->m_cntUnknownHeaders > 0 )
@@ -1811,7 +1855,15 @@ static char * GetHeaderVar( LSAPI_Request * pReq, const char * name )
1811
1855
  ++p; ++pKey;
1812
1856
  }
1813
1857
  if (( pKey == pKeyEnd )&& (!*p ))
1814
- return pReq->m_pHttpHeader + pCur->valueOff;
1858
+ {
1859
+ pValue = pReq->m_pHttpHeader + pCur->valueOff;
1860
+
1861
+ if ( *(pValue + pCur->valueLen) != '\0')
1862
+ {
1863
+ *(pValue + pCur->valueLen) = '\0';
1864
+ }
1865
+ return pValue;
1866
+ }
1815
1867
  ++pCur;
1816
1868
  }
1817
1869
  }
@@ -1861,9 +1913,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
1861
1913
  int ret;
1862
1914
  int count = 0;
1863
1915
  struct _headerInfo headers[512];
1916
+
1864
1917
  if ( !pReq || !fn )
1865
1918
  return -1;
1866
-
1919
+
1920
+ if ( !pReq->m_pHeaderIndex )
1921
+ return 0;
1922
+
1867
1923
  for( i = 0; i < H_TRANSFER_ENCODING; ++i )
1868
1924
  {
1869
1925
  if ( pReq->m_pHeaderIndex->m_headerOff[i] )
@@ -1894,6 +1950,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq,
1894
1950
  {
1895
1951
  pKey = pReq->m_pHttpHeader + pCur->nameOff;
1896
1952
  keyLen = pCur->nameLen;
1953
+ *(pKey + keyLen ) = 0;
1897
1954
 
1898
1955
  pValue = pReq->m_pHttpHeader + pCur->valueOff;
1899
1956
  *(pValue + pCur->valueLen ) = 0;
@@ -2353,6 +2410,8 @@ typedef struct _lsapi_prefork_server
2353
2410
  int m_iAvoidFork;
2354
2411
 
2355
2412
  lsapi_child_status * m_pChildrenStatus;
2413
+ lsapi_child_status * m_pChildrenStatusCur;
2414
+ lsapi_child_status * m_pChildrenStatusEnd;
2356
2415
 
2357
2416
  }lsapi_prefork_server;
2358
2417
 
@@ -2388,7 +2447,7 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork )
2388
2447
  if ( g_prefork_server->m_iMaxIdleChildren == 0 )
2389
2448
  g_prefork_server->m_iMaxIdleChildren = 1;
2390
2449
  g_prefork_server->m_iChildrenMaxIdleTime = 300;
2391
- g_prefork_server->m_iMaxReqProcessTime = 300;
2450
+ g_prefork_server->m_iMaxReqProcessTime = 3600;
2392
2451
  return 0;
2393
2452
  }
2394
2453
 
@@ -2441,11 +2500,15 @@ static void lsapi_cleanup(int signal)
2441
2500
  static lsapi_child_status * find_child_status( int pid )
2442
2501
  {
2443
2502
  lsapi_child_status * pStatus = g_prefork_server->m_pChildrenStatus;
2444
- lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatus + g_prefork_server->m_iMaxChildren * 2;
2503
+ lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatusEnd;
2445
2504
  while( pStatus < pEnd )
2446
2505
  {
2447
2506
  if ( pStatus->m_pid == pid )
2507
+ {
2508
+ if ( pStatus + 1 > g_prefork_server->m_pChildrenStatusCur )
2509
+ g_prefork_server->m_pChildrenStatusCur = pStatus + 1;
2448
2510
  return pStatus;
2511
+ }
2449
2512
  ++pStatus;
2450
2513
  }
2451
2514
  return NULL;
@@ -2470,13 +2533,22 @@ static void lsapi_sigchild( int signal )
2470
2533
  int dump = WCOREDUMP( status );
2471
2534
  fprintf( stderr, "Child process with pid: %d was killed by signal: %d, core dump: %d\n", pid, sig_num, dump );
2472
2535
  }
2536
+ if ( pid == s_pid_dump_debug_info )
2537
+ {
2538
+ pid = 0;
2539
+ continue;
2540
+ }
2473
2541
  child_status = find_child_status( pid );
2474
2542
  if ( child_status )
2475
2543
  {
2476
2544
  child_status->m_pid = 0;
2477
2545
  --g_prefork_server->m_iCurChildren;
2546
+
2478
2547
  }
2479
2548
  }
2549
+ while(( g_prefork_server->m_pChildrenStatusCur > g_prefork_server->m_pChildrenStatus )
2550
+ &&( g_prefork_server->m_pChildrenStatusCur[-1].m_pid == 0 ))
2551
+ --g_prefork_server->m_pChildrenStatusCur;
2480
2552
 
2481
2553
  }
2482
2554
 
@@ -2485,7 +2557,7 @@ static int lsapi_init_children_status()
2485
2557
  int size = 4096;
2486
2558
 
2487
2559
  char * pBuf;
2488
- size = g_prefork_server->m_iMaxChildren * sizeof( lsapi_child_status ) * 2;
2560
+ size = (g_prefork_server->m_iMaxChildren + g_prefork_server->m_iExtraChildren ) * sizeof( lsapi_child_status ) * 2;
2489
2561
  size = (size + 4095 ) / 4096 * 4096;
2490
2562
  pBuf =( char*) mmap( NULL, size, PROT_READ | PROT_WRITE,
2491
2563
  MAP_ANON | MAP_SHARED, -1, 0 );
@@ -2495,16 +2567,22 @@ static int lsapi_init_children_status()
2495
2567
  return -1;
2496
2568
  }
2497
2569
  memset( pBuf, 0, size );
2498
- g_prefork_server->m_pChildrenStatus = (lsapi_child_status *)pBuf;
2570
+ g_prefork_server->m_pChildrenStatus = (lsapi_child_status *)pBuf;
2571
+ g_prefork_server->m_pChildrenStatusCur = (lsapi_child_status *)pBuf;
2572
+ g_prefork_server->m_pChildrenStatusEnd = (lsapi_child_status *)pBuf + size / sizeof( lsapi_child_status );
2499
2573
  return 0;
2500
2574
  }
2501
2575
 
2502
2576
  static void dump_debug_info( lsapi_child_status * pStatus, long tmCur )
2503
2577
  {
2504
2578
  char achCmd[1024];
2505
- int pid = fork();
2506
- if ( pid != 0 )
2507
- return;
2579
+ if ( s_pid_dump_debug_info )
2580
+ {
2581
+ if ( kill( s_pid_dump_debug_info, 0 ) == 0 )
2582
+ return;
2583
+ }
2584
+ s_pid_dump_debug_info = fork();
2585
+
2508
2586
  fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n",
2509
2587
  ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter,
2510
2588
  tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
@@ -2521,7 +2599,7 @@ static void lsapi_check_child_status( long tmCur )
2521
2599
  int dying = 0;
2522
2600
  int count = 0;
2523
2601
  lsapi_child_status * pStatus = g_prefork_server->m_pChildrenStatus;
2524
- lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatus + g_prefork_server->m_iMaxChildren * 2;
2602
+ lsapi_child_status * pEnd = g_prefork_server->m_pChildrenStatusCur;
2525
2603
  while( pStatus < pEnd )
2526
2604
  {
2527
2605
  tobekilled = 0;
@@ -2534,13 +2612,15 @@ static void lsapi_check_child_status( long tmCur )
2534
2612
  if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)||
2535
2613
  ( idle > g_prefork_server->m_iMaxIdleChildren ))
2536
2614
  {
2537
- tobekilled = SIGUSR1;
2615
+ ++pStatus->m_iKillSent;
2616
+ //tobekilled = SIGUSR1;
2538
2617
  }
2539
2618
  else
2540
2619
  {
2541
2620
  if (( s_max_idle_secs> 0)&&(tmCur - pStatus->m_tmWaitBegin > s_max_idle_secs + 5 ))
2542
2621
  {
2543
- tobekilled = SIGUSR1;
2622
+ ++pStatus->m_iKillSent;
2623
+ //tobekilled = SIGUSR1;
2544
2624
  }
2545
2625
  }
2546
2626
  if ( !tobekilled )
@@ -2567,14 +2647,21 @@ static void lsapi_check_child_status( long tmCur )
2567
2647
  }
2568
2648
  if ( tobekilled )
2569
2649
  {
2570
- kill( pStatus->m_pid, tobekilled );
2571
- ++pStatus->m_iKillSent;
2572
- ++dying;
2650
+ if (( kill( pStatus->m_pid, tobekilled ) == -1 )&&( errno == ESRCH ))
2651
+ {
2652
+ pStatus->m_pid = 0;
2653
+ --count;
2654
+ }
2655
+ else
2656
+ {
2657
+ ++pStatus->m_iKillSent;
2658
+ ++dying;
2659
+ }
2573
2660
  }
2574
2661
  }
2575
2662
  ++pStatus;
2576
2663
  }
2577
- if ( g_prefork_server->m_iCurChildren != count )
2664
+ if ( abs( g_prefork_server->m_iCurChildren - count ) > 1 )
2578
2665
  {
2579
2666
  fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Childen: %d, count: %d, idle: %d, dying: %d\n", getpid(),
2580
2667
  g_prefork_server->m_iCurChildren, count, idle, dying );
@@ -2616,6 +2703,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2616
2703
  fd_set readfds;
2617
2704
  struct timeval timeout;
2618
2705
 
2706
+ sigset_t mask;
2707
+ sigset_t orig_mask;
2708
+
2619
2709
  lsapi_init_children_status();
2620
2710
 
2621
2711
  setsid();
@@ -2664,6 +2754,8 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2664
2754
 
2665
2755
  if ( pServer->m_iCurChildren >= (pServer->m_iMaxChildren + pServer->m_iExtraChildren ) )
2666
2756
  {
2757
+ fprintf( stderr, "Reached max children process limit: %d, extra: %d, current: %d, please increase LSAPI_CHILDREN.\n",
2758
+ pServer->m_iMaxChildren, pServer->m_iExtraChildren, pServer->m_iCurChildren );
2667
2759
  usleep( 100000 );
2668
2760
  continue;
2669
2761
  }
@@ -2702,9 +2794,21 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2702
2794
  child_status = find_child_status( 0 );
2703
2795
  if ( child_status )
2704
2796
  memset( child_status, 0, sizeof( *child_status ) );
2797
+
2798
+ sigemptyset( &mask );
2799
+ sigaddset( &mask, SIGCHLD );
2800
+
2801
+ if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 )
2802
+ {
2803
+ perror( "sigprocmask(SIG_BLOCK) to block SIGCHLD" );
2804
+ }
2805
+
2705
2806
  pid = fork();
2807
+
2706
2808
  if ( !pid )
2707
2809
  {
2810
+ if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2811
+ perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK in child" );
2708
2812
  g_prefork_server = NULL;
2709
2813
  s_ppid = getppid();
2710
2814
  s_req_processed = 0;
@@ -2723,8 +2827,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2723
2827
  sigaction( SIGUSR1, &old_usr1, 0 );
2724
2828
  //init_conn_key( pReq->m_fd );
2725
2829
  lsapi_notify_pid( pReq->m_fd );
2726
- if ( s_accept_notify )
2727
- return notify_req_received( pReq->m_fd );
2830
+ s_notified_pid = 1;
2831
+ //if ( s_accept_notify )
2832
+ // return notify_req_received( pReq->m_fd );
2728
2833
  return 0;
2729
2834
  }
2730
2835
  else if ( pid == -1 )
@@ -2744,6 +2849,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2744
2849
  close( pReq->m_fd );
2745
2850
  pReq->m_fd = -1;
2746
2851
 
2852
+ if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0)
2853
+ perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK" );
2854
+
2747
2855
  }
2748
2856
  else
2749
2857
  {
@@ -2754,8 +2862,8 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re
2754
2862
  }
2755
2863
  }
2756
2864
  sigaction( SIGUSR1, &old_usr1, 0 );
2757
- kill( -getpgrp(), SIGUSR1 );
2758
- lsapi_all_children_must_die(); /* Sorry, children ;-) */
2865
+ //kill( -getpgrp(), SIGUSR1 );
2866
+ //lsapi_all_children_must_die(); /* Sorry, children ;-) */
2759
2867
  return -1;
2760
2868
 
2761
2869
  }
@@ -2808,7 +2916,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2808
2916
  {
2809
2917
  if ( !g_running )
2810
2918
  return -1;
2811
- if (( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2919
+ if ((s_req_processed)&&( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2812
2920
  return -1;
2813
2921
  FD_ZERO( &readfds );
2814
2922
  FD_SET( fd, &readfds );
@@ -2836,7 +2944,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
2836
2944
  }
2837
2945
  else if ( ret >= 1 )
2838
2946
  {
2839
- if (( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2947
+ if (s_req_processed && ( s_pChildStatus )&&( s_pChildStatus->m_iKillSent ))
2840
2948
  return -1;
2841
2949
  if ( fd == pReq->m_fdListen )
2842
2950
  {
@@ -2969,6 +3077,51 @@ static void unset_lsapi_envs()
2969
3077
  }
2970
3078
  }
2971
3079
 
3080
+ static int lsapi_initSuEXEC()
3081
+ {
3082
+ int i;
3083
+ struct passwd * pw;
3084
+ s_defaultUid = 0;
3085
+ s_defaultGid = 0;
3086
+ if ( s_uid == 0 )
3087
+ {
3088
+ const char * p = getenv( "LSAPI_DEFAULT_UID" );
3089
+ if ( p )
3090
+ {
3091
+ i = atoi( p );
3092
+ if ( i > 0 )
3093
+ s_defaultUid = i;
3094
+ }
3095
+ p = getenv( "LSAPI_DEFAULT_GID" );
3096
+ if ( p )
3097
+ {
3098
+ i = atoi( p );
3099
+ if ( i > 0 )
3100
+ s_defaultGid = i;
3101
+ }
3102
+ p = getenv( "LSAPI_SECRET" );
3103
+ if (( !p )||( readSecret(p) == -1 ))
3104
+ return -1;
3105
+ if ( g_prefork_server )
3106
+ {
3107
+ if ( g_prefork_server->m_iMaxChildren < 100 )
3108
+ g_prefork_server->m_iMaxChildren = 100;
3109
+ if ( g_prefork_server->m_iExtraChildren < 1000 )
3110
+ g_prefork_server->m_iExtraChildren = 1000;
3111
+ }
3112
+ }
3113
+ if ( !s_defaultUid || !s_defaultGid )
3114
+ {
3115
+ pw = getpwnam( "nobody" );
3116
+ if ( !s_defaultUid )
3117
+ s_defaultUid = pw->pw_uid;
3118
+ if ( !s_defaultGid )
3119
+ s_defaultGid = pw->pw_gid;
3120
+ }
3121
+ return 0;
3122
+ }
3123
+
3124
+
2972
3125
  int LSAPI_Init_Env_Parameters( fn_select_t fp )
2973
3126
  {
2974
3127
  const char *p;
@@ -3082,7 +3235,25 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
3082
3235
  }
3083
3236
 
3084
3237
 
3085
-
3238
+ int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
3239
+ const char * pBody, int bodyLen )
3240
+ {
3241
+ LSAPI_SetRespStatus_r( pReq, code );
3242
+ if ( pRespHeaders )
3243
+ {
3244
+ while( *pRespHeaders )
3245
+ {
3246
+ LSAPI_AppendRespHeader_r( pReq, *pRespHeaders, strlen( *pRespHeaders ) );
3247
+ ++pRespHeaders;
3248
+ }
3249
+ }
3250
+ if ( pBody &&( bodyLen > 0 ))
3251
+ {
3252
+ LSAPI_Write_r( pReq, pBody, bodyLen );
3253
+ }
3254
+ LSAPI_Finish_r( pReq );
3255
+ return 0;
3256
+ }
3086
3257
 
3087
3258
 
3088
3259
  static void lsapi_MD5Transform(uint32 buf[4], uint32 const in[16]);
@@ -3206,7 +3377,7 @@ void lsapi_MD5Final(unsigned char digest[16], struct lsapi_MD5Context *ctx)
3206
3377
  lsapi_MD5Transform(ctx->buf, (uint32 *) ctx->in);
3207
3378
  byteReverse((unsigned char *) ctx->buf, 4);
3208
3379
  memmove(digest, ctx->buf, 16);
3209
- memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
3380
+ memset(ctx, 0, sizeof(*ctx)); /* In case it's sensitive */
3210
3381
  }
3211
3382
 
3212
3383
  /* The four core functions - F1 is optimized somewhat */
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright (c) 2005, Lite Speed Technologies Inc.
2
+ Copyright (c) 2002-2015, Lite Speed Technologies Inc.
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
@@ -30,14 +30,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
30
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
  */
32
32
 
33
- /***************************************************************************
34
- lsapilib.h - description
35
- -------------------
36
- begin : Mon Feb 21 2005
37
- copyright : (C) 2005 by George Wang
38
- email : gwang@litespeedtech.com
39
- ***************************************************************************/
40
-
41
33
 
42
34
  #ifndef _LSAPILIB_H_
43
35
  #define _LSAPILIB_H_
@@ -182,6 +174,9 @@ int LSAPI_AppendRespHeader_r( LSAPI_Request * pReq, const char * pBuf, int len )
182
174
  int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName,
183
175
  const char * pHeaderValue );
184
176
 
177
+ int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders,
178
+ const char * pBody, int bodyLen );
179
+
185
180
  static inline int LSAPI_SetRespStatus_r( LSAPI_Request * pReq, int code )
186
181
  {
187
182
  if ( !pReq )
@@ -253,6 +248,7 @@ static inline off_t LSAPI_GetReqBodyRemain_r( LSAPI_Request * pReq )
253
248
  }
254
249
 
255
250
 
251
+
256
252
  int LSAPI_Is_Listen(void);
257
253
 
258
254
  static inline int LSAPI_Accept( void )
@@ -332,6 +328,9 @@ static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
332
328
  static inline int LSAPI_SetRespStatus( int code )
333
329
  { return LSAPI_SetRespStatus_r( &g_req, code ); }
334
330
 
331
+ static inline int LSAPI_ErrResponse( int code, const char ** pRespHeaders, const char * pBody, int bodyLen )
332
+ { return LSAPI_ErrResponse_r( &g_req, code, pRespHeaders, pBody, bodyLen ); }
333
+
335
334
  int LSAPI_IsRunning(void);
336
335
 
337
336
  int LSAPI_CreateListenSock( const char * pBind, int backlog );
@@ -1,7 +1,7 @@
1
1
 
2
2
  #include "ruby.h"
3
3
 
4
- #ifdef RUBY_19
4
+ #if defined( RUBY_19 ) || defined( RUBY_2 )
5
5
  #include <ruby/util.h>
6
6
  #else
7
7
  #include "util.h"
@@ -43,7 +43,7 @@ typedef struct lsapi_data
43
43
  {
44
44
  LSAPI_Request * req;
45
45
  VALUE env;
46
- int (* fn_write)( LSAPI_Request *, const char * , int );
46
+ ssize_t (* fn_write)( LSAPI_Request *, const char * , size_t );
47
47
 
48
48
  }lsapi_data;
49
49
 
@@ -217,7 +217,7 @@ static VALUE lsapi_eval_string_wrap(VALUE self, VALUE str)
217
217
  }
218
218
  else
219
219
  {
220
- Check_SafeStr(str);
220
+ SafeStringValue(str);
221
221
  }
222
222
  return rb_eval_string_wrap(StringValuePtr(str), NULL);
223
223
  }
@@ -307,7 +307,7 @@ static VALUE lsapi_printf(int argc, VALUE *argv, VALUE out)
307
307
 
308
308
  static VALUE lsapi_puts _((int, VALUE*, VALUE));
309
309
 
310
- #ifdef RUBY_19
310
+ #if defined( RUBY_19 ) || defined( RUBY_2 )
311
311
  static VALUE lsapi_puts_ary(VALUE ary, VALUE out, int recur )
312
312
  {
313
313
  VALUE tmp;
@@ -365,7 +365,7 @@ static VALUE lsapi_puts(int argc, VALUE *argv, VALUE out)
365
365
  line = rb_str_new2("nil");
366
366
  break;
367
367
  case T_ARRAY:
368
- #ifdef RUBY_19
368
+ #if defined( RUBY_19 ) || defined( RUBY_2 )
369
369
  rb_exec_recursive(lsapi_puts_ary, argv[i], out);
370
370
  #else
371
371
  rb_protect_inspect(lsapi_puts_ary, argv[i], out);
@@ -502,7 +502,7 @@ static VALUE lsapi_eof(VALUE self)
502
502
  }
503
503
  Data_Get_Struct(self, lsapi_data, data);
504
504
  */
505
- return (LSAPI_GetReqBodyRemain( &g_req ) <= 0) ? Qtrue : Qfalse;
505
+ return (LSAPI_GetReqBodyRemain_r( &g_req ) <= 0) ? Qtrue : Qfalse;
506
506
  }
507
507
 
508
508
  static VALUE lsapi_binmode(VALUE self)
@@ -561,7 +561,8 @@ void Init_lsapi()
561
561
 
562
562
  LSAPI_Init();
563
563
 
564
- LSAPI_Init_Env_Parameters( rb_thread_select );
564
+ //LSAPI_Init_Env_Parameters( rb_thread_select );
565
+ LSAPI_Init_Env_Parameters( select );
565
566
 
566
567
  s_pid = getpid();
567
568
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsapi
3
3
  version: !ruby/object:Gem::Version
4
- version: '4.1'
4
+ version: '4.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - LiteSpeed Technologies Inc.
@@ -38,17 +38,17 @@ require_paths:
38
38
  - lib
39
39
  required_ruby_version: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ! '>='
41
+ - - '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
50
  rubyforge_project: ruby-lsapi
51
- rubygems_version: 2.0.6
51
+ rubygems_version: 2.0.3
52
52
  signing_key:
53
53
  specification_version: 4
54
54
  summary: A ruby extension for fast communication with LiteSpeed Web Server.