Skip to content
Open
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
30 changes: 29 additions & 1 deletion tests/LTbasic2.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ 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 exec_found; /* executable found in result */
int cwd_found; /* cwd found in result */
Expand All @@ -64,6 +65,12 @@ int main(int argc, char **argv) {
cwd_found = 0;
fd_found = 0;
fd = -1;
pipes_found = 0;
pipes_seen = 0;
if (pipe(pipefd)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create pipe only once before loop?

perror("pipe");
return 1;
}
if (stat(argv[0], &exec_stat)) {
fprintf(stderr, "Cannot stat %s, skipping executable check\n",
argv[0]);
Expand Down Expand Up @@ -116,6 +123,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,12 +169,19 @@ 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)) {
close(pipefd[0]);
close(pipefd[1]);
if (!(exec_found && cwd_found && fd_found &&
(!pipes_seen || pipes_found == pipes_seen))) {
return 1;
}
}
Expand Down
Loading