Browse Source

vcc: change the implementation of m4_hook

intirain 4 years ago
parent
commit
867199c80e
4 changed files with 41 additions and 14 deletions
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/config.h
  3. 2 2
      include/vcc/version.h
  4. 37 10
      plugins/m4/m4.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
 VCC_MINOR 		= 29
-VCC_PATCH 		= 0
+VCC_PATCH 		= 1
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 1 - 1
include/vcc/config.h

@@ -1 +1 @@
-#define INSTALL_PATH "/home/ubuntu/vcc"
+#define INSTALL_PATH "/root/vcc"

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.29.0 Sun 12 Jun 2022 02:07:09 PM CST ubuntu"
-#define VCC_SEMVER "vcc 1.29.0-rc "
+#define VCC_VERSION "VCC 1.29.1 Sun Jun 12 07:56:17 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.29.1-rc "

+ 37 - 10
plugins/m4/m4.c

@@ -105,8 +105,15 @@ static inline int check_hist_enabled(void) {
 }
 
 
-int m4_write_predef(int fd) {
-	struct history *hist;
+/* this causes a infinite recursion, which is the thing m4 programmers are afraid of.  */
+
+int m4_write_predef(char *buf) {
+	(void) buf;
+	
+#if 0
+	struct history 		*hist;
+	char 			*p;
+	char 			s[128];
 
 	if (!check_hist_enabled()) {
 		fprintf(stderr, _("the history plugin (hist) doesn't insert so m4 preder can't work. \n"));
@@ -117,30 +124,44 @@ int m4_write_predef(int fd) {
 	hist = hist_getmsg(1);
 
 	if (!hist) 
-		return 0;
+		p = "\n";
+	else 
+		p = hist->msg;
 
-	dprintf(fd, "divert(-1)define(`LAST_MSG', `%s'\n)divert(0)dnl\n", hist->msg);
+	sprintf(s, "divert(-1)define(`LAST_MSG', `%s'\n)divert(0)dnl\n", p);
+	strcat(buf, s);
 
+#endif
 	return 0;
 }
 
 
 char *m4_hook(struct hook_info *hi) {
-	int 	fdt, size;
+	int 	fdt;
 	FILE 	*fp;
 	char 	*p;
 
-	if (unlikely((fdt = open("/tmp/.vcc-tmp", O_WRONLY | O_TRUNC | O_CREAT, 0666)) < 0)) {
+	if (unlikely((fdt = open("/tmp/.vcc-tmp", O_WRONLY | O_TRUNC | O_CREAT | O_APPEND, 0666)) < 0)) {
 		perror("open");
 
 		return NULL;
 	}
+
+	if (unlikely(!(p = malloc(8192)))) {
+		fprintf(stderr, "*** malloc() failed\n");
+
+		return NULL;
+	}
+
+	memset(p, 0, 8192);
 	
-	write(fdt, m4cachep, m4cache_size);
-	m4_write_predef(fdt);
+	if (m4cachep) 
+		strcat(p, m4cachep);
 
-	size = strlen(hi->msg) + 1;
-	write(fdt, hi->msg, size);
+	m4_write_predef(p);
+	strcat(p, hi->msg);
+
+	write(fdt, p, strlen(p));
 	close(fdt);
 
 	if (unlikely(!(fp = popen("/bin/m4 /tmp/.vcc-tmp", "r")))) {
@@ -166,6 +187,12 @@ int m4_init(void) {
 	m4cachep = NULL;
 	m4cache_size = 0;
 
+	if (check_hist_enabled()) {
+		fprintf(stderr, "*** fatal: enable m4 after the hist enabled will cause a RECURSION when try to use LAST_MSG! \n");
+
+		return 1;
+	}
+
 	register_hook(HOOK_SEND, m4_hook);
 	return 0;
 }