r2768 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Sun Jun 22 10:50:24 CEST 2008
Author: phk
Date: 2008-06-22 10:50:23 +0200 (Sun, 22 Jun 2008)
New Revision: 2768
Modified:
trunk/varnish-cache/bin/varnishd/mgt_vcc.c
Log:
Use VLU to assemble output from the C-compiler.
Close all fd's above stderr before exec'ing the C-compiler.
Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-06-22 08:10:38 UTC (rev 2767)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-06-22 08:50:23 UTC (rev 2768)
@@ -47,6 +47,7 @@
#include "compat/asprintf.h"
#endif
#include "vsb.h"
+#include "vlu.h"
#include "vqueue.h"
@@ -201,6 +202,16 @@
* Errors goes in sb;
*/
+static int
+mgt_cc_vlu(void *priv, const char *str)
+{
+ struct vsb *vsb;
+
+ vsb = priv;
+ vsb_printf(vsb, "C-compiler said: %s\n", str);
+ return (0);
+}
+
static char *
mgt_run_cc(const char *source, struct vsb *sb)
{
@@ -208,10 +219,10 @@
struct vsb cmdsb;
char sf[] = "./vcl.########.c";
char *of;
- char buf[128];
int p[2], sfd, srclen, status;
pid_t pid;
void *dlh;
+ struct vlu *vlu;
/* Create temporary C source file */
sfd = vtmpfile(sf);
@@ -235,6 +246,7 @@
/* Name the output shared library by overwriting the final 'c' */
of = strdup(sf);
XXXAN(of);
+ assert(of[sizeof sf - 2] == 'c');
of[sizeof sf - 2] = 'o';
AN(vsb_new(&cmdsb, cmdline, sizeof cmdline, 0));
mgt_make_cc_cmd(&cmdsb, sf, of);
@@ -249,6 +261,8 @@
free(of);
return (NULL);
}
+ assert(p[0] > STDERR_FILENO);
+ assert(p[1] > STDERR_FILENO);
if ((pid = fork()) < 0) {
vsb_printf(sb, "%s(): fork() failed: %s",
__func__, strerror(errno));
@@ -259,21 +273,22 @@
return (NULL);
}
if (pid == 0) {
- AZ(close(p[0]));
AZ(close(STDIN_FILENO));
assert(open("/dev/null", O_RDONLY) == STDIN_FILENO);
assert(dup2(p[1], STDOUT_FILENO) == STDOUT_FILENO);
assert(dup2(p[1], STDERR_FILENO) == STDERR_FILENO);
+ /* Close all other fds */
+ for (sfd = STDERR_FILENO + 1; sfd < 100; sfd++)
+ (void)close(sfd);
(void)execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
_exit(1);
}
AZ(close(p[1]));
- do {
- status = read(p[0], buf, sizeof buf);
- if (status > 0)
- vsb_printf(sb, "C-Compiler said: %.*s", status, buf);
- } while (status > 0);
+ vlu = VLU_New(sb, mgt_cc_vlu, 0);
+ while (!VLU_Fd(p[0], vlu))
+ continue;
AZ(close(p[0]));
+ VLU_Destroy(vlu);
(void)unlink(sf);
if (waitpid(pid, &status, 0) < 0) {
vsb_printf(sb, "%s(): waitpid() failed: %s",
More information about the varnish-commit
mailing list