[master] 01c4b27 Move creation of workdir to be a jail method.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Feb 18 11:12:51 CET 2015
commit 01c4b2787f18e8c547055b77d6b9a243bda5a5cd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Feb 18 10:12:15 2015 +0000
Move creation of workdir to be a jail method.
Neuter solaris jail entirely on platforms which don't have it.
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 718e6a4..b51be28 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -79,6 +79,7 @@ enum jail_master_e {
typedef int jail_init_f(char **);
typedef void jail_master_f(enum jail_master_e);
typedef void jail_subproc_f(enum jail_subproc_e);
+typedef void jail_make_workdir_f(const char *dname);
struct jail_tech {
unsigned magic;
@@ -87,11 +88,13 @@ struct jail_tech {
jail_init_f *init;
jail_master_f *master;
jail_subproc_f *subproc;
+ jail_make_workdir_f *make_workdir;
};
void VJ_Init(const char *j_arg);
void VJ_master(enum jail_master_e jme);
void VJ_subproc(enum jail_subproc_e jse);
+void VJ_make_workdir(const char *dname);
extern const struct jail_tech jail_tech_unix;
extern const struct jail_tech jail_tech_solaris;
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index c52b3cf..d35d42c 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -525,6 +525,7 @@ mgt_cli_telnet(const char *T_arg)
char abuf[VTCP_ADDRBUFSIZE];
char pbuf[VTCP_PORTBUFSIZE];
+ AN(T_arg);
n = VSS_resolve(T_arg, NULL, &ta);
if (n == 0) {
REPORT(LOG_ERR, "-T %s Could not be resolved\n", T_arg);
@@ -639,8 +640,8 @@ Marg_poker(const struct vev *e, int what)
void
mgt_cli_master(const char *M_arg)
{
- (void)M_arg;
+ AN(M_arg);
M_nta = VSS_resolve(M_arg, NULL, &M_ta);
if (M_nta <= 0) {
fprintf(stderr, "Could resolve -M argument to address\n");
diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c
index 081e9e8..ac791ff 100644
--- a/bin/varnishd/mgt/mgt_jail.c
+++ b/bin/varnishd/mgt/mgt_jail.c
@@ -31,8 +31,13 @@
#include "config.h"
+#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
#include "mgt/mgt.h"
#include "vav.h"
@@ -74,7 +79,9 @@ static const struct jail_tech jail_tech_none = {
static const struct jail_tech *vjt;
static const struct choice vj_choice[] = {
+#ifdef HAVE_SETPPRIV
{ "solaris", &jail_tech_solaris },
+#endif
{ "unix", &jail_tech_unix },
{ "none", &jail_tech_none },
{ NULL, NULL },
@@ -125,3 +132,32 @@ VJ_subproc(enum jail_subproc_e jse)
CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
vjt->subproc(jse);
}
+
+void
+VJ_make_workdir(const char *dname)
+{
+ int fd;
+
+ AN(dname);
+ CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
+ if (vjt->make_workdir != NULL) {
+ vjt->make_workdir(dname);
+ return;
+ }
+
+ if (mkdir(dname, 0755) < 0 && errno != EEXIST)
+ ARGV_ERR("Cannot create working directory '%s': %s\n",
+ dname, strerror(errno));
+
+ if (chdir(dname) < 0)
+ ARGV_ERR("Cannot change to working directory '%s': %s\n",
+ dname, strerror(errno));
+
+ fd = open("_.testfile", O_RDWR|O_CREAT|O_EXCL, 0600);
+ if (fd < 0)
+ ARGV_ERR("Error: Cannot create test-file in %s (%s)\n"
+ "Check permissions (or delete old directory)\n",
+ dname, strerror(errno));
+ AZ(close(fd));
+ AZ(unlink("_.testfile"));
+}
diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c
index d5538a1..a603359 100644
--- a/bin/varnishd/mgt/mgt_jail_solaris.c
+++ b/bin/varnishd/mgt/mgt_jail_solaris.c
@@ -203,6 +203,9 @@
*/
#include "config.h"
+
+#ifdef HAVE_SETPPRIV
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -214,28 +217,6 @@
#include "common/heritage.h"
#include "common/params.h"
-#ifndef HAVE_SETPPRIV
-
-/* ============================================================
- * on platforms without setppriv, fail the init to mark that
- * this jail is unavailable
- */
-
-static int __match_proto__(jail_init_f)
-vjs_init(char **args)
-{
- (void) args;
- return 1;
-}
-
-const struct jail_tech jail_tech_solaris = {
- .magic = JAIL_TECH_MAGIC,
- .name = "solaris (unavailable)",
- .init = vjs_init,
-};
-
-#else /* HAVE_SETPPRIV */
-
#ifdef HAVE_PRIV_H
#include <priv.h>
#endif
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 1a6cf3b..a2e823b 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -31,7 +31,6 @@
#include "config.h"
-#include <sys/stat.h>
#include <sys/utsname.h>
#include <ctype.h>
@@ -362,7 +361,7 @@ init_params(struct cli *cli)
int
main(int argc, char * const *argv)
{
- int o, fd;
+ int o;
unsigned C_flag = 0;
unsigned F_flag = 0;
const char *b_arg = NULL;
@@ -535,10 +534,7 @@ main(int argc, char * const *argv)
S_arg = optarg;
break;
case 'T':
- if (*optarg != '\0')
- T_arg = optarg;
- else
- T_arg = NULL;
+ T_arg = optarg;
break;
case 'V':
/* XXX: we should print the ident here */
@@ -620,21 +616,7 @@ main(int argc, char * const *argv)
else
openlog("varnishd", LOG_PID, LOG_LOCAL0);
- if (mkdir(dirname, 0755) < 0 && errno != EEXIST)
- ARGV_ERR("Cannot create working directory '%s': %s\n",
- dirname, strerror(errno));
-
- if (chdir(dirname) < 0)
- ARGV_ERR("Cannot change to working directory '%s': %s\n",
- dirname, strerror(errno));
-
- fd = open("_.testfile", O_RDWR|O_CREAT|O_EXCL, 0600);
- if (fd < 0)
- ARGV_ERR("Error: Cannot create test-file in %s (%s)\n"
- "Check permissions (or delete old directory)\n",
- dirname, strerror(errno));
- AZ(close(fd));
- AZ(unlink("_.testfile"));
+ VJ_make_workdir(dirname);
/* XXX: should this be relative to the -n arg ? */
if (P_arg && (pfh = VPF_Open(P_arg, 0644, NULL)) == NULL)
More information about the varnish-commit
mailing list