Kaydet (Commit) e1f29f7c authored tarafından Gürer Özen's avatar Gürer Özen

comar içi hatalar FAIL değil ERROR döndürsün

ipc/rpc düzenlemeleri
dahası gelecek...
üst 8c488c16
......@@ -24,18 +24,19 @@ class Link:
RESULT = 0
FAIL = 1
DENIED = 2
RESULT_START = 3
RESULT_END = 4
NOTIFY = 5
ERROR = 3
RESULT_START = 4
RESULT_END = 5
NOTIFY = 6
# following cmds are sent by internal methods, thus not visible to outside
__LOCALIZE = 6
__REGISTER = 7
__REMOVE = 8
__CALL = 9
__CALL_PACKAGE = 10
__ASKNOTIFY = 11
__GETLIST = 12
__CHECKACL = 13
__LOCALIZE = 7
__REGISTER = 8
__REMOVE = 9
__CALL = 10
__CALL_PACKAGE = 11
__ASKNOTIFY = 12
__GETLIST = 13
__CHECKACL = 14
def __init__(self, sockname="/tmp/comar"):
try:
......@@ -181,7 +182,7 @@ def test_basic(class_="Time.Clock", package="hwclock", script="../betikler/clock
print "Reply", reply
if reply[0] == com.RESULT:
break
elif reply[1] == com.FAIL:
elif reply[1] == com.ERROR:
print "Oops, test failed!"
return
print "Checking list..."
......@@ -191,7 +192,7 @@ def test_basic(class_="Time.Clock", package="hwclock", script="../betikler/clock
print "Reply", reply
if reply[0] == com.RESULT:
break
elif reply[1] == com.FAIL:
elif reply[1] == com.ERROR:
print "Oops, test failed!"
return
print "Removing the package..."
......@@ -201,7 +202,7 @@ def test_basic(class_="Time.Clock", package="hwclock", script="../betikler/clock
print "Reply", reply
if reply[0] == com.RESULT:
break
elif reply[1] == com.FAIL:
elif reply[1] == com.ERROR:
print "Oops, test failed!"
return
print "Checking list again..."
......@@ -211,7 +212,7 @@ def test_basic(class_="Time.Clock", package="hwclock", script="../betikler/clock
print "Reply", reply
if reply[0] == com.RESULT:
break
elif reply[1] == com.FAIL:
elif reply[1] == com.ERROR:
print "Oops, test failed!"
return
print "Basic functionality is OK :)"
......@@ -21,24 +21,26 @@ extern "C" {
#define COMAR_RESULT 0
#define COMAR_FAIL 1
#define COMAR_DENIED 2
#define COMAR_RESULT_START 3
#define COMAR_RESULT_END 4
#define COMAR_NOTIFY 5
#define COMAR_ERROR 3
#define COMAR_RESULT_START 4
#define COMAR_RESULT_END 5
#define COMAR_NOTIFY 6
// commands to the daemon
#define COMAR_LOCALIZE 6
#define COMAR_REGISTER 7
#define COMAR_REMOVE 8
#define COMAR_CALL 9
#define COMAR_CALL_PACKAGE 10
#define COMAR_ASKNOTIFY 11
#define COMAR_GETLIST 12
#define COMAR_CHECKACL 13
#define COMAR_LOCALIZE 7
#define COMAR_REGISTER 8
#define COMAR_REMOVE 9
#define COMAR_CALL 10
#define COMAR_CALL_PACKAGE 11
#define COMAR_ASKNOTIFY 12
#define COMAR_GETLIST 13
#define COMAR_CHECKACL 14
#define COMAR_CMD_MAX 14
#define COMAR_CMD_MAX 15
#define COMAR_CMD_NAMES \
"Result", \
"Fail", \
"Denied", \
"Error", \
"ResultStart", \
"ResultEnd", \
"Notify", \
......
......@@ -12,9 +12,11 @@
// ipc commands
enum {
CMD_DIED,
CMD_FAIL,
CMD_RESULT,
CMD_RESULT_START,
CMD_RESULT_END,
CMD_FAIL,
CMD_ERROR,
CMD_REGISTER,
CMD_REMOVE,
CMD_CALL,
......
......@@ -50,7 +50,7 @@
<method name="deleteHost"/>
</class>
<class name="Link">
<method name="scan"/>
<method name="getActiveLinks"/>
<method name="setAddress"/>
<method name="getInformation"/>
<method name="getStatus"/>
......@@ -64,4 +64,4 @@
</group>
</comarModel>
</comarModel>
\ No newline at end of file
......@@ -32,6 +32,21 @@ c_call(PyObject *self, PyObject *args)
return Py_None;
}
static PyObject *
c_fail(PyObject *self, PyObject *args)
{
const char *name;
size_t size;
if (!PyArg_ParseTuple(args, "s#", &name, &size))
return NULL;
// FIXME: fail here :)
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
c_notify(PyObject *self, PyObject *args)
{
......@@ -48,6 +63,7 @@ c_notify(PyObject *self, PyObject *args)
}
static PyMethodDef methods[] = {
{ "fail", c_fail, METH_VARARGS, "Abort script and return a fail message" },
{ "call", c_call, METH_VARARGS, "Call a method from COMAR system model" },
{ "notify", c_notify, METH_VARARGS, "Send a notification event" },
{ NULL, NULL, 0, NULL }
......
......@@ -78,13 +78,13 @@ do_register(int node, const char *app, const char *fname)
buf = load_file(fname, NULL);
if (!buf) {
send_result(CMD_FAIL, "no file", 7);
send_result(CMD_ERROR, "no file", 7);
return -1;
}
e = csl_compile(buf, "test", &code, &codelen);
if (e) {
send_result(CMD_FAIL, "compile error", 13);
send_result(CMD_ERROR, "compile error", 13);
return -1;
}
......@@ -125,7 +125,7 @@ do_execute(int node, const char *app)
if (0 != db_get_code(model_parent(node), app, &code, &code_size)) return -1;
e = csl_execute(code, code_size, model_get_method(node), &res, &res_size);
if (e) {
send_result(CMD_FAIL, "err", 3);
send_result(CMD_ERROR, "err", 3);
} else {
send_result(CMD_RESULT, res, res_size);
}
......@@ -153,7 +153,7 @@ do_call(int node)
log_debug(LOG_JOB, "Call(%s)\n", model_get_path(node));
if (db_get_apps(model_parent(node), &apps) != 0) {
send_result(CMD_FAIL, "no app", 6);
send_result(CMD_ERROR, "no app", 6);
exit(1);
}
......@@ -168,6 +168,8 @@ do_call(int node)
int cnt = 0;
size_t size;
// FIXME: package count, error msg for fork
send_result(CMD_RESULT_START, NULL, 0);
for (t = apps; t; t = s) {
s = strchr(t, '/');
if (s) {
......@@ -186,6 +188,7 @@ do_call(int node)
proc_send(TO_PARENT, cmd, ipc, size);
//--cnt;
}
send_result(CMD_RESULT_END, NULL, 0);
}
free(apps);
......@@ -213,6 +216,10 @@ do_getlist(int node)
if (db_get_apps(node, &apps) != 0) {
send_result(CMD_RESULT, NULL, 0);
} else {
char *t;
for (t = apps; *t; t++) {
if (*t == '/') *t = ' ';
}
send_result(CMD_RESULT, apps, 0);
}
return 0;
......
......@@ -59,7 +59,10 @@ main(int argc, char *argv[])
break;
case CMD_NOTIFY:
case CMD_RESULT:
case CMD_RESULT_START:
case CMD_RESULT_END:
case CMD_FAIL:
case CMD_ERROR:
proc_recv(p, &ipc, size);
proc_send(rpc, cmd, ipc, size);
free(ipc);
......
......@@ -25,12 +25,15 @@
/* rpc commands, keep in sync with bindings */
enum {
// outgoing
RPC_RESULT = 0,
RPC_FAIL,
RPC_DENIED,
RPC_ERROR,
RPC_RESULT_START,
RPC_RESULT_END,
RPC_NOTIFY,
// incoming
RPC_LOCALIZE,
RPC_REGISTER,
RPC_REMOVE,
......@@ -335,7 +338,7 @@ pipe_listen(void)
int sock, max;
tv.tv_sec = 0;
tv.tv_usec = 500000;
tv.tv_usec = 250000;
FD_ZERO(&fds);
max = 0;
......@@ -391,6 +394,23 @@ pipe_listen(void)
return 0;
}
void
forward_reply(struct ProcChild *p, size_t size, int cmd)
{
struct connection *c;
char *s;
size_t sz;
ipc_recv(p, size);
for (c = conns; c; c = c->next) {
if (c == (struct connection *) ipc_get_data()) {
ipc_get_arg(&s, &sz);
write_rpc(c, cmd, ipc_get_id(), s, sz);
return;
}
}
}
void
rpc_unix_start(void)
{
......@@ -407,31 +427,37 @@ rpc_unix_start(void)
while (1) {
while (1 == proc_listen(&p, &cmd, &size, 0)) {
if (cmd == CMD_NOTIFY) {
ipc_recv(p, size);
for (c = conns; c; c = c->next) {
int no = ipc_get_node();
if (notify_is_marked(c->notify_mask, no)) {
// FIXME: return argument too
const char *name = model_get_path(no);
write_rpc(c, RPC_NOTIFY, 0, name, strlen(name));
switch (cmd) {
case CMD_NOTIFY:
ipc_recv(p, size);
for (c = conns; c; c = c->next) {
int no = ipc_get_node();
if (notify_is_marked(c->notify_mask, no)) {
// FIXME: return argument too
const char *name = model_get_path(no);
write_rpc(c, RPC_NOTIFY, 0, name, strlen(name));
}
}
}
continue;
} else if (cmd != CMD_RESULT && cmd != CMD_FAIL) continue;
ipc_recv(p, size);
for (c = conns; c; c = c->next) {
if (c == (struct connection *) ipc_get_data()) {
char *s;
size_t sz;
ipc_get_arg(&s, &sz);
if (cmd == CMD_RESULT)
cmd = RPC_RESULT;
else
cmd = RPC_FAIL;
write_rpc(c, cmd, ipc_get_id(), s, sz);
continue;
case CMD_RESULT_START:
forward_reply(p, size, RPC_RESULT_START);
break;
}
case CMD_RESULT_END:
forward_reply(p, size, RPC_RESULT_END);
break;
case CMD_RESULT:
forward_reply(p, size, RPC_RESULT);
break;
case CMD_FAIL:
forward_reply(p, size, RPC_FAIL);
break;
case CMD_ERROR:
forward_reply(p, size, RPC_ERROR);
break;
default:
// this shouldn't happen, warn and skip
log_error("RPC: Unexpected internal command %d\n", cmd);
ipc_recv(p, size);
}
}
pipe_listen();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment