You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by mt...@apache.org on 2010/05/14 17:47:41 UTC
svn commit: r944324 - in /trafficserver/traffic/trunk/iocore/utils:
I_Layout.h Layout.cc Makefile.am
Author: mturk
Date: Fri May 14 15:47:40 2010
New Revision: 944324
URL: http://svn.apache.org/viewvc?rev=944324&view=rev
Log:
Second part of resolving TS-345, the Layout class. It uses new ink_filepath_merge to calculate all layout paths at runtime. It should be used instead current path guessing/calculating code across various places
Added:
trafficserver/traffic/trunk/iocore/utils/I_Layout.h (with props)
trafficserver/traffic/trunk/iocore/utils/Layout.cc
Modified:
trafficserver/traffic/trunk/iocore/utils/Makefile.am
Added: trafficserver/traffic/trunk/iocore/utils/I_Layout.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/I_Layout.h?rev=944324&view=auto
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/I_Layout.h (added)
+++ trafficserver/traffic/trunk/iocore/utils/I_Layout.h Fri May 14 15:47:40 2010
@@ -0,0 +1,79 @@
+/** @file
+
+ Layout
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ @section details Details
+
+ Part of the utils library which contains classes that use multiple
+ components of the IO-Core to implement some useful functionality. The
+ classes also serve as good examples of how to use the IO-Core.
+
+ */
+
+#ifndef _I_Layout_h
+#define _I_Layout_h
+
+
+/**
+ The Layout is a simple place holder for the distribution layout.
+
+ */
+struct Layout
+{
+ char *prefix;
+ char *exec_prefix;
+ char *bindir;
+ char *sbindir;
+ char *sysconfdir;
+ char *datadir;
+ char *includedir;
+ char *libdir;
+ char *libexecdir;
+ char *localstatedir;
+ char *sharedstatedir;
+ char *mandir;
+ char *infodir;
+
+ Layout(const char *prefix = 0);
+ ~Layout();
+
+ /**
+ Return file path relative to Layout->prefix
+ Memory is allocated, so use free() when no longer needed
+
+ */
+ char *relative(const char *file);
+};
+
+/**
+ Creates a Layout Object with the given prefix. If no
+ prefix is given, the prefix defaults to the one specified
+ at the compile time.
+
+ */
+void create_default_layout(const char *prefix = 0);
+
+/**
+ Returns the Layout object created by create_default_layout().
+ */
+Layout *default_layout();
+
+#endif
Propchange: trafficserver/traffic/trunk/iocore/utils/I_Layout.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: trafficserver/traffic/trunk/iocore/utils/Layout.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Layout.cc?rev=944324&view=auto
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Layout.cc (added)
+++ trafficserver/traffic/trunk/iocore/utils/Layout.cc Fri May 14 15:47:40 2010
@@ -0,0 +1,170 @@
+/** @file
+
+ A brief file description
+
+ @section license License
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#include "inktomi++.h"
+#include "I_Layout.h"
+
+#define DEFAULT_TS_DIRECTORY_FILE SYSCONFDIR "/trafficserver-root"
+
+static Layout *layout = NULL;
+
+Layout *
+default_layout()
+{
+ if (layout == NULL) {
+ ink_assert("need to call create_default_layout before accessing" "default_layout()");
+ }
+ return layout;
+}
+
+void
+create_default_layout(const char *prefix)
+{
+ layout = NEW(new Layout(prefix));
+}
+
+static char *
+layout_relative(const char *root, const char *file)
+{
+ char path[PATH_MAX];
+
+ if (ink_filepath_merge(path, PATH_MAX, root, file,
+ INK_FILEPATH_TRUENAME)) {
+ int err = errno;
+ // Log error
+ if (err == EACCES) {
+ ink_error("Cannot merge path '%s' above the root '%s'\n", file, root);
+ } else if (err == E2BIG) {
+ ink_error("Excedding file name length limit of %d characters\n", PATH_MAX);
+ }
+ else {
+ // TODO: Make some pretty errors.
+ ink_error("Cannot merge '%s' with '%s' error=%d\n", file, root, err);
+ }
+ return NULL;
+ }
+ return strdup(path);
+}
+
+char *
+Layout::relative(const char *file)
+{
+ return layout_relative(prefix, file);
+}
+
+Layout::Layout(const char *_prefix)
+{
+ if (_prefix) {
+ prefix = strdup(_prefix);
+ }
+ else {
+ FILE *fp;
+ char *env_path;
+ char path[PATH_MAX];
+ size_t path_len = PATH_MAX - 1;
+ struct stat s;
+ int err;
+
+ if ((env_path = getenv("TS_ROOT"))) {
+ ink_strncpy(path, env_path, path_len);
+ // strip trailing "/" if it exists
+ int len = strlen(path);
+ if (path[len - 1] == '/') {
+ path[len - 1] = '\0';
+ }
+ } else {
+ if ((fp = fopen(DEFAULT_TS_DIRECTORY_FILE, "r")) != NULL) {
+ if (fgets(path, path_len, fp) == NULL) {
+ fclose(fp);
+ ink_error("Invalid contents in %s. "
+ "Please set correct path in env variable TS_ROOT\n",
+ DEFAULT_TS_DIRECTORY_FILE);
+ return;
+ }
+ // strip newline if it exists
+ int len = strlen(path);
+ if (path[len - 1] == '\n') {
+ path[len - 1] = '\0';
+ }
+ // strip trailing "/" if it exists
+ len = strlen(path);
+ if (path[len - 1] == '/') {
+ path[len - 1] = '\0';
+ }
+
+ fclose(fp);
+ } else {
+ // Use compile time --prefix
+ ink_strncpy(path, PREFIX, path_len);
+ }
+ }
+
+ if ((err = stat(path, &s)) < 0) {
+ ink_error("unable to stat() TS_ROOT '%s': %d %d, %s\n",
+ path, err, errno, strerror(errno));
+ return;
+ }
+ prefix = strdup(path);
+ }
+ exec_prefix = layout_relative(prefix, EXEC_PREFIX);
+ bindir = layout_relative(prefix, BINDIR);
+ sbindir = layout_relative(prefix, SBINDIR);
+ sysconfdir = layout_relative(prefix, SYSCONFDIR);
+ datadir = layout_relative(prefix, DATADIR);
+ includedir = layout_relative(prefix, INCLUDEDIR);
+ libdir = layout_relative(prefix, LIBDIR);
+ libexecdir = layout_relative(prefix, LIBEXECDIR);
+ localstatedir = layout_relative(prefix, LOCALSTATEDIR);
+ sharedstatedir = layout_relative(prefix, SHAREDSTATEDIR);
+ mandir = layout_relative(prefix, MANDIR);
+ infodir = layout_relative(prefix, INFODIR);
+
+#ifdef DEBUG
+// TODO: Use a propper Debug logging
+//
+#define PrintSTR(var) \
+ fprintf(stdout, "%18s = '%s'\n", "--" #var, (var == NULL? "NULL" : var));
+
+ fprintf(stdout, "Layout configuration\n");
+ PrintSTR(prefix);
+ PrintSTR(exec_prefix);
+ PrintSTR(bindir);
+ PrintSTR(sbindir);
+ PrintSTR(sysconfdir);
+ PrintSTR(datadir);
+ PrintSTR(includedir);
+ PrintSTR(libdir);
+ PrintSTR(libexecdir);
+ PrintSTR(localstatedir);
+ PrintSTR(sharedstatedir);
+ PrintSTR(mandir);
+ PrintSTR(infodir);
+#endif
+
+}
+
+Layout::~Layout()
+{
+ if (prefix)
+ xfree(prefix);
+}
Modified: trafficserver/traffic/trunk/iocore/utils/Makefile.am
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/iocore/utils/Makefile.am?rev=944324&r1=944323&r2=944324&view=diff
==============================================================================
--- trafficserver/traffic/trunk/iocore/utils/Makefile.am (original)
+++ trafficserver/traffic/trunk/iocore/utils/Makefile.am Fri May 14 15:47:40 2010
@@ -19,19 +19,34 @@
AM_CPPFLAGS = \
-I$(top_srcdir)/librecords \
-I$(top_srcdir)/iocore/eventsystem \
- -I$(top_srcdir)/libinktomi++
+ -I$(top_srcdir)/libinktomi++ \
+ -DPREFIX=\"$(prefix)\" \
+ -DEXEC_PREFIX=\"$(exec_prefix)\" \
+ -DBINDIR=\"$(bindir)\" \
+ -DSBINDIR=\"$(sbindir)\" \
+ -DSYSCONFDIR=\"$(sysconfdir)\" \
+ -DDATADIR=\"$(datadir)\" \
+ -DINCLUDEDIR=\"$(includedir)\" \
+ -DLIBDIR=\"$(libdir)\" \
+ -DLIBEXECDIR=\"$(libexecdir)\" \
+ -DLOCALSTATEDIR=\"$(localstatedir)\" \
+ -DSHAREDSTATEDIR=\"$(sharedstatedir)\" \
+ -DMANDIR=\"$(mandir)\" \
+ -DINFODIR=\"$(infodir)\"
DEFS += @IOCORE_MODULARIZED_DEFS@
noinst_LIBRARIES = libinkutils.a
libinkutils_a_SOURCES = \
+ I_Layout.h \
I_Machine.h \
I_MTInteractor.h \
I_OneWayMultiTunnel.h \
I_OneWayTunnel.h \
I_OpQueue.h \
I_RadixSort.h \
+ Layout.cc \
MTInteractor.cc \
Machine.cc \
OneWayMultiTunnel.cc \