[zeromq-dev] [czmq] API design of zproc_run
Michal Vyskocil
michal.vyskocil at gmail.com
Sun Mar 19 22:37:23 CET 2017
Hi Luca,
the "problem" is more ergonomy than anything else. See
http://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html
> The argument *arg0* *should* point to a filename string that is
associated with the process being started by one of the *exec* functions
So following is legal
```
char **args = {"-c", "ls", NULL};
execve ("/bin/bash", args, NULL);
```
it call /bin/bash with argv [0] "-c". My idea is that use path as argv [0]
by default. And when needed it'd be easy to add a code allowing user set
argv [0] to whatever he wants to.
On Sun, Mar 19, 2017 at 7:51 PM, Luca Boccassi <luca.boccassi at gmail.com>
wrote:
> On Sun, 2017-03-19 at 10:07 +0100, Michal Vyskocil wrote:
> > Hi,
> >
> > I have finished a first draft of zproc class for czmq. It should
> > provide
> > nice and easy to use API to execute and communicate with subcommands.
> > I was
> > inspired by Python https://docs.python.org/3/library/subprocess.html
> > module. zproc use zeromq sockets to pass data in or from the
> > subprocess.
> > That means that the concept of unix pipes now runs through any libzmq
> > transport well :)
> >
> > Right now it works for libzmq4 and Linux and OSX.
> > I tried to make API simple and easy to use and to provide zproject
> > API
> > model from start. The problem is zproc_run. Right now I simply copy
> > execve
> > from unix, so the prototype look this way.
> >
> > int zproc_run (zproc_t *self, const char *filename, char *const
> > argv[], char *const envp[])
> >
> >
> >
> > There are three problems
> >
> > 1. Incompatible with API model
> > 2. Does not look really nice to me
> > 3. argv [0] is different from filename, so developer must not
> > forget to
> > pass at least something as argv.
> >
> >
> >
> > Given my knowledge of czmq API, I'd say the best way to go is to
> >
> > // Adds an argument to process command line
> > void zproc_arg (zproc_t *self, const char *format, ...);
> >
> > // Adds an enviroment variable for a process
> > void zproc_env (zproc_t *self, const char *key, const char *format,
> > ...);
> >
> > // Execute the subprocess, return -1 if execution fails
> > int zproc_run ();
> >
> >
> > So the sample usage would be
> >
> >
> > zproc_t *cat = zproc_new ();
> > zproc_arg (self, "%s", "cat"); // Note that filename and
> > argv[0] are two distincs things
> > zproc_arg (self, "%s", "-A");
> > zproc_arg (self, "%s", "/etc/passwd");
> >
> > zproc_env (self, "LC_ALL", "%s", "C");
> > zproc_run ();
> >
> >
> > However I am not convinced if this is the best API ever. And I still
> > did
> > not solved argv[0] problem. Are there any ideas for better API?
>
> Looks fine to me! I would recommend having sensible default values when
> possible.
>
> Could you expand a bit more on the argv[0] issue?
>
> Kind regards,
> Luca Boccassi
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
--
best regards
Michal Vyskocil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170319/181500de/attachment.htm>
More information about the zeromq-dev
mailing list