int main(int argc, const char **argv) { const char *socket_path; static const char *usage[] = { "git-credential-cache--daemon [opts] <socket_path>", NULL }; int debug = 0; const struct option options[] = { OPT_BOOL(0, "debug", &debug, N_("print debugging messages to stderr")), OPT_END() }; argc = parse_options(argc, argv, NULL, options, usage, 0); socket_path = argv[0]; if (!socket_path) usage_with_options(usage, options); check_socket_directory(socket_path); register_tempfile(&socket_file, socket_path); serve_cache(socket_path, debug); delete_tempfile(&socket_file); return 0; }
int cmd_main(int argc, const char **argv) { const char *socket_path; int ignore_sighup = 0; static const char *usage[] = { "git-credential-cache--daemon [opts] <socket_path>", NULL }; int debug = 0; const struct option options[] = { OPT_BOOL(0, "debug", &debug, N_("print debugging messages to stderr")), OPT_END() }; git_config_get_bool("credentialcache.ignoresighup", &ignore_sighup); argc = parse_options(argc, argv, NULL, options, usage, 0); socket_path = argv[0]; if (!socket_path) usage_with_options(usage, options); if (!is_absolute_path(socket_path)) die("socket directory must be an absolute path"); init_socket_directory(socket_path); register_tempfile(&socket_file, socket_path); if (ignore_sighup) signal(SIGHUP, SIG_IGN); serve_cache(socket_path, debug); delete_tempfile(&socket_file); return 0; }
/* return NULL on success, else hostname running the gc */ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) { struct lock_file lock = LOCK_INIT; char my_host[HOST_NAME_MAX + 1]; struct strbuf sb = STRBUF_INIT; struct stat st; uintmax_t pid; FILE *fp; int fd; char *pidfile_path; if (is_tempfile_active(pidfile)) /* already locked */ return NULL; if (xgethostname(my_host, sizeof(my_host))) xsnprintf(my_host, sizeof(my_host), "unknown"); pidfile_path = git_pathdup("gc.pid"); fd = hold_lock_file_for_update(&lock, pidfile_path, LOCK_DIE_ON_ERROR); if (!force) { static char locking_host[HOST_NAME_MAX + 1]; static char *scan_fmt; int should_exit; if (!scan_fmt) scan_fmt = xstrfmt("%s %%%ds", "%"SCNuMAX, HOST_NAME_MAX); fp = fopen(pidfile_path, "r"); memset(locking_host, 0, sizeof(locking_host)); should_exit = fp != NULL && !fstat(fileno(fp), &st) && /* * 12 hour limit is very generous as gc should * never take that long. On the other hand we * don't really need a strict limit here, * running gc --auto one day late is not a big * problem. --force can be used in manual gc * after the user verifies that no gc is * running. */ time(NULL) - st.st_mtime <= 12 * 3600 && fscanf(fp, scan_fmt, &pid, locking_host) == 2 && /* be gentle to concurrent "gc" on remote hosts */ (strcmp(locking_host, my_host) || !kill(pid, 0) || errno == EPERM); if (fp != NULL) fclose(fp); if (should_exit) { if (fd >= 0) rollback_lock_file(&lock); *ret_pid = pid; free(pidfile_path); return locking_host; } } strbuf_addf(&sb, "%"PRIuMAX" %s", (uintmax_t) getpid(), my_host); write_in_full(fd, sb.buf, sb.len); strbuf_release(&sb); commit_lock_file(&lock); pidfile = register_tempfile(pidfile_path); free(pidfile_path); return NULL; }