source@mandoc.bsd.lv
 help / color / Atom feed
* mandoc: In fs_lookup(), use stat(2) rather than access(2) to check file 
@ 2019-05-03 17:31 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-05-03 17:31 UTC (permalink / raw)
  To: source

Log Message:
-----------
In fs_lookup(), use stat(2) rather than access(2) to check file existence.
Some mildly broken real-world packages on some operating systems
contain dangling symlinks in manual page directories: pestering the
user to run makewhatis(8) makes no sense because that won't help.
On the other hand, missing read permissions deserve ugly error messages
and are unlikely to occur in practice anyway.

Fixing an issue reported by Lorenzo Beretta <loreb at github>
as part of https://github.com/void-linux/void-packages/issues/9868 .

Modified Files:
--------------
    mandoc:
        TODO
        main.c

Revision Data
-------------
Index: TODO
===================================================================
RCS file: /home/cvs/mandoc/mandoc/TODO,v
retrieving revision 1.293
retrieving revision 1.294
diff -LTODO -LTODO -u -p -r1.293 -r1.294
--- TODO
+++ TODO
@@ -217,12 +217,6 @@ are mere guesses, and some may be wrong.
 
 --- missing misc features ----------------------------------------------
 
-- dead .so links should be entered into the database to avoid:
-  man -M. lvm-config
-  man: outdated mandoc.db lacks lvm-config(8) entry, run makewhatis /co/void-man
-  https://github.com/void-linux/void-packages/issues/9868
-  loc *  exist **  algo *  size *  imp **
-
 - man -ks 1,8 route; kn@ Jul 13, 2018 orally
 
 - italic correction (\/) in PostScript mode
Index: main.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/main.c,v
retrieving revision 1.325
retrieving revision 1.326
diff -Lmain.c -Lmain.c -u -p -r1.325 -r1.326
--- main.c
+++ main.c
@@ -21,6 +21,7 @@
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/param.h>	/* MACHINE */
+#include <sys/stat.h>
 #include <sys/wait.h>
 
 #include <assert.h>
@@ -713,6 +714,7 @@ fs_lookup(const struct manpaths *paths, 
 	const char *sec, const char *arch, const char *name,
 	struct manpage **res, size_t *ressz)
 {
+	struct stat	 sb;
 	glob_t		 globinfo;
 	struct manpage	*page;
 	char		*file;
@@ -722,13 +724,13 @@ fs_lookup(const struct manpaths *paths, 
 	form = FORM_SRC;
 	mandoc_asprintf(&file, "%s/man%s/%s.%s",
 	    paths->paths[ipath], sec, name, sec);
-	if (access(file, R_OK) != -1)
+	if (stat(file, &sb) != -1)
 		goto found;
 	free(file);
 
 	mandoc_asprintf(&file, "%s/cat%s/%s.0",
 	    paths->paths[ipath], sec, name);
-	if (access(file, R_OK) != -1) {
+	if (stat(file, &sb) != -1) {
 		form = FORM_CAT;
 		goto found;
 	}
@@ -737,7 +739,7 @@ fs_lookup(const struct manpaths *paths, 
 	if (arch != NULL) {
 		mandoc_asprintf(&file, "%s/man%s/%s/%s.%s",
 		    paths->paths[ipath], sec, arch, name, sec);
-		if (access(file, R_OK) != -1)
+		if (stat(file, &sb) != -1)
 			goto found;
 		free(file);
 	}
@@ -751,13 +753,16 @@ fs_lookup(const struct manpaths *paths, 
 	if (globres == 0)
 		file = mandoc_strdup(*globinfo.gl_pathv);
 	globfree(&globinfo);
-	if (globres == 0)
-		goto found;
+	if (globres == 0) {
+		if (stat(file, &sb) != -1)
+			goto found;
+		free(file);
+	}
 	if (res != NULL || ipath + 1 != paths->sz)
 		return 0;
 
 	mandoc_asprintf(&file, "%s.%s", name, sec);
-	globres = access(file, R_OK);
+	globres = stat(file, &sb);
 	free(file);
 	return globres != -1;
 
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03 17:31 mandoc: In fs_lookup(), use stat(2) rather than access(2) to check file schwarze

source@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-source

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git