~ubuntu-branches/ubuntu/maverick/libcgroup/maverick-proposed

« back to all changes in this revision

Viewing changes to src/tools/cgconfig.c

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-08-26 11:29:17 UTC
  • Revision ID: james.westby@ubuntu.com-20090826112917-402ews2uj6v350d2
Tags: upstream-0.34
ImportĀ upstreamĀ versionĀ 0.34

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Copyright IBM Corporation. 2007
 
4
 *
 
5
 * Authors:     Dhaval Giani <dhaval@linux.vnet.ibm.com>
 
6
 *              Balbir Singh <balbir@linux.vnet.ibm.com>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify it
 
9
 * under the terms of version 2.1 of the GNU Lesser General Public License
 
10
 * as published by the Free Software Foundation.
 
11
 *
 
12
 * This program is distributed in the hope that it would be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
 *
 
16
 * Code initiated and designed by Dhaval Giani. All faults are most likely
 
17
 * his mistake.
 
18
 */
 
19
 
 
20
#include <libcgroup.h>
 
21
#include <libcgroup-internal.h>
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include <errno.h>
 
26
#include <getopt.h>
 
27
 
 
28
 
 
29
static void usage(char *progname)
 
30
{
 
31
        printf("Usage: %s [OPTION] [FILE]\n", basename(progname));
 
32
        printf("Parse and load the specified cgroups configuration file\n");
 
33
        printf("\n");
 
34
        printf("  -h, --help            Display this help\n");
 
35
        printf("  -l, --load=FILE       Parse and load the cgroups configuration file\n");
 
36
        exit(2);
 
37
}
 
38
 
 
39
int main(int argc, char *argv[])
 
40
{
 
41
        int c;
 
42
        char filename[PATH_MAX];
 
43
        int ret;
 
44
        static struct option options[] = {
 
45
                {"help", 0, 0, 'h'},
 
46
                {"load", 1, 0, 'l'},
 
47
                {0, 0, 0, 0}
 
48
        };
 
49
 
 
50
        if (argc < 2)
 
51
                usage(argv[0]); /* usage() exits */
 
52
 
 
53
        while ((c = getopt_long(argc, argv, "hl:", options, NULL)) > 0) {
 
54
                switch (c) {
 
55
                case 'h':
 
56
                        usage(argv[0]);
 
57
                        break;
 
58
                case 'l':
 
59
                        strncpy(filename, optarg, PATH_MAX);
 
60
                        ret = cgroup_config_load_config(filename);
 
61
                        if (ret) {
 
62
                                printf("Loading configuration file %s "
 
63
                                        "failed\n%s\n", filename,
 
64
                                        cgroup_strerror(ret));
 
65
                                exit(3);
 
66
                        }
 
67
                        return 0;
 
68
                default:
 
69
                        usage(argv[0]);
 
70
                        break;
 
71
                }
 
72
        }
 
73
        return 0;
 
74
}