MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / db_send

Function db_send

lua/syssp.c:427–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425}
426
427static int db_send(Lua L) {
428 FILE *f;
429 char buf[1024];
430 int rownum = 1;
431 char *cmd;
432 SP sp = getsp(L);
433
434 if (sp) {
435 sp->max_num_instructions = 1000000; //allow large number of steps
436 }
437
438 if (!lua_isstring(L, 1))
439 return luaL_error(L, "Expected string argument");
440
441 if (gbl_uses_password) {
442 if (sp && sp->clnt) {
443 int bdberr;
444 if (bdb_tbl_op_access_get(thedb->bdb_env, NULL, 0, "",
445 sp->clnt->current_user.name, &bdberr)) {
446 return luaL_error(L, "User doesn't have access to run this command.");
447 }
448 }
449 }
450
451 cmd = (char*) lua_tostring(L, -1);
452 lua_settop(L, 0);
453
454 lua_createtable(L, 0, 0);
455
456 f = tmpfile();
457 if (!f)
458 {
459 logmsg(LOGMSG_FATAL, "%s:%d SYSTEM RAN OUT OF FILE DESCRIPTORS!!! EXITING\n",
460 __FILE__, __LINE__);
461 clean_exit();
462 }
463 /* kludge spackle, engage */
464 io_override_set_std(f);
465 process_command(thedb, cmd, strlen(cmd), 0);
466 io_override_set_std(NULL);
467 rewind(f);
468 while (fgets(buf, sizeof(buf), f)) {
469 char *s;
470 s = strchr(buf, '\n');
471 if (s) *s = 0;
472
473 lua_createtable(L, 0, 1);
474
475 lua_pushstring(L, "out");
476 lua_pushstring(L, buf);
477 lua_settable(L, -3);
478
479 lua_rawseti(L, -2, rownum++);
480 }
481 fclose(f);
482
483 return 1;
484}

Callers

nothing calls this directly

Calls 11

lua_isstringFunction · 0.85
luaL_errorFunction · 0.85
bdb_tbl_op_access_getFunction · 0.85
lua_settopFunction · 0.85
lua_createtableFunction · 0.85
clean_exitFunction · 0.85
io_override_set_stdFunction · 0.85
lua_pushstringFunction · 0.85
lua_settableFunction · 0.85
lua_rawsetiFunction · 0.85
logmsgFunction · 0.50

Tested by

no test coverage detected