aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-11-24 00:44:28 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-11-24 00:44:28 +0200
commit68796f86fe6abae13debf253c0e16b4bac9c1bca (patch)
tree5ab80057618ae33c10f44c9be1ee307e367747ff /src/pies.c
parent2d3d121453b19003c6454e7c6b4ed98164e7d531 (diff)
downloadpies-68796f86fe6abae13debf253c0e16b4bac9c1bca.tar.gz
pies-68796f86fe6abae13debf253c0e16b4bac9c1bca.tar.bz2
Handle non-stream sockets. Pies can now replace inetd (- inetd.conf and built-in services).
* src/pies.c (component_keywords): New keywords: wait, socket-type. (component_verify): Add more checks. * src/pies.h (CF_WAIT): New define. (struct component): New member: socket_type. (struct pies_url): Rename proto to scheme. New members: proto, proto_s, port_s (register_listener): Remove proto. (register_socket): New proto. (create_socket): Change signature. (disable_socket, enable_socket): New protos. * src/progman.c (close_fds): New function. (open_redirector): Use close_fds. (prog_start): Use close_fds. Update call to create_socket. Disable socket if wait is set. (progman_accept): Support non-stream (and stream+wait) sockets. (component_fixup_depend): Update call to create_socket. Call register_socket. (run_command): Use close_fds. Re-enable socket if wait is set. * src/socket.c (create_socket): Take additional argument: socket_type. (register_socket): New function. (disable_socket, enable_socket): New functions. (pies_pause): Add missing break. * src/url.c (url_parse_host): Accept service name and numberic port number. (url_parse_proto): Rename to url_parse_scheme. All callers updated. (url_parse_scheme): Allow for optional protocol specification in scheme field (after a '+' sign). (pies_url_destroy): Free new fields.
Diffstat (limited to 'src/pies.c')
-rw-r--r--src/pies.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/src/pies.c b/src/pies.c
index dbe4ca0..2bf127c 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -712,6 +712,36 @@ _cb_url (enum grecs_callback_command cmd,
return 0;
}
+static int
+_cb_socket_type (enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr, grecs_value_t *value, void *cb_data)
+{
+ int t;
+
+ if (assert_scalar_stmt (locus, cmd)
+ || assert_grecs_value_type (locus, value, GRECS_TYPE_STRING))
+ return 1;
+
+ if (strcmp (value->v.string, "stream") == 0)
+ t = SOCK_STREAM;
+ else if (strcmp (value->v.string, "dgram") == 0)
+ t = SOCK_DGRAM;
+ else if (strcmp (value->v.string, "rdm") == 0)
+ t = SOCK_RDM;
+ else if (strcmp (value->v.string, "seqpacket") == 0)
+ t = SOCK_SEQPACKET;
+ else if (strcmp (value->v.string, "raw") == 0)
+ t = SOCK_RAW;
+ else
+ {
+ grecs_error (locus, 0, _("bad socket type"));
+ return 0;
+ }
+ *(int*)varptr = t;
+ return 0;
+}
+
static struct tokendef modetab[] = {
{"exec", pies_comp_exec},
{"wait", pies_comp_exec},
@@ -791,6 +821,14 @@ _cb_disabled (enum grecs_callback_command cmd,
return _cb_bitmask (cmd, locus, varptr, value, CF_DISABLED);
}
+static int
+_cb_wait (enum grecs_callback_command cmd,
+ grecs_locus_t *locus,
+ void *varptr, grecs_value_t *value, void *cb_data)
+{
+ return _cb_bitmask (cmd, locus, varptr, value, CF_WAIT);
+}
+
struct grecs_keyword component_keywords[] = {
{"mode",
/* TRANSLATORS: The words between '{' and '}' are keywords, do not
@@ -846,6 +884,13 @@ struct grecs_keyword component_keywords[] = {
offsetof (struct component, flags),
_cb_precious,
},
+ {"wait",
+ NULL,
+ N_("Wait for the server program to return."),
+ grecs_type_bool, NULL,
+ offsetof (struct component, flags),
+ _cb_wait,
+ },
{"max-instances",
NULL,
N_("Maximum number of running instances."),
@@ -859,6 +904,12 @@ struct grecs_keyword component_keywords[] = {
offsetof (struct component, socket_url),
_cb_url,
},
+ {"socket-type",
+ N_("type: stream | dgram | raw | rdm | seqpacket"),
+ N_("Set socket type."),
+ grecs_type_int, NULL,
+ offsetof (struct component, socket_type),
+ _cb_socket_type },
{"pass-fd-socket",
N_("name"),
N_("Pass fd through this socket."),
@@ -978,7 +1029,7 @@ make_full_name (const char *dir, const char *file)
}
static int
-component_verify (struct component *comp, grecs_locus_t * locus)
+component_verify (struct component *comp, grecs_locus_t *locus)
{
int header = 0;
int i;
@@ -1013,7 +1064,7 @@ component_verify (struct component *comp, grecs_locus_t * locus)
if (comp->dir)
{
char *p = make_full_name (comp->dir, comp->pass_fd_socket);
- //free (comp->pass_fd_socket);
+ /*free (comp->pass_fd_socket);*/
comp->pass_fd_socket = p;
}
else
@@ -1032,6 +1083,22 @@ component_verify (struct component *comp, grecs_locus_t * locus)
}
}
+ if (comp->mode == pies_comp_inetd)
+ {
+ if ((comp->flags & CF_WAIT) && comp->socket_type == SOCK_STREAM)
+ {
+ if (comp->max_instances)
+ COMPERR ("%s", _("max-instances ignored"));
+ else
+ comp->max_instances = 1;
+ }
+ }
+ else if (comp->flags & CF_WAIT)
+ {
+ COMPERR ("%s", _("wait is useless in this mode"));
+ comp->flags &= ~CF_WAIT;
+ }
+
if (comp->mode != pies_comp_exec
&& comp->redir[RETR_OUT].type != redir_null)
{
@@ -1071,6 +1138,7 @@ component_create (const char *name)
comp->facility = log_facility;
comp->redir[RETR_OUT].type = comp->redir[RETR_ERR].type = redir_null;
comp->tag = xstrdup (name);
+ comp->socket_type = SOCK_STREAM;
}
return comp;
}

Return to:

Send suggestions and report system problems to the System administrator.