Exemplo n.º 1
0
static hostlist_t 
_read_genders_attr(char *attr, int iopt)
{
    FILE *f;
    hostlist_t hl = hostlist_create(NULL);
    char cmd[LINEBUFSIZE];
    char buf[LINEBUFSIZE];

    /* 
     *   xpopen sets uid back to real user id, so it is ok to use 
     *     "nodeattr" from user's path here
     */
    snprintf(cmd, sizeof(cmd), "%s %s%s -%sn %s", _PATH_NODEATTR, 
             gfile ? "-f " : "",
             gfile ? gfile : "",
             iopt ? "" : "r", attr);

    f = xpopen(cmd, "r");
    if (f == NULL)
        errx("%p: error running \"%s\"\n", _PATH_NODEATTR);
    while (fgets(buf, LINEBUFSIZE, f) != NULL) {
        xstrcln(buf, NULL);
        if (hostlist_push(hl, buf) <= 0)
            err("%p: warning: target `%s' not parsed\n", buf);
    }
    if (xpclose(f) != 0)
        errx("%p: error running nodeattr\n");

    return hl;
}
Exemplo n.º 2
0
static int
unixware_init(SCSI *usalp)
{
    FILE		*cmd;
    int		hba = 0, bus = 0, usal = 0, tgt = 0, lun = 0;
    int		nusal = -1, lhba = -1, lbus = 0;
    int		atapi, fd, nopen = 0, pos = 0, len = 0;
    int		s, t, l;
    int		scan_disks;
    char		lines[MAXLINE];
    char		class[MAXLINE];
    char		ident[MAXLINE];
    char		devnm[MAXPATH];
    char		dname[MAXPATH];
    struct stat 	stbuf;
    dev_t		ptdev, major, minor, node;
    char		**evsave;
    extern	char		**environ;

    /* Check for validity of primary hostbus adapter node */

    if (stat(PRIM_HBA, &stbuf) < 0) {
        if (usalp->errstr)
            snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
                     "Can not stat() primary hba (%s)",
                     PRIM_HBA);
        return (-1);
    }

    if (!S_ISCHR(stbuf.st_mode)) {
        if (usalp->errstr)
            snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
                     "Primary hba (%s) not a character device",
                     PRIM_HBA);
        return (-1);
    }

    major = getmajor(stbuf.st_rdev);

    /*
     * Check whether we want to scan all devices
     */
    if (getenv(SCAN_ALL) != NULL) {
        scan_disks = 1;
    } else {
        scan_disks = 0;
    }

    /* read pdiconfig output and get all attached scsi devices ! */

    evsave = environ;
    environ = 0;
    if ((cmd = xpopen(SCSI_CFG, "r")) == NULL) {
        if (usalp->errstr)
            snprintf(usalp->errstr, SCSI_ERRSTR_SIZE,
                     "Error popen() for \"%s\"",
                     SCSI_CFG);
        environ = evsave;
        return (-1);
    }
    environ = evsave;


    for (;;) {
        if (fgets(lines, MAXLINE, cmd) == NULL)
            break;

        memset(class, '\0', sizeof (class));
        memset(ident, '\0', sizeof (ident));

        if (lines[0] == ' ') {
            sscanf(lines, SCAN_DEV, &bus, &tgt, &lun, class, &pos);
            hba = lhba;
        } else {