]> sourceware.org Git - lvm2.git/blob - tools/lvmcmdlib.c
thin: tighten discard string conversions
[lvm2.git] / tools / lvmcmdlib.c
1 /*
2 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 *
5 * This file is part of LVM2.
6 *
7 * This copyrighted material is made available to anyone wishing to use,
8 * modify, copy, or redistribute it subject to the terms and conditions
9 * of the GNU Lesser General Public License v.2.1.
10 *
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, write to the Free Software Foundation,
13 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 */
15
16 #include "tools.h"
17 #include "lvm2cmdline.h"
18 #include "label.h"
19 #include "memlock.h"
20 #include "lvm-version.h"
21
22 #include "lvm2cmd.h"
23
24 #include <signal.h>
25 #include <syslog.h>
26 #include <libgen.h>
27 #include <sys/stat.h>
28 #include <time.h>
29 #include <sys/resource.h>
30
31 void *cmdlib_lvm2_init(unsigned static_compile)
32 {
33 struct cmd_context *cmd;
34
35 lvm_register_commands();
36
37 init_is_static(static_compile);
38 if (!(cmd = init_lvm()))
39 return NULL;
40
41 return (void *) cmd;
42 }
43
44 int lvm2_run(void *handle, const char *cmdline)
45 {
46 int argc, ret, oneoff = 0;
47 char *args[MAX_ARGS], **argv, *cmdcopy = NULL;
48 struct cmd_context *cmd;
49
50 argv = args;
51
52 if (!handle) {
53 oneoff = 1;
54 if (!(handle = lvm2_init())) {
55 log_error("Handle initialisation failed.");
56 return ECMD_FAILED;
57 }
58 }
59
60 cmd = (struct cmd_context *) handle;
61
62 cmd->argv = argv;
63
64 if (!(cmdcopy = dm_strdup(cmdline))) {
65 log_error("Cmdline copy failed.");
66 ret = ECMD_FAILED;
67 goto out;
68 }
69
70 if (lvm_split(cmdcopy, &argc, argv, MAX_ARGS) == MAX_ARGS) {
71 log_error("Too many arguments. Limit is %d.", MAX_ARGS);
72 ret = EINVALID_CMD_LINE;
73 goto out;
74 }
75
76 if (!argc) {
77 log_error("No command supplied");
78 ret = EINVALID_CMD_LINE;
79 goto out;
80 }
81
82 /* FIXME Temporary - move to libdevmapper */
83 ret = ECMD_PROCESSED;
84 if (!strcmp(cmdline, "_memlock_inc"))
85 memlock_inc_daemon(cmd);
86 else if (!strcmp(cmdline, "_memlock_dec"))
87 memlock_dec_daemon(cmd);
88 else
89 ret = lvm_run_command(cmd, argc, argv);
90
91 out:
92 dm_free(cmdcopy);
93
94 if (oneoff)
95 lvm2_exit(handle);
96
97 return ret;
98 }
99
100 void lvm2_disable_dmeventd_monitoring(void *handle) {
101 init_dmeventd_monitor(DMEVENTD_MONITOR_IGNORE);
102 }
103
104 void lvm2_log_level(void *handle, int level)
105 {
106 struct cmd_context *cmd = (struct cmd_context *) handle;
107
108 cmd->default_settings.verbose = level - VERBOSE_BASE_LEVEL;
109 }
110
111 void lvm2_log_fn(lvm2_log_fn_t log_fn)
112 {
113 init_log_fn(log_fn);
114 }
115
116 void lvm2_exit(void *handle)
117 {
118 struct cmd_context *cmd = (struct cmd_context *) handle;
119
120 lvm_fin(cmd);
121 }
This page took 0.042313 seconds and 5 git commands to generate.