aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-02-20 22:33:00 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-02-20 22:42:46 +0200
commit46130027d8e6e91951226456174e6ad471ddc50f (patch)
treef88ce6edd9b078b5f331497bc452525f3c4c9c94 /src/pies.c
parente6902abfddb4d7b16dc9a4231a3781f354a08cd5 (diff)
downloadpies-46130027d8e6e91951226456174e6ad471ddc50f.tar.gz
pies-46130027d8e6e91951226456174e6ad471ddc50f.tar.bz2
Improve control interface
This commit implements the following operations on the new /conf endpoints: GET /conf/runtime - List configuration PUT /conf/runtime - Reload configuration POST /conf/runtime - Post new configuration GET /conf/files - List configuration files DELETE /conf/files - Delete some or all configuration files from the list POST /conf/files - Install new configuration file Piesctl supports the following new commands: piesctl config reload piesctl config file clear piesctl config file add SYNTAX NAME piesctl config file del[ete] NAME [NAME...] piesctl config file list * src/ctl.c (res_conf): New function. (restab): New endpoint /conf * src/pies.c (config_file_add): Set free_entry. (config_file_remove, config_file_remove_all) (config_file_list_serialize): New functions. (pies_config_parse): Bail out if tree processing fails. (pies_reload): Remove unused function. (main): Redo ACTION_RELOAD handling. Handle ACTION_COMMIT. * src/pies.h (ACTION_COMMIT): New action. (config_file_remove, config_file_remove_all) (config_file_list_serialize) (pies_read_config, progman_gc): New protos. * src/piesctl.c (cmdline_parser_state): New struct (next_token, peek_token): Take ptr to cmdline_parser_state as argument. (parse_error, require_token, assert_eol) (piesctl_format): New functions. (parse_condition_to_uri): Rewrite using piesctl_format. New subcommand: config. Improve help output.
Diffstat (limited to 'src/pies.c')
-rw-r--r--src/pies.c88
1 files changed, 70 insertions, 18 deletions
diff --git a/src/pies.c b/src/pies.c
index cb4d2f5..59f3bbb 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -98,6 +98,17 @@ str_to_config_syntax (const char *str)
return NULL;
}
+static void
+config_file_free (void *ptr)
+{
+ if (ptr)
+ {
+ struct config_file *file = ptr;
+ grecs_free (file->name);
+ grecs_free (file);
+ }
+}
+
void
config_file_add (struct config_syntax *syntax, const char *name)
{
@@ -105,7 +116,10 @@ config_file_add (struct config_syntax *syntax, const char *name)
file->syntax = syntax;
file->name = grecs_strdup (name);
if (!config_list)
- config_list = grecs_list_create ();
+ {
+ config_list = grecs_list_create ();
+ config_list->free_entry = config_file_free;
+ }
grecs_list_append (config_list, file);
}
@@ -114,6 +128,45 @@ config_file_add_type (enum config_syntax_type syntax, const char *name)
{
config_file_add (&config_syntax_tab[syntax], name);
}
+
+int
+config_file_remove (const char *name)
+{
+ struct grecs_list_entry *ep;
+
+ for (ep = config_list->head; ep; ep = ep->next)
+ {
+ struct config_file *file = ep->data;
+ if (strcmp (file->name, name) == 0)
+ {
+ grecs_list_remove_entry (config_list, ep);
+ config_file_free (file);
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void
+config_file_remove_all (void)
+{
+ grecs_list_clear (config_list);
+}
+
+void
+config_file_list_serialize (struct json_value *ar)
+{
+ struct grecs_list_entry *ep;
+
+ for (ep = config_list->head; ep; ep = ep->next)
+ {
+ struct config_file *file = ep->data;
+ struct json_value *obj = json_new_object ();
+ json_object_set (obj, "syntax", json_new_string (file->syntax->name));
+ json_object_set (obj, "file", json_new_string (file->name));
+ json_array_append (ar, obj);
+ }
+}
/* Logging */
static int
@@ -1492,6 +1545,9 @@ pies_config_parse (char const *name)
grecs_tree_free (tree);
+ if (grecs_error_count)
+ return 1;
+
return 0;
}
@@ -1527,22 +1583,6 @@ pies_read_config (void)
return err;
}
-
-int
-pies_reload (void)
-{
- int rc = pies_read_config ();
- if (rc == 0)
- {
- component_config_commit ();
- if (init_process)
- sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
- progman_create_sockets ();
- progman_start ();
- }
-
- return rc;
-}
static struct config_syntax *current_syntax = &config_syntax_tab[CONF_PIES];
@@ -2186,7 +2226,19 @@ main (int argc, char **argv)
break;
case ACTION_RELOAD:
- pies_reload ();
+ if (pies_read_config ())
+ {
+ action = ACTION_CONT;
+ break;
+ }
+ /* fall through */
+ case ACTION_COMMIT:
+ component_config_commit ();
+ if (init_process)
+ sysvinit_runlevel_setup (PIES_COMP_DEFAULT);
+ progman_create_sockets ();
+ progman_start ();
+
pies_schedule_children (PIES_CHLD_WAKEUP);
action = ACTION_CONT;
break;

Return to:

Send suggestions and report system problems to the System administrator.