[asterisk-commits] mnicholson: branch mnicholson/asttest r247895 - in /team/mnicholson/asttest/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 19 09:11:33 CST 2010


Author: mnicholson
Date: Fri Feb 19 09:11:29 2010
New Revision: 247895

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247895
Log:
Restructured the asterisk installation directory and limited the set of files copied from it.  This change allows passing '-a /' to asttest to work properly.

Modified:
    team/mnicholson/asttest/asttest/Makefile
    team/mnicholson/asttest/asttest/lua/astlib.c
    team/mnicholson/asttest/asttest/lua/astlib.lua

Modified: team/mnicholson/asttest/asttest/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/Makefile?view=diff&rev=247895&r1=247894&r2=247895
==============================================================================
--- team/mnicholson/asttest/asttest/Makefile (original)
+++ team/mnicholson/asttest/asttest/Makefile Fri Feb 19 09:11:29 2010
@@ -86,7 +86,10 @@
 #lua/%.o: lua/%.c lua/%_lua.h include/asttest/lua/%.h
 
 asterisk:
-	cd ../ && ./configure --enable-dev-mode --prefix=$(AST_INSTALL_DIR) --localstatedir=$(AST_INSTALL_DIR)/var
+	cd ../ && ./configure --enable-dev-mode \
+		--prefix=$(AST_INSTALL_DIR)/usr \
+		--sysconfdir=$(AST_INSTALL_DIR)/etc \
+		--localstatedir=$(AST_INSTALL_DIR)/var
 	$(MAKE) -C ../ install
 	$(MAKE) -C ../ samples
 

Modified: team/mnicholson/asttest/asttest/lua/astlib.c
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lua/astlib.c?view=diff&rev=247895&r1=247894&r2=247895
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.c (original)
+++ team/mnicholson/asttest/asttest/lua/astlib.c Fri Feb 19 09:11:29 2010
@@ -33,6 +33,68 @@
 #include <unistd.h>
 
 /*!
+ * \brief Make the parent directories of a given path.
+ * \param pathname the path to create
+ * \param mode the mode of the created directories
+ *
+ * Create the parent directories of a given path if they do not exist.  If the
+ * given string does not end in '/' then the last path component will be
+ * treated as a file name and ignored.
+ *
+ * \note In the case of an error, errno should be set.
+ * \retval 0 success
+ * \retval -1 error
+ */
+static int mkdir_p(const char *pathname, mode_t mode) {
+	char buf[PATH_MAX + 1];
+	const char *c = pathname;
+
+	while ((c = strchr(c, '/'))) {
+		c++;
+		if (c - pathname > PATH_MAX) {
+			errno = ENAMETOOLONG;
+			goto e_return;
+		}
+
+		strncpy(buf, pathname, c - pathname);
+		buf[c - pathname] = '\0';
+
+		if (mkdir(buf, mode) && errno != EEXIST) {
+			goto e_return;
+		}
+	}
+
+	return 0;
+
+e_return:
+	return -1;
+}
+
+/*!
+ * \brief Symlink a file.
+ * \param L the lua state to use
+ * \param src the source file
+ * \param dst the destination file
+ *
+ * \retval 0 success
+ * \retval -1 error
+ */
+static int symlink_file(lua_State *L, const char *src, const char *dst) {
+	if (symlink(src, dst)) {
+		lua_pushstring(L, "error symlink '");
+		lua_pushstring(L, dst);
+		lua_pushstring(L, "': ");
+		lua_pushstring(L, strerror(errno));
+		lua_concat(L, 4);
+		goto e_return;
+	}
+	return 0;
+
+e_return:
+	return -1;
+}
+
+/*!
  * \brief Recursively symlink and copy a directory.
  * \param L the lua state to use
  * \param src the source directory
@@ -93,12 +155,7 @@
 				goto e_closedir;
 			}
 		} else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
-			if (symlink(src_path, dst_path)) {
-				lua_pushstring(L, "error symlink '");
-				lua_pushstring(L, dst_path);
-				lua_pushstring(L, "': ");
-				lua_pushstring(L, strerror(errno));
-				lua_concat(L, 4);
+			if (symlink_file(L, src_path, dst_path)) {
 				goto e_closedir;
 			}
 		} else {
@@ -233,7 +290,7 @@
 	lua_setfield(L, -2, "index");
 
 	lua_getfield(L, LUA_REGISTRYINDEX, "astlib_path");
-	lua_pushliteral(L, "/sbin/asterisk");
+	lua_pushliteral(L, "/usr/sbin/asterisk");
 	lua_concat(L, 2);
 	lua_setfield(L, -2, "asterisk_binary");
 	return 1;
@@ -274,7 +331,31 @@
 static int create_work_area(lua_State *L) {
 	const char *work_area;
 	const char *asterisk_path;
+	char src_buf[PATH_MAX], dst_buf[PATH_MAX];
 	mode_t dir_mode = S_IRWXU | S_IRGRP| S_IXGRP| S_IROTH | S_IXOTH;
+	int i;
+
+	/* directories must end in '/' */
+	const char *asterisk_dirs[] = {
+		"/etc/asterisk/",
+		"/usr/lib/asterisk/modules/",
+		"/usr/include/asterisk/",
+		"/var/lib/asterisk/",
+		"/var/run/asterisk/",
+		"/var/log/asterisk/",
+		"/var/spool/asterisk/",
+		NULL,
+	};
+
+	const char *asterisk_files[] = {
+		"/usr/sbin/astcanary",
+		"/usr/sbin/asterisk",
+		"/usr/sbin/astgenkey",
+		"/usr/sbin/autosupport",
+		"/usr/sbin/rasterisk",
+		"/usr/sbin/safe_asterisk",
+		NULL,
+	};
 
 	luaL_checktype(L, 1, LUA_TTABLE);
 
@@ -286,28 +367,45 @@
 	lua_getfield(L, LUA_REGISTRYINDEX, "astlib_path");
 	asterisk_path = lua_tostring(L, -1);
 
-	if (mkdir("tmp", dir_mode) && errno != EEXIST) {
-		lua_pushstring(L, "error creating tmp directory for work area: ");
-		lua_pushstring(L, strerror(errno));
-		lua_concat(L, 2);
-		return lua_error(L);
-	}
-
-	if (mkdir(work_area, dir_mode)) {
-		lua_pushstring(L, "unable to create work area (");
-		lua_pushstring(L, work_area);
-		lua_pushstring(L, "): ");
-		lua_pushstring(L, strerror(errno));
-		lua_concat(L, 4);
-		return lua_error(L);
-	}
-
-	if (symlink_copy_dir(L, asterisk_path, work_area)) {
-		lua_pushstring(L, "\nerror initilizing work area");
-		lua_concat(L, 2);
-		return lua_error(L);
-	}
-
+	/* copy directories */
+	for (i = 0; asterisk_dirs[i]; i++) {
+		snprintf(src_buf, sizeof(src_buf), "%s%s", asterisk_path, asterisk_dirs[i]);
+		snprintf(dst_buf, sizeof(dst_buf), "%s%s", work_area, asterisk_dirs[i]);
+		if (mkdir_p(dst_buf, dir_mode)) {
+			lua_pushstring(L, "unable to create directory in work area (");
+			lua_pushstring(L, dst_buf);
+			lua_pushstring(L, "): ");
+			lua_pushstring(L, strerror(errno));
+			lua_concat(L, 4);
+			return lua_error(L);
+		}
+
+		if (symlink_copy_dir(L, src_buf, dst_buf)) {
+			lua_pushstring(L, "\nerror initilizing work area");
+			lua_concat(L, 2);
+			return lua_error(L);
+		}
+	}
+
+	/* copy files */
+	for (i = 0; asterisk_files[i]; i++) {
+		snprintf(src_buf, sizeof(src_buf), "%s%s", asterisk_path, asterisk_files[i]);
+		snprintf(dst_buf, sizeof(dst_buf), "%s%s", work_area, asterisk_files[i]);
+		if (mkdir_p(dst_buf, dir_mode)) {
+			lua_pushstring(L, "unable to create directory in work area (");
+			lua_pushstring(L, dst_buf);
+			lua_pushstring(L, "): ");
+			lua_pushstring(L, strerror(errno));
+			lua_concat(L, 4);
+			return lua_error(L);
+		}
+
+		if (symlink_file(L, src_buf, dst_buf)) {
+			lua_pushstring(L, "\nerror initilizing work area");
+			lua_concat(L, 2);
+			return lua_error(L);
+		}
+	}
 	return 0;
 }
 

Modified: team/mnicholson/asttest/asttest/lua/astlib.lua
URL: http://svnview.digium.com/svn/asterisk/team/mnicholson/asttest/asttest/lua/astlib.lua?view=diff&rev=247895&r1=247894&r2=247895
==============================================================================
--- team/mnicholson/asttest/asttest/lua/astlib.lua (original)
+++ team/mnicholson/asttest/asttest/lua/astlib.lua Fri Feb 19 09:11:29 2010
@@ -140,7 +140,7 @@
 	local c = self:new_config("asterisk.conf")
 	local s = c:new_section("directories")
 	s["astetcdir"] = self:path("/etc/asterisk")
-	s["astmoddir"] = self:path("/lib/asterisk/modules")
+	s["astmoddir"] = self:path("/usr/lib/asterisk/modules")
 	s["astvarlibdir"] = self:path("/var/lib/asterisk")
 	s["astdbdir"] = self:path("/var/lib/asterisk")
 	s["astkeydir"] = self:path("/var/lib/asterisk")




More information about the asterisk-commits mailing list