svn commit: trunk/busybox: applets archival coreutils debianutils i etc...

vda at busybox.net vda at busybox.net
Sun Feb 11 08:19:29 PST 2007


Author: vda
Date: 2007-02-11 08:19:28 -0800 (Sun, 11 Feb 2007)
New Revision: 17854

Log:
syslogd: fix "readpath bug" by using readlink instead
libbb: rename xgetcwd and xreadlink


Modified:
   trunk/busybox/applets/busybox.c
   trunk/busybox/archival/tar.c
   trunk/busybox/coreutils/ls.c
   trunk/busybox/coreutils/pwd.c
   trunk/busybox/coreutils/stat.c
   trunk/busybox/debianutils/readlink.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/copy_file.c
   trunk/busybox/libbb/lineedit.c
   trunk/busybox/libbb/simplify_path.c
   trunk/busybox/libbb/xgetcwd.c
   trunk/busybox/libbb/xreadlink.c
   trunk/busybox/shell/hush.c
   trunk/busybox/shell/lash.c
   trunk/busybox/sysklogd/syslogd.c


Changeset:
Modified: trunk/busybox/applets/busybox.c
===================================================================
--- trunk/busybox/applets/busybox.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/applets/busybox.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -92,7 +92,7 @@
 
 		/* link */
 // XXX: FIXME: this is broken. Why not just use argv[0] ?
-		busybox = xreadlink("/proc/self/exe");
+		busybox = xmalloc_readlink_or_warn("/proc/self/exe");
 		if (!busybox)
 			return 1;
 		install_links(busybox, use_symbolic_links);

Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/archival/tar.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -273,8 +273,8 @@
 					tbInfo->hlInfo->name, 0);
 #endif
 	} else if (S_ISLNK(statbuf->st_mode)) {
-		char *lpath = xreadlink(fileName);
-		if (!lpath)		/* Already printed err msg inside xreadlink() */
+		char *lpath = xmalloc_readlink_or_warn(fileName);
+		if (!lpath)
 			return FALSE;
 		header.typeflag = SYMTYPE;
 		strncpy(header.linkname, lpath, sizeof(header.linkname));

Modified: trunk/busybox/coreutils/ls.c
===================================================================
--- trunk/busybox/coreutils/ls.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/coreutils/ls.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -664,7 +664,7 @@
 			break;
 		case LIST_SYMLINK:
 			if (S_ISLNK(dn->dstat.st_mode)) {
-				char *lpath = xreadlink(dn->fullname);
+				char *lpath = xmalloc_readlink_or_warn(dn->fullname);
 				if (!lpath) break;
 				printf(" -> ");
 #if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR

Modified: trunk/busybox/coreutils/pwd.c
===================================================================
--- trunk/busybox/coreutils/pwd.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/coreutils/pwd.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -16,7 +16,8 @@
 {
 	char *buf;
 
-	if ((buf = xgetcwd(NULL)) != NULL) {
+	buf = xrealloc_getcwd_or_warn(NULL);
+	if (buf != NULL) {
 		puts(buf);
 		fflush_stdout_and_exit(EXIT_SUCCESS);
 	}

Modified: trunk/busybox/coreutils/stat.c
===================================================================
--- trunk/busybox/coreutils/stat.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/coreutils/stat.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -188,7 +188,7 @@
 	case 'N':
 		strncat(pformat, "s", buf_len);
 		if (S_ISLNK(statbuf->st_mode)) {
-			char *linkname = xreadlink(filename);
+			char *linkname = xmalloc_readlink_or_warn(filename);
 			if (linkname == NULL) {
 				bb_perror_msg("cannot read symbolic link '%s'", filename);
 				return;
@@ -477,7 +477,7 @@
 		pw_ent = getpwuid(statbuf.st_uid);
 
 		if (S_ISLNK(statbuf.st_mode))
-			linkname = xreadlink(filename);
+			linkname = xmalloc_readlink_or_warn(filename);
 		if (linkname)
 			printf("  File: \"%s\" -> \"%s\"\n", filename, linkname);
 		else

Modified: trunk/busybox/debianutils/readlink.c
===================================================================
--- trunk/busybox/debianutils/readlink.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/debianutils/readlink.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -38,7 +38,7 @@
 	if (opt) {
 		buf = realpath(fname, bb_common_bufsiz1);
 	} else {
-		buf = xreadlink(fname);
+		buf = xmalloc_readlink_or_warn(fname);
 	}
 
 	if (!buf)

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/include/libbb.h	2007-02-11 16:19:28 UTC (rev 17854)
@@ -258,8 +258,8 @@
 extern DIR *xopendir(const char *path);
 extern DIR *warn_opendir(const char *path);
 
-char *xgetcwd(char *cwd);
-char *xreadlink(const char *path);
+char *xrealloc_getcwd_or_warn(char *cwd);
+char *xmalloc_readlink_or_warn(const char *path);
 char *xmalloc_realpath(const char *path);
 extern void xstat(const char *filename, struct stat *buf);
 extern pid_t spawn(char **argv);

Modified: trunk/busybox/libbb/copy_file.c
===================================================================
--- trunk/busybox/libbb/copy_file.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/libbb/copy_file.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -233,7 +233,7 @@
 		} else if (S_ISLNK(source_stat.st_mode)) {
 			char *lpath;
 
-			lpath = xreadlink(source);
+			lpath = xmalloc_readlink_or_warn(source);
 			if (symlink(lpath, dest) < 0) {
 				bb_perror_msg("cannot create symlink '%s'", dest);
 				free(lpath);

Modified: trunk/busybox/libbb/lineedit.c
===================================================================
--- trunk/busybox/libbb/lineedit.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/libbb/lineedit.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -1090,7 +1090,7 @@
 	size_t cur_prmt_len = 0;
 	char flg_not_length = '[';
 	char *prmt_mem_ptr = xzalloc(1);
-	char *pwd_buf = xgetcwd(0);
+	char *pwd_buf = xrealloc_getcwd_or_warn(NULL);
 	char buf2[PATH_MAX + 1];
 	char buf[2];
 	char c;

Modified: trunk/busybox/libbb/simplify_path.c
===================================================================
--- trunk/busybox/libbb/simplify_path.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/libbb/simplify_path.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -16,7 +16,7 @@
 	if (path[0] == '/')
 		start = xstrdup(path);
 	else {
-		s = xgetcwd(NULL);
+		s = xrealloc_getcwd_or_warn(NULL);
 		start = concat_path_file(s, path);
 		free(s);
 	}

Modified: trunk/busybox/libbb/xgetcwd.c
===================================================================
--- trunk/busybox/libbb/xgetcwd.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/libbb/xgetcwd.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -18,7 +18,7 @@
 */
 
 char *
-xgetcwd(char *cwd)
+xrealloc_getcwd_or_warn(char *cwd)
 {
 	char *ret;
 	unsigned path_max;
@@ -26,7 +26,7 @@
 	path_max = (unsigned) PATH_MAX;
 	path_max += 2;                /* The getcwd docs say to do this. */
 
-	if (cwd==0)
+	if (cwd == NULL)
 		cwd = xmalloc(path_max);
 
 	while ((ret = getcwd(cwd, path_max)) == NULL && errno == ERANGE) {

Modified: trunk/busybox/libbb/xreadlink.c
===================================================================
--- trunk/busybox/libbb/xreadlink.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/libbb/xreadlink.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -11,7 +11,7 @@
  * yourself. You have been warned.
  */
 
-char *xreadlink(const char *path)
+char *xmalloc_readlink_or_warn(const char *path)
 {
 	enum { GROWBY = 80 }; /* how large we will grow strings by */
 

Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/shell/hush.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -423,8 +423,8 @@
 static const char *set_cwd(void)
 {
 	if (cwd == bb_msg_unknown)
-		cwd = NULL;     /* xgetcwd(arg) called free(arg) */
-	cwd = xgetcwd((char *)cwd);
+		cwd = NULL;     /* xrealloc_getcwd_or_warn(arg) called free(arg) */
+	cwd = xrealloc_getcwd_or_warn((char *)cwd);
 	if (!cwd)
 		cwd = bb_msg_unknown;
 	return cwd;

Modified: trunk/busybox/shell/lash.c
===================================================================
--- trunk/busybox/shell/lash.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/shell/lash.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -217,7 +217,7 @@
 		bb_perror_msg("cd: %s", newdir);
 		return EXIT_FAILURE;
 	}
-	cwd = xgetcwd((char *)cwd);
+	cwd = xrealloc_getcwd_or_warn((char *)cwd);
 	if (!cwd)
 		cwd = bb_msg_unknown;
 	return EXIT_SUCCESS;
@@ -342,7 +342,7 @@
 /* built-in 'pwd' handler */
 static int builtin_pwd(struct child_prog ATTRIBUTE_UNUSED *dummy)
 {
-	cwd = xgetcwd((char *)cwd);
+	cwd = xrealloc_getcwd_or_warn((char *)cwd);
 	if (!cwd)
 		cwd = bb_msg_unknown;
 	puts(cwd);
@@ -1569,7 +1569,7 @@
 	}
 
 	/* initialize the cwd -- this is never freed...*/
-	cwd = xgetcwd(0);
+	cwd = xrealloc_getcwd_or_warn(NULL);
 	if (!cwd)
 		cwd = bb_msg_unknown;
 

Modified: trunk/busybox/sysklogd/syslogd.c
===================================================================
--- trunk/busybox/sysklogd/syslogd.c	2007-02-11 14:52:07 UTC (rev 17853)
+++ trunk/busybox/sysklogd/syslogd.c	2007-02-11 16:19:28 UTC (rev 17854)
@@ -24,9 +24,6 @@
 
 #define DEBUG 0
 
-/* Path to the unix socket */
-static const char *dev_log_name;
-
 /* Path for the file where all log messages are written */
 static const char *logFilePath = "/var/log/messages";
 static int logFD = -1;
@@ -446,7 +443,6 @@
 {
 	timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0);
 	puts("syslogd exiting");
-	unlink(dev_log_name);
 	if (ENABLE_FEATURE_IPC_SYSLOG)
 		ipcsyslog_cleanup();
 	exit(1);
@@ -464,9 +460,9 @@
 static void do_syslogd(void)
 {
 	struct sockaddr_un sunx;
-	socklen_t addr_len;
 	int sock_fd;
 	fd_set fds;
+	char *dev_log_name;
 
 	/* Set up signal handlers */
 	signal(SIGINT, quit_signal);
@@ -480,22 +476,33 @@
 	signal(SIGALRM, do_mark);
 	alarm(markInterval);
 
-	dev_log_name = xmalloc_realpath(_PATH_LOG);
-	if (!dev_log_name)
-		dev_log_name = _PATH_LOG;
+	memset(&sunx, 0, sizeof(sunx));
+	sunx.sun_family = AF_UNIX;
+	strcpy(sunx.sun_path, "/dev/log");
 
-	/* Unlink old /dev/log (or object it points to) */
-	unlink(dev_log_name);
+	/* Unlink old /dev/log or object it points to. */
+	/* (if it exists, bind will fail) */
+	logmode = LOGMODE_NONE;
+	dev_log_name = xmalloc_readlink_or_warn("/dev/log");
+	logmode = LOGMODE_STDIO;
+	if (dev_log_name) {
+		int fd = xopen(".", O_NONBLOCK);
+		xchdir("/dev");
+		/* we do not check whether this is a link also */
+		unlink(dev_log_name);
+		fchdir(fd);
+		close(fd);
+		safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path));
+		free(dev_log_name);
+	} else {
+		unlink("/dev/log");
+	}
 
-	memset(&sunx, 0, sizeof(sunx));
-	sunx.sun_family = AF_UNIX;
-	strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path));
 	sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
-	addr_len = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
-	xbind(sock_fd, (struct sockaddr *) &sunx, addr_len);
+	xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx));
 
-	if (chmod(dev_log_name, 0666) < 0) {
-		bb_perror_msg_and_die("cannot set permission on %s", dev_log_name);
+	if (chmod("/dev/log", 0666) < 0) {
+		bb_perror_msg_and_die("cannot set permission on /dev/log");
 	}
 	if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) {
 		ipcsyslog_init();



More information about the busybox-cvs mailing list