Skip to content

Commit

Permalink
updated librdi to use new error system
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbjohnson4224 committed Oct 23, 2011
1 parent aff8fdf commit 964bd6b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
6 changes: 3 additions & 3 deletions libc/errno/errorstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
static const char *__errorstr_table[EUNK] = {
NULL, // 0 ENONE
"! toobig", // 1 E2BIG
"! access", // 2 EACCES
"! denied", // 2 EACCES
"! addrinuse", // 3 EADDRINUSE
"! addrnotavail", // 4 EADDRNOTAVAIL
"! afnosupport", // 5 EAFNOSUPPORT
Expand Down Expand Up @@ -108,10 +108,10 @@ static struct s_table *__errorstr_lookup = NULL;
* not, NULL is returned and errno is set to EINVAL.
*/

const char *errorstr(int errnum) {
char *errorstr(int errnum) {

if (errnum > 0 && errnum < EUNK) {
return __errorstr_table[errnum];
return strdup(__errorstr_table[errnum]);
}
else {
errno = EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion libc/inc/errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extern int errnov[MAX_THREADS];
* the format of an error, ENONE (zero) is returned.
*/

const char *errorstr(int errnum);
char *errorstr(int errnum);

int iserror (const char *error_str);
int geterror(const char *error_str);
Expand Down
13 changes: 7 additions & 6 deletions librdi/class_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#include <rho/proc.h>
#include <rho/ipc.h>
Expand Down Expand Up @@ -72,11 +73,11 @@ static char *__open(struct robject *self, rp_t src, int argc, char **argv) {
status = STAT_OPEN;
}
else {
return strdup("! arg");
return errorstr(EINVAL);
}

if (!robject_check_access(self, src, status &~ STAT_OPEN)) {
return strdup("! denied");
return errorstr(EACCES);
}

if (status) {
Expand All @@ -95,7 +96,7 @@ static char *__close(struct robject *self, rp_t src, int argc, char **argv) {
return strdup("T");
}
else {
return strdup("! arg");
return errorstr(EINVAL);
}
}

Expand Down Expand Up @@ -141,7 +142,7 @@ static char *_get_access(struct robject *r, rp_t src, int argc, char **argv) {
user = atoi(argv[1]);
}
else {
return strdup("! arg");
return errorstr(EINVAL);
}

bitmap = robject_get_access(r, user);
Expand All @@ -162,7 +163,7 @@ static char *_set_access(struct robject *r, rp_t src, int argc, char **argv) {
sscanf(argv[2], "%X", &bitmap);
}
else {
return strdup("! arg");
return errorstr(EINVAL);
}

robject_set_access(r, user, bitmap);
Expand Down Expand Up @@ -204,7 +205,7 @@ static char *_cons(rp_t src, int argc, char **argv) {
}
}

return strdup("! arg");
return errorstr(EINVAL);
}

static void __rcall_handler(struct msg *msg) {
Expand Down
15 changes: 8 additions & 7 deletions librdi/class_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include <rho/proc.h>

Expand Down Expand Up @@ -67,7 +68,7 @@ static char *_find(struct robject *r, rp_t src, int argc, char **argv) {
const char *tail;
bool link;

if (argc <= 1) return strdup("! arg");
if (argc <= 1) return errorstr(EINVAL);

// check for link follow flag
if (argc == 2) {
Expand All @@ -85,7 +86,7 @@ static char *_find(struct robject *r, rp_t src, int argc, char **argv) {
// find resource
file = __find(r, path, &tail);

if (!file) return strdup("! nfound");
if (!file) return errorstr(ENOENT);

if (robject_check_type(file, "link") && !(!tail && link)) {
/* return redirect to symlink */
Expand Down Expand Up @@ -138,13 +139,13 @@ static char *_link(struct robject *r, rp_t src, int argc, char **argv) {
index = RP_INDEX(ator(argv[2]));

if (RP_PID(ator(argv[2])) != getpid()) {
return strdup("! extern");
return errorstr(EXDEV);
}

hardlink = robject_get(index);
if (!hardlink) {
// link does not exist
return strdup("! noent");
return errorstr(ENOENT);
}

lookup = strvcat("dirent-", entry, NULL);
Expand All @@ -170,7 +171,7 @@ static char *_link(struct robject *r, rp_t src, int argc, char **argv) {
return strdup("T");
}

return strdup("! arg");
return errorstr(EINVAL);
}

static char *_unlink(struct robject *r, rp_t src, int argc, char **argv) {
Expand All @@ -186,7 +187,7 @@ static char *_unlink(struct robject *r, rp_t src, int argc, char **argv) {
if (!robject_get_data(r, lookup)) {
// entry does not exist, fail
free(lookup);
return strdup("! noent");
return errorstr(ENOENT);
}

robject_set_data(r, lookup, NULL);
Expand All @@ -213,7 +214,7 @@ static char *_unlink(struct robject *r, rp_t src, int argc, char **argv) {
return strdup("T");
}

return strdup("! arg");
return errorstr(EINVAL);
}

struct robject *rdi_class_dir;
Expand Down
5 changes: 3 additions & 2 deletions librdi/class_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include <rho/proc.h>
#include <rho/page.h>
Expand All @@ -31,7 +32,7 @@ rdi_write_hook rdi_global_write_hook;
rdi_mmap_hook rdi_global_mmap_hook;
rdi_share_hook rdi_global_share_hook;

static void __rdi_read (struct msg *msg) {
static void __rdi_read(struct msg *msg) {
rdi_read_hook read_hook;
struct robject *file;
struct msg *reply;
Expand Down Expand Up @@ -258,7 +259,7 @@ static char *_size(struct robject *r, rp_t src, int argc, char **argv) {
}

static char *_reset(struct robject *r, rp_t src, int argc, char **argv) {
return strdup("! nosys");
return errorstr(ENOSYS);
}

struct robject *rdi_class_file;
Expand Down
14 changes: 3 additions & 11 deletions librdi/class_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>

#include <rho/proc.h>

Expand All @@ -41,17 +42,13 @@ static char *_find(struct robject *r, rp_t src, int argc, char **argv) {
return rtoa(RP_CONS(getpid(), r->index));
}

return strdup("! arg");
return errorstr(EINVAL);
}

static char *_set_link(struct robject *r, rp_t src, int argc, char **argv) {
char *link;
char *old;

if (!robject_check_access(r, src, ACCS_WRITE)) {
return strdup("! denied");
}

if (argc == 2) {
link = argv[1];

Expand All @@ -62,15 +59,10 @@ static char *_set_link(struct robject *r, rp_t src, int argc, char **argv) {
return strdup("T");
}

return strdup("! arg");
return errorstr(EINVAL);
}

static char *_get_link(struct robject *r, rp_t src, int argc, char **argv) {

if (!robject_check_access(r, src, ACCS_READ)) {
return strdup("! denied");
}

return strdup(robject_get_data(r, "link"));
}

Expand Down
6 changes: 3 additions & 3 deletions util/rcall/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ int main(int argc, char **argv) {
reply = rcall(ctrl, args);

if (!reply) {
printf("(no reply)\n");
printf("! nosys (not implemented)\n");
return 1;
}

if (iserror(reply)) {
printf("reply: %s (%s)\n", reply, strerror(geterror(reply)));
printf("%s (%s)\n", reply, strerror(geterror(reply)));
}
else {
printf("reply: %s\n", reply);
printf("%s\n", reply);
}

return 0;
Expand Down

0 comments on commit 964bd6b

Please sign in to comment.