Ignore:
Timestamp:
Nov 6, 2007, 11:01:53 AM (13 years ago)
Author:
Bruno Cornec
Message:
  • Better output for mindi-busybox revision
  • Remove dummy file created on NFS - report from Arnaud Tiger <arnaud.tiger_at_hp.com>
  • strace useful for debug
  • fix new versions for pb (2.0.0 for mindi and 1.7.2 for mindi-busybox)
  • fix build process for mindi-busybox + options used in that version (dd for label-partitions-as-necessary)
  • fix typo in label-partitions-as-necessary which doesn't seem to work
  • Update to busybox 1.7.2
  • perl is now required at restore time to support uuid swap partitions (and will be used for many other thigs

in the future for sure)

  • next mindi version will be 2.0.0 due to all the changes made in it (udev may break working distros)
  • small optimization in mindi on keyboard handling (one single find instead of multiple)
  • better interaction for USB device when launching mindi manually
  • attempt to automatically guess block disk size for ramdisk
  • fix typos in bkphw
  • Fix the remaining problem with UUID support for swap partitions
  • Updates mondoarchive man page for USB support
  • Adds preliminary Hardware support to mindi (Proliant SSSTK)
  • Tries to add udev support also for rhel4
  • Fix UUID support which was still broken.
  • Be conservative in test for the start-nfs script
  • Update config file for mindi-busybox for 1.7.2 migration
  • Try to run around a busybox bug (1.2.2 pb on inexistant links)
  • Add build content for mindi-busybox in pb
  • Remove distributions content for mindi-busybox
  • Fix a warning on inexistant raidtab
  • Solve problem on tmpfs in restore init (Problem of inexistant symlink and busybox)
  • Create MONDO_CACHE and use it everywhere + creation at start
  • Really never try to eject a USB device
  • Fix a issue with &> usage (replaced with 1> and 2>)
  • Adds magic file to depllist in order to have file working + ldd which helps for debugging issues
  • tty modes correct to avoid sh error messages
  • Use ext3 normally and not ext2 instead
  • USB device should be corrected after reading (take 1st part)
  • Adds a mount_USB_here function derived from mount_CDROM_here
  • usb detection place before /dev detection in device name at restore time
  • Fix when restoring from USB: media is asked in interactive mode
  • Adds USB support for mondorestore
  • mount_cdrom => mount_media
  • elilo.efi is now searched throughout /boot/efi and not in a fixed place as there is no standard
  • untar-and-softlink => untar (+ interface change)
  • suppress useless softlinks creation/removal in boot process
  • avoids udevd messages on groups
  • Increase # of disks to 99 as in mindi at restore time (should be a conf file parameter)
  • skip existing big file creation
  • seems to work correctly for USB mindi boot
  • Adds group and tty link to udev conf
  • Always load usb-torage (even 2.6) to initiate USB bus discovery
  • Better printing of messages
  • Attempt to fix a bug in supporting OpenSusE 10.3 kernel for initramfs (mindi may now use multiple regex for kernel initrd detection)
  • Links were not correctly done as non relative for modules in mindi
  • exclusion of modules denied now works
  • Also create modules in their ordinary place, so that classical modprobe works + copy modules.dep
  • Fix bugs for DENY_MODS handling
  • Add device /dev/console for udev
  • ide-generic should now really be excluded
  • Fix a bug in major number for tty
  • If udev then adds modprobe/insmod to rootfs
  • tty0 is also cretaed with udev
  • ide-generic put rather in DENY_MODS
  • udevd remove from deplist s handled in mindi directly
  • better default for mindi when using --usb
  • Handles dynamically linked busybox (in case we want to use it soon ;-)
  • Adds fixed devices to create for udev
  • ide-generic should not be part of the initrd when using libata v2
  • support a dynamically linked udev (case on Ubuntu 7.10 and Mandriva 2008.0 so should be quite generic) This will give incitation to move to dyn. linked binaries in the initrd which will help for other tasks (ia6 4)
  • Improvement in udev support (do not use cl options not available in busybox)
  • Udev in mindi
    • auto creation of the right links at boot time with udev-links.conf(from Mandriva 2008.0)
    • rework startup of udev as current makes kernel crash (from Mandriva 2008.0)
    • add support for 64 bits udev
  • Try to render MyInsmod? silent at boot time
  • Adds udev support (mandatory for newest distributions to avoid remapping of devices in a different way as on the original system)
  • We also need vaft format support for USB boot
  • Adds libusual support (Ubuntu 7.10 needs it for USB)
  • Improve Ubuntu/Debian? keyboard detection and support
  • pbinit adapted to new pb (0.8.10). Filtering of docs done in it
  • Suppress some mondo warnings and errors on USB again
  • Tries to fix lack of files in deb mindi package
  • Verify should now work for USB devices
  • More log/mesages improvement for USB support
  • - Supress g_erase_tmpdir_and_scratchdir
  • Improve some log messages for USB support
  • Try to improve install in mindi to avoid issues with isolinux.cfg not installed vene if in the pkg :-(
  • Improve mindi-busybox build
  • In conformity with pb 0.8.9
  • Add support for Ubuntu 7.10 in build process
  • Add USB Key button to Menu UI (CD streamer removed)
  • Attempt to fix error messages on tmp/scratch files at the end by removing those dir at the latest possible.
  • Fix a bug linked to the size of the -E param which could be used (Arnaud Tiger/René? Ribaud).
  • Integrate ~/.pbrc content into mondorescue.pb (required project-builder >= 0.8.7)
  • Put mondorescue in conformity with new pb filtering rules
  • Add USB support at restore time (no test done yet). New start-usb script PB varibale added where useful
  • Unmounting USB device before removal of temporary scratchdir
  • Stil refining USB copy back to mondo (one command was not executed)
  • No need to have the image subdor in the csratchdir when USB.
  • umount the USB partition before attempting to use it
  • Remove useless copy from mindi to mondo at end of USB handling

(risky merge, we are raising the limits of 2 diverging branches. The status of stable is not completely sure as such. Will need lots of tests, but it's not yet done :-()
(merge -r1692:1769 $SVN_M/branches/2.2.5)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/sysklogd/logread.c

    r821 r1770  
    1010 */
    1111
    12 
    13 #include "busybox.h"
    14 #include <stdio.h>
    15 #include <stdlib.h>
    16 #include <string.h>
     12#include "libbb.h"
    1713#include <sys/ipc.h>
    18 #include <sys/types.h>
    1914#include <sys/sem.h>
    2015#include <sys/shm.h>
    21 #include <signal.h>
    22 #include <setjmp.h>
    23 #include <unistd.h>
    2416
    25 static const long KEY_ID = 0x414e4547; /*"GENA"*/
     17#define DEBUG 0
     18
     19enum { KEY_ID = 0x414e4547 }; /* "GENA" */
    2620
    2721static struct shbuf_ds {
    28     int size;       // size of data written
    29     int head;       // start of message list
    30     int tail;       // end of message list
    31     char data[1];       // data/messages
    32 } *buf = NULL;          // shared memory pointer
    33 
     22    int32_t size;           // size of data - 1
     23    int32_t tail;           // end of message list
     24    char data[1];           // messages
     25} *shbuf;
    3426
    3527// Semaphore operation structures
     
    3729static struct sembuf SMrdn[2] = {{1, 0}, {0, +1, SEM_UNDO}}; // set SMrdn
    3830
    39 static int  log_shmid = -1; // ipc shared memory id
    40 static int  log_semid = -1; // ipc semaphore id
    41 static jmp_buf  jmp_env;
    4231
    43 static void error_exit(const char *str);
    44 static void interrupted(int sig);
     32static void error_exit(const char *str) ATTRIBUTE_NORETURN;
     33static void error_exit(const char *str)
     34{
     35    //release all acquired resources
     36    shmdt(shbuf);
     37    bb_perror_msg_and_die(str);
     38}
    4539
    4640/*
    4741 * sem_up - up()'s a semaphore.
    4842 */
    49 static inline void sem_up(int semid)
     43static void sem_up(int semid)
    5044{
    51     if ( semop(semid, SMrup, 1) == -1 )
     45    if (semop(semid, SMrup, 1) == -1)
    5246        error_exit("semop[SMrup]");
    5347}
    5448
    55 /*
    56  * sem_down - down()'s a semaphore
    57  */
    58 static inline void sem_down(int semid)
     49static void interrupted(int sig ATTRIBUTE_UNUSED)
    5950{
    60     if ( semop(semid, SMrdn, 2) == -1 )
    61         error_exit("semop[SMrdn]");
     51    signal(SIGINT, SIG_IGN);
     52    shmdt(shbuf);
     53    exit(0);
    6254}
    6355
     56int logread_main(int argc, char **argv);
    6457int logread_main(int argc, char **argv)
    6558{
    66     int i;
    67     int follow=0;
     59    int cur;
     60    int log_semid; /* ipc semaphore id */
     61    int log_shmid; /* ipc shared memory id */
     62    smallint follow = getopt32(argv, "f");
    6863
    69     if (argc == 2 && argv[1][0]=='-' && argv[1][1]=='f') {
    70         follow = 1;
    71     } else {
    72         /* no options, no getopt */
    73         if (argc > 1)
    74             bb_show_usage();
    75     }
     64    log_shmid = shmget(KEY_ID, 0, 0);
     65    if (log_shmid == -1)
     66        bb_perror_msg_and_die("can't find syslogd buffer");
    7667
    77     // handle interrupt signal
    78     if (setjmp(jmp_env)) goto output_end;
     68    /* Attach shared memory to our char* */
     69    shbuf = shmat(log_shmid, NULL, SHM_RDONLY);
     70    if (shbuf == NULL)
     71        bb_perror_msg_and_die("can't access syslogd buffer");
    7972
    80     // attempt to redefine ^C signal
     73    log_semid = semget(KEY_ID, 0, 0);
     74    if (log_semid == -1)
     75        error_exit("can't get access to semaphores for syslogd buffer");
     76
    8177    signal(SIGINT, interrupted);
    8278
    83     if ( (log_shmid = shmget(KEY_ID, 0, 0)) == -1)
    84         error_exit("Can't find circular buffer");
     79    /* Suppose atomic memory read */
     80    /* Max possible value for tail is shbuf->size - 1 */
     81    cur = shbuf->tail;
    8582
    86     // Attach shared memory to our char*
    87     if ( (buf = shmat(log_shmid, NULL, SHM_RDONLY)) == NULL)
    88         error_exit("Can't get access to circular buffer from syslogd");
     83    /* Loop for logread -f, one pass if there was no -f */
     84    do {
     85        unsigned shbuf_size;
     86        unsigned shbuf_tail;
     87        const char *shbuf_data;
     88#if ENABLE_FEATURE_LOGREAD_REDUCED_LOCKING
     89        int i;
     90        int len_first_part;
     91        int len_total = len_total; /* for gcc */
     92        char *copy = copy; /* for gcc */
     93#endif
     94        if (semop(log_semid, SMrdn, 2) == -1)
     95            error_exit("semop[SMrdn]");
    8996
    90     if ( (log_semid = semget(KEY_ID, 0, 0)) == -1)
    91         error_exit("Can't get access to semaphone(s) for circular buffer from syslogd");
     97        /* Copy the info, helps gcc to realize that it doesn't change */
     98        shbuf_size = shbuf->size;
     99        shbuf_tail = shbuf->tail;
     100        shbuf_data = shbuf->data; /* pointer! */
    92101
    93     // Suppose atomic memory move
    94     i = follow ? buf->tail : buf->head;
     102        if (DEBUG)
     103            printf("cur:%d tail:%i size:%i\n",
     104                    cur, shbuf_tail, shbuf_size);
    95105
    96     do {
    97 #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING
    98         char *buf_data;
    99         int log_len,j;
    100 #endif
    101 
    102         sem_down(log_semid);
    103 
    104         //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size);
    105         if (buf->head == buf->tail || i==buf->tail) {
    106             if (follow) {
     106        if (!follow) {
     107            /* advance to oldest complete message */
     108            /* find NUL */
     109            cur += strlen(shbuf_data + cur);
     110            if (cur >= shbuf_size) { /* last byte in buffer? */
     111                cur = strnlen(shbuf_data, shbuf_tail);
     112                if (cur == shbuf_tail)
     113                    goto unlock; /* no complete messages */
     114            }
     115            /* advance to first byte of the message */
     116            cur++;
     117            if (cur >= shbuf_size) /* last byte in buffer? */
     118                cur = 0;
     119        } else { /* logread -f */
     120            if (cur == shbuf_tail) {
    107121                sem_up(log_semid);
    108                 sleep(1);   /* TODO: replace me with a sleep_on */
     122                fflush(stdout);
     123                sleep(1); /* TODO: replace me with a sleep_on */
    109124                continue;
    110             } else {
    111                 printf("<empty syslog>\n");
    112125            }
    113126        }
    114127
    115         // Read Memory
    116 #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING
    117         log_len = buf->tail - i;
    118         if (log_len < 0)
    119             log_len += buf->size;
    120         buf_data = (char *)xmalloc(log_len);
    121 
    122         if (buf->tail < i) {
    123             memcpy(buf_data, buf->data+i, buf->size-i);
    124             memcpy(buf_data+buf->size-i, buf->data, buf->tail);
    125         } else {
    126             memcpy(buf_data, buf->data+i, buf->tail-i);
     128        /* Read from cur to tail */
     129#if ENABLE_FEATURE_LOGREAD_REDUCED_LOCKING
     130        len_first_part = len_total = shbuf_tail - cur;
     131        if (len_total < 0) {
     132            /* message wraps: */
     133            /* [SECOND PART.........FIRST PART] */
     134            /*  ^data      ^tail    ^cur      ^size */
     135            len_total += shbuf_size;
    127136        }
    128         i = buf->tail;
    129 
     137        copy = xmalloc(len_total + 1);
     138        if (len_first_part < 0) {
     139            /* message wraps (see above) */
     140            len_first_part = shbuf_size - cur;
     141            memcpy(copy + len_first_part, shbuf_data, shbuf_tail);
     142        }
     143        memcpy(copy, shbuf_data + cur, len_first_part);
     144        copy[len_total] = '\0';
     145        cur = shbuf_tail;
    130146#else
    131         while ( i != buf->tail) {
    132             printf("%s", buf->data+i);
    133             i+= strlen(buf->data+i) + 1;
    134             if (i >= buf->size )
    135                 i=0;
     147        while (cur != shbuf_tail) {
     148            fputs(shbuf_data + cur, stdout);
     149            cur += strlen(shbuf_data + cur) + 1;
     150            if (cur >= shbuf_size)
     151                cur = 0;
    136152        }
    137153#endif
    138         // release the lock on the log chain
     154 unlock:
     155        /* release the lock on the log chain */
    139156        sem_up(log_semid);
    140157
    141 #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING
    142         for (j=0; j < log_len; j+=strlen(buf_data+j)+1) {
    143             printf("%s", buf_data+j);
    144             if (follow)
    145                 fflush(stdout);
     158#if ENABLE_FEATURE_LOGREAD_REDUCED_LOCKING
     159        for (i = 0; i < len_total; i += strlen(copy + i) + 1) {
     160            fputs(copy + i, stdout);
    146161        }
    147         free(buf_data);
     162        free(copy);
    148163#endif
    149         fflush(stdout);
    150164    } while (follow);
    151165
    152 output_end:
    153     if (log_shmid != -1)
    154         shmdt(buf);
     166    shmdt(shbuf);
    155167
    156     return EXIT_SUCCESS;
     168    fflush_stdout_and_exit(EXIT_SUCCESS);
    157169}
    158 
    159 static void interrupted(int sig){
    160     signal(SIGINT, SIG_IGN);
    161     longjmp(jmp_env, 1);
    162 }
    163 
    164 static void error_exit(const char *str){
    165     bb_perror_msg(str);
    166     //release all acquired resources
    167     if (log_shmid != -1)
    168         shmdt(buf);
    169 
    170     exit(1);
    171 }
Note: See TracChangeset for help on using the changeset viewer.