Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/util-linux/mdev.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 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 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/util-linux/mdev.c

    r3232 r3621  
    9898
    9999#include "libbb.h"
     100#include "common_bufsiz.h"
    100101#include "xregex.h"
    101102
     
    284285#endif
    285286    struct rule cur_rule;
    286     char timestr[sizeof("60.123456")];
     287    char timestr[sizeof("HH:MM:SS.123456")];
    287288} FIX_ALIASING;
    288 #define G (*(struct globals*)&bb_common_bufsiz1)
     289#define G (*(struct globals*)bb_common_bufsiz1)
    289290#define INIT_G() do { \
     291    setup_common_bufsiz(); \
    290292    IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.maj = -1;) \
    291293    IF_NOT_FEATURE_MDEV_CONF(G.cur_rule.mode = 0660;) \
     
    324326    }
    325327    make_default_cur_rule();
    326 }
    327 
    328 /* In later versions, endofname is in libbb */
    329 #define endofname mdev_endofname
    330 static
    331 const char* FAST_FUNC
    332 endofname(const char *name)
    333 {
    334 #define is_name(c)      ((c) == '_' || isalpha((unsigned char)(c)))
    335 #define is_in_name(c)   ((c) == '_' || isalnum((unsigned char)(c)))
    336     if (!is_name(*name))
    337         return name;
    338     while (*++name) {
    339         if (!is_in_name(*name))
    340             break;
    341     }
    342     return name;
    343328}
    344329
     
    418403
    419404        /* 2nd field: uid:gid - device ownership */
    420         if (get_uidgid(&G.cur_rule.ugid, tokens[1], /*allow_numeric:*/ 1) == 0) {
     405        if (get_uidgid(&G.cur_rule.ugid, tokens[1]) == 0) {
    421406            bb_error_msg("unknown user/group '%s' on line %d", tokens[1], G.parser->lineno);
    422407            goto next_rule;
     
    424409
    425410        /* 3rd field: mode - device permissions */
    426         bb_parse_mode(tokens[2], &G.cur_rule.mode);
     411        G.cur_rule.mode = bb_parse_mode(tokens[2], G.cur_rule.mode);
    427412
    428413        /* 4th field (opt): ">|=alias" or "!" to not create the node */
     
    489474        parse_next_rule();
    490475        if (G.rule_vec) { /* mdev -s */
    491             rule = memcpy(xmalloc(sizeof(G.cur_rule)), &G.cur_rule, sizeof(G.cur_rule));
     476            rule = xmemdup(&G.cur_rule, sizeof(G.cur_rule));
    492477            G.rule_vec = xrealloc_vector(G.rule_vec, 4, G.rule_idx);
    493478            G.rule_vec[G.rule_idx++] = rule;
     
    628613     */
    629614    type = S_IFCHR;
    630     if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0))
     615    if (strstr(path, "/block/") || (G.subsystem && is_prefixed_with(G.subsystem, "block")))
    631616        type = S_IFBLK;
    632617
     
    941926    struct timeval tv;
    942927    gettimeofday(&tv, NULL);
    943     sprintf(G.timestr, "%u.%06u", (unsigned)tv.tv_sec % 60, (unsigned)tv.tv_usec);
     928    sprintf(
     929        strftime_HHMMSS(G.timestr, sizeof(G.timestr), &tv.tv_sec),
     930        ".%06u",
     931        (unsigned)tv.tv_usec
     932    );
    944933    return G.timestr;
    945934}
     
    961950 */
    962951static int
    963 wait_for_seqfile(const char *seq)
     952wait_for_seqfile(unsigned expected_seq)
    964953{
    965954    /* We time out after 2 sec */
     
    976965    for (;;) {
    977966        int seqlen;
    978         char seqbuf[sizeof(int)*3 + 2];
     967        char seqbuf[sizeof(long)*3 + 2];
     968        unsigned seqbufnum;
    979969
    980970        if (seq_fd < 0) {
     
    982972            if (seq_fd < 0)
    983973                break;
     974            close_on_exec_on(seq_fd);
    984975        }
    985976        seqlen = pread(seq_fd, seqbuf, sizeof(seqbuf) - 1, 0);
     
    990981        }
    991982        seqbuf[seqlen] = '\0';
    992         if (seqbuf[0] == '\n') {
     983        if (seqbuf[0] == '\n' || seqbuf[0] == '\0') {
    993984            /* seed file: write out seq ASAP */
    994             xwrite_str(seq_fd, seq);
     985            xwrite_str(seq_fd, utoa(expected_seq));
    995986            xlseek(seq_fd, 0, SEEK_SET);
    996987            dbg2("first seq written");
    997988            break;
    998989        }
    999         if (strcmp(seq, seqbuf) == 0) {
     990        seqbufnum = atoll(seqbuf);
     991        if (seqbufnum == expected_seq) {
    1000992            /* correct idx */
    1001993            break;
    1002994        }
     995        if (seqbufnum > expected_seq) {
     996            /* a later mdev runs already (this was seen by users to happen) */
     997            /* do not overwrite seqfile on exit */
     998            close(seq_fd);
     999            seq_fd = -1;
     1000            break;
     1001        }
    10031002        if (do_once) {
    1004             dbg2("%s waiting for '%s'", curtime(), seqbuf);
     1003            dbg2("%s mdev.seq='%s', need '%u'", curtime(), seqbuf, expected_seq);
    10051004            do_once = 0;
    10061005        }
     
    10101009        }
    10111010        if (--timeout == 0) {
    1012             dbg1("%s waiting for '%s'", "timed out", seqbuf);
     1011            dbg1("%s mdev.seq='%s'", "timed out", seqbuf);
    10131012            break;
    10141013        }
     
    10931092        char *env_devpath;
    10941093        unsigned my_pid;
     1094        unsigned seqnum = seqnum; /* for compiler */
    10951095        int seq_fd;
    10961096        smalluint op;
     
    11011101         * DEVPATH is like "/block/sda" or "/class/input/mice"
    11021102         */
     1103        env_devname = getenv("DEVNAME"); /* can be NULL */
     1104        G.subsystem = getenv("SUBSYSTEM");
    11031105        action = getenv("ACTION");
    1104         op = index_in_strings(keywords, action);
    1105         env_devname = getenv("DEVNAME"); /* can be NULL */
    11061106        env_devpath = getenv("DEVPATH");
    1107         G.subsystem = getenv("SUBSYSTEM");
    11081107        if (!action || !env_devpath /*|| !G.subsystem*/)
    11091108            bb_show_usage();
    11101109        fw = getenv("FIRMWARE");
    11111110        seq = getenv("SEQNUM");
     1111        op = index_in_strings(keywords, action);
    11121112
    11131113        my_pid = getpid();
    11141114        open_mdev_log(seq, my_pid);
    11151115
    1116         seq_fd = seq ? wait_for_seqfile(seq) : -1;
     1116        seq_fd = -1;
     1117        if (seq) {
     1118            seqnum = atoll(seq);
     1119            seq_fd = wait_for_seqfile(seqnum);
     1120        }
    11171121
    11181122        dbg1("%s "
     
    11421146        dbg1("%s exiting", curtime());
    11431147        if (seq_fd >= 0) {
    1144             xwrite_str(seq_fd, utoa(xatou(seq) + 1));
     1148            xwrite_str(seq_fd, utoa(seqnum + 1));
    11451149            signal_mdevs(my_pid);
    11461150        }
Note: See TracChangeset for help on using the changeset viewer.