예제 #1
0
int
main(int argc, char **argv)
{
    int numQueues;
    char **queues;
    struct queueInfoEnt *queueInfo;
    char lflag = FALSE;
    int cc;
    char *host;
    char *user;

    numQueues = 0;
    user = host = NULL;

    if (lsb_init(argv[0]) < 0) {
        lsb_perror("lsb_init");
        return -1;
    }

    while ((cc = getopt(argc, argv, "Vhlwm:u:")) != EOF) {
        switch (cc) {
            case 'l':
                lflag = TRUE;
                if (wflag) {
                    usage(argv[0]);
                    return -1;
                }
                break;
            case 'w':
                wflag = TRUE;
                if (lflag) {
                    usage(argv[0]);
                    return -1;
                }
                break;
            case 'm':
                if (host != NULL || *optarg == '\0')
                    usage(argv[0]);
                host = optarg;
                break;
            case 'u':
                if (user != NULL || *optarg == '\0')
                    usage(argv[0]);
                user = optarg;
                break;
            case 'V':
                fputs(_LS_VERSION_, stderr);
                return 0;
            case 'h':
            default:
                usage(argv[0]);
            return -1;
        }
    }

    queues = NULL;
    numQueues = 0;

    if (optind < argc) {
        numQueues = argc - optind;
        queues = calloc(argc - optind, sizeof(char *));
        for (cc = 0; cc < argc - optind; cc++)
            queues[cc] = argv[optind + cc];
    }

    TIMEIT(0, (queueInfo = lsb_queueinfo(queues,
                                         &numQueues,
                                         host,
                                         user,
                                         0)), "lsb_queueinfo");

    if (!queueInfo) {
        if (lsberrno == LSBE_BAD_QUEUE && queues)
            lsb_perror(queues[numQueues]);
        else {
            switch (lsberrno) {
                case LSBE_BAD_HOST   :
                case LSBE_QUEUE_HOST :
                    lsb_perror(host);
                    break;
                case LSBE_BAD_USER   :
                case LSBE_QUEUE_USE  :
                    lsb_perror(user);
                    break;
                default :
                    lsb_perror(NULL);
            }
        }
        _free_(queues);
        return -1;
    }

    if (lflag)
        prtQueuesLong(numQueues, queueInfo);
    else
        prtQueuesShort(numQueues, queueInfo);

    _free_(queues);

    return 0;
}
예제 #2
0
파일: bqueues.c 프로젝트: ryukun11/openlava
int
main(int argc, char **argv)
{
    int numQueues;
    char **queueNames=NULL, **queues = NULL;
    struct queueInfoEnt *queueInfo;
    char lflag = FALSE;
    int cc, defaultQ = FALSE;
    char *host = NULL, *user = NULL;
    int rc;

    numQueues = 0;

    rc = _i18n_init ( I18N_CAT_MIN );

    if (lsb_init(argv[0]) < 0) {
        lsb_perror("lsb_init");
        exit(-1);
    }

    while ((cc = getopt(argc, argv, "Vhlwm:u:")) != EOF) {
        switch (cc) {
        case 'l':
            lflag = TRUE;
            if (wflag)
                usage(argv[0]);
            break;
        case 'w':
            wflag = TRUE;
            if (lflag)
                usage(argv[0]);
            break;
        case 'm':
            if (host != NULL || *optarg == '\0')
                usage(argv[0]);
            host = optarg;
            break;
        case 'u':
            if (user != NULL || *optarg == '\0')
                usage(argv[0]);
            user = optarg;
            break;
        case 'V':
            fputs(_LS_VERSION_, stderr);
            exit(0);
        case 'h':
        default:
            usage(argv[0]);
        }
    }

    numQueues = getNames(argc,
                         argv,
                         optind,
                         &queueNames,
                         &defaultQ,
                         "queue");
    if (!defaultQ && numQueues != 0)
        queues = queueNames;
    else
        queues = NULL;

    TIMEIT(0, (queueInfo = lsb_queueinfo(queues,
                                         &numQueues,
                                         host,
                                         user,
                                         0)), "lsb_queueinfo");

    if (!queueInfo) {
        if (lsberrno == LSBE_BAD_QUEUE && queues)
            lsb_perror(queues[numQueues]);
        else {
            switch (lsberrno) {
            case LSBE_BAD_HOST   :
            case LSBE_QUEUE_HOST :
                lsb_perror (host);
                break;
            case LSBE_BAD_USER   :
            case LSBE_QUEUE_USE  :
                lsb_perror (user);
                break;
            default :
                lsb_perror (NULL);
            }
        }
        return -1;
    }

    if (lflag)
        prtQueuesLong(numQueues, queueInfo);
    else
        prtQueuesShort(numQueues, queueInfo);

    return 0;
}