Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / tools / lvmcmdlib.c
blob25f74da7169ddaa83225c8cb26f3eafedefdbeb9
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
7 * This file is part of LVM2.
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #include "tools.h"
19 #include "lvm2cmdline.h"
20 #include "label.h"
21 #include "memlock.h"
22 #include "lvm-version.h"
24 #include "lvm2cmd.h"
26 #include <signal.h>
27 #include <syslog.h>
28 #include <libgen.h>
29 #include <sys/stat.h>
30 #include <time.h>
31 #include <sys/resource.h>
33 void *cmdlib_lvm2_init(unsigned static_compile)
35 struct cmd_context *cmd;
37 lvm_register_commands();
39 init_is_static(static_compile);
40 if (!(cmd = init_lvm()))
41 return NULL;
43 return (void *) cmd;
46 int lvm2_run(void *handle, const char *cmdline)
48 int argc, ret, oneoff = 0;
49 char *args[MAX_ARGS], **argv, *cmdcopy = NULL;
50 struct cmd_context *cmd;
52 argv = args;
54 if (!handle) {
55 oneoff = 1;
56 if (!(handle = lvm2_init())) {
57 log_error("Handle initialisation failed.");
58 return ECMD_FAILED;
62 cmd = (struct cmd_context *) handle;
64 cmd->argv = argv;
66 if (!(cmdcopy = dm_strdup(cmdline))) {
67 log_error("Cmdline copy failed.");
68 ret = ECMD_FAILED;
69 goto out;
72 if (lvm_split(cmdcopy, &argc, argv, MAX_ARGS) == MAX_ARGS) {
73 log_error("Too many arguments. Limit is %d.", MAX_ARGS);
74 ret = EINVALID_CMD_LINE;
75 goto out;
78 if (!argc) {
79 log_error("No command supplied");
80 ret = EINVALID_CMD_LINE;
81 goto out;
84 /* FIXME Temporary - move to libdevmapper */
85 ret = ECMD_PROCESSED;
86 if (!strcmp(cmdline, "_memlock_inc"))
87 memlock_inc_daemon();
88 else if (!strcmp(cmdline, "_memlock_dec"))
89 memlock_dec_daemon();
90 else
91 ret = lvm_run_command(cmd, argc, argv);
93 out:
94 dm_free(cmdcopy);
96 if (oneoff)
97 lvm2_exit(handle);
99 return ret;
102 void lvm2_log_level(void *handle, int level)
104 struct cmd_context *cmd = (struct cmd_context *) handle;
106 cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL;
108 return;
111 void lvm2_log_fn(lvm2_log_fn_t log_fn)
113 init_log_fn(log_fn);
116 void lvm2_exit(void *handle)
118 struct cmd_context *cmd = (struct cmd_context *) handle;
120 lvm_fin(cmd);