Commit 06b3c206 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

And rename the various file-accesors to VFIL_

Remove srandomdev() look-alike, we already have a compat version
parent 368197ad
......@@ -44,6 +44,7 @@
#include "vcli.h"
#include "vsub.h"
#include "vcl.h"
#include "vfil.h"
#include "cli_priv.h"
#include "mgt_cli.h"
......@@ -227,7 +228,7 @@ mgt_run_cc(const char *vcl, struct vsb *sb, int C_flag)
struct vcc_priv vp;
/* Create temporary C source file */
sfd = vtmpfile(sf);
sfd = VFIL_tmpfile(sf);
if (sfd < 0) {
VSB_printf(sb, "Failed to create %s: %s", sf, strerror(errno));
return (NULL);
......@@ -245,7 +246,7 @@ mgt_run_cc(const char *vcl, struct vsb *sb, int C_flag)
}
if (C_flag) {
csrc = vreadfile(NULL, sf, NULL);
csrc = VFIL_readfile(NULL, sf, NULL);
XXXAN(csrc);
(void)fputs(csrc, stdout);
free(csrc);
......@@ -517,7 +518,7 @@ mcf_config_load(struct cli *cli, const char * const *av, void *priv)
return;
}
vcl = vreadfile(mgt_vcl_dir, av[3], NULL);
vcl = VFIL_readfile(mgt_vcl_dir, av[3], NULL);
if (vcl == NULL) {
VCLI_Out(cli, "Cannot open '%s'", av[3]);
VCLI_SetResult(cli, CLIS_PARAM);
......
......@@ -55,12 +55,17 @@
#include "vav.h"
#include "vin.h"
#include "vfil.h"
#include "vtim.h"
#include "heritage.h"
#include "mgt.h"
#include "hash_slinger.h"
#include "stevedore.h"
#ifndef HAVE_SRANDOMDEV
#include "compat/srandomdev.h"
#endif
struct heritage heritage;
volatile struct params *params;
unsigned d_flag = 0;
......@@ -355,7 +360,7 @@ main(int argc, char * const *argv)
for (o = getdtablesize(); o > STDERR_FILENO; o--)
(void)close(o);
AZ(seed_random());
srandomdev();
mgt_got_fd(STDERR_FILENO);
......@@ -543,7 +548,7 @@ main(int argc, char * const *argv)
}
if (f_arg != NULL) {
vcl = vreadfile(NULL, f_arg, NULL);
vcl = VFIL_readfile(NULL, f_arg, NULL);
if (vcl == NULL) {
fprintf(stderr, "Cannot read '%s': %s\n",
f_arg, strerror(errno));
......
......@@ -44,6 +44,7 @@ nobase_noinst_HEADERS = \
vct.h \
vend.h \
vev.h \
vfil.h \
vin.h \
vlu.h \
vmb.h \
......
......@@ -41,12 +41,6 @@ struct vsb;
/* from libvarnish/version.c */
void VCS_Message(const char *);
/* from libvarnish/vtmpfile.c */
int seed_random(void);
int vtmpfile(char *);
char *vreadfile(const char *pfx, const char *fn, ssize_t *sz);
char *vreadfd(int fd, ssize_t *sz);
/* Safe printf into a fixed-size buffer */
#define bprintf(buf, fmt, ...) \
do { \
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
/* from libvarnish/vfil.c */
int seed_random(void);
int VFIL_tmpfile(char *);
char *VFIL_readfile(const char *pfx, const char *fn, ssize_t *sz);
char *VFIL_readfd(int fd, ssize_t *sz);
......@@ -19,6 +19,7 @@ libvarnish_la_SOURCES = \
vct.c \
version.c \
vev.c \
vfil.c \
vin.c \
vlu.c \
vmb.c \
......@@ -26,8 +27,7 @@ libvarnish_la_SOURCES = \
vre.c \
vsb.c \
vsha256.c \
vss.c \
vtmpfile.c
vss.c
libvarnish_la_CFLAGS = -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
libvarnish_la_LIBADD = ${RT_LIBS} ${NET_LIBS} ${LIBM} @PCRE_LIBS@
......
......@@ -39,30 +39,12 @@
#include <sys/stat.h>
#include "vas.h"
#include "vfil.h"
#include "libvarnish.h"
int
seed_random(void)
{
int fd;
unsigned seed;
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1) {
/* urandom not available, fall back to something
* weaker */
srandom(time(NULL));
return (0);
}
if (read(fd, &seed, sizeof seed) != sizeof seed)
return (1);
(void)close(fd);
srandom(seed);
return (0);
}
int
vtmpfile(char *template)
VFIL_tmpfile(char *template)
{
char *b, *e, *p;
int fd;
......@@ -99,7 +81,7 @@ vtmpfile(char *template)
}
char *
vreadfd(int fd, ssize_t *sz)
VFIL_readfd(int fd, ssize_t *sz)
{
struct stat st;
char *f;
......@@ -119,7 +101,7 @@ vreadfd(int fd, ssize_t *sz)
}
char *
vreadfile(const char *pfx, const char *fn, ssize_t *sz)
VFIL_readfile(const char *pfx, const char *fn, ssize_t *sz)
{
int fd, err;
char *r;
......@@ -134,7 +116,7 @@ vreadfile(const char *pfx, const char *fn, ssize_t *sz)
fd = open(fn, O_RDONLY);
if (fd < 0)
return (NULL);
r = vreadfd(fd, sz);
r = VFIL_readfd(fd, sz);
err = errno;
AZ(close(fd));
errno = err;
......
......@@ -61,6 +61,7 @@
#include "vcc_compile.h"
#include "libvcl.h"
#include "vfil.h"
struct method method_tab[] = {
#define VCL_MET_MAC(l,U,m) { "vcl_"#l, m, VCL_MET_##U },
......@@ -409,7 +410,7 @@ vcc_file_source(const struct vcc *tl, struct vsb *sb, const char *fn)
char *f;
struct source *sp;
f = vreadfile(tl->vcl_dir, fn, NULL);
f = VFIL_readfile(tl->vcl_dir, fn, NULL);
if (f == NULL) {
VSB_printf(sb, "Cannot read file '%s': %s\n",
fn, strerror(errno));
......
......@@ -42,6 +42,7 @@
#include "../../bin/varnishd/cache.h"
#include "vcc_if.h"
#include "vfil.h"
struct frfile {
unsigned magic;
......@@ -102,7 +103,7 @@ vmod_fileread(struct sess *sp, struct vmod_priv *priv, const char *file_name)
return (frf->contents);
}
s = vreadfile(NULL, file_name, NULL);
s = VFIL_readfile(NULL, file_name, NULL);
if (s != NULL) {
ALLOC_OBJ(frf, CACHED_FILE_MAGIC);
AN(frf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment