@@ -297,6 +297,8 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */
297
297
free (wpc -> pm -> status );
298
298
free (wpc -> pm -> ping );
299
299
free (wpc -> pm -> pong );
300
+ free (wpc -> sticky_cookie );
301
+ free (wpc -> sticky_route );
300
302
if (wpc -> listen_options ) {
301
303
free (wpc -> listen_options -> owner );
302
304
free (wpc -> listen_options -> group );
@@ -347,6 +349,9 @@ static struct xml_conf_section xml_section_fpm_worker_pool_config = {
347
349
{ XML_CONF_SCALAR , "rlimit_files" , & xml_conf_set_slot_integer , offsetof(struct fpm_worker_pool_config_s , rlimit_files ) },
348
350
{ XML_CONF_SCALAR , "rlimit_core" , & fpm_conf_set_rlimit_core , 0 },
349
351
{ XML_CONF_SCALAR , "max_requests" , & xml_conf_set_slot_integer , offsetof(struct fpm_worker_pool_config_s , max_requests ) },
352
+ { XML_CONF_SCALAR , "sticky" , & xml_conf_set_slot_boolean , offsetof(struct fpm_worker_pool_config_s , sticky ) },
353
+ { XML_CONF_SCALAR , "sticky_cookie" , & xml_conf_set_slot_string , offsetof(struct fpm_worker_pool_config_s , sticky_cookie ) },
354
+ { XML_CONF_SCALAR , "sticky_route" , & xml_conf_set_slot_string , offsetof(struct fpm_worker_pool_config_s , sticky_route ) },
350
355
{ XML_CONF_SCALAR , "catch_workers_output" , & fpm_conf_set_catch_workers_output , 0 },
351
356
{ XML_CONF_SUBSECTION , "pm" , & fpm_conf_set_pm_subsection , offsetof(struct fpm_worker_pool_config_s , pm ) },
352
357
{ 0 , 0 , 0 , 0 }
@@ -475,6 +480,64 @@ static int fpm_conf_process_all_pools() /* {{{ */
475
480
close (fd );
476
481
}
477
482
}
483
+ if (wp -> config -> sticky ) {
484
+ char * cookie = wp -> config -> sticky_cookie ;
485
+ char * route = wp -> config -> sticky_route ;
486
+ int i ;
487
+
488
+ if (!cookie ) {
489
+ wp -> config -> sticky_cookie = strdup ("FPMCOOKIE" );
490
+ } else {
491
+ if (strlen (cookie ) < 2 ) {
492
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] the sticky cookie '%s' is not long enough" , wp -> config -> name , cookie );
493
+ return (-1 );
494
+ }
495
+
496
+ for (i = 0 ; i < strlen (cookie ); i ++ ) {
497
+ if (!isalnum (cookie [i ])) {
498
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] the sticky cookie '%s' must containt only the alphanum characters" , wp -> config -> name , cookie );
499
+ return (-1 );
500
+ }
501
+ }
502
+ }
503
+
504
+ if (!route ) {
505
+ char * hostname ;
506
+ hostname = malloc (sizeof (char ) * (FPM_CONF_MAX_HOSTNAME_LENGTH + 1 ));
507
+ if (!hostname ) {
508
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] sticky: unable to malloc memory for hostname" , wp -> config -> name );
509
+ return (-1 );
510
+ }
511
+ if (gethostname (hostname , FPM_CONF_MAX_HOSTNAME_LENGTH ) != 0 ) {
512
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] sticky: unable to retrieve hostname" , wp -> config -> name );
513
+ return (-1 );
514
+ }
515
+ hostname [FPM_CONF_MAX_HOSTNAME_LENGTH ] = '\0' ;
516
+ wp -> config -> sticky_route = strdup (hostname );
517
+ zlog (ZLOG_STUFF , ZLOG_NOTICE , "[pool %s] the sticky route has been set to the local hostname '%s'" , wp -> config -> name , wp -> config -> sticky_route );
518
+ free (hostname );
519
+ } else {
520
+ if (strlen (route ) < 2 ) {
521
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] the sticky route '%s' is not long enough" , wp -> config -> name , route );
522
+ return (-1 );
523
+ }
524
+
525
+ for (i = 0 ; i < strlen (route ); i ++ ) {
526
+ if (!isalnum (route [i ])) {
527
+ zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] the sticky route '%s' must containt only the alphanum characters" , wp -> config -> name , route );
528
+ return (-1 );
529
+ }
530
+ }
531
+ }
532
+ zlog (ZLOG_STUFF , ZLOG_NOTICE , "[pool %s] sticky is set to %s=%s" , wp -> config -> name , wp -> config -> sticky_cookie , wp -> config -> sticky_route );
533
+ } else {
534
+ if (wp -> config -> sticky_route ) {
535
+ free (wp -> config -> sticky_route );
536
+ }
537
+ if (wp -> config -> sticky_cookie ) {
538
+ free (wp -> config -> sticky_cookie );
539
+ }
540
+ }
478
541
479
542
if (wp -> config -> pm -> ping && * wp -> config -> pm -> ping ) {
480
543
char * ping = wp -> config -> pm -> ping ;
0 commit comments