Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/dialects/darwin/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ static void process_pipe_common(struct lsof_context *ctx,
size_t sz;

Lf->type = LSOF_FILE_PIPE;
enter_file_info(ctx, &pi->pfi);
/*
* Enter the pipe handle as the device.
*/
Expand Down
37 changes: 34 additions & 3 deletions tests/LTbasic2.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,27 @@ int main(int argc, char **argv) {
struct stat cwd_stat;
struct stat tmp_stat;
int fd;
int pipefd[2], pipes_found, pipes_seen;
int round;
int status = 0;
int exec_found; /* executable found in result */
int cwd_found; /* cwd found in result */
int fd_found; /* opened fd found in result */

if (pipe(pipefd)) {
perror("pipe");
return 1;
}

for (round = 0; round < 3; round++) {
printf("Testing round %d\n", round);

exec_found = 0;
cwd_found = 0;
fd_found = 0;
fd = -1;
pipes_found = 0;
pipes_seen = 0;
if (stat(argv[0], &exec_stat)) {
fprintf(stderr, "Cannot stat %s, skipping executable check\n",
argv[0]);
Expand Down Expand Up @@ -116,6 +125,20 @@ int main(int argc, char **argv) {
cwd_found = 1;
}
} else if (f->fd_type == LSOF_FD_NUMERIC) {
/* Use the actual modes: Solaris pipes are bidirectional. */
for (int i = 0; i < 2; i++) {
if (p->pid == getpid() && f->fd_num == pipefd[i]) {
int flags = fcntl(pipefd[i], F_GETFL);
pipes_seen |= 1 << i;
int mode = flags & O_ACCMODE;
enum lsof_file_access_mode access =
mode == O_RDONLY ? LSOF_FILE_ACCESS_READ :
mode == O_WRONLY ? LSOF_FILE_ACCESS_WRITE :
LSOF_FILE_ACCESS_READ_WRITE;
if (flags != -1 && f->access == access)
pipes_found |= 1 << i;
}
}
/* check if fd matches */
if (f->fd_num == fd && f->inode == tmp_stat.st_ino &&
f->dev == tmp_stat.st_dev) {
Expand Down Expand Up @@ -148,14 +171,22 @@ int main(int argc, char **argv) {
if (!fd_found) {
fprintf(stderr, "ERROR!!! opened regular file wasn't found.\n");
}
/* Some dialects do not report pipes; check the ones they report. */
if (pipes_seen && pipes_found != pipes_seen)
fprintf(stderr,
"ERROR!!! pipe access modes missing or incorrect.\n");
/* cleanup created temporary file */
if (fd >= 0) {
close(fd);
unlink("LTbasic2-tmp");
}
if (!(exec_found && cwd_found && fd_found)) {
return 1;
if (!(exec_found && cwd_found && fd_found &&
(!pipes_seen || pipes_found == pipes_seen))) {
status = 1;
break;
}
}
return 0;
close(pipefd[0]);
close(pipefd[1]);
return status;
}
Loading