Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/applets


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (9 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 added
1 deleted
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/applets/applet_tables.c

    r3232 r3621  
    1515#include <stdio.h>
    1616#include <unistd.h>
     17#include <ctype.h>
    1718
    1819#undef ARRAY_SIZE
     
    4142enum { NUM_APPLETS = ARRAY_SIZE(applets) };
    4243
    43 static int offset[NUM_APPLETS];
    44 
    4544static int cmp_name(const void *a, const void *b)
    4645{
     
    5049}
    5150
     51static int str_isalnum_(const char *s)
     52{
     53    while (*s) {
     54        if (!isalnum(*s) && *s != '_')
     55            return 0;
     56        s++;
     57    }
     58    return 1;
     59}
     60
    5261int main(int argc, char **argv)
    5362{
    54     int i;
    55     int ofs;
    56     unsigned MAX_APPLET_NAME_LEN = 1;
     63    int i, j;
     64
     65    // In find_applet_by_name(), before linear search, narrow it down
     66    // by looking at N "equidistant" names. With ~350 applets:
     67    // KNOWN_APPNAME_OFFSETS  cycles
     68    //                     0    9057
     69    //                     2    4604 + ~100 bytes of code
     70    //                     4    2407 + 4 bytes
     71    //                     8    1342 + 8 bytes
     72    //                    16     908 + 16 bytes
     73    //                    32     884 + 32 bytes
     74    // With 8, int16_t applet_nameofs[] table has 7 elements.
     75    int KNOWN_APPNAME_OFFSETS = 8;
     76    // With 128 applets we do two linear searches, with 1..7 strcmp's in the first one
     77    // and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's.
     78    if (NUM_APPLETS < 128)
     79        KNOWN_APPNAME_OFFSETS = 4;
     80    if (NUM_APPLETS < 32)
     81        KNOWN_APPNAME_OFFSETS = 0;
    5782
    5883    qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
    5984
    60     ofs = 0;
    61     for (i = 0; i < NUM_APPLETS; i++) {
    62         offset[i] = ofs;
    63         ofs += strlen(applets[i].name) + 1;
    64     }
    65     /* We reuse 4 high-order bits of offset array for other purposes,
    66      * so if they are indeed needed, refuse to proceed */
    67     if (ofs > 0xfff)
    68         return 1;
    6985    if (!argv[1])
    7086        return 1;
    71 
    7287    i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
    7388    if (i < 0)
     
    8499        printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
    85100    }
    86     printf("\n");
     101
     102    printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
     103    if (KNOWN_APPNAME_OFFSETS > 0) {
     104        int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
     105        for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
     106            index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS;
     107        ofs = 0;
     108        for (i = 0; i < NUM_APPLETS; i++) {
     109            for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++)
     110                if (i == index[j])
     111                    offset[j] = ofs;
     112            ofs += strlen(applets[i].name) + 1;
     113        }
     114        /* If the list of names is too long refuse to proceed */
     115        if (ofs > 0xffff)
     116            return 1;
     117        printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
     118        for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++)
     119            printf("%d,\n", offset[i]);
     120        printf("};\n\n");
     121    }
    87122
    88123    //printf("#ifndef SKIP_definitions\n");
     
    90125    for (i = 0; i < NUM_APPLETS; i++) {
    91126        printf("\"%s\" \"\\0\"\n", applets[i].name);
    92         if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
    93             MAX_APPLET_NAME_LEN = strlen(applets[i].name);
     127//      if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
     128//          MAX_APPLET_NAME_LEN = strlen(applets[i].name);
    94129    }
    95130    printf(";\n\n");
     131
     132    for (i = 0; i < NUM_APPLETS; i++) {
     133        if (str_isalnum_(applets[i].name))
     134            printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
     135    }
     136    printf("\n");
    96137
    97138    printf("#ifndef SKIP_applet_main\n");
     
    103144    printf("#endif\n\n");
    104145
    105     printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
    106     for (i = 0; i < NUM_APPLETS; i++) {
    107         printf("0x%04x,\n",
    108             offset[i]
    109146#if ENABLE_FEATURE_PREFER_APPLETS
    110             + (applets[i].nofork << 12)
    111             + (applets[i].noexec << 13)
     147    printf("const uint8_t applet_flags[] ALIGN1 = {\n");
     148    i = 0;
     149    while (i < NUM_APPLETS) {
     150        int v = applets[i].nofork + (applets[i].noexec << 1);
     151        if (++i < NUM_APPLETS)
     152            v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2;
     153        if (++i < NUM_APPLETS)
     154            v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4;
     155        if (++i < NUM_APPLETS)
     156            v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6;
     157        printf("0x%02x,\n", v);
     158        i++;
     159    }
     160    printf("};\n\n");
    112161#endif
     162
    113163#if ENABLE_FEATURE_SUID
    114             + (applets[i].need_suid << 14) /* 2 bits */
     164    printf("const uint8_t applet_suid[] ALIGN1 = {\n");
     165    i = 0;
     166    while (i < NUM_APPLETS) {
     167        int v = applets[i].need_suid; /* 2 bits */
     168        if (++i < NUM_APPLETS)
     169            v |= applets[i].need_suid << 2;
     170        if (++i < NUM_APPLETS)
     171            v |= applets[i].need_suid << 4;
     172        if (++i < NUM_APPLETS)
     173            v |= applets[i].need_suid << 6;
     174        printf("0x%02x,\n", v);
     175        i++;
     176    }
     177    printf("};\n\n");
    115178#endif
    116         );
    117     }
    118     printf("};\n\n");
    119179
    120180#if ENABLE_FEATURE_INSTALLER
     
    131191#endif
    132192    //printf("#endif /* SKIP_definitions */\n");
    133     printf("\n");
    134     printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
     193//  printf("\n");
     194//  printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
    135195
    136196    if (argv[2]) {
  • branches/3.3/mindi-busybox/applets/install.sh

    r3232 r3621  
    66prefix=$1
    77if [ -z "$prefix" ]; then
    8     echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
     8    echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
    99    exit 1
    1010fi
    1111
     12# Source the configuration
     13. ./.config
     14
    1215h=`sort busybox.links | uniq`
     16
     17sharedlib_dir="0_lib"
    1318
    1419linkopts=""
    1520scriptwrapper="n"
     21binaries="n"
    1622cleanup="0"
    1723noclobber="0"
     
    1925    --hardlinks)     linkopts="-f";;
    2026    --symlinks)      linkopts="-fs";;
     27    --binaries)      binaries="y";;
    2128    --scriptwrapper) scriptwrapper="y";swrapall="y";;
    2229    --sw-sh-hard)    scriptwrapper="y";linkopts="-f";;
     
    4148        rm -f "$prefix/$libdir/$i" || exit 1
    4249        if [ -f "$i" ]; then
     50            echo "   Installing $i to the target at $prefix/$libdir/"
    4351            cp -pPR "$i" "$prefix/$libdir/" || exit 1
    44             chmod 0644 "$prefix/$libdir/$i" || exit 1
     52            chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
    4553        fi
    4654    done
     
    6977for i in $h; do
    7078    appdir=`dirname "$i"`
     79    app=`basename "$i"`
    7180    mkdir -p "$prefix/$appdir" || exit 1
    7281    if [ "$scriptwrapper" = "y" ]; then
     
    7988        fi
    8089        echo "  $prefix/$i"
     90    elif [ "$binaries" = "y" ]; then
     91        # Copy the binary over rather
     92        if [ -e $sharedlib_dir/$app ]; then
     93            if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
     94                echo "   Copying $sharedlib_dir/$app to $prefix/$i"
     95                cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
     96            else
     97                echo "  $prefix/$i already exists"
     98            fi
     99        else
     100            echo "Error: Could not find $sharedlib_dir/$app"
     101            exit 1
     102        fi
    81103    else
    82104        if [ "$2" = "--hardlinks" ]; then
  • branches/3.3/mindi-busybox/applets/usage_compressed

    r2725 r3621  
    1111
    1212# Some people were bitten by their system lacking a (proper) od
    13 od -v -t x1 </dev/null >/dev/null
     13od -v -b </dev/null >/dev/null
    1414if test $? != 0; then
    15     echo 'od tool is not installed or cannot accept "-v -t x1" options'
     15    echo 'od tool is not installed or cannot accept "-v -b" options'
    1616    exit 1
    1717fi
     
    2020
    2121echo '#define UNPACKED_USAGE "" \'
    22 "$loc/usage" | od -v -t x1 \
     22"$loc/usage" | od -v -b \
     23| grep -v '^ ' \
    2324| $SED -e 's/^[^ ]*//' \
    2425    -e 's/ //g' \
    2526    -e '/^$/d' \
    26     -e 's/\(..\)/\\x\1/g' \
     27    -e 's/\(...\)/\\\1/g' \
    2728    -e 's/^/"/' \
    2829    -e 's/$/" \\/'
    2930echo ''
     31# "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
     32#0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
     33#         000010 000010 026533 063144 020135 026533 020143 047503
     34#0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
     35#         043116 044504 056522 055440 066055 046040 043517 044506
     36#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
     37#         042514 020135 026533 020141 041501 044524 047117 044506
    3038
    3139echo '#define PACKED_USAGE \'
     
    4048##  -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
    4149##  -e 's/$/ \\/'
    42 "$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
     50"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
     51| grep -v '^ ' \
    4352| $SED -e 's/^[^ ]*//' \
    4453    -e 's/ //g' \
    4554    -e '/^$/d' \
    46     -e 's/\(..\)/0x\1,/g' \
     55    -e 's/\(...\)/0\1,/g' \
    4756    -e 's/$/ \\/'
    4857echo ''
Note: See TracChangeset for help on using the changeset viewer.