projects
/
project
/
uci.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lua: include /opt/local/lib and /opt/local/include in the search path on mac os x
[project/uci.git]
/
cli.c
diff --git
a/cli.c
b/cli.c
index
0e98aa7
..
144cdde
100644
(file)
--- a/
cli.c
+++ b/
cli.c
@@
-98,6
+98,8
@@
uci_lookup_section_ref(struct uci_section *s)
}
if (!ti) {
ti = malloc(sizeof(struct uci_type_list));
}
if (!ti) {
ti = malloc(sizeof(struct uci_type_list));
+ if (!ti)
+ return NULL;
memset(ti, 0, sizeof(struct uci_type_list));
ti->next = type_list;
type_list = ti;
memset(ti, 0, sizeof(struct uci_type_list));
ti->next = type_list;
type_list = ti;
@@
-110,8
+112,12
@@
uci_lookup_section_ref(struct uci_section *s)
} else {
typestr = realloc(typestr, maxlen);
}
} else {
typestr = realloc(typestr, maxlen);
}
- sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
+ if (typestr)
+ sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
ti->idx++;
ti->idx++;
+
return typestr;
}
return typestr;
}
@@
-252,6
+258,7
@@
static int package_cmd(int cmd, char *tuple)
{
struct uci_element *e = NULL;
struct uci_ptr ptr;
{
struct uci_element *e = NULL;
struct uci_ptr ptr;
+ int ret = 0;
if (uci_lookup_ptr(ctx, &ptr, tuple, true) != UCI_OK) {
cli_perror();
if (uci_lookup_ptr(ctx, &ptr, tuple, true) != UCI_OK) {
cli_perror();
@@
-266,8
+273,10
@@
static int package_cmd(int cmd, char *tuple)
case CMD_COMMIT:
if (flags & CLI_FLAG_NOCOMMIT)
return 0;
case CMD_COMMIT:
if (flags & CLI_FLAG_NOCOMMIT)
return 0;
- if (uci_commit(ctx, &ptr.p, false) != UCI_OK)
+ if (uci_commit(ctx, &ptr.p, false) != UCI_OK)
{
cli_perror();
cli_perror();
+ ret = 1;
+ }
break;
case CMD_EXPORT:
uci_export(ctx, stdout, ptr.p, true);
break;
case CMD_EXPORT:
uci_export(ctx, stdout, ptr.p, true);
@@
-276,7
+285,7
@@
static int package_cmd(int cmd, char *tuple)
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
if (!(ptr.flags & UCI_LOOKUP_COMPLETE)) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
- ret
urn
1;
+ ret
=
1;
}
switch(e->type) {
case UCI_TYPE_PACKAGE:
}
switch(e->type) {
case UCI_TYPE_PACKAGE:
@@
-295,8
+304,9
@@
static int package_cmd(int cmd, char *tuple)
break;
}
break;
}
- uci_unload(ctx, ptr.p);
- return 0;
+ if (ptr.p)
+ uci_unload(ctx, ptr.p);
+ return ret;
}
static int uci_do_import(int argc, char **argv)
}
static int uci_do_import(int argc, char **argv)
@@
-444,7
+454,7
@@
static int uci_do_section_cmd(int cmd, int argc, char **argv)
ret = uci_add_list(ctx, &ptr);
break;
case CMD_REORDER:
ret = uci_add_list(ctx, &ptr);
break;
case CMD_REORDER:
- if (!ptr.s) {
+ if (!ptr.s
|| !ptr.value
) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
return 1;
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
return 1;
@@
-627,6
+637,11
@@
int main(int argc, char **argv)
delimiter = optarg;
break;
case 'f':
delimiter = optarg;
break;
case 'f':
+ if (input != stdin) {
+ perror("uci");
+ return 1;
+ }
+
input = fopen(optarg, "r");
if (!input) {
perror("uci");
input = fopen(optarg, "r");
if (!input) {
perror("uci");
@@
-687,10
+702,9
@@
int main(int argc, char **argv)
ret = uci_cmd(argc - 1, argv + 1);
if (input != stdin)
fclose(input);
ret = uci_cmd(argc - 1, argv + 1);
if (input != stdin)
fclose(input);
- if (ret == 255) {
+
+ if (ret == 255)
uci_usage();
uci_usage();
- return 0;
- }
uci_free_context(ctx);
uci_free_context(ctx);