Subject: Re: [ast-users] ksh93 custom builtins
--------
> I am playing around with custom buildins for ksh93. See the following source
> file which compiles without error into a shared library libhello.so.
>
> #include
>
> int
> b_hello(int argc, char *argv[], void *extra)
> {
> if (argc != 2) {
> printf("Usage: hello arg\n");
> return(2);
> }
>
> printf("Hello %s\n",argv[1]);
>
> return(0);
> }
>
> int
> b_hello1(int argc, char *argv[], void *extra)
> {
> if (argc != 2) {
> printf("Usage: hello1 arg\n");
> return(2);
> }
>
> printf("Hello1 %s\n",argv[1]);
>
> return(0);
> }
>
> void
> lib_init(int c)
> {
> printf("LIBHELLO initialized\n");
> sh_addbuiltin("hello1", b_hello1, 0);
> }
>
> I load the builtins in libhello.so as follows
>
> $ builtin -f ./libhello.so hello
>
> Things works as expected if I do not call sh_addbuiltin() in lib_init() or
> elsewhere. However if I call sh_addbuiltin() my terminal session
> disappears (killed?) without any core dump.
>
> My questions are as follows. In lib_init() can you call sh_addbuiltin()
> to load a builtin such as hello1? The KSK-93 FAQ seems to indicate
> that this should work (Q4 - SHELL EXTENSIONS) What am I doing
> wrong which is causing sh_addbuiltin() to fail? Incorrect headers?
> Do I need to include some library I am unaware of?
>
> - FPMurphy
>
I tried compiling the code you sent into a shared library and I
ran
builtin -f ./libhello.so hello
I am able to run
hello world
and
hello1 world
without any problem.
What version of linux/unix are you running? What version of ksh93
are you running?
With the current version of ksh93, lib_init() can take a second
options, void *context.
If you have included <shell.h> (which is recommended), there is
no need to do anything with the context pointer.
By including <shell.h>, stdio calls will automatically get mapped
to sfio calls and then prototype for sh_addbuiltin() is provided.
Otherwise, you should inlcude <shcmd.h> and then call
LIB_INIT(context)
which will initialize context so that the shell knows that
you are not using sfio.
In any event I was able to build and run the code you sent
with or without including any of these headers.
David Korn
[EMAIL PROTECTED]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users