chflags: Add SIGINFO support.

This is copied from chmod r311668.

MFC after:	2 weeks
This commit is contained in:
Bryan Drewery 2018-03-07 01:55:38 +00:00
parent 0cc4c55e45
commit fdee29d7d5
2 changed files with 26 additions and 3 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)chflags.1 8.4 (Berkeley) 5/2/95
.\" $FreeBSD$
.\"
.Dd March 4, 2018
.Dd March 6, 2018
.Dt CHFLAGS 1
.Os
.Sh NAME
@ -217,6 +217,16 @@ setting.
See
.Xr security 7
for more information on this setting.
.Pp
If
.Nm
receives a
.Dv SIGINFO
signal (see the
.Cm status
argument for
.Xr stty 1 ) ,
then the current filename as well as the old and new flags are displayed.
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO

View File

@ -51,13 +51,23 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static volatile sig_atomic_t siginfo;
static void usage(void);
static void
siginfo_handler(int sig __unused)
{
siginfo = 1;
}
int
main(int argc, char *argv[])
{
@ -108,6 +118,8 @@ main(int argc, char *argv[])
if (argc < 2)
usage();
(void)signal(SIGINFO, siginfo_handler);
if (Rflag) {
if (hflag)
errx(1, "the -R and -h options may not be "
@ -188,13 +200,14 @@ main(int argc, char *argv[])
atflag) == -1 && !fflag) {
warn("%s", p->fts_path);
rval = 1;
} else if (vflag) {
} else if (vflag || siginfo) {
(void)printf("%s", p->fts_path);
if (vflag > 1)
if (vflag > 1 || siginfo)
(void)printf(": 0%lo -> 0%lo",
(u_long)p->fts_statp->st_flags,
newflags);
(void)printf("\n");
siginfo = 0;
}
}
if (errno)