Date: Sun, 8 Jun 2014 17:02:43 GMT From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r269258 - soc2014/pedrosouza/lua_loader/head/sys/boot/common Message-ID: <201406081702.s58H2hW8023831@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pedrosouza Date: Sun Jun 8 17:02:43 2014 New Revision: 269258 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269258 Log: Implemented interp_lua_incl Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c Sun Jun 8 15:38:40 2014 (r269257) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/common/interp_lua.c Sun Jun 8 17:02:43 2014 (r269258) @@ -116,7 +116,7 @@ data_chunk ds; ds.data = (void*)str; ds.size = size; - res = lua_load(L, read_chunk, &ds, "do_string_", 0); + res = lua_load(L, read_chunk, &ds, "do_string", 0); res = lua_pcall(L, 0, LUA_MULTRET, 0); return res; } @@ -163,67 +163,54 @@ int interp_lua_incl(void *ctx, const char *filename) { -#if 0 - lua_State *luap; struct interp_lua_softc *softc; struct stat st; - char *filebuf, *errstr; - int fd, filebufoff, i, rleft, rread; + int fd, r; + char *buf; + const char *errstr; - printf("[Lua] Including file %s.\n", filename); + softc = ctx; - if ((strcmp(filename, "/boot/loader.rc") == 0) || - (strcmp(filename, "/boot/boot.conf") == 0)) { - printf("Skipping loader.rc and boot.conf"); - return (0); + fd = open(filename, O_RDONLY); + if (fd < 0) { + printf("Failed to open file %s\n", filename); + return 1; } - softc = ctx; - luap = softc->luap; + r = fstat(fd, &st); + if (r != 0) { + printf("Failed to retrieve file stat!\n"); + close(fd); + return 1; + } - fd = open(filename, O_RDONLY); - if (fd < 0) { - printf("Couldn't open file %s\n", filename); - return (1); + buf = malloc(st.st_size); + if (buf == NULL) { + printf("Failed to alloc buf!\n"); + close(fd); + return 1; } - i = stat(filename, &st); - assert(i == 0); - filebuf = malloc(st.st_size); - assert(filebuf != NULL); - memset(filebuf, 0, st.st_size); - - /* - * XX: Investigate stat() vs logic problem. I'm getting - * more bytes that the file really has. - */ - - - rleft = st.st_size - 1; - filebufoff = 0; - for (;;) { - rread = read(fd, filebuf + filebufoff, rleft); - assert(rread >= 0); - rleft -= rread; - filebufoff += rread; - if (rread == 0 || rleft <= 0) { - break; - } + + r = read(fd, buf, st.st_size); + if (r != st.st_size) { + printf("Failed to read file (%d/%d)!\n", r, (unsigned int)st.st_size); + free(buf); + close(fd); + return 1; } - close(fd); - i = LUA_DOSTRING(luap, filebuf); - free(filebuf); - if ((i != 0) && (lua_isnil(luap, -1) == 0)) { - errstr = lua_tostring(luap, -1); - if (errstr == NULL) { - errstr = "internal error; errstr must be string"; - } - printf("Problem with script execution:\n\n"); - printf("\t'%s'\n\n", errstr); - lua_pop(luap, 1); + + if (do_string(softc->luap, buf, st.st_size) != 0) { + errstr = lua_tostring(softc->luap, -1); + errstr = errstr == NULL ? "unknown" : errstr; + printf("Failed to run %s file with error: %s.\n", filename, errstr); + lua_pop(softc->luap, 1); } -#endif - return (0); + + free(buf); + close(fd); + + return 0; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406081702.s58H2hW8023831>