logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

pathchk.1p (11166B)


  1. '\" et
  2. .TH PATHCHK "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. pathchk
  12. \(em check pathnames
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. pathchk \fB[\fR-p\fB] [\fR-P\fB] \fIpathname\fR...
  17. .fi
  18. .SH DESCRIPTION
  19. The
  20. .IR pathchk
  21. utility shall check that one or more pathnames are valid (that is, they
  22. could be used to access or create a file without causing syntax errors)
  23. and portable (that is, no filename truncation results). More
  24. extensive portability checks are provided by the
  25. .BR \-p
  26. and
  27. .BR \-P
  28. options.
  29. .P
  30. By default, the
  31. .IR pathchk
  32. utility shall check each component of each
  33. .IR pathname
  34. operand based on the underlying file system. A diagnostic shall be
  35. written for each
  36. .IR pathname
  37. operand that:
  38. .IP " *" 4
  39. Is longer than
  40. {PATH_MAX}
  41. bytes (see
  42. .BR "Pathname Variable Values"
  43. in the Base Definitions volume of POSIX.1\(hy2017,
  44. .IR "\fB<limits.h>\fP")
  45. .IP " *" 4
  46. Contains any component longer than
  47. {NAME_MAX}
  48. bytes in its containing directory
  49. .IP " *" 4
  50. Contains any component in a directory that is not searchable
  51. .IP " *" 4
  52. Contains any byte sequence that is not valid in its
  53. containing directory
  54. .P
  55. The format of the diagnostic message is not specified, but shall
  56. indicate the error detected and the corresponding
  57. .IR pathname
  58. operand.
  59. .P
  60. It shall not be considered an error if one or more components of a
  61. .IR pathname
  62. operand do not exist as long as a file matching the pathname specified
  63. by the missing components could be created that does not violate any of
  64. the checks specified above.
  65. .SH OPTIONS
  66. The
  67. .IR pathchk
  68. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  69. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  70. .P
  71. The following option shall be supported:
  72. .IP "\fB\-p\fP" 10
  73. Instead of performing checks based on the underlying file system, write
  74. a diagnostic for each
  75. .IR pathname
  76. operand that:
  77. .RS 10
  78. .IP " *" 4
  79. Is longer than
  80. {_POSIX_PATH_MAX}
  81. bytes (see
  82. .BR "Minimum Values"
  83. in the Base Definitions volume of POSIX.1\(hy2017,
  84. .IR "\fB<limits.h>\fP")
  85. .IP " *" 4
  86. Contains any component longer than
  87. {_POSIX_NAME_MAX}
  88. bytes
  89. .IP " *" 4
  90. Contains any character in any component that is not in the portable
  91. filename character set
  92. .RE
  93. .IP "\fB\-P\fP" 10
  94. Write a diagnostic for each
  95. .IR pathname
  96. operand that:
  97. .RS 10
  98. .IP " *" 4
  99. Contains a component whose first character is the
  100. <hyphen-minus>
  101. character
  102. .IP " *" 4
  103. Is empty
  104. .RE
  105. .SH OPERANDS
  106. The following operand shall be supported:
  107. .IP "\fIpathname\fR" 10
  108. A pathname to be checked.
  109. .SH STDIN
  110. Not used.
  111. .SH "INPUT FILES"
  112. None.
  113. .SH "ENVIRONMENT VARIABLES"
  114. The following environment variables shall affect the execution of
  115. .IR pathchk :
  116. .IP "\fILANG\fP" 10
  117. Provide a default value for the internationalization variables that are
  118. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  119. .IR "Section 8.2" ", " "Internationalization Variables"
  120. the precedence of internationalization variables used to determine the
  121. values of locale categories.)
  122. .IP "\fILC_ALL\fP" 10
  123. If set to a non-empty string value, override the values of all the
  124. other internationalization variables.
  125. .IP "\fILC_CTYPE\fP" 10
  126. Determine the locale for the interpretation of sequences of bytes of
  127. text data as characters (for example, single-byte as opposed to
  128. multi-byte characters in arguments).
  129. .IP "\fILC_MESSAGES\fP" 10
  130. .br
  131. Determine the locale that should be used to affect the format and
  132. contents of diagnostic messages written to standard error.
  133. .IP "\fINLSPATH\fP" 10
  134. Determine the location of message catalogs for the processing of
  135. .IR LC_MESSAGES .
  136. .SH "ASYNCHRONOUS EVENTS"
  137. Default.
  138. .SH STDOUT
  139. Not used.
  140. .SH STDERR
  141. The standard error shall be used only for diagnostic messages.
  142. .SH "OUTPUT FILES"
  143. None.
  144. .SH "EXTENDED DESCRIPTION"
  145. None.
  146. .SH "EXIT STATUS"
  147. The following exit values shall be returned:
  148. .IP "\00" 6
  149. All
  150. .IR pathname
  151. operands passed all of the checks.
  152. .IP >0 6
  153. An error occurred.
  154. .SH "CONSEQUENCES OF ERRORS"
  155. Default.
  156. .LP
  157. .IR "The following sections are informative."
  158. .SH "APPLICATION USAGE"
  159. The
  160. .IR test
  161. utility can be used to determine whether a given pathname names an
  162. existing file; it does not, however, give any indication of whether or
  163. not any component of the pathname was truncated in a directory where
  164. the _POSIX_NO_TRUNC feature is not in effect. The
  165. .IR pathchk
  166. utility does not check for file existence; it performs checks to
  167. determine whether a pathname does exist or could be created with no
  168. pathname component truncation.
  169. .P
  170. The
  171. .IR noclobber
  172. option in the shell (see the
  173. .IR "\fIset\fR\^"
  174. special built-in) can be used to atomically create a file. As with all
  175. file creation semantics in the System Interfaces volume of POSIX.1\(hy2017, it guarantees atomic creation,
  176. but still depends on applications to agree on conventions and cooperate
  177. on the use of files after they have been created.
  178. .P
  179. To verify that a pathname meets the requirements of filename
  180. portability, applications should use both the
  181. .BR \-p
  182. and
  183. .BR \-P
  184. options together.
  185. .SH EXAMPLES
  186. To verify that all pathnames in an imported data interchange archive
  187. are legitimate and unambiguous on the current system:
  188. .sp
  189. .RS 4
  190. .nf
  191. # This example assumes that no pathnames in the archive
  192. # contain <newline> characters.
  193. pax -f archive | sed -e \(aqs/[\(ha[:alnum:]]/\e\e&/g\(aq | xargs pathchk --
  194. if [ $? -eq 0 ]
  195. then
  196. pax -r -f archive
  197. else
  198. echo Investigate problems before importing files.
  199. exit 1
  200. fi
  201. .fi
  202. .P
  203. .RE
  204. .P
  205. To verify that all files in the current directory hierarchy could be
  206. moved to any system conforming to the System Interfaces volume of POSIX.1\(hy2017 that also supports the
  207. .IR pax
  208. utility:
  209. .sp
  210. .RS 4
  211. .nf
  212. find . -exec pathchk -p -P {} +
  213. if [ $? -eq 0 ]
  214. then
  215. pax -w -f ../archive .
  216. else
  217. echo Portable archive cannot be created.
  218. exit 1
  219. fi
  220. .fi
  221. .P
  222. .RE
  223. .P
  224. To verify that a user-supplied pathname names a readable file and that
  225. the application can create a file extending the given path without
  226. truncation and without overwriting any existing file:
  227. .sp
  228. .RS 4
  229. .nf
  230. case $- in
  231. *C*) reset="";;
  232. *) reset="set +C"
  233. set -C;;
  234. esac
  235. test -r "$path" && pathchk "$path.out" &&
  236. rm "$path.out" > "$path.out"
  237. if [ $? -ne 0 ]; then
  238. printf "%s: %s not found or %s.out fails \e
  239. creation checks.\en" $0 "$path$path"
  240. $reset # Reset the noclobber option in case a trap
  241. # on EXIT depends on it.
  242. exit 1
  243. fi
  244. $reset
  245. PROCESSING < "$path" > "$path.out"
  246. .fi
  247. .P
  248. .RE
  249. .P
  250. The following assumptions are made in this example:
  251. .IP " 1." 4
  252. .BR PROCESSING
  253. represents the code that is used by the application to use
  254. .BR $path
  255. once it is verified that
  256. .BR $path.out
  257. works as intended.
  258. .IP " 2." 4
  259. The state of the
  260. .IR noclobber
  261. option is unknown when this code is invoked and should be set on exit
  262. to the state it was in when this code was invoked. (The
  263. .BR reset
  264. variable is used in this example to restore the initial state.)
  265. .IP " 3." 4
  266. Note the usage of:
  267. .RS 4
  268. .sp
  269. .RS 4
  270. .nf
  271. rm "$path.out" > "$path.out"
  272. .fi
  273. .P
  274. .RE
  275. .IP " a." 4
  276. The
  277. .IR pathchk
  278. command has already verified, at this point, that
  279. .BR $path.out
  280. is not truncated.
  281. .IP " b." 4
  282. With the
  283. .IR noclobber
  284. option set, the shell verifies that
  285. .BR $path.out
  286. does not already exist before invoking
  287. .IR rm .
  288. .IP " c." 4
  289. If the shell succeeded in creating
  290. .BR $path.out ,
  291. .IR rm
  292. removes it so that the application can create the file again in the
  293. .BR PROCESSING
  294. step.
  295. .IP " d." 4
  296. If the
  297. .BR PROCESSING
  298. step wants the file to exist already when it is invoked, the:
  299. .RS 4
  300. .sp
  301. .RS 4
  302. .nf
  303. rm "$path.out" > "$path.out"
  304. .fi
  305. .P
  306. .RE
  307. .P
  308. should be replaced with:
  309. .sp
  310. .RS 4
  311. .nf
  312. > "$path.out"
  313. .fi
  314. .P
  315. .RE
  316. .P
  317. which verifies that the file did not already exist, but leaves
  318. .BR $path.out
  319. in place for use by
  320. .BR PROCESSING .
  321. .RE
  322. .RE
  323. .SH RATIONALE
  324. The
  325. .IR pathchk
  326. utility was new for the ISO\ POSIX\(hy2:\|1993 standard. It, along with the
  327. .IR set
  328. .BR \-C (\c
  329. .IR noclobber )
  330. option added to the shell, replaces the
  331. .IR mktemp ,
  332. .IR validfnam ,
  333. and
  334. .IR create
  335. utilities that appeared in early proposals. All of these utilities were
  336. attempts to solve several common problems:
  337. .IP " *" 4
  338. Verify the validity (for several different definitions of ``valid'') of
  339. a pathname supplied by a user, generated by an application, or imported
  340. from an external source.
  341. .IP " *" 4
  342. Atomically create a file.
  343. .IP " *" 4
  344. Perform various string handling functions to generate a temporary
  345. filename.
  346. .P
  347. The
  348. .IR create
  349. utility, included in an early proposal, provided checking and atomic
  350. creation in a single invocation of the utility; these are orthogonal
  351. issues and need not be grouped into a single utility. Note that the
  352. .IR noclobber
  353. option also provides a way of creating a lock for process
  354. synchronization; since it provides an atomic
  355. .IR create ,
  356. there is no race between a test for existence and the following
  357. creation if it did not exist.
  358. .P
  359. Having a function like
  360. \fItmpnam\fR()
  361. in the ISO\ C standard is important in many high-level languages. The shell
  362. programming language, however, has built-in string manipulation
  363. facilities, making it very easy to construct temporary filenames. The
  364. names needed obviously depend on the application, but are frequently of
  365. a form similar to:
  366. .sp
  367. .RS 4
  368. .nf
  369. \fB$TMPDIR/\fIapplication_abbreviation\fB$$.\fIsuffix\fR
  370. .fi
  371. .P
  372. .RE
  373. .P
  374. In cases where there is likely to be contention for a given suffix, a
  375. simple shell
  376. .BR for
  377. or
  378. .BR while
  379. loop can be used with the shell
  380. .IR noclobber
  381. option to create a file without risk of collisions, as long as
  382. applications trying to use the same filename name space are cooperating
  383. on the use of files after they have been created.
  384. .P
  385. For historical purposes,
  386. .BR \-p
  387. does not check for the use of the
  388. <hyphen-minus>
  389. character as the first character in a component of the pathname, or for
  390. an empty
  391. .IR pathname
  392. operand.
  393. .SH "FUTURE DIRECTIONS"
  394. None.
  395. .SH "SEE ALSO"
  396. .IR "Section 2.7" ", " "Redirection",
  397. .IR "\fIset\fR\^",
  398. .IR "\fItest\fR\^"
  399. .P
  400. The Base Definitions volume of POSIX.1\(hy2017,
  401. .IR "Chapter 8" ", " "Environment Variables",
  402. .IR "Section 12.2" ", " "Utility Syntax Guidelines",
  403. .IR "\fB<limits.h>\fP"
  404. .\"
  405. .SH COPYRIGHT
  406. Portions of this text are reprinted and reproduced in electronic form
  407. from IEEE Std 1003.1-2017, Standard for Information Technology
  408. -- Portable Operating System Interface (POSIX), The Open Group Base
  409. Specifications Issue 7, 2018 Edition,
  410. Copyright (C) 2018 by the Institute of
  411. Electrical and Electronics Engineers, Inc and The Open Group.
  412. In the event of any discrepancy between this version and the original IEEE and
  413. The Open Group Standard, the original IEEE and The Open Group Standard
  414. is the referee document. The original Standard can be obtained online at
  415. http://www.opengroup.org/unix/online.html .
  416. .PP
  417. Any typographical or formatting errors that appear
  418. in this page are most likely
  419. to have been introduced during the conversion of the source files to
  420. man page format. To report such errors, see
  421. https://www.kernel.org/doc/man-pages/reporting_bugs.html .