34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * This file and its contents are supplied under the terms of the
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Common Development and Distribution License ("CDDL"), version 1.0.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * You may only use this file in accordance with the terms of version
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * 1.0 of the CDDL.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * A full copy of the text of the CDDL should have accompanied this
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * source. A copy of the CDDL is also available via the Internet at
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
dfc0fed81813380fb526f1a003d3be17ab26ce3bRobert Mustacchi * Copyright (c) 2013 Joyent, Inc. All Rights reserved.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Pfdinfo.c - obtain open file information.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Allocate an fd_info structure and stick it on the list.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * (Unless one already exists.) The list is sorted in
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * reverse order. We will traverse it in that order later.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * This makes the usual ordered insert *fast*.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore for (i = 0; i < P->num_fd; i++, fip = list_next(fip)) {
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore if ((fip = calloc(1, sizeof (*fip))) == NULL)
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore list_link(fip, next ? next : (void *)&(P->fd_head));
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Attempt to load the open file information from a live process.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * In the unlikely case there are *no* file descriptors open,
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * we will keep rescanning the proc directory, which will be empty.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * This is an edge case it isn't worth adding additional state to
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * to eliminate.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore if (P->state != PS_DEAD && P->state != PS_IDLE) {
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore * Try to get the path information first.
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore (void) snprintf(dir_name, sizeof (dir_name),
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore info->pr_fileflags = pr_fcntl(P, fd, F_GETXFL, 0);
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore info->pr_fdflags = pr_fcntl(P, fd, F_GETFD, 0);
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore info->pr_offset = pr_llseek(P, fd, 0, SEEK_CUR);
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore /* attempt to determine the path to it */
d907f8b938aec9d8b57fdb15c241b98641b8b052Dave Eddy /* not applicable */
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'AmorePfdinfo_iter(struct ps_prochandle *P, proc_fdinfo_f *func, void *cd)
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore /* Make sure we have live data, if appropriate */
34bdffbf3e3c188027e767e631f717b10159316dGarrett D'Amore /* NB: We walk the list backwards. */