aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 11:28:28 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-19 18:30:01 +0300
commit1153970626892573e5966e135e8d81185f4ea53c (patch)
tree773fdf5a8d00ec2ef752c3a8fd5f32c79829cf23 /src
downloadeclat-1153970626892573e5966e135e8d81185f4ea53c.tar.gz
eclat-1153970626892573e5966e135e8d81185f4ea53c.tar.bz2
Initial commit
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore2
-rw-r--r--src/Makefile.am44
-rw-r--r--src/accfile.c105
-rw-r--r--src/cmdline.opt226
-rw-r--r--src/config.c110
-rw-r--r--src/diag.c108
-rw-r--r--src/eclat.c162
-rw-r--r--src/eclat.h81
-rw-r--r--src/error.c64
-rw-r--r--src/startinst.c28
10 files changed, 930 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..2f6973f
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,2 @@
+cmdline.h
+eclat
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..a16aff8
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,44 @@
+# This file is part of Eclat
+# Copyright (C) 2012 Sergey Poznyakoff
+#
+# Eclat is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Eclat is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Eclat. If not, see <http://www.gnu.org/licenses/>.
+
+bin_PROGRAMS=eclat
+
+eclat_SOURCES=\
+ accfile.c\
+ cmdline.h\
+ config.c\
+ diag.c\
+ eclat.c\
+ eclat.h\
+ startinst.c
+
+AM_LDFLAGS = $(CURL_LIBS)
+LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a
+INCLUDES = -I$(top_srcdir)/grecs/src/ -I$(top_srcdir)/lib $(CURL_CFLAGS)
+AM_CPPFLAGS= \
+ -DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
+ -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
+ -DDEFAULT_PREPROCESSOR="$(DEFAULT_PREPROCESSOR)"
+
+BUILT_SOURCES=cmdline.h
+EXTRA_DIST=cmdline.opt
+
+SUFFIXES=.opt .c .h
+
+.opt.h:
+ m4 -s $(top_srcdir)/grecs/build-aux/getopt.m4 $< | sed '1d' > $@
+
diff --git a/src/accfile.c b/src/accfile.c
new file mode 100644
index 0000000..3fe669d
--- /dev/null
+++ b/src/accfile.c
@@ -0,0 +1,105 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+char *access_file_name;
+
+static void
+skipline(FILE *fp)
+{
+ int c;
+
+ while ((c = getc(fp)) != EOF && c != '\n')
+ ;
+}
+
+int
+access_file_lookup(const char *id, char **access_key_ptr, char **secret_key_ptr)
+{
+ int rc;
+ int c;
+ FILE *fp;
+ size_t line = 0;
+ struct grecs_txtacc *acc;
+
+ if (!access_file_name)
+ return 1;
+ fp = fopen(access_file_name, "r");
+ if (!fp) {
+ err("cannot open \"%s\": %s",
+ access_file_name, strerror(errno));
+ return 1;
+ }
+
+ while ((c = getc(fp)) != EOF) {
+ line++;
+ while (c != EOF && (c == ' ' || c == '\t'))
+ c = getc(fp);
+ if (c == '\n')
+ continue;
+ if (c == '#') {
+ skipline(fp);
+ continue;
+ }
+ if (c == EOF)
+ break;
+ if (id) {
+ const char *p;
+
+ for (p = id; c != EOF && c != ':' && *p == c; p++)
+ c = getc(fp);
+ if (c == EOF)
+ break;
+ if (c == '\n')
+ continue;
+ if (c != ':') {
+ skipline(fp);
+ continue;
+ }
+ } else {
+ acc = grecs_txtacc_create();
+ while ((c = getc(fp)) != EOF && c != ':') {
+ if (c == '\n') {
+ err("%s:%u: incomplete line",
+ access_file_name, line);
+ break;
+ }
+ grecs_txtacc_grow_char(acc, c);
+ }
+ if (c == ':') {
+ grecs_txtacc_grow_char(acc, 0);
+ *access_key_ptr = grecs_txtacc_finish(acc, 1);
+ }
+ grecs_txtacc_free(acc);
+ }
+ break;
+ }
+
+ if (c == ':') {
+ acc = grecs_txtacc_create();
+ while ((c = getc(fp)) != EOF && c != '\n')
+ grecs_txtacc_grow_char(acc, c);
+ grecs_txtacc_grow_char(acc, 0);
+ *secret_key_ptr = grecs_txtacc_finish(acc, 1);
+ rc = 0;
+ } else
+ rc = 1;
+
+ fclose(fp);
+
+ return rc;
+}
diff --git a/src/cmdline.opt b/src/cmdline.opt
new file mode 100644
index 0000000..25dc542
--- /dev/null
+++ b/src/cmdline.opt
@@ -0,0 +1,226 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_GETOPT_H
+# include <getopt.h>
+#endif
+
+static char *pp_cmd_buffer;
+static size_t pp_cmd_bufsize;
+static size_t pp_cmd_buflevel;
+
+struct replvar {
+ char **s_ptr;
+ char *s_val;
+};
+
+int
+replace_string_var(void *p)
+{
+ struct replvar *rv = p;
+ *rv->s_ptr = rv->s_val;
+ return 0;
+}
+
+OPTIONS_BEGIN("eclat",
+ [<EC2 Command Line Administrator Tool>],[<>],
+ [<gnu>],
+ [<copyright_year=2012>],
+ [<copyright_holder=Sergey Poznyakoff>])
+
+GROUP(Selecting program mode)
+
+OPTION(lint,t,,
+ [<parse configuration file and exit>])
+BEGIN
+ lint_mode = 1;
+END
+
+OPTION(,E,,
+ [<preprocess config and exit>])
+BEGIN
+ preprocess_only = 1;
+END
+
+OPTION(dry-run,n,,
+ [<do nothing, print almost everything>])
+BEGIN
+ dry_run_mode = 1;
+END
+
+OPTION(config-file,c,FILE,
+ [<use FILE instead of the default configuration>])
+BEGIN
+ conffile = optarg;
+END
+
+GROUP(Commands)
+
+OPTION(start-instances,,,
+ [<Start named instances>])
+BEGIN
+ eclat_command = eclat_command_start_instances;
+END
+
+OPTION(stop-instances,,,
+ [<Stop named instances>])
+BEGIN
+ eclat_command = eclat_command_stop_instances;
+END
+
+GROUP(Modifiers)
+
+OPTION(region,,NAME,
+ [<define AWS region>])
+BEGIN
+ struct replvar *rv = grecs_malloc(sizeof(*rv));
+ rv->s_ptr = &region_name;
+ rv->s_val = optarg;
+ add_config_finish_hook(replace_string_var, rv);
+END
+
+OPTION(access-file,a,NAME,
+ [<set access file>])
+BEGIN
+ struct replvar *rv = grecs_malloc(sizeof(*rv));
+ rv->s_ptr = &access_file_name;
+ rv->s_val = optarg;
+ add_config_finish_hook(replace_string_var, rv);
+END
+
+OPTION(access-key,O,KEY,
+ [<set access key to use>])
+BEGIN
+ access_key = optarg;
+END
+
+OPTION(secret-key,W,KEY,
+ [<set secret key to use>])
+BEGIN
+ secret_key = optarg;
+END
+
+OPTION(ssl,,,
+ [<use SSL (HTTPS) connection>])
+BEGIN
+ use_ssl = 1;
+END
+
+GROUP(Preprocessor control)
+
+OPTION(include-directory,I,DIR,
+ [<add include directory>])
+BEGIN
+ grecs_preproc_add_include_dir(optarg);
+END
+
+OPTION(define,D,SYMBOL[=VALUE],
+ [<define a preprocessor symbol>])
+BEGIN
+ size_t len;
+ char *p;
+
+ len = 4;
+ for (p = optarg; *p; p++) {
+ if (*p == '\\' || *p == '"')
+ len++;
+ len++;
+ }
+
+ if (pp_cmd_buflevel + len + 1 > pp_cmd_bufsize) {
+ pp_cmd_bufsize = pp_cmd_buflevel + len + 1;
+ pp_cmd_buffer = grecs_realloc(pp_cmd_buffer, pp_cmd_bufsize);
+ }
+ memcpy(pp_cmd_buffer + pp_cmd_buflevel, " \"-D", 4);
+ pp_cmd_buflevel += 4;
+
+ p = optarg;
+ do {
+ if (*p == '\\' || *p == '"')
+ pp_cmd_buffer[pp_cmd_buflevel++] = '\\';
+ pp_cmd_buffer[pp_cmd_buflevel++] = *p;
+ } while (*p++);
+END
+
+OPTION(preprocessor,,COMMAND,
+ [<use COMMAND instead of the default preprocessor>])
+BEGIN
+ grecs_preprocessor = optarg;
+END
+
+OPTION(no-preprocessor,,,
+ [<disable preprocessing>])
+BEGIN
+ grecs_preprocessor = NULL;
+END
+
+GROUP(Debugging)
+
+OPTION(dump-grammar-trace,,,
+ [<dump configuration grammar traces>])
+BEGIN
+ grecs_gram_trace (1);
+END
+
+OPTION(dump-lex-trace,,,
+ [<dump lexical analyzer traces>])
+BEGIN
+ grecs_lex_trace (1);
+END
+
+OPTION(debug,d,CAT[.LEVEL],
+ [<set debugging level>])
+BEGIN
+ if (parse_debug_level(optarg)) {
+ die(EX_USAGE, "invalid debugging category or level");
+ }
+END
+
+GROUP([<Additional help>])
+OPTION(config-help,,,
+ [<show configuration file summary>])
+BEGIN
+ config_help();
+ exit(0);
+END
+
+OPTIONS_END
+
+void
+set_program_name(const char *arg)
+{
+ program_name = strrchr(arg, '/');
+ if (!program_name)
+ program_name = arg;
+ else
+ program_name++;
+}
+
+void
+parse_options(int argc, char *argv[], int *index)
+{
+ GETOPT(argc, argv, *index, exit(EX_USAGE))
+
+ if (pp_cmd_buffer && grecs_preprocessor) {
+ char *cmd = grecs_malloc(strlen(grecs_preprocessor) +
+ pp_cmd_buflevel + 1);
+ strcpy(cmd, grecs_preprocessor);
+ strcat(cmd, pp_cmd_buffer);
+ grecs_preprocessor = cmd;
+ free(pp_cmd_buffer);
+ }
+}
+
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..184b42a
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,110 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+struct config_finish_hook_entry
+{
+ struct config_finish_hook_entry *next;
+ config_finish_hook_t fun;
+ void *data;
+};
+
+static struct config_finish_hook_entry *cfh_head, *cfh_tail;
+
+void
+add_config_finish_hook(config_finish_hook_t fun, void *data)
+{
+ struct config_finish_hook_entry *ent = grecs_malloc(sizeof(*ent));
+ ent->next = NULL;
+ ent->fun = fun;
+ ent->data = data;
+ if (cfh_tail)
+ cfh_tail->next = ent;
+ else
+ cfh_head = ent;
+ cfh_tail = ent;
+}
+
+int
+run_config_finish_hooks()
+{
+ struct config_finish_hook_entry *p;
+ int rc = 0;
+
+ for (p = cfh_head; p; p = p->next)
+ rc |= p->fun(p->data);
+ return rc;
+}
+
+static struct grecs_keyword eclat_kw[] = {
+ { "host", "hostname",
+ "Send queries to <hostname> instead of the default host",
+ grecs_type_string, GRECS_DFLT, &default_host },
+ { "access-file", "file",
+ "Specify a file containing `accessID:accessKey' pairs",
+ grecs_type_string, GRECS_DFLT, &access_file_name },
+ { "region", "name",
+ "Define default AWS region",
+ grecs_type_string, GRECS_DFLT, &region_name },
+
+ { NULL }
+};
+
+void
+config_help()
+{
+ static char docstring[] =
+ N_("Configuration file structure for eclat.\n"
+ "For more information, use `info eclat configuration'.");
+ grecs_print_docstring(docstring, 0, stdout);
+ grecs_print_statement_array(eclat_kw, 1, 0, stdout);
+}
+
+static void
+grecs_print_diag(grecs_locus_t const *locus, int err, int errcode,
+ const char *msg)
+{
+ diag(locus, err ? NULL : "warning", "%s", msg);
+}
+
+void
+config_init()
+{
+ grecs_include_path_setup(DEFAULT_VERSION_INCLUDE_DIR,
+ DEFAULT_INCLUDE_DIR, NULL);
+ grecs_preprocessor = DEFAULT_PREPROCESSOR;
+ grecs_log_to_stderr = 1;
+ grecs_adjust_string_locations = 1;
+ grecs_print_diag_fun = grecs_print_diag;
+}
+
+void
+config_finish(struct grecs_node *tree)
+{
+ struct grecs_node *node;
+
+ grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR);
+ if (debug_level[ECLAT_DEBCAT_CONF]) {
+ grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr);
+ fputc('\n', stdout);
+ }
+ if (grecs_error_count || run_config_finish_hooks())
+ exit(EX_CONFIG);
+}
+
+
+
diff --git a/src/diag.c b/src/diag.c
new file mode 100644
index 0000000..30ffa34
--- /dev/null
+++ b/src/diag.c
@@ -0,0 +1,108 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+const char *program_name;
+
+void
+vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap)
+{
+ if (program_name)
+ fprintf(stderr, "%s: ", program_name);
+
+ if (locus) {
+ size_t size = 0;
+
+ if (locus->beg.col == 0)
+ fprintf(stderr, "%s:%u",
+ locus->beg.file,
+ locus->beg.line);
+ else if (strcmp(locus->beg.file, locus->end.file))
+ fprintf(stderr, "%s:%u.%u-%s:%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.file,
+ locus->end.line, locus->end.col);
+ else if (locus->beg.line != locus->end.line)
+ fprintf(stderr, "%s:%u.%u-%u.%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.line, locus->end.col);
+ else
+ fprintf(stderr, "%s:%u.%u-%u",
+ locus->beg.file,
+ locus->beg.line, locus->beg.col,
+ locus->end.col);
+ fprintf(stderr, ": ");
+ }
+
+ if (qual)
+ fprintf(stderr, "%s: ", qual);
+ vfprintf(stderr, fmt, ap);
+ fputc('\n', stderr);
+}
+
+void
+diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vdiag(locus, qual, fmt, ap);
+ va_end(ap);
+}
+
+void
+die(int status, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vdiag(NULL, NULL, fmt, ap);
+ va_end(ap);
+ exit(status);
+}
+
+void
+err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vdiag(NULL, NULL, fmt, ap);
+ va_end(ap);
+}
+
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vdiag(NULL, "warning", fmt, ap);
+ va_end(ap);
+}
+
+void
+debug_printf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vdiag(NULL, "debug", fmt, ap);
+ va_end(ap);
+}
diff --git a/src/eclat.c b/src/eclat.c
new file mode 100644
index 0000000..3d2572d
--- /dev/null
+++ b/src/eclat.c
@@ -0,0 +1,162 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+char *conffile = SYSCONFDIR "/eclat.conf" ;
+int lint_mode;
+int debug_level[ECLAT_DEBCAT_MAX];
+int dry_run_mode;
+int preprocess_only = 0;
+
+char *default_host = "ec2.amazonaws.com";
+int use_ssl;
+char *access_key;
+char *secret_key;
+char *region_name;
+enum eclat_command eclat_command;
+
+char *url_base;
+
+
+struct debug_trans {
+ const char *name;
+ size_t length;
+ int cat;
+};
+
+static struct debug_trans debug_trans[] = {
+#define S(s) #s, sizeof(#s)-1
+ { S(main), ECLAT_DEBCAT_MAIN },
+ { S(cfgram), ECLAT_DEBCAT_CFGRAM },
+ { S(cflex), ECLAT_DEBCAT_CFLEX },
+ { S(conf), ECLAT_DEBCAT_CONF },
+ { NULL }
+};
+
+static int
+parse_debug_level(const char *arg)
+{
+ unsigned long cat, lev;
+ char *p;
+
+ if (isascii(*arg) && isdigit(*arg)) {
+ cat = strtoul(arg, &p, 10);
+ if (cat > ECLAT_DEBCAT_MAX)
+ return -1;
+ } else {
+ size_t len = strcspn(arg, ".");
+ struct debug_trans *dp;
+
+ for (dp = debug_trans; dp->name; dp++)
+ if (dp->length == len &&
+ memcmp(dp->name, arg, len) == 0)
+ break;
+
+ if (!dp->name)
+ return -1;
+ cat = dp->cat;
+ p = (char*) arg + len;
+ }
+
+ if (*p == 0)
+ lev = 100;
+ else if (*p != '.')
+ return -1;
+ else {
+ lev = strtoul(p + 1, &p, 10);
+ if (*p)
+ return -1;
+ }
+ debug_level[cat] = lev;
+ return 0;
+}
+
+#include "cmdline.h"
+
+eclat_command_handler_t handler_tab[] = {
+ NULL,
+ eclat_start_instance,
+ eclat_stop_instance
+};
+
+int
+main(int argc, char **argv)
+{
+ int index, rc;
+ struct grecs_node *tree;
+ CURL *curl;
+ size_t size;
+
+ set_program_name(argv[0]);
+ config_init();
+ parse_options(argc, argv, &index);
+
+ argc -= index;
+ argv += index;
+
+ grecs_gram_trace(debug_level[ECLAT_DEBCAT_CFGRAM]);
+ grecs_lex_trace(debug_level[ECLAT_DEBCAT_CFLEX]);
+
+ if (preprocess_only)
+ exit(grecs_preproc_run(conffile, grecs_preprocessor) ?
+ EX_CONFIG : 0);
+
+ if (access(conffile, R_OK) == 0) {
+ tree = grecs_parse(conffile);
+ if (!tree)
+ exit(EX_CONFIG);
+ config_finish(tree);
+ /* Prevent texttab from being freed by grecs_tree_free.
+ FIXME: A dirty kludge, needed to preserve file names
+ in locus structures. A proper solution would be to have
+ our own texttab for that purpose. */
+ tree->v.texttab = NULL;
+ grecs_tree_free(tree);
+ } else if (errno == ENOENT) {
+ warn("no configuration file");
+ run_config_finish_hooks();
+ } else
+ die(EX_OSFILE, "cannot access \"%s\": %s",
+ conffile, strerror(errno));
+
+ if (lint_mode)
+ exit(0);
+
+ if (!secret_key) {
+ if (access_file_lookup(access_key, &access_key, &secret_key))
+ die(EX_UNAVAILABLE,
+ "cannot find authentication credentials");
+ }
+
+ if (eclat_command == eclat_command_unspecified)
+ die(EX_USAGE, "no command given");
+
+ url_base = NULL;
+ size = 0;
+ if (use_ssl)
+ grecs_asprintf(&url_base, &size, "https://%s", default_host);
+ else
+ grecs_asprintf(&url_base, &size, "http://%s", default_host);
+
+
+ curl = curl_easy_init();
+ if (!curl)
+ die(EX_UNAVAILABLE, "curl_easy_init failed");
+ rc = handler_tab[eclat_command](curl, argc, argv);
+ curl_easy_cleanup(curl);
+ exit(rc);
+}
diff --git a/src/eclat.h b/src/eclat.h
new file mode 100644
index 0000000..0fb4fd7
--- /dev/null
+++ b/src/eclat.h
@@ -0,0 +1,81 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+#include <sysexits.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <curl/curl.h>
+#include "grecs.h"
+#include "wordsplit.h"
+#include "libeclat.h"
+
+#define ECLAT_DEBCAT_MAIN 0
+#define ECLAT_DEBCAT_CFGRAM 1
+#define ECLAT_DEBCAT_CFLEX 2
+#define ECLAT_DEBCAT_CONF 3
+#define ECLAT_DEBCAT_MAX 4
+
+extern const char *program_name;
+extern int debug_level[];
+
+extern char *default_host;
+extern int use_ssl;
+extern char *region_name;
+extern char *access_file_name;
+extern char *access_key;
+extern char *secret_key;
+extern char *url_base;
+
+#define debug(cat, lev, s) \
+ do { \
+ if (debug_level[cat] >= (lev)) \
+ debug_printf s; \
+ } while(0)
+
+void die(int status, const char *fmt, ...);
+void vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt,
+ va_list ap);
+void diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...);
+void err(const char *fmt, ...);
+void warn(const char *fmt, ...);
+void debug_printf(const char *fmt, ...);
+
+typedef int (*config_finish_hook_t) (void*);
+
+void add_config_finish_hook(config_finish_hook_t fun, void *data);
+
+void config_help(void);
+void config_init(void);
+void config_finish(struct grecs_node *tree);
+int run_config_finish_hooks(void);
+
+enum eclat_command {
+ eclat_command_unspecified,
+ eclat_command_start_instances,
+ eclat_command_stop_instances
+};
+
+extern enum eclat_command eclat_command;
+
+typedef int (*eclat_command_handler_t) (CURL *curl, int argc, char **argv);
+
+int eclat_start_instance(CURL *curl, int argc, char **argv);
+int eclat_stop_instance(CURL *curl, int argc, char **argv);
diff --git a/src/error.c b/src/error.c
new file mode 100644
index 0000000..6c86d34
--- /dev/null
+++ b/src/error.c
@@ -0,0 +1,64 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+#include <stdargs.h>
+#include <stdio.h>
+
+char *program_name;
+
+void
+diag(const char *qual, const char *fmt, va_list ap)
+{
+ if (program_name)
+ fprintf(stderr, "%s: ", program_name);
+ if (qual)
+ fprintf(stderr, "%s: ", qual);
+ va_start(ap, fmt);
+ vfprintf(stderr, ftm, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+}
+
+void
+err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ diag(NULL, ftm, ap);
+ va_end(ap);
+}
+
+void
+warn(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ diag("warning", ftm, ap);
+ va_end(ap);
+}
+
+void
+debug_printf(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ diag("debug", ftm, ap);
+ va_end(ap);
+}
diff --git a/src/startinst.c b/src/startinst.c
new file mode 100644
index 0000000..f07e50a
--- /dev/null
+++ b/src/startinst.c
@@ -0,0 +1,28 @@
+/* This file is part of Eclat.
+ Copyright (C) 2012 Sergey Poznyakoff.
+
+ Eclat is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Eclat is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "eclat.h"
+
+int
+eclat_start_instance(CURL *curl, int argc, char **argv)
+{
+}
+
+int
+eclat_stop_instance(CURL *curl, int argc, char **argv)
+{
+}
+

Return to:

Send suggestions and report system problems to the System administrator.