version 1.53, 2015/10/17 04:41:37 |
version 1.54, 2015/11/13 08:30:18 |
|
|
int |
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
int opt, pair[2], fd, idx, mode; |
int opt, pair[2], fd, idx, mode, error; |
char *home; |
char *home; |
struct passwd *pw; |
struct passwd *pw; |
struct imsgbuf ibuf; |
struct imsgbuf ibuf; |
|
|
msg.error = errno; |
msg.error = errno; |
} else |
} else |
fd = STDIN_FILENO; |
fd = STDIN_FILENO; |
} else if (lstat(argv[idx], &msg.sb) == -1) { |
|
fd = -1; |
|
msg.error = errno; |
|
} else { |
} else { |
/* |
if (Lflag) |
* pledge(2) doesn't let us pass directory file |
error = stat(argv[idx], &msg.sb); |
* descriptors around - but in fact we don't need them, |
else |
* so just don't open directories or symlinks (which |
error = lstat(argv[idx], &msg.sb); |
* could be to directories). |
if (error == -1) { |
*/ |
|
mode = msg.sb.st_mode; |
|
if (!S_ISDIR(mode) && !S_ISLNK(mode)) { |
|
fd = open(argv[idx], O_RDONLY|O_NONBLOCK); |
|
if (fd == -1 && |
|
(errno == ENFILE || errno == EMFILE)) |
|
err(1, "open"); |
|
} else |
|
fd = -1; |
fd = -1; |
if (S_ISLNK(mode)) |
msg.error = errno; |
read_link(&msg, argv[idx]); |
} else { |
|
/* |
|
* pledge(2) doesn't let us pass directory file |
|
* descriptors around - but in fact we don't |
|
* need them, so just don't open directories or |
|
* symlinks (which could be to directories). |
|
*/ |
|
mode = msg.sb.st_mode; |
|
if (!S_ISDIR(mode) && !S_ISLNK(mode)) { |
|
fd = open(argv[idx], |
|
O_RDONLY|O_NONBLOCK); |
|
if (fd == -1 && (errno == ENFILE || |
|
errno == EMFILE)) |
|
err(1, "open"); |
|
} else |
|
fd = -1; |
|
if (S_ISLNK(mode)) |
|
read_link(&msg, argv[idx]); |
|
} |
} |
} |
send_message(&ibuf, &msg, sizeof msg, fd); |
send_message(&ibuf, &msg, sizeof msg, fd); |
|
|
|
|
free(copy); |
free(copy); |
} |
} |
|
|
if (Lflag) { |
if (!Lflag && stat(path, &sb) == -1) |
if (stat(path, &msg->sb) == -1) |
msg->link_target = errno; |
msg->error = errno; |
|
} else { |
|
if (stat(path, &sb) == -1) |
|
msg->link_target = errno; |
|
} |
|
} |
} |
|
|
static __dead void |
static __dead void |