Esempio n. 1
0
static void print_service_line(Config *config, char c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, int nl) {
    char ifname[IF_NAMESIZE];

#if defined(HAVE_GDBM) || defined(HAVE_DBM)
    if (!config->no_db_lookup)
        type = stdb_lookup(type);
#endif

    if (config->parsable) {
        char sn[AVAHI_DOMAIN_NAME_MAX], *e = sn;
        size_t l = sizeof(sn);

        printf("%c;%s;%s;%s;%s;%s%s",
               c,
               interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : ("n/a"),
               protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : ("n/a"),
               avahi_escape_label(name, strlen(name), &e, &l), type, domain, nl ? "\n" : "");

    } else {
        char label[AVAHI_LABEL_MAX];
        make_printable(name, label);

        printf("%c %6s %4s %-*s %-20s %s\n",
               c,
               interface != AVAHI_IF_UNSPEC ? if_indextoname(interface, ifname) : ("n/a"),
               protocol != AVAHI_PROTO_UNSPEC ? avahi_proto_to_string(protocol) : ("n/a"),
               n_columns-35, label, type, domain);
    }

    fflush(stdout);
}
Esempio n. 2
0
char *
getmnton(struct mount *m, struct namecache_list *ncplist, struct nchandle *ncr)
{
    static struct mount mount_l;
    static struct mtab {
        struct mtab *next;
        struct mount *m;
        char mntonname[MNAMELEN];
    } *mhead = NULL;
    struct mtab *mt;
    struct namecache *ncp;
    struct namecache ncp_copy;
    static char path[1024];
    int i;

    /*
     * If no ncp is passed try to find one via ncplist.  Make sure
     * we are using the correct mount pointer or the matching code
     * will not know how to transition mount points properly.
     */
    if (ncr == NULL || ncr->ncp == NULL) {
        ncp = ncplist->tqh_first;
    } else {
        ncp = ncr->ncp;
        if (ncr->mount)
            m = ncr->mount;
    }

    /*
     * If we have an ncp, traceback the path.  This is a kvm pointer.
     */
    if (ncp) {
        if (!kread(m, &mount_l, sizeof(struct mount))) {
            warnx("can't read mount table at %p", (void *)m);
            return (NULL);
        }
        i = sizeof(path) - 1;
        path[i] = 0;
        while (ncp) {
            /*
             * If this is the root of the mount then traverse
             * to the parent mount.
             */
            if (ncp == mount_l.mnt_ncmountpt.ncp) {
                ncp = mount_l.mnt_ncmounton.ncp;
                if (ncp == NULL)
                    break;
                m = mount_l.mnt_ncmounton.mount;
                if (!kread(m, &mount_l, sizeof(struct mount))) {
                    warnx("can't read mount table at %p", (void *)m);
                    return (NULL);
                }
            }

            /*
             * Ok, pull out the ncp and extract the name
             */
            if (!kread(ncp, &ncp_copy, sizeof(ncp_copy))) {
                warnx("can't read ncp at %p", ncp);
                return (NULL);
            }
            if (i <= ncp_copy.nc_nlen)
                break;
            i -= ncp_copy.nc_nlen;
            if (!kread(ncp_copy.nc_name, path + i, ncp_copy.nc_nlen)) {
                warnx("can't read ncp %p path component at %p", ncp, ncp_copy.nc_name);
                return (NULL);
            }
            make_printable(path + i, ncp_copy.nc_nlen);
            path[--i] = '/';
            ncp = ncp_copy.nc_parent;
        }
        if (i == sizeof(path) - 1)
            path[--i] = '/';
        return(path + i);
    }

    /*
     * If all else fails print out the mount point path
     */
    for (mt = mhead; mt != NULL; mt = mt->next) {
        if (m == mt->m)
            return (mt->mntonname);
    }
    if (!kread(m, &mount_l, sizeof(struct mount))) {
        warnx("can't read mount table at %p", (void *)m);
        return (NULL);
    }
    if ((mt = malloc(sizeof (struct mtab))) == NULL)
        err(1, NULL);
    mt->m = m;
    bcopy(&mount_l.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN);
    mt->next = mhead;
    mhead = mt;
    return (mt->mntonname);
}
Esempio n. 3
0
/*
 * print open files attributed to this process
 */
void
dofiles(struct kinfo_proc *kp, struct proc *p)
{
    int i;
    struct file file;
    struct filedesc filed;
    struct ktrace_node ktrace_node;

    Uname = user_from_uid(kp->kp_uid, 0);
    Pid = kp->kp_pid;
    Comm = kp->kp_comm;
    make_printable(Comm, strlen(Comm));

    if (p->p_fd == NULL)
        return;
    if (!kread(p->p_fd, &filed, sizeof (filed))) {
        dprintf(stderr, "can't read filedesc at %p for pid %d\n",
                (void *)p->p_fd, Pid);
        return;
    }
    /*
     * root directory vnode, if one
     */
    if (filed.fd_rdir)
        vtrans(filed.fd_rdir, &filed.fd_nrdir, RDIR, FREAD, 0);
    /*
     * current working directory vnode
     */
    vtrans(filed.fd_cdir, &filed.fd_ncdir, CDIR, FREAD, 0);
    /*
     * ktrace vnode, if one
     */
    if (p->p_tracenode) {
        if (kread(p->p_tracenode, &ktrace_node, sizeof (ktrace_node)))
            vtrans(ktrace_node.kn_vp, NULL, TRACE, FREAD|FWRITE, 0);
    }
    /*
     * text vnode, if one
     */
    if (p->p_textvp)
        vtrans(p->p_textvp, NULL, TEXT, FREAD, 0);
    /*
     * open files
     */
    ALLOC_OFILES(filed.fd_lastfile+1);
    if (!kread(filed.fd_files, ofiles,
               (filed.fd_lastfile+1) * sizeof(struct fdnode))) {
        dprintf(stderr,
                "can't read file structures at %p for pid %d\n",
                (void *)filed.fd_files, Pid);
        return;
    }
    for (i = 0; i <= filed.fd_lastfile; i++) {
        if (ofiles[i].fp == NULL)
            continue;
        if (!kread(ofiles[i].fp, &file, sizeof (struct file))) {
            dprintf(stderr, "can't read file %d at %p for pid %d\n",
                    i, (void *)ofiles[i].fp, Pid);
            continue;
        }
        if (file.f_type == DTYPE_VNODE) {
            vtrans((struct vnode *)file.f_data, &file.f_nchandle,
                   i, file.f_flag, file.f_offset);
        } else if (file.f_type == DTYPE_SOCKET) {
            if (checkfile == 0)
                socktrans((struct socket *)file.f_data, i);
        }
#ifdef DTYPE_PIPE
        else if (file.f_type == DTYPE_PIPE) {
            if (checkfile == 0)
                pipetrans((struct pipe *)file.f_data, i,
                          file.f_flag);
        }
#endif
#ifdef DTYPE_FIFO
        else if (file.f_type == DTYPE_FIFO) {
            if (checkfile == 0)
                vtrans((struct vnode *)file.f_data,
                       &file.f_nchandle,
                       i, file.f_flag, file.f_offset);
        }
#endif
        else {
            dprintf(stderr,
                    "unknown file type %d for file %d of pid %d\n",
                    file.f_type, i, Pid);
        }
    }
}