]> git.cameronkatri.com Git - freebsd-patches.git/blob - mount-8-Add-libxo-3-support.patch
Remove mandoc man(1) patch
[freebsd-patches.git] / mount-8-Add-libxo-3-support.patch
1 From 9d8571e84bf2c006b5053a776358c148b641a48f Mon Sep 17 00:00:00 2001
2 From: Cameron Katri <me@cameronkatri.com>
3 Date: Thu, 20 May 2021 15:04:10 -0400
4 Subject: [PATCH] mount(8): Add libxo(3) support
5
6 ---
7 sbin/mount/Makefile | 2 +-
8 sbin/mount/mount.8 | 14 ++++-
9 sbin/mount/mount.c | 150 ++++++++++++++++++++++++++++----------------
10 3 files changed, 111 insertions(+), 55 deletions(-)
11
12 diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile
13 index 68c7ee9819d..34ba498a2a3 100644
14 --- a/sbin/mount/Makefile
15 +++ b/sbin/mount/Makefile
16 @@ -7,6 +7,6 @@ SRCS= mount.c mount_fs.c getmntopts.c vfslist.c
17 MAN= mount.8
18 # We do NOT install the getmntopts.3 man page.
19
20 -LIBADD= util
21 +LIBADD= util xo
22
23 .include <bsd.prog.mk>
24 diff --git a/sbin/mount/mount.8 b/sbin/mount/mount.8
25 index 3aee1bb8615..59a0f6bb032 100644
26 --- a/sbin/mount/mount.8
27 +++ b/sbin/mount/mount.8
28 @@ -28,7 +28,7 @@
29 .\" @(#)mount.8 8.8 (Berkeley) 6/16/94
30 .\" $FreeBSD$
31 .\"
32 -.Dd August 28, 2019
33 +.Dd May 18, 2021
34 .Dt MOUNT 8
35 .Os
36 .Sh NAME
37 @@ -36,14 +36,17 @@
38 .Nd mount file systems
39 .Sh SYNOPSIS
40 .Nm
41 +.Op Fl -libxo
42 .Op Fl adflpruvw
43 .Op Fl F Ar fstab
44 .Op Fl o Ar options
45 .Op Fl t Oo Cm no Oc Ns Cm Ar type Ns Op Cm , Ns Ar type ...
46 .Nm
47 +.Op Fl -libxo
48 .Op Fl dfpruvw
49 .Ar special | node
50 .Nm
51 +.Op Fl -libxo
52 .Op Fl dfpruvw
53 .Op Fl o Ar options
54 .Op Fl t Oo Cm no Oc Ns Cm Ar type Ns Op Cm , Ns Ar type ...
55 @@ -72,6 +75,13 @@ this list is printed.
56 .Pp
57 The options are as follows:
58 .Bl -tag -width indent
59 +.It Fl -libxo
60 +Generate output via
61 +.Xr libxo 3
62 +in a selection of different human and machine readable formats.
63 +See
64 +.Xr xo_parse_args 3
65 +for details on command line arguments.
66 .It Fl a
67 All the file systems described in
68 .Xr fstab 5
69 @@ -552,6 +562,8 @@ support for a particular file system might be provided either on a static
70 .Xr setfacl 1 ,
71 .Xr nmount 2 ,
72 .Xr acl 3 ,
73 +.Xr libxo 3 ,
74 +.Xr xo_parse_args 3 ,
75 .Xr mac 4 ,
76 .Xr cd9660 5 ,
77 .Xr devfs 5 ,
78 diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
79 index fad999c97dc..de30dd39afe 100644
80 --- a/sbin/mount/mount.c
81 +++ b/sbin/mount/mount.c
82 @@ -60,11 +60,18 @@ __FBSDID("$FreeBSD$");
83 #include <string.h>
84 #include <unistd.h>
85 #include <libutil.h>
86 +#include <libxo/xo.h>
87
88 #include "extern.h"
89 #include "mntopts.h"
90 #include "pathnames.h"
91
92 +#define EXIT(a) { \
93 + xo_close_container("mount"); \
94 + xo_finish(); \
95 + exit(a); \
96 + }
97 +
98 /* `meta' options */
99 #define MOUNT_META_OPTION_FSTAB "fstab"
100 #define MOUNT_META_OPTION_CURRENT "current"
101 @@ -146,21 +153,21 @@ exec_mountprog(const char *name, const char *execname, char *const argv[])
102
103 switch (pid = fork()) {
104 case -1: /* Error. */
105 - warn("fork");
106 - exit (1);
107 + xo_warn("fork");
108 + EXIT(1);
109 case 0: /* Child. */
110 /* Go find an executable. */
111 execvP(execname, _PATH_SYSPATH, argv);
112 if (errno == ENOENT) {
113 - warn("exec %s not found", execname);
114 + xo_warn("exec %s not found", execname);
115 if (execname[0] != '/') {
116 - warnx("in path: %s", _PATH_SYSPATH);
117 + xo_warnx("in path: %s", _PATH_SYSPATH);
118 }
119 }
120 - exit(1);
121 + EXIT(1);
122 default: /* Parent. */
123 if (waitpid(pid, &status, 0) < 0) {
124 - warn("waitpid");
125 + xo_warn("waitpid");
126 return (1);
127 }
128
129 @@ -168,7 +175,7 @@ exec_mountprog(const char *name, const char *execname, char *const argv[])
130 if (WEXITSTATUS(status) != 0)
131 return (WEXITSTATUS(status));
132 } else if (WIFSIGNALED(status)) {
133 - warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
134 + xo_warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
135 return (1);
136 }
137 break;
138 @@ -185,7 +192,7 @@ specified_ro(const char *arg)
139
140 optbuf = strdup(arg);
141 if (optbuf == NULL)
142 - err(1, NULL);
143 + xo_err(1, NULL);
144
145 for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
146 if (strcmp(opt, "ro") == 0) {
147 @@ -220,13 +227,13 @@ restart_mountd(void)
148 * happened due to the bugs in pidfile(3).
149 */
150 if (mountdpid <= 0) {
151 - warnx("mountd pid %d, refusing to send SIGHUP", mountdpid);
152 + xo_warnx("mountd pid %d, refusing to send SIGHUP", mountdpid);
153 return;
154 }
155
156 /* We have mountd(8) PID in mountdpid varible, let's signal it. */
157 if (kill(mountdpid, SIGHUP) == -1)
158 - err(1, "signal mountd");
159 + xo_err(1, "signal mountd");
160 }
161
162 int
163 @@ -244,6 +251,12 @@ main(int argc, char *argv[])
164 options = NULL;
165 vfslist = NULL;
166 vfstype = "ufs";
167 +
168 + argc = xo_parse_args(argc, argv);
169 + if (argc < 0)
170 + return (argc);
171 + xo_open_container("mount");
172 +
173 while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1)
174 switch (ch) {
175 case 'a':
176 @@ -285,7 +298,7 @@ main(int argc, char *argv[])
177 break;
178 case 't':
179 if (vfslist != NULL)
180 - errx(1, "only one -t option may be specified");
181 + xo_errx(1, "only one -t option may be specified");
182 vfslist = makevfslist(optarg);
183 vfstype = optarg;
184 break;
185 @@ -318,7 +331,7 @@ main(int argc, char *argv[])
186 case 0:
187 if ((mntsize = getmntinfo(&mntbuf,
188 verbose ? MNT_WAIT : MNT_NOWAIT)) == 0)
189 - err(1, "getmntinfo");
190 + xo_err(1, "getmntinfo");
191 if (all) {
192 while ((fs = getfsent()) != NULL) {
193 if (BADTYPE(fs->fs_type))
194 @@ -347,12 +360,17 @@ main(int argc, char *argv[])
195 rval = 1;
196 }
197 } else if (fstab_style) {
198 + xo_open_list("fstab");
199 for (i = 0; i < mntsize; i++) {
200 if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
201 continue;
202 + xo_open_instance("fstab");
203 putfsent(&mntbuf[i]);
204 + xo_close_instance("fstab");
205 }
206 + xo_close_list("fstab");
207 } else {
208 + xo_open_list("mounted");
209 for (i = 0; i < mntsize; i++) {
210 if (checkvfsname(mntbuf[i].f_fstypename,
211 vfslist))
212 @@ -360,10 +378,13 @@ main(int argc, char *argv[])
213 if (!verbose &&
214 (mntbuf[i].f_flags & MNT_IGNORE) != 0)
215 continue;
216 + xo_open_instance("mounted");
217 prmount(&mntbuf[i]);
218 + xo_close_instance("mounted");
219 }
220 + xo_close_list("mounted");
221 }
222 - exit(rval);
223 + EXIT(rval);
224 case 1:
225 if (vfslist != NULL)
226 usage();
227 @@ -373,7 +394,7 @@ main(int argc, char *argv[])
228 mntfromname = NULL;
229 have_fstab = 0;
230 if ((mntbuf = getmntpt(*argv)) == NULL)
231 - errx(1, "not currently mounted %s", *argv);
232 + xo_errx(1, "not currently mounted %s", *argv);
233 /*
234 * Only get the mntflags from fstab if both mntpoint
235 * and mntspec are identical. Also handle the special
236 @@ -411,10 +432,10 @@ main(int argc, char *argv[])
237 }
238 if ((fs = getfsfile(*argv)) == NULL &&
239 (fs = getfsspec(*argv)) == NULL)
240 - errx(1, "%s: unknown special file or file system",
241 + xo_errx(1, "%s: unknown special file or file system",
242 *argv);
243 if (BADTYPE(fs->fs_type))
244 - errx(1, "%s has unknown file system type",
245 + xo_errx(1, "%s has unknown file system type",
246 *argv);
247 rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
248 init_flags, options, fs->fs_mntops);
249 @@ -460,7 +481,7 @@ main(int argc, char *argv[])
250 if (rval == 0 && getuid() == 0)
251 restart_mountd();
252
253 - exit(rval);
254 + EXIT(rval);
255 }
256
257 int
258 @@ -537,7 +558,7 @@ append_arg(struct cpa *sa, char *arg)
259 sa->sz = sa->sz == 0 ? 8 : sa->sz * 2;
260 sa->a = realloc(sa->a, sizeof(*sa->a) * sa->sz);
261 if (sa->a == NULL)
262 - errx(1, "realloc failed");
263 + xo_errx(1, "realloc failed");
264 }
265 sa->a[++sa->c] = arg;
266 }
267 @@ -553,7 +574,7 @@ mountfs(const char *vfstype, const char *spec, const char *name, int flags,
268
269 /* resolve the mountpoint with realpath(3) */
270 if (checkpath(name, mntpath) != 0) {
271 - warn("%s", mntpath);
272 + xo_warn("%s", mntpath);
273 return (1);
274 }
275 name = mntpath;
276 @@ -596,12 +617,12 @@ mountfs(const char *vfstype, const char *spec, const char *name, int flags,
277
278 if (debug) {
279 if (use_mountprog(vfstype))
280 - printf("exec: %s", execname);
281 + xo_emit("{Lwc:exec}{:execname/%s}", execname);
282 else
283 - printf("mount -t %s", vfstype);
284 + xo_emit("{:execname/mount}{P: }{l:opts/-t}{P: }{l:opts/%s}", vfstype);
285 for (i = 1; i < mnt_argv.c; i++)
286 - (void)printf(" %s", mnt_argv.a[i]);
287 - (void)printf("\n");
288 + xo_emit("{P: }{l:opts}", mnt_argv.a[i]);
289 + xo_emit("\n");
290 free(optbuf);
291 free(mountprog);
292 mountprog = NULL;
293 @@ -620,13 +641,22 @@ mountfs(const char *vfstype, const char *spec, const char *name, int flags,
294
295 if (verbose) {
296 if (statfs(name, &sf) < 0) {
297 - warn("statfs %s", name);
298 + xo_warn("statfs %s", name);
299 return (1);
300 }
301 - if (fstab_style)
302 + if (fstab_style) {
303 + xo_open_list("fstab");
304 + xo_open_instance("fstab");
305 putfsent(&sf);
306 - else
307 + xo_close_instance("fstab");
308 + xo_close_list("fstab");
309 + } else {
310 + xo_open_list("mounted");
311 + xo_open_instance("mounted");
312 prmount(&sf);
313 + xo_close_instance("mounted");
314 + xo_close_list("mounted");
315 + }
316 }
317
318 return (ret);
319 @@ -639,14 +669,15 @@ prmount(struct statfs *sfp)
320 unsigned int i;
321 struct mntoptnames *o;
322 struct passwd *pw;
323 + char *fsidbuf;
324
325 - (void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname,
326 - sfp->f_fstypename);
327 + xo_emit("{:special}{L: on }{:node}{L: (}{:fstype}", sfp->f_mntfromname,
328 + sfp->f_mntonname, sfp->f_fstypename);
329
330 flags = sfp->f_flags & MNT_VISFLAGMASK;
331 for (o = optnames; flags != 0 && o->o_opt != 0; o++)
332 if (flags & o->o_opt) {
333 - (void)printf(", %s", o->o_name);
334 + xo_emit("{D:, }{l:opts}", o->o_name);
335 flags &= ~o->o_opt;
336 }
337 /*
338 @@ -654,28 +685,37 @@ prmount(struct statfs *sfp)
339 * or privileged non-root user.
340 */
341 if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) {
342 - (void)printf(", mounted by ");
343 + xo_emit("{D:, }{L:mounted by }");
344 if ((pw = getpwuid(sfp->f_owner)) != NULL)
345 - (void)printf("%s", pw->pw_name);
346 + xo_emit("{:mounter}", pw->pw_name);
347 else
348 - (void)printf("%d", sfp->f_owner);
349 + xo_emit("{:mounter}", sfp->f_owner);
350 }
351 if (verbose) {
352 - if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
353 - (void)printf(", writes: sync %ju async %ju",
354 + if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0) {
355 + xo_open_container("writes");
356 + xo_emit("{D:, }{Lwc:writes}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}",
357 (uintmax_t)sfp->f_syncwrites,
358 (uintmax_t)sfp->f_asyncwrites);
359 - if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0)
360 - (void)printf(", reads: sync %ju async %ju",
361 + xo_close_container("writes");
362 + }
363 + if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0) {
364 + xo_open_container("reads");
365 + xo_emit("{D:, }{Lwc:reads}{Lw:sync}{w:sync/%ju}{Lw:async}{:async/%ju}",
366 (uintmax_t)sfp->f_syncreads,
367 (uintmax_t)sfp->f_asyncreads);
368 + xo_close_container("reads");
369 + }
370 if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
371 - (void)printf(", fsid ");
372 + xo_emit("{D:, }{Lw:fsid}");
373 + fsidbuf = strdup("");
374 for (i = 0; i < sizeof(sfp->f_fsid); i++)
375 - (void)printf("%02x", ((u_char *)&sfp->f_fsid)[i]);
376 + asprintf(&fsidbuf, "%s%02x", fsidbuf, ((u_char *)&sfp->f_fsid)[i]);
377 + xo_emit("{:fsid}", fsidbuf);
378 + free(fsidbuf);
379 }
380 }
381 - (void)printf(")\n");
382 + xo_emit("{D:)}\n");
383 }
384
385 struct statfs *
386 @@ -703,7 +743,7 @@ catopt(char *s0, const char *s1)
387
388 if (s0 && *s0) {
389 if (asprintf(&cp, "%s,%s", s0, s1) == -1)
390 - errx(1, "asprintf failed");
391 + xo_errx(1, "asprintf failed");
392 } else
393 cp = strdup(s1);
394
395 @@ -758,7 +798,7 @@ mangle(char *options, struct cpa *a)
396 }
397
398 if (mountprog == NULL) {
399 - errx(1, "Need value for -o mountprog");
400 + xo_errx(1, "Need value for -o mountprog");
401 }
402 continue;
403 } else if (strcmp(p, "userquota") == 0) {
404 @@ -824,7 +864,7 @@ update_options(char *opts, char *fstab, int curflags)
405 newopt = NULL;
406 for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
407 if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
408 - errx(1, "malloc failed");
409 + xo_errx(1, "malloc failed");
410
411 strcpy(tmpopt, "no");
412 strcat(tmpopt, o);
413 @@ -867,11 +907,11 @@ void
414 usage(void)
415 {
416
417 - (void)fprintf(stderr, "%s\n%s\n%s\n",
418 + xo_error("%s\n%s\n%s\n",
419 "usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
420 " mount [-dfpruvw] special | node",
421 " mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
422 - exit(1);
423 + EXIT(1);
424 }
425
426 void
427 @@ -899,32 +939,36 @@ putfsent(struct statfs *ent)
428 }
429
430 l = strlen(ent->f_mntfromname);
431 - printf("%s%s%s%s", ent->f_mntfromname,
432 + xo_emit("{:device}{P:/%s}{P:/%s}{P:/%s}",
433 + ent->f_mntfromname,
434 l < 8 ? "\t" : "",
435 l < 16 ? "\t" : "",
436 l < 24 ? "\t" : " ");
437 l = strlen(ent->f_mntonname);
438 - printf("%s%s%s%s", ent->f_mntonname,
439 + xo_emit("{:mntpoint}{P:/%s}{P:/%s}{P:/%s}",
440 + ent->f_mntonname,
441 l < 8 ? "\t" : "",
442 l < 16 ? "\t" : "",
443 l < 24 ? "\t" : " ");
444 - printf("%s\t", ent->f_fstypename);
445 + xo_emit("{:fstype}{P:\t}", ent->f_fstypename);
446 l = strlen(opts);
447 - printf("%s%s", opts,
448 + xo_emit("{:opts}{P:/%s}", opts,
449 l < 8 ? "\t" : " ");
450 free(opts);
451
452 if ((fst = getfsspec(ent->f_mntfromname)))
453 - printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
454 + xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n",
455 + fst->fs_freq, fst->fs_passno);
456 else if ((fst = getfsfile(ent->f_mntonname)))
457 - printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
458 + xo_emit("{P:\t}{n:dump/%u}{P: }{n:pass/%u}\n",
459 + fst->fs_freq, fst->fs_passno);
460 else if (strcmp(ent->f_fstypename, "ufs") == 0) {
461 if (strcmp(ent->f_mntonname, "/") == 0)
462 - printf("\t1 1\n");
463 + xo_emit("{P:\t}{n:dump/1}{P: }{n:pass/1}\n");
464 else
465 - printf("\t2 2\n");
466 + xo_emit("{P:\t}{n:dump/2}{P: }{n:pass/2}\n");
467 } else
468 - printf("\t0 0\n");
469 + xo_emit("{P:\t}{n:dump/0}{P: }{n:pass/0}\n");
470 }
471
472
473 --
474 2.31.1
475