Tizen 2.1 base
[external/device-mapper.git] / doc / example_cmdlib.c
1 /*
2  * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
3  *
4  * This file is part of LVM2.
5  *
6  * This copyrighted material is made available to anyone wishing to use,
7  * modify, copy, or redistribute it subject to the terms and conditions
8  * of the GNU General Public License v.2.
9  *
10  * You should have received a copy of the GNU General Public License
11  * along with this program; if not, write to the Free Software Foundation,
12  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
13  */
14
15 #include "lvm2cmd.h"
16 #include <stdio.h>
17
18 /* All output gets passed to this function line-by-line */
19 void test_log_fn(int level, const char *file, int line,
20                  int dm_errno, const char *format)
21 {
22         /* Extract and process output here rather than printing it */
23
24         if (level != 4)
25                 return;
26
27         printf("%s\n", format);
28         return;
29 }
30
31 int main(int argc, char **argv)
32 {
33         void *handle;
34         int r;
35
36         lvm2_log_fn(test_log_fn);
37
38         handle = lvm2_init();
39
40         lvm2_log_level(handle, 1);
41         r = lvm2_run(handle, "vgs --noheadings vg1");
42
43         /* More commands here */
44
45         lvm2_exit(handle);
46
47         return r;
48 }
49