From owner-svn-soc-all@FreeBSD.ORG Sun Jun 8 17:02:44 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 34E37FFE for ; Sun, 8 Jun 2014 17:02:44 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 156AC26AC for ; Sun, 8 Jun 2014 17:02:44 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s58H2hgT023947 for ; Sun, 8 Jun 2014 17:02:43 GMT (envelope-from pedrosouza@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s58H2hW8023831 for svn-soc-all@FreeBSD.org; Sun, 8 Jun 2014 17:02:43 GMT (envelope-from pedrosouza@FreeBSD.org) Date: Sun, 8 Jun 2014 17:02:43 GMT Message-Id: <201406081702.s58H2hW8023831@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to pedrosouza@FreeBSD.org using -f From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r269258 - soc2014/pedrosouza/lua_loader/head/sys/boot/common MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jun 2014 17:02:44 -0000 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; }