libutil/recurse: Use a single path buffer, and directory fd
This way, we don't use PATH_MAX bytes on the stack per path component, and don't have to keep copying the complete path around.
This commit is contained in:
10
chown.c
10
chown.c
@@ -17,18 +17,18 @@ static gid_t gid = -1;
|
||||
static int ret = 0;
|
||||
|
||||
static void
|
||||
chownpwgr(const char *path, struct stat *st, void *data, struct recursor *r)
|
||||
chownpwgr(int dirfd, const char *name, struct stat *st, void *data, struct recursor *r)
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
if ((r->maxdepth == 0 && r->follow == 'P') || (r->follow == 'H' && r->depth) || (hflag && !(r->depth)))
|
||||
flags |= AT_SYMLINK_NOFOLLOW;
|
||||
|
||||
if (fchownat(AT_FDCWD, path, uid, gid, flags) < 0) {
|
||||
weprintf("chown %s:", path);
|
||||
if (fchownat(dirfd, name, uid, gid, flags) < 0) {
|
||||
weprintf("chown %s:", r->path);
|
||||
ret = 1;
|
||||
} else if (S_ISDIR(st->st_mode)) {
|
||||
recurse(path, NULL, r);
|
||||
recurse(dirfd, name, NULL, r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ main(int argc, char *argv[])
|
||||
usage();
|
||||
|
||||
for (argc--, argv++; *argv; argc--, argv++)
|
||||
recurse(*argv, NULL, &r);
|
||||
recurse(AT_FDCWD, *argv, NULL, &r);
|
||||
|
||||
return ret || recurse_status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user