Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151879033
D55023.id170906.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D55023.id170906.diff
View Options
diff --git a/usr.bin/runat/runat.1.sav b/usr.bin/runat/runat.1
--- a/usr.bin/runat/runat.1.sav
+++ b/usr.bin/runat/runat.1
@@ -3,7 +3,7 @@
.\"
.\" SPDX-License-Identifier: BSD-2-Clause
.\"
-.Dd April 15, 2025
+.Dd January 30, 2026
.Dt RUNAT 1
.Os
.Sh NAME
@@ -11,8 +11,10 @@
.Nd run a shell command on a named attribute directory
.Sh SYNOPSIS
.Nm
-.Op Ar file
-.Op Ar shell command
+.Op Fl S
+.Op Fl Fl
+.Ar file
+.Ar shell-command
.Sh DESCRIPTION
The
.Nm
@@ -27,6 +29,19 @@
argument and then performs the shell command via
.Xr sh 1 .
.Pp
+The following options are available:
+.Bl -tag -width Ds
+.It Fl S, Fl Fl symlink
+.Ar file
+must be a symbolic link and the named attribute directory for the
+symbolic link is to be used.
+.It Fl Fl
+is the end of options and may be used to handle a
+.Ar file
+with a name that begins with
+.Dq - .
+.El
+.Pp
If a named attribute directory does not exist for
.Ar file ,
an empty one will be created.
@@ -50,6 +65,15 @@
$ runat myfile cp /etc/hosts attrhosts # creates attrhosts
$ runat myfile cat attrhosts # displays contents of attrhosts
.Ed
+.sp
+For a symbolic link called
+.Dq mysymlink :
+.Bd -literal
+$ runat mysymlink ls -l # lists the attributes for the
+ # file mysymlink refers to
+$ runat -S mysymlink ls -l # lists the attributes for the
+ # symbolic link mysymlink
+.Ed
.Sh SEE ALSO
.Xr sh 1 ,
.Xr fchdir 2 ,
diff --git a/usr.bin/runat/runat.c.sav b/usr.bin/runat/runat.c
--- a/usr.bin/runat/runat.c.sav
+++ b/usr.bin/runat/runat.c
@@ -5,20 +5,29 @@
*/
#include <sys/param.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
#include <fcntl.h>
+#include <getopt.h>
#include <paths.h>
#include <signal.h>
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+static struct option longopts[] = {
+ { "symlink", no_argument, NULL, 'S' },
+ { "-", no_argument, NULL, '-' },
+ { NULL, 0, NULL, 0}
+};
+
static void
usage(void)
{
- (void)fprintf(stderr, "usage: runat <file> "
+ (void)fprintf(stderr, "usage: runat [-S/--symlink] [--] <file> "
"<shell command>\n");
exit(1);
}
@@ -26,15 +35,29 @@
int
main(int argc, char *argv[])
{
- int i, file_fd, nameddir_fd, outsiz;
+ struct stat sb;
+ int ch, file_fd, flags, i, longindex, nameddir_fd, outsiz;
char *buf;
long named_enabled;
size_t pos, siz;
+ bool done_args;
- if (argc <= 2)
- usage();
- argv++;
- argc--;
+ flags = O_RDONLY | O_CLOEXEC;
+ done_args = false;
+ while (!done_args && (ch = getopt_long(argc, argv, "S-", longopts,
+ &longindex)) != -1)
+ switch (ch) {
+ case 'S':
+ flags |= O_NOFOLLOW | O_PATH;
+ break;
+ case '-':
+ done_args = true;
+ break;
+ default:
+ usage();
+ }
+ argv += optind;
+ argc -= optind;
if (argc < 2)
usage();
@@ -61,9 +84,16 @@
}
buf[pos - 1] = '\0';
- file_fd = open(argv[0], O_RDONLY | O_CLOEXEC, 0);
+ file_fd = open(argv[0], flags, 0);
if (file_fd < 0)
err(1, "Cannot open %s", argv[0]);
+ if ((flags & O_PATH) != 0) {
+ /* Check to ensure the file is a symbolic link. */
+ if (fstat(file_fd, &sb) < 0)
+ err(1, "Cannot stat symlink %s", argv[0]);
+ if (!S_ISLNK(sb.st_mode))
+ errx(1, "File %s is not a symbolic link", argv[0]);
+ }
nameddir_fd = openat(file_fd, ".", O_RDONLY | O_CLOEXEC | O_NAMEDATTR,
0);
if (nameddir_fd < 0)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 12, 7:32 AM (7 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28407202
Default Alt Text
D55023.id170906.diff (3 KB)
Attached To
Mode
D55023: runat: Add -h to manipulate a symbolic link's named attribute dir
Attached
Detach File
Event Timeline
Log In to Comment