Merge branch 'jk/common-main'
There are certain house-keeping tasks that need to be performed at the very beginning of any Git program, and programs that are not built-in commands had to do them exactly the same way as "git" potty does. It was easy to make mistakes in one-off standalone programs (like test helpers). A common "main()" function that calls cmd_main() of individual program has been introduced to make it harder to make mistakes. * jk/common-main: mingw: declare main()'s argv as const common-main: call git_setup_gettext() common-main: call restore_sigpipe_to_default() common-main: call sanitize_stdfds() common-main: call git_extract_argv0_path() add an extra level of indirection to main()
This commit is contained in:
16
daemon.c
16
daemon.c
@ -1,6 +1,5 @@
|
||||
#include "cache.h"
|
||||
#include "pkt-line.h"
|
||||
#include "exec_cmd.h"
|
||||
#include "run-command.h"
|
||||
#include "strbuf.h"
|
||||
#include "string-list.h"
|
||||
@ -32,7 +31,7 @@ static const char daemon_usage[] =
|
||||
" [<directory>...]";
|
||||
|
||||
/* List of acceptable pathname prefixes */
|
||||
static char **ok_paths;
|
||||
static const char **ok_paths;
|
||||
static int strict_paths;
|
||||
|
||||
/* If this is set, git-daemon-export-ok is not required */
|
||||
@ -240,7 +239,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi)
|
||||
}
|
||||
|
||||
if ( ok_paths && *ok_paths ) {
|
||||
char **pp;
|
||||
const char **pp;
|
||||
int pathlen = strlen(path);
|
||||
|
||||
/* The validation is done on the paths after enter_repo
|
||||
@ -1192,7 +1191,7 @@ static int serve(struct string_list *listen_addr, int listen_port,
|
||||
return service_loop(&socklist);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int cmd_main(int argc, const char **argv)
|
||||
{
|
||||
int listen_port = 0;
|
||||
struct string_list listen_addr = STRING_LIST_INIT_NODUP;
|
||||
@ -1202,12 +1201,8 @@ int main(int argc, char **argv)
|
||||
struct credentials *cred = NULL;
|
||||
int i;
|
||||
|
||||
git_setup_gettext();
|
||||
|
||||
git_extract_argv0_path(argv[0]);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
char *arg = argv[i];
|
||||
const char *arg = argv[i];
|
||||
const char *v;
|
||||
|
||||
if (skip_prefix(arg, "--listen=", &v)) {
|
||||
@ -1381,8 +1376,7 @@ int main(int argc, char **argv)
|
||||
if (detach) {
|
||||
if (daemonize())
|
||||
die("--detach not supported on this platform");
|
||||
} else
|
||||
sanitize_stdfds();
|
||||
}
|
||||
|
||||
if (pid_file)
|
||||
write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid());
|
||||
|
||||
Reference in New Issue
Block a user