svn commit: r311669 - head/usr.sbin/chown
Conrad E. Meyer
cem at FreeBSD.org
Sun Jan 8 06:58:44 UTC 2017
Author: cem
Date: Sun Jan 8 06:58:42 2017
New Revision: 311669
URL: https://svnweb.freebsd.org/changeset/base/311669
Log:
chown/chgrp: Add SIGINFO handler
PR: 191884
Submitted by: Dan McGregor <dan.mcgregor at usask.ca>
Reviewed by: mjg@ (earlier version)
Modified:
head/usr.sbin/chown/chgrp.1
head/usr.sbin/chown/chown.8
head/usr.sbin/chown/chown.c
Modified: head/usr.sbin/chown/chgrp.1
==============================================================================
--- head/usr.sbin/chown/chgrp.1 Sun Jan 8 06:50:53 2017 (r311668)
+++ head/usr.sbin/chown/chgrp.1 Sun Jan 8 06:58:42 2017 (r311669)
@@ -31,7 +31,7 @@
.\" @(#)chgrp.1 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd April 20, 2015
+.Dd January 7, 2017
.Dt CHGRP 1
.Os
.Sh NAME
@@ -120,6 +120,17 @@ The user invoking
.Nm
must belong to the specified group and be the owner of the file,
or be the super-user.
+.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 group names are
+displayed.
.Sh FILES
.Bl -tag -width /etc/group -compact
.It Pa /etc/group
Modified: head/usr.sbin/chown/chown.8
==============================================================================
--- head/usr.sbin/chown/chown.8 Sun Jan 8 06:50:53 2017 (r311668)
+++ head/usr.sbin/chown/chown.8 Sun Jan 8 06:58:42 2017 (r311669)
@@ -28,7 +28,7 @@
.\" @(#)chown.8 8.3 (Berkeley) 3/31/94
.\" $FreeBSD$
.\"
-.Dd April 20, 2015
+.Dd January 7, 2017
.Dt CHOWN 8
.Os
.Sh NAME
@@ -135,6 +135,17 @@ group name.
.Pp
The ownership of a file may only be altered by a super-user for
obvious security reasons.
+.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 file owner and group
+are displayed.
.Sh EXIT STATUS
.Ex -std
.Sh COMPATIBILITY
Modified: head/usr.sbin/chown/chown.c
==============================================================================
--- head/usr.sbin/chown/chown.c Sun Jan 8 06:50:53 2017 (r311668)
+++ head/usr.sbin/chown/chown.c Sun Jan 8 06:58:42 2017 (r311669)
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <grp.h>
#include <libgen.h>
#include <pwd.h>
+#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -63,11 +64,20 @@ static void a_uid(const char *);
static void chownerr(const char *);
static uid_t id(const char *, const char *);
static void usage(void);
+static void print_info(const FTSENT *, int);
static uid_t uid;
static gid_t gid;
static int ischown;
static const char *gname;
+static volatile sig_atomic_t siginfo;
+
+static void
+siginfo_handler(int sig __unused)
+{
+
+ siginfo = 1;
+}
int
main(int argc, char **argv)
@@ -119,6 +129,8 @@ main(int argc, char **argv)
if (argc < 2)
usage();
+ (void)signal(SIGINFO, siginfo_handler);
+
if (Rflag) {
if (hflag && (Hflag || Lflag))
errx(1, "the -R%c and -h options may not be "
@@ -189,6 +201,10 @@ main(int argc, char **argv)
default:
break;
}
+ if (siginfo) {
+ print_info(p, 2);
+ siginfo = 0;
+ }
if ((uid == (uid_t)-1 || uid == p->fts_statp->st_uid) &&
(gid == (gid_t)-1 || gid == p->fts_statp->st_gid))
continue;
@@ -196,35 +212,8 @@ main(int argc, char **argv)
== -1 && !fflag) {
chownerr(p->fts_path);
rval = 1;
- } else if (vflag) {
- printf("%s", p->fts_path);
- if (vflag > 1) {
- if (ischown) {
- printf(": %ju:%ju -> %ju:%ju",
- (uintmax_t)
- p->fts_statp->st_uid,
- (uintmax_t)
- p->fts_statp->st_gid,
- (uid == (uid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_uid :
- (uintmax_t)uid,
- (gid == (gid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_gid :
- (uintmax_t)gid);
- } else {
- printf(": %ju -> %ju",
- (uintmax_t)
- p->fts_statp->st_gid,
- (gid == (gid_t)-1) ?
- (uintmax_t)
- p->fts_statp->st_gid :
- (uintmax_t)gid);
- }
- }
- printf("\n");
- }
+ } else if (vflag)
+ print_info(p, vflag);
}
if (errno)
err(1, "fts_read");
@@ -315,3 +304,26 @@ usage(void)
"usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ...");
exit(1);
}
+
+static void
+print_info(const FTSENT *p, int vflag)
+{
+
+ printf("%s", p->fts_path);
+ if (vflag > 1) {
+ if (ischown) {
+ printf(": %ju:%ju -> %ju:%ju",
+ (uintmax_t)p->fts_statp->st_uid,
+ (uintmax_t)p->fts_statp->st_gid,
+ (uid == (uid_t)-1) ?
+ (uintmax_t)p->fts_statp->st_uid : (uintmax_t)uid,
+ (gid == (gid_t)-1) ?
+ (uintmax_t)p->fts_statp->st_gid : (uintmax_t)gid);
+ } else {
+ printf(": %ju -> %ju", (uintmax_t)p->fts_statp->st_gid,
+ (gid == (gid_t)-1) ?
+ (uintmax_t)p->fts_statp->st_gid : (uintmax_t)gid);
+ }
+ }
+ printf("\n");
+}
More information about the svn-src-head
mailing list