diff --git a/plugins/psgi/psgi_loader.c b/plugins/psgi/psgi_loader.c index fefbcb30..1bc0c23c 100644 --- a/plugins/psgi/psgi_loader.c +++ b/plugins/psgi/psgi_loader.c @@ -437,13 +437,7 @@ int init_psgi_app(struct wsgi_request *wsgi_req, char *app, uint16_t app_len, Pe wi->error = uperl.tmp_error_stash; wi->responder0 = uperl.tmp_stream_responder; - // check if we need to emulate fork() COW - if (uwsgi.mywid == 0) { - for(i=1;i<=uwsgi.numproc;i++) { - memcpy(&uwsgi.workers[i].apps[id], &uwsgi.workers[0].apps[id], sizeof(struct uwsgi_app)); - uwsgi.workers[i].apps_cnt = uwsgi_apps_cnt; - } - } + uwsgi_emulate_cow_for_apps(id); // restore context if required diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 5d220890..ebc7ce54 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -418,13 +418,8 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre } } - // check if we need to emulate fork() COW - if (uwsgi.mywid == 0) { - for(i=1;i<=uwsgi.numproc;i++) { - memcpy(&uwsgi.workers[i].apps[id], &uwsgi.workers[0].apps[id], sizeof(struct uwsgi_app)); - uwsgi.workers[i].apps_cnt = uwsgi_apps_cnt; - } - } + // emulate COW + uwsgi_emulate_cow_for_apps(id); return id; diff --git a/plugins/rack/rack_plugin.c b/plugins/rack/rack_plugin.c index c62aef07..6f1c92dc 100644 --- a/plugins/rack/rack_plugin.c +++ b/plugins/rack/rack_plugin.c @@ -385,6 +385,9 @@ ready: struct uwsgi_app *ua = uwsgi_add_app(ur.app_id, 7, (char*)"", 0, NULL, NULL); ua->started_at = now; ua->startup_time = uwsgi_now() - now; + + uwsgi_emulate_cow_for_apps(ur.app_id); + if (ur.gc_freq <= 1) { uwsgi_log("RACK app %d loaded in %d seconds at %p (GC frequency: AGGRESSIVE)\n", ur.app_id, (int) ua->startup_time, ur.call); } diff --git a/utils.c b/utils.c index a086a8a2..ad4d631e 100644 --- a/utils.c +++ b/utils.c @@ -4008,6 +4008,18 @@ int uwsgi_file_to_string_list(char *filename, struct uwsgi_string_list **list) { return 0; } +void uwsgi_emulate_cow_for_apps(int id) { + int i; + // check if we need to emulate fork() COW + if (uwsgi.mywid == 0) { + for(i=1;i<=uwsgi.numproc;i++) { + memcpy(&uwsgi.workers[i].apps[id], &uwsgi.workers[0].apps[id], sizeof(struct uwsgi_app)); + uwsgi.workers[i].apps_cnt = uwsgi_apps_cnt; + } + } +} + + // in the future we will need to use the best clock source for each os/system time_t uwsgi_now() { return time(NULL); diff --git a/uwsgi.h b/uwsgi.h index 863196fd..b87f5e60 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2661,6 +2661,8 @@ void uwsgi_flush_logs(void); void uwsgi_register_cheaper_algo(char *, int(*) (void)); +void uwsgi_emulate_cow_for_apps(int); + #ifdef UWSGI_AS_SHARED_LIBRARY int uwsgi_init(int, char **, char **); #endif