View | Details | Raw Unified | Return to bug 51078
Collapse All | Expand All

(-)httpd-2.2.17_orig/modules/generators/fcgid_conf.c (+49 lines)
Lines 749-754 Link Here
749
    return NULL;
749
    return NULL;
750
}
750
}
751
751
752
753
#ifdef WIN32
754
/* FcgidWin32PreventOrphans
755
 *
756
 *        When Apache process gets recycled or shutdown abruptly, CGI processes 
757
 *        spawned by mod_fcgid will get orphaned. Orphaning happens mostly when
758
 *        Apache worker threads take more than 30 seconds to exit gracefully.
759
 *    
760
 */    
761
const char *set_win32_prevent_process_orphans(cmd_parms *cmd, void *dummy, char *arg)
762
{
763
    server_rec *s = cmd->server;
764
    fcgid_server_conf *config = ap_get_module_config(s->module_config, &fcgid_module);
765
    
766
    if (config != NULL && config->hJobObjectForAutoCleanup == NULL){
767
768
        /* Create Win32 job object to prevent CGI process oprhaning
769
         */
770
        JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info = { 0 };
771
        config->hJobObjectForAutoCleanup = CreateJobObject(NULL, NULL);
772
773
        if (config->hJobObjectForAutoCleanup == NULL){
774
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
775
                             "mod_fcgid: Error enabling CGI process orphan prevention: %d " 
776
                             "unable to create job object.", apr_get_os_error());
777
                return NULL;
778
        }
779
780
        /* Set job info so that all spawned CGI processes are associated with mod_fcgid
781
         */        
782
        job_info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
783
        if(SetInformationJobObject(config->hJobObjectForAutoCleanup, 
784
                                   JobObjectExtendedLimitInformation, &job_info, sizeof(job_info)) == 0){
785
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
786
                             "mod_fcgid: Error enabling CGI process orphan prevention: %d "
787
                             "unable set job object information.", apr_get_os_error());
788
                CloseHandle(config->hJobObjectForAutoCleanup);
789
                config->hJobObjectForAutoCleanup = NULL;
790
                return NULL;        
791
        }
792
793
        ap_log_error(APLOG_MARK, APLOG_INFO, 0, NULL,
794
            "mod_fcgid: Enabled CGI process orphaning prevention flag.");    
795
    }
796
797
    return NULL;
798
}
799
#endif /*WIN32*/
800
752
fcgid_cmd_conf *get_access_info(request_rec * r, int *authoritative)
801
fcgid_cmd_conf *get_access_info(request_rec * r, int *authoritative)
753
{
802
{
754
    fcgid_dir_conf *config =
803
    fcgid_dir_conf *config =
(-)httpd-2.2.17_orig/modules/generators/fcgid_conf.h (+4 lines)
Lines 71-76 Link Here
71
    int termination_score;
71
    int termination_score;
72
    int time_score;
72
    int time_score;
73
    int zombie_scan_interval;
73
    int zombie_scan_interval;
74
#ifdef WIN32
75
    /* FcgidWin32PreventOrphans - Win32 CGI processes automatic cleanup */    
76
    HANDLE hJobObjectForAutoCleanup;
77
#endif /*WIN32*/
74
    /* global or vhost
78
    /* global or vhost
75
     * scalar values have corresponding _set field to aid merging
79
     * scalar values have corresponding _set field to aid merging
76
     */
80
     */
(-)httpd-2.2.17_orig/modules/generators/fcgid_pm_win.c (+7 lines)
Lines 262-267 Link Here
262
apr_status_t procmgr_stop_procmgr(void *server)
262
apr_status_t procmgr_stop_procmgr(void *server)
263
{
263
{
264
    apr_status_t status;
264
    apr_status_t status;
265
    fcgid_server_conf *conf =
266
            ap_get_module_config(((server_rec*)server)->module_config, &fcgid_module);
265
267
266
    /* Tell the world to die */
268
    /* Tell the world to die */
267
    g_must_exit = 1;
269
    g_must_exit = 1;
Lines 279-284 Link Here
279
        }
281
        }
280
    }
282
    }
281
283
284
    /* Cleanup the Job object if present */
285
    if (conf != NULL && conf->hJobObjectForAutoCleanup != NULL) {
286
            CloseHandle(conf->hJobObjectForAutoCleanup);        
287
    }
288
    
282
    if (g_wakeup_thread)
289
    if (g_wakeup_thread)
283
        return apr_thread_join(&status, g_wakeup_thread);
290
        return apr_thread_join(&status, g_wakeup_thread);
284
291
(-)httpd-2.2.17_orig/modules/generators/fcgid_proc_win.c (+19 lines)
Lines 176-182 Link Here
176
    if (rv != APR_SUCCESS) {
176
    if (rv != APR_SUCCESS) {
177
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
177
        ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
178
                     "mod_fcgid: can't run %s", wargv[0]);
178
                     "mod_fcgid: can't run %s", wargv[0]);
179
		return rv;
179
    }
180
    }
181
    /* LTAC - FcgidWin32PreventOrphans feature*/
182
    do{
183
        fcgid_server_conf *sconf = ap_get_module_config(procinfo->main_server->
184
                                                    module_config, &fcgid_module);      
185
        if (sconf == NULL){
186
            ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
187
                         "mod_fcgid: fcgi server configuration info unavailable");
188
            break;            
189
        }
190
        /* Is FcgidWin32PreventOrphans enabled? */
191
        if(sconf->hJobObjectForAutoCleanup != NULL){
192
            /* Associate cgi process to current process */
193
            if(AssignProcessToJobObject(sconf->hJobObjectForAutoCleanup, procnode->proc_id.hproc) == 0){
194
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, procinfo->main_server,
195
                    "mod_fcgid: unable to assign child process to job object %d", apr_get_os_error());                    
196
            }
197
        }
198
    }while(0);
180
199
181
    return rv;
200
    return rv;
182
}
201
}
(-)httpd-2.2.17_orig/modules/generators/mod_fcgid.c (-1 / +18 lines)
Lines 802-807 Link Here
802
    return APR_SUCCESS;
802
    return APR_SUCCESS;
803
}
803
}
804
804
805
#ifdef WIN32
806
const char *set_win32_prevent_process_orphans(cmd_parms *cmd, void *dummy, 
807
                                              char *arg);
808
#endif /*WIN32*/
809
810
805
static const command_rec fcgid_cmds[] = {
811
static const command_rec fcgid_cmds[] = {
806
    AP_INIT_TAKE1("FcgidAccessChecker", set_access_info, NULL,
812
    AP_INIT_TAKE1("FcgidAccessChecker", set_access_info, NULL,
807
                  ACCESS_CONF | OR_FILEINFO,
813
                  ACCESS_CONF | OR_FILEINFO,
Lines 895-901 Link Here
895
    AP_INIT_TAKE1("FcgidZombieScanInterval", set_zombie_scan_interval, NULL,
901
    AP_INIT_TAKE1("FcgidZombieScanInterval", set_zombie_scan_interval, NULL,
896
                  RSRC_CONF,
902
                  RSRC_CONF,
897
                  "scan interval for zombie process"),
903
                  "scan interval for zombie process"),
898
904
#ifdef WIN32
905
    /* Apache when run as windows service during shutdown/restart of service process (master/parent) will terminate child httpd
906
     * process within 30 seconds (refer \server\mpm\winnt\mpm_winnt.c:master_main()  int timeout = 30000; ~line#1142), therefore
907
     * if Apache worker threads are too busy to react to Master's graceful exit signal within 30 seconds - mod_fcgid cleanup 
908
     * routines will not get invoked (refer \server\mpm\winnt\child.c: child_main() apr_pool_destroy(pchild); ~line#2275) thereby
909
     * orphaning all mod_fcgid spwaned CGI processes. 
910
     * Therefore we utilize Win32 JobObjects to clean up child processes automatically so that CGI processes are gauranteed to 
911
     * get killed during abnormal mod_fcgid termination.
912
     */
913
    AP_INIT_NO_ARGS("FcgidWin32PreventOrphans", set_win32_prevent_process_orphans, NULL, RSRC_CONF,
914
                    "CGI process orphaning will be prevented during Apache child recycling or abrupt shutdowns"),
915
#endif /*WIN32*/
899
    /* The following directives are all deprecated in favor
916
    /* The following directives are all deprecated in favor
900
     * of a consistent use of the Fcgid prefix.
917
     * of a consistent use of the Fcgid prefix.
901
     * Add all new command above this line.
918
     * Add all new command above this line.

Return to bug 51078