Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/miscutils/makedevs.c

    r1765 r2725  
    1111
    1212#if ENABLE_FEATURE_MAKEDEVS_LEAF
    13 int makedevs_main(int argc, char **argv);
     13/*
     14makedevs NAME TYPE MAJOR MINOR FIRST LAST [s]
     15TYPEs:
     16b       Block device
     17c       Character device
     18f       FIFO
     19
     20FIRST..LAST specify numbers appended to NAME.
     21If 's' is the last argument, the base device is created as well.
     22Examples:
     23        makedevs /dev/ttyS c 4 66 2 63   ->  ttyS2-ttyS63
     24        makedevs /dev/hda b 3 0 0 8 s    ->  hda,hda1-hda8
     25*/
     26int makedevs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    1427int makedevs_main(int argc, char **argv)
    1528{
    1629    mode_t mode;
    17     char *basedev, *type, *nodname, buf[255];
     30    char *basedev, *type, *nodname, *buf;
    1831    int Smajor, Sminor, S, E;
    1932
    20     if (argc < 7 || *argv[1]=='-')
     33    if (argc < 7 || argv[1][0] == '-')
    2134        bb_show_usage();
    2235
    2336    basedev = argv[1];
     37    buf = xasprintf("%s%u", argv[1], (unsigned)-1);
    2438    type = argv[2];
    25     Smajor = xatoi_u(argv[3]);
    26     Sminor = xatoi_u(argv[4]);
    27     S = xatoi_u(argv[5]);
    28     E = xatoi_u(argv[6]);
    29     nodname = argc == 8 ? basedev : buf;
     39    Smajor = xatoi_positive(argv[3]);
     40    Sminor = xatoi_positive(argv[4]);
     41    S = xatoi_positive(argv[5]);
     42    E = xatoi_positive(argv[6]);
     43    nodname = argv[7] ? basedev : buf;
    3044
    3145    mode = 0660;
    32 
    3346    switch (type[0]) {
    3447    case 'c':
     
    4659
    4760    while (S <= E) {
    48         int sz;
    49 
    50         sz = snprintf(buf, sizeof(buf), "%s%d", basedev, S);
    51         if (sz < 0 || sz >= sizeof(buf))  /* libc different */
    52             bb_error_msg_and_die("%s too large", basedev);
    53 
    54     /* if mode != S_IFCHR and != S_IFBLK third param in mknod() ignored */
    55 
     61        sprintf(buf, "%s%u", basedev, S);
     62
     63        /* if mode != S_IFCHR and != S_IFBLK,
     64         * third param in mknod() ignored */
    5665        if (mknod(nodname, mode, makedev(Smajor, Sminor)))
    57             bb_error_msg("failed to create: %s", nodname);
    58 
    59         if (nodname == basedev) /* ex. /dev/hda - to /dev/hda1 ... */
     66            bb_perror_msg("can't create '%s'", nodname);
     67
     68        /*if (nodname == basedev)*/ /* ex. /dev/hda - to /dev/hda1 ... */
    6069            nodname = buf;
    6170        S++;
     
    6877#elif ENABLE_FEATURE_MAKEDEVS_TABLE
    6978
    70 /* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */
    71 
    72 int makedevs_main(int argc, char **argv);
    73 int makedevs_main(int argc, char **argv)
     79/* Licensed under GPLv2 or later, see file LICENSE in this source tree. */
     80
     81int makedevs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     82int makedevs_main(int argc UNUSED_PARAM, char **argv)
    7483{
    75     FILE *table = stdin;
    76     char *rootdir = NULL;
    77     char *line = NULL;
    78     int linenum = 0;
     84    parser_t *parser;
     85    char *line = (char *)"-";
    7986    int ret = EXIT_SUCCESS;
    8087
     88    opt_complementary = "=1"; /* exactly one param */
    8189    getopt32(argv, "d:", &line);
    82     if (line)
    83         table = xfopen(line, "r");
    84 
    85     if (optind >= argc || (rootdir=argv[optind])==NULL) {
    86         bb_error_msg_and_die("root directory not specified");
    87     }
    88 
    89     xchdir(rootdir);
     90    argv += optind;
     91
     92    xchdir(*argv); /* ensure root dir exists */
    9093
    9194    umask(0);
    9295
    93     printf("rootdir=%s\n", rootdir);
    94     if (line) {
    95         printf("table='%s'\n", line);
     96    printf("rootdir=%s\ntable=", *argv);
     97    if (NOT_LONE_DASH(line)) {
     98        printf("'%s'\n", line);
    9699    } else {
    97         printf("table=<stdin>\n");
    98     }
    99 
    100     while ((line = xmalloc_getline(table))) {
     100        puts("<stdin>");
     101    }
     102
     103    parser = config_open(line);
     104    while (config_read(parser, &line, 1, 1, "# \t", PARSE_NORMAL)) {
     105        int linenum;
    101106        char type;
    102         unsigned int mode = 0755;
    103         unsigned int major = 0;
    104         unsigned int minor = 0;
    105         unsigned int count = 0;
    106         unsigned int increment = 0;
    107         unsigned int start = 0;
     107        unsigned mode = 0755;
     108        unsigned major = 0;
     109        unsigned minor = 0;
     110        unsigned count = 0;
     111        unsigned increment = 0;
     112        unsigned start = 0;
    108113        char name[41];
    109114        char user[41];
    110115        char group[41];
    111         char *full_name;
     116        char *full_name = name;
    112117        uid_t uid;
    113118        gid_t gid;
    114119
    115         linenum++;
    116 
    117         if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u", name,
    118                         &type, &mode, user, group, &major,
    119                         &minor, &start, &increment, &count)) ||
    120                 ((major | minor | start | count | increment) > 255))
    121         {
    122             if (*line=='\0' || *line=='#' || isspace(*line))
    123                 continue;
    124             bb_error_msg("line %d invalid: '%s'", linenum, line);
     120        linenum = parser->lineno;
     121
     122        if ((2 > sscanf(line, "%40s %c %o %40s %40s %u %u %u %u %u",
     123                    name, &type, &mode, user, group,
     124                    &major, &minor, &start, &increment, &count))
     125         || ((unsigned)(major | minor | start | count | increment) > 255)
     126        ) {
     127            bb_error_msg("invalid line %d: '%s'", linenum, line);
    125128            ret = EXIT_FAILURE;
    126129            continue;
    127130        }
    128         if (name[0] == '#') {
    129             continue;
    130         }
    131131
    132132        gid = (*group) ? get_ug_id(group, xgroup2gid) : getgid();
    133133        uid = (*user) ? get_ug_id(user, xuname2uid) : getuid();
    134         full_name = concat_path_file(rootdir, name);
     134        /* We are already in the right root dir,
     135         * so make absolute paths relative */
     136        if ('/' == *full_name)
     137            full_name++;
    135138
    136139        if (type == 'd') {
    137140            bb_make_directory(full_name, mode | S_IFDIR, FILEUTILS_RECUR);
    138141            if (chown(full_name, uid, gid) == -1) {
    139                 bb_perror_msg("line %d: chown failed for %s", linenum, full_name);
    140                 ret = EXIT_FAILURE;
    141                 goto loop;
    142             }
    143             if ((mode != -1) && (chmod(full_name, mode) < 0)){
    144                 bb_perror_msg("line %d: chmod failed for %s", linenum, full_name);
    145                 ret = EXIT_FAILURE;
    146                 goto loop;
     142 chown_fail:
     143                bb_perror_msg("line %d: can't chown %s", linenum, full_name);
     144                ret = EXIT_FAILURE;
     145                continue;
     146            }
     147            if (chmod(full_name, mode) < 0) {
     148 chmod_fail:
     149                bb_perror_msg("line %d: can't chmod %s", linenum, full_name);
     150                ret = EXIT_FAILURE;
     151                continue;
    147152            }
    148153        } else if (type == 'f') {
     
    151156                bb_perror_msg("line %d: regular file '%s' does not exist", linenum, full_name);
    152157                ret = EXIT_FAILURE;
    153                 goto loop;
    154             }
    155             if (chown(full_name, uid, gid) == -1) {
    156                 bb_perror_msg("line %d: chown failed for %s", linenum, full_name);
    157                 ret = EXIT_FAILURE;
    158                 goto loop;
    159             }
    160             if ((mode != -1) && (chmod(full_name, mode) < 0)){
    161                 bb_perror_msg("line %d: chmod failed for %s", linenum, full_name);
    162                 ret = EXIT_FAILURE;
    163                 goto loop;
    164             }
     158                continue;
     159            }
     160            if (chown(full_name, uid, gid) < 0)
     161                goto chown_fail;
     162            if (chmod(full_name, mode) < 0)
     163                goto chmod_fail;
    165164        } else {
    166165            dev_t rdev;
     166            unsigned i;
     167            char *full_name_inc;
    167168
    168169            if (type == 'p') {
    169170                mode |= S_IFIFO;
    170             }
    171             else if (type == 'c') {
     171            } else if (type == 'c') {
    172172                mode |= S_IFCHR;
    173             }
    174             else if (type == 'b') {
     173            } else if (type == 'b') {
    175174                mode |= S_IFBLK;
    176175            } else {
    177176                bb_error_msg("line %d: unsupported file type %c", linenum, type);
    178177                ret = EXIT_FAILURE;
    179                 goto loop;
    180             }
    181 
    182             if (count > 0) {
    183                 int i;
    184                 char *full_name_inc;
    185 
    186                 full_name_inc = xmalloc(strlen(full_name) + 4);
    187                 for (i = start; i < count; i++) {
    188                     sprintf(full_name_inc, "%s%d", full_name, i);
    189                     rdev = makedev(major, minor + (i * increment - start));
    190                     if (mknod(full_name_inc, mode, rdev) == -1) {
    191                         bb_perror_msg("line %d: cannot create node %s", linenum, full_name_inc);
    192                         ret = EXIT_FAILURE;
    193                     }
    194                     else if (chown(full_name_inc, uid, gid) == -1) {
    195                         bb_perror_msg("line %d: chown failed for %s", linenum, full_name_inc);
    196                         ret = EXIT_FAILURE;
    197                     }
    198                     if ((mode != -1) && (chmod(full_name_inc, mode) < 0)){
    199                         bb_perror_msg("line %d: chmod failed for %s", linenum, full_name_inc);
    200                         ret = EXIT_FAILURE;
    201                     }
    202                 }
    203                 free(full_name_inc);
    204             } else {
    205                 rdev = makedev(major, minor);
    206                 if (mknod(full_name, mode, rdev) == -1) {
    207                     bb_perror_msg("line %d: cannot create node %s", linenum, full_name);
     178                continue;
     179            }
     180
     181            full_name_inc = xmalloc(strlen(full_name) + sizeof(int)*3 + 2);
     182            if (count)
     183                count--;
     184            for (i = start; i <= start + count; i++) {
     185                sprintf(full_name_inc, count ? "%s%u" : "%s", full_name, i);
     186                rdev = makedev(major, minor + (i - start) * increment);
     187                if (mknod(full_name_inc, mode, rdev) < 0) {
     188                    bb_perror_msg("line %d: can't create node %s", linenum, full_name_inc);
     189                    ret = EXIT_FAILURE;
     190                } else if (chown(full_name_inc, uid, gid) < 0) {
     191                    bb_perror_msg("line %d: can't chown %s", linenum, full_name_inc);
     192                    ret = EXIT_FAILURE;
     193                } else if (chmod(full_name_inc, mode) < 0) {
     194                    bb_perror_msg("line %d: can't chmod %s", linenum, full_name_inc);
    208195                    ret = EXIT_FAILURE;
    209196                }
    210                 else if (chown(full_name, uid, gid) == -1) {
    211                     bb_perror_msg("line %d: chown failed for %s", linenum, full_name);
    212                     ret = EXIT_FAILURE;
    213                 }
    214                 if ((mode != -1) && (chmod(full_name, mode) < 0)){
    215                     bb_perror_msg("line %d: chmod failed for %s", linenum, full_name);
    216                     ret = EXIT_FAILURE;
    217                 }
    218             }
     197            }
     198            free(full_name_inc);
    219199        }
    220 loop:
    221         free(line);
    222         free(full_name);
    223     }
    224     fclose(table);
     200    }
     201    if (ENABLE_FEATURE_CLEAN_UP)
     202        config_close(parser);
    225203
    226204    return ret;
Note: See TracChangeset for help on using the changeset viewer.