Mailing List Archive

r1528 - trunk/varnish-cache/bin/varnishd
Author: cecilihf
Date: 2007-06-15 14:26:56 +0200 (Fri, 15 Jun 2007)
New Revision: 1528

Modified:
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
A change in the default value of the name, and test for correct naming convention


Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 11:23:13 UTC (rev 1527)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-06-15 12:26:56 UTC (rev 1528)
@@ -506,18 +506,31 @@
char *path;
char *old_path;
int renaming;
+ char hostname[1024];
+ char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789.-";
(void)par;

if (arg != NULL) {
+ if (strlen(arg) == 0) {
+ gethostname(hostname, sizeof hostname);
+ arg = hostname;
+ }
/* Check that the new name follows hostname convention */
- /* [a-zA-Z0-9.-] */
+ if (strspn(arg, valid_chars) != strlen(arg)) {
+ cli_out(cli, "Error: %s is an invalid name\n", arg);
+ cli_result(cli, CLIS_PARAM);
+ return;
+ }
asprintf(&old_path, "/tmp/%s", master.name);
/* Create/rename the temporary varnish directory */
asprintf(&path, "/tmp/%s", arg);
- renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode));
+ renaming = (master.name && !stat(old_path, &st_old) &&
+ S_ISDIR(st_old.st_mode));
if (stat(path, &st)) {
if (renaming) {
- if (renaming && rename(old_path, path)) {
+ if (rename(old_path, path)) {
cli_out(cli,
"Error: Directory %s could not be "
"renamed to %s",
@@ -548,6 +561,7 @@
exit (2);
}
/* Everything is fine, store the (new) name */
+ free(master.name);
master.name = strdup(arg);
}
else
@@ -734,7 +748,7 @@
"naming conventions. Makes it possible to run "
"multiple varnishd instances on one server.\n"
EXPERIMENTAL,
- "hostname" },
+ "", "hostname" },
{ NULL, NULL, NULL }
};


Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 11:23:13 UTC (rev 1527)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-06-15 12:26:56 UTC (rev 1528)
@@ -411,7 +411,10 @@
struct cli cli[1];
struct pidfh *pfh = NULL;
char buf[BUFSIZ];
-
+ char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789.-";
+
setbuf(stdout, NULL);
setbuf(stderr, NULL);

@@ -451,6 +454,10 @@
h_arg = optarg;
break;
case 'n':
+ if (strspn(optarg, valid_chars) != strlen(optarg)) {
+ fprintf(stderr, "%s is not a valid name\n", optarg);
+ exit(1);
+ }
MCF_ParamSet(cli, "name", optarg);
break;
case 'P':