=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.252 retrieving revision 1.256 diff -u -p -r1.252 -r1.256 --- mandoc/main.c 2015/10/22 21:03:43 1.252 +++ mandoc/main.c 2015/11/07 14:22:29 1.256 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.252 2015/10/22 21:03:43 schwarze Exp $ */ +/* $Id: main.c,v 1.256 2015/11/07 14:22:29 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014, 2015 Ingo Schwarze @@ -24,7 +24,9 @@ #include #include +#if HAVE_ERR #include +#endif #include #include #include @@ -101,8 +103,6 @@ static int toptions(struct curparse *, char *); static void usage(enum argmode) __attribute__((noreturn)); static int woptions(struct curparse *, char *); -extern char *__progname; - static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; static char help_arg[] = "help"; static char *help_argv[] = {help_arg, NULL}; @@ -116,6 +116,7 @@ main(int argc, char *argv[]) struct curparse curp; struct mansearch search; struct tag_files *tag_files; + const char *progname; char *auxpaths; char *defos; unsigned char *uc; @@ -132,20 +133,29 @@ main(int argc, char *argv[]) int use_pager; int c; -#if !HAVE_PROGNAME +#if HAVE_PROGNAME + progname = getprogname(); +#else if (argc < 1) - __progname = mandoc_strdup("mandoc"); - else if ((__progname = strrchr(argv[0], '/')) == NULL) - __progname = argv[0]; + progname = mandoc_strdup("mandoc"); + else if ((progname = strrchr(argv[0], '/')) == NULL) + progname = argv[0]; else - ++__progname; + ++progname; + setprogname(progname); #endif #if HAVE_SQLITE3 - if (strcmp(__progname, BINM_MAKEWHATIS) == 0) + if (strncmp(progname, "mandocdb", 8) == 0 || + strcmp(progname, BINM_MAKEWHATIS) == 0) return mandocdb(argc, argv); #endif +#if HAVE_PLEDGE + if (pledge("stdio rpath tmppath proc exec flock", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + /* Search options. */ memset(&conf, 0, sizeof(conf)); @@ -155,13 +165,13 @@ main(int argc, char *argv[]) memset(&search, 0, sizeof(struct mansearch)); search.outkey = "Nd"; - if (strcmp(__progname, BINM_MAN) == 0) + if (strcmp(progname, BINM_MAN) == 0) search.argmode = ARG_NAME; - else if (strcmp(__progname, BINM_APROPOS) == 0) + else if (strcmp(progname, BINM_APROPOS) == 0) search.argmode = ARG_EXPR; - else if (strcmp(__progname, BINM_WHATIS) == 0) + else if (strcmp(progname, BINM_WHATIS) == 0) search.argmode = ARG_WORD; - else if (strncmp(__progname, "help", 4) == 0) + else if (strncmp(progname, "help", 4) == 0) search.argmode = ARG_NAME; else search.argmode = ARG_FILE; @@ -285,6 +295,11 @@ main(int argc, char *argv[]) !isatty(STDOUT_FILENO)) use_pager = 0; +#if HAVE_PLEDGE + if (!use_pager && pledge("stdio rpath flock", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + /* Parse arguments. */ if (argc > 0) { @@ -299,7 +314,7 @@ main(int argc, char *argv[]) */ if (search.argmode == ARG_NAME) { - if (*__progname == 'h') { + if (*progname == 'h') { if (argc == 0) { argv = help_argv; argc = 1; @@ -411,6 +426,12 @@ main(int argc, char *argv[]) /* mandoc(1) */ +#if HAVE_PLEDGE + if (pledge(use_pager ? "stdio rpath tmppath proc exec" : + "stdio rpath", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif + if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths)) return (int)MANDOCLEVEL_BADARG; @@ -591,7 +612,7 @@ fs_lookup(const struct manpaths *paths, size_t ipath, found: #if HAVE_SQLITE3 - warnx("outdated mandoc.db lacks %s(%s) entry, run makewhatis %s\n", + warnx("outdated mandoc.db lacks %s(%s) entry, run makewhatis %s", name, sec, paths->paths[ipath]); #endif *res = mandoc_reallocarray(*res, ++*ressz, sizeof(struct manpage)); @@ -721,6 +742,7 @@ parse(struct curparse *curp, int fd, const char *file) } } if (man->macroset == MACROSET_MAN) { + man_validate(man); switch (curp->outtype) { case OUTT_HTML: html_man(curp->outdata, man); @@ -930,7 +952,7 @@ mmsg(enum mandocerr t, enum mandoclevel lvl, { const char *mparse_msg; - fprintf(stderr, "%s: %s:", __progname, file); + fprintf(stderr, "%s: %s:", getprogname(), file); if (line) fprintf(stderr, "%d:%d:", line, col + 1); @@ -1000,6 +1022,10 @@ spawn_pager(struct tag_files *tag_files) case 0: break; default: +#if HAVE_PLEDGE + if (pledge("stdio rpath tmppath", NULL) == -1) + err((int)MANDOCLEVEL_SYSERR, "pledge"); +#endif return pager_pid; }