Subject: pkg/33220: bash builtins cannot access bash symbols
To: None <,,>
From: None <>
List: pkgsrc-bugs
Date: 04/08/2006 18:30:00
>Number:         33220
>Category:       pkg
>Synopsis:       bash builtins cannot access bash symbols
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 08 18:30:00 +0000 2006
>Originator:     Tavis Ormandy
>Release:        NetBSD 2.1.0_STABLE
NetBSD sdf 2.1.0_STABLE NetBSD 2.1.0_STABLE (sdf) #0: Tue Mar 14 07:50:31 UTC 2006  root@sverige:/var/src/src/sys/arch/alpha/compile/sdf alpha
The bash shell allows you to write builtins and store them in a shared object, which are then loaded using the enable command. On NetBSD, this doesnt work as symbols that bash exports, such as make_builtin_argv() and last_pid_created are not available. This works on three linux systems I tested.

#include <stdio.h>
#include <stdlib.h>

/* This file is also available here if the formatting does not survive
 * $ gcc -shared -o builtin.c 
 * $ enable -f ./ btest
 * $ btest
 * bash: enable: cannot open shared object ./ ./ Undefined symbol "make_builtin_argv" (symnum = 21)

typedef struct word_desc { char *word; int flags;} WORD_DESC;
typedef struct word_list { struct word_list *next; WORD_DESC *word;}  WORD_LIST;
typedef int sh_builtin_func_t (WORD_LIST *);
int btest(WORD_LIST *list);
char **make_builtin_argv (WORD_LIST *list, int *argc);

struct builtin { 
    char *name;
    sh_builtin_func_t *function;
    int flags;
    char * const *doc;
    const char *shortdoc;
    char *handle;

char *btestusage[] = { "btest prints hello and exits", 0x00 };
struct builtin btest_struct = { "btest", btest, 1, btestusage, "btest", 0x00 };

int btest(WORD_LIST *list){ 
    int argc;
    char **argv;

    if (!(argv = (char **) make_builtin_argv (list, &argc)))
        return 1;
    fprintf(stdout, "hello from %s\n", argv[0]);

    return 42;