check allocation and return some other error codes too

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8291 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-05-24 20:21:14 +00:00
parent 13d179001f
commit 28ce975ff7

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998 Kungliga Tekniska H<>gskolan * Copyright (c) 1998 - 2000 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved. * All rights reserved.
* *
@@ -55,14 +55,34 @@ ss_create_invocation(const char *subsystem,
int *code) int *code)
{ {
struct ss_subst *ss; struct ss_subst *ss;
if(num_subsystems >= sizeof(subsystems) / sizeof(subsystems[0])) { if(num_subsystems >= sizeof(subsystems) / sizeof(subsystems[0])) {
*code = 17; *code = 17;
return 0; return 0;
} }
ss = &subsystems[num_subsystems]; ss = &subsystems[num_subsystems];
ss->name = subsystem ? strdup(subsystem) : NULL; ss->name = ss->version = ss->info = NULL;
ss->version = version ? strdup(version) : NULL; if (subsystem != NULL) {
ss->info = info ? strdup(info) : NULL; ss->name = strdup (subsystem);
if (ss->name == NULL) {
*code = ENOMEM;
return 0;
}
}
if (version != NULL) {
ss->version = strdup (version);
if (ss->version == NULL) {
*code = ENOMEM;
return 0;
}
}
if (info != NULL) {
ss->info = strdup (info);
if (ss->info == NULL) {
*code = ENOMEM;
return 0;
}
}
ss->table = table; ss->table = table;
*code = 0; *code = 0;
return num_subsystems++; return num_subsystems++;
@@ -87,8 +107,12 @@ int
ss_execute_command(int index, char **argv) ss_execute_command(int index, char **argv)
{ {
int argc = 0; int argc = 0;
int ret;
while(argv[argc++]); while(argv[argc++]);
sl_command(subsystems[index].table, argc, argv); ret = sl_command(subsystems[index].table, argc, argv);
if (ret == SL_BADCOMMAND)
return SS_ET_COMMAND_NOT_FOUND;
return 0; return 0;
} }
@@ -98,10 +122,15 @@ ss_execute_line (int index, const char *line)
char *buf = strdup(line); char *buf = strdup(line);
int argc; int argc;
char **argv; char **argv;
int ret;
if (buf == NULL)
return ENOMEM;
sl_make_argv(buf, &argc, &argv); sl_make_argv(buf, &argc, &argv);
sl_command(subsystems[index].table, argc, argv); ret = sl_command(subsystems[index].table, argc, argv);
free(buf); free(buf);
if (ret == SL_BADCOMMAND)
return SS_ET_COMMAND_NOT_FOUND;
return 0; return 0;
} }
@@ -109,9 +138,9 @@ int
ss_listen (int index) ss_listen (int index)
{ {
char *prompt = malloc(strlen(subsystems[index].name) + 3); char *prompt = malloc(strlen(subsystems[index].name) + 3);
if(prompt == NULL) { if (prompt = NULL)
abort(); return ENOMEM;
}
strcpy(prompt, subsystems[index].name); strcpy(prompt, subsystems[index].name);
strcat(prompt, ": "); strcat(prompt, ": ");
sl_loop(subsystems[index].table, prompt); sl_loop(subsystems[index].table, prompt);