void dll_entry(void) { set_die_routine(die_dll); set_error_routine(handle_error); set_warn_routine(handle_warning); set_die_is_recursing_routine(die_is_recursing_dll); libgit_initialize(); }
int cmd_main(int argc, const char **argv) { char *method = getenv("REQUEST_METHOD"); char *dir; struct service_cmd *cmd = NULL; char *cmd_arg = NULL; int i; struct strbuf hdr = STRBUF_INIT; set_die_routine(die_webcgi); set_die_is_recursing_routine(die_webcgi_recursing); if (!method) die("No REQUEST_METHOD from server"); if (!strcmp(method, "HEAD")) method = "GET"; dir = getdir(); for (i = 0; i < ARRAY_SIZE(services); i++) { struct service_cmd *c = &services[i]; regex_t re; regmatch_t out[1]; if (regcomp(&re, c->pattern, REG_EXTENDED)) die("Bogus regex in service table: %s", c->pattern); if (!regexec(&re, dir, 1, out, 0)) { size_t n; if (strcmp(method, c->method)) return bad_request(&hdr, c); cmd = c; n = out[0].rm_eo - out[0].rm_so; cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1); dir[out[0].rm_so] = 0; break; } regfree(&re); } if (!cmd) not_found(&hdr, "Request not supported: '%s'", dir); setup_path(); if (!enter_repo(dir, 0)) not_found(&hdr, "Not a git repository: '%s'", dir); git_config(git_default_config, NULL); if (!getenv("GIT_HTTP_EXPORT_ALL") && access("git-daemon-export-ok", F_OK) ) not_found(&hdr, "Repository not exported: '%s'", dir); http_config(); max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER", max_request_buffer); cmd->imp(&hdr, cmd_arg); return 0; }
int start_async(struct async *async) { int need_in, need_out; int fdin[2], fdout[2]; int proc_in, proc_out; need_in = async->in < 0; if (need_in) { if (pipe(fdin) < 0) { if (async->out > 0) close(async->out); return error("cannot create pipe: %s", strerror(errno)); } async->in = fdin[1]; } need_out = async->out < 0; if (need_out) { if (pipe(fdout) < 0) { if (need_in) close_pair(fdin); else if (async->in) close(async->in); return error("cannot create pipe: %s", strerror(errno)); } async->out = fdout[0]; } if (need_in) proc_in = fdin[0]; else if (async->in) proc_in = async->in; else proc_in = -1; if (need_out) proc_out = fdout[1]; else if (async->out) proc_out = async->out; else proc_out = -1; #ifdef NO_PTHREADS /* Flush stdio before fork() to avoid cloning buffers */ fflush(NULL); async->pid = fork(); if (async->pid < 0) { error("fork (async) failed: %s", strerror(errno)); goto error; } if (!async->pid) { if (need_in) close(fdin[1]); if (need_out) close(fdout[0]); git_atexit_clear(); process_is_async = 1; exit(!!async->proc(proc_in, proc_out, async->data)); } mark_child_for_cleanup(async->pid); if (need_in) close(fdin[0]); else if (async->in) close(async->in); if (need_out) close(fdout[1]); else if (async->out) close(async->out); #else if (!main_thread_set) { /* * We assume that the first time that start_async is called * it is from the main thread. */ main_thread_set = 1; main_thread = pthread_self(); pthread_key_create(&async_key, NULL); pthread_key_create(&async_die_counter, NULL); set_die_routine(die_async); set_die_is_recursing_routine(async_die_is_recursing); } if (proc_in >= 0) set_cloexec(proc_in); if (proc_out >= 0) set_cloexec(proc_out); async->proc_in = proc_in; async->proc_out = proc_out; { int err = pthread_create(&async->tid, NULL, run_thread, async); if (err) { error("cannot create thread: %s", strerror(err)); goto error; } } #endif return 0; error: if (need_in) close_pair(fdin); else if (async->in) close(async->in); if (need_out) close_pair(fdout); else if (async->out) close(async->out); return -1; }
void dll_entry() { set_die_routine(die_dll); set_die_is_recursing_routine(die_is_recursing_dll); }
int cmd_main(int argc, const char **argv) { char *method = getenv("REQUEST_METHOD"); char *dir; struct service_cmd *cmd = NULL; char *cmd_arg = NULL; int i; set_die_routine(die_webcgi); set_die_is_recursing_routine(die_webcgi_recursing); if (!method) die("No REQUEST_METHOD from server"); if (!strcmp(method, "HEAD")) method = "GET"; dir = getdir(); for (i = 0; i < ARRAY_SIZE(services); i++) { struct service_cmd *c = &services[i]; regex_t re; regmatch_t out[1]; if (regcomp(&re, c->pattern, REG_EXTENDED)) die("Bogus regex in service table: %s", c->pattern); if (!regexec(&re, dir, 1, out, 0)) { size_t n; if (strcmp(method, c->method)) { const char *proto = getenv("SERVER_PROTOCOL"); if (proto && !strcmp(proto, "HTTP/1.1")) { http_status(405, "Method Not Allowed"); hdr_str("Allow", !strcmp(c->method, "GET") ? "GET, HEAD" : c->method); } else http_status(400, "Bad Request"); hdr_nocache(); end_headers(); return 0; } cmd = c; n = out[0].rm_eo - out[0].rm_so; cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1); dir[out[0].rm_so] = 0; break; } regfree(&re); } if (!cmd) not_found("Request not supported: '%s'", dir); setup_path(); if (!enter_repo(dir, 0)) not_found("Not a git repository: '%s'", dir); if (!getenv("GIT_HTTP_EXPORT_ALL") && access("git-daemon-export-ok", F_OK) ) not_found("Repository not exported: '%s'", dir); http_config(); max_request_buffer = git_env_ulong("GIT_HTTP_MAX_REQUEST_BUFFER", max_request_buffer); cmd->imp(cmd_arg); return 0; }