Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (14 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/devfsd.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
     3 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    44 */
    55
     
    5454      Richard Gooch, c/o ATNF, P. O. Box 76, Epping, N.S.W., 2121, Australia.
    5555*/
    56 
    57 //#include <sys/wait.h>
    58 //#include <sys/ioctl.h>
    59 //#include <sys/socket.h>
    60 #include <sys/un.h>
    61 #include <dirent.h>
    62 #include <syslog.h>
    63 #include <sys/sysmacros.h>
    6456#include "libbb.h"
    6557#include "xregex.h"
    66 
     58#include <syslog.h>
     59
     60#include <sys/un.h>
     61#include <sys/sysmacros.h>
    6762
    6863/* Various defines taken from linux/major.h */
     
    8176/* Various defines taken from linux/devfs_fs.h */
    8277#define DEVFSD_PROTOCOL_REVISION_KERNEL  5
    83 #define DEVFSD_IOCTL_BASE   'd'
     78#define DEVFSD_IOCTL_BASE   'd'
    8479/*  These are the various ioctls  */
    8580#define DEVFSDIOC_GET_PROTO_REV         _IOR(DEVFSD_IOCTL_BASE, 0, int)
     
    9893/*  Never change this otherwise the binary interface will change   */
    9994
    100 struct devfsd_notify_struct
    101 {   /*  Use native C types to ensure same types in kernel and user space     */
    102     unsigned int type;           /*  DEVFSD_NOTIFY_* value                   */
    103     unsigned int mode;           /*  Mode of the inode or device entry       */
    104     unsigned int major;          /*  Major number of device entry            */
    105     unsigned int minor;          /*  Minor number of device entry            */
    106     unsigned int uid;            /*  Uid of process, inode or device entry   */
    107     unsigned int gid;            /*  Gid of process, inode or device entry   */
    108     unsigned int overrun_count;  /*  Number of lost events                   */
    109     unsigned int namelen;        /*  Number of characters not including '\0' */
    110     /*  The device name MUST come last                                       */
    111     char devname[DEVFS_PATHLEN]; /*  This will be '\0' terminated            */
     95struct devfsd_notify_struct {
     96    /*  Use native C types to ensure same types in kernel and user space     */
     97    unsigned int type;           /*  DEVFSD_NOTIFY_* value                   */
     98    unsigned int mode;           /*  Mode of the inode or device entry       */
     99    unsigned int major;          /*  Major number of device entry            */
     100    unsigned int minor;          /*  Minor number of device entry            */
     101    unsigned int uid;            /*  Uid of process, inode or device entry   */
     102    unsigned int gid;            /*  Gid of process, inode or device entry   */
     103    unsigned int overrun_count;  /*  Number of lost events                   */
     104    unsigned int namelen;        /*  Number of characters not including '\0' */
     105    /*  The device name MUST come last                                       */
     106    char devname[DEVFS_PATHLEN]; /*  This will be '\0' terminated            */
    112107};
    113108
     
    157152#define AC_RESTORE                  11
    158153
    159 struct permissions_type
    160 {
     154struct permissions_type {
    161155    mode_t mode;
    162156    uid_t uid;
     
    164158};
    165159
    166 struct execute_type
    167 {
     160struct execute_type {
    168161    char *argv[MAX_ARGS + 1];  /*  argv[0] must always be the programme  */
    169162};
    170163
    171 struct copy_type
    172 {
     164struct copy_type {
    173165    const char *source;
    174166    const char *destination;
    175167};
    176168
    177 struct action_type
    178 {
     169struct action_type {
    179170    unsigned int what;
    180171    unsigned int when;
    181172};
    182173
    183 struct config_entry_struct
    184 {
     174struct config_entry_struct {
    185175    struct action_type action;
    186176    regex_t preg;
     
    195185};
    196186
    197 struct get_variable_info
    198 {
     187struct get_variable_info {
    199188    const struct devfsd_notify_struct *info;
    200189    const char *devname;
     
    289278#define info_logger(p, fmt, args...)
    290279#define msg_logger(p, fmt, args...)
    291 #define msg_logger_and_die(p, fmt, args...)           exit(1)
     280#define msg_logger_and_die(p, fmt, args...)           exit(EXIT_FAILURE)
    292281#define error_logger(p, fmt, args...)
    293 #define error_logger_and_die(p, fmt, args...)         exit(1)
     282#define error_logger_and_die(p, fmt, args...)         exit(EXIT_FAILURE)
    294283#endif
    295284
     
    337326/*  Public functions follow  */
    338327
    339 int devfsd_main(int argc, char **argv);
     328int devfsd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    340329int devfsd_main(int argc, char **argv)
    341330{
     
    372361
    373362    fd = xopen(".devfsd", O_RDONLY);
    374 
    375     if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0)
    376         bb_perror_msg_and_die("FD_CLOEXEC");
    377 
     363    close_on_exec_on(fd);
    378364    xioctl(fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev);
    379365
     
    395381    xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, 0);
    396382
     383    /*  Set up SIGHUP and SIGUSR1 handlers  */
    397384    sigemptyset(&new_action.sa_mask);
    398385    new_action.sa_flags = 0;
    399 
    400     /*  Set up SIGHUP and SIGUSR1 handlers  */
    401386    new_action.sa_handler = signal_handler;
    402     if (sigaction(SIGHUP, &new_action, NULL) != 0 || sigaction(SIGUSR1, &new_action, NULL) != 0)
    403         bb_error_msg_and_die("sigaction");
    404 
    405     printf("%s v%s  started for %s\n",applet_name, DEVFSD_VERSION, mount_point);
     387    sigaction_set(SIGHUP, &new_action);
     388    sigaction_set(SIGUSR1, &new_action);
     389
     390    printf("%s v%s started for %s\n", applet_name, DEVFSD_VERSION, mount_point);
    406391
    407392    /*  Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions  */
     
    412397
    413398    if (ENABLE_DEVFSD_FG_NP && no_polling)
    414         exit(0);
     399        exit(EXIT_SUCCESS);
    415400
    416401    if (ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG)
     
    469454            return;
    470455        }
    471         if ((fp = fopen(path, "r")) != NULL) {
     456        fp = fopen_for_read(path);
     457        if (fp != NULL) {
    472458            while (fgets(buf, STRING_LENGTH, fp) != NULL) {
    473459                /*  Skip whitespace  */
     
    564550            new->action.what = AC_PERMISSIONS;
    565551            /*  Get user and group  */
    566             if ((ptr = strchr(p[0], '.')) == NULL) {
     552            ptr = strchr(p[0], '.');
     553            if (ptr == NULL) {
    567554                msg = "UID.GID";
    568555                goto process_config_line_err; /*"missing '.' in UID.GID"*/
     
    651638    while (!caught_signal) {
    652639        errno = 0;
    653         bytes = read(fd,(char *) &info, sizeof info);
     640        bytes = read(fd, (char *) &info, sizeof info);
    654641        if (caught_signal)
    655642            break;      /*  Must test for this first     */
     
    749736
    750737static void action_modload(const struct devfsd_notify_struct *info,
    751                 const struct config_entry_struct *entry ATTRIBUTE_UNUSED)
     738                const struct config_entry_struct *entry UNUSED_PARAM)
    752739/*  [SUMMARY] Load a module.
    753740    <info> The devfs change.
     
    765752    argv[5] = NULL;
    766753
    767     wait4pid(xspawn(argv));
     754    spawn_and_wait(argv);
    768755    free(argv[4]);
    769756}  /*  End Function action_modload  */
     
    797784    }
    798785    argv[count] = NULL;
    799     wait4pid(spawn(argv));
     786    spawn_and_wait(argv);
    800787}   /*  End Function action_execute  */
    801788
     
    955942    free(dpath);
    956943    if (S_ISLNK(source_stat.st_mode) || (source_stat.st_mode & S_ISVTX))
    957         copy_inode(dpath, &dest_stat,(source_stat.st_mode & ~S_ISVTX) , spath, &source_stat);
     944        copy_inode(dpath, &dest_stat, (source_stat.st_mode & ~S_ISVTX), spath, &source_stat);
    958945
    959946    if (S_ISDIR(source_stat.st_mode))
    960         dir_operation(RESTORE, spath, rootlen,NULL);
     947        dir_operation(RESTORE, spath, rootlen, NULL);
    961948}
    962949
     
    983970        /*  Same type  */
    984971        if (S_ISLNK(source_stat->st_mode)) {
    985             if ((source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1)) < 0
    986                 || (dest_len   = readlink(destpath  , dest_link  , STRING_LENGTH - 1)) < 0
     972            source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1);
     973            if ((source_len < 0)
     974             || (dest_len = readlink(destpath, dest_link, STRING_LENGTH - 1)) < 0
    987975            )
    988976                return FALSE;
     
    1003991    switch (source_stat->st_mode & S_IFMT) {
    1004992        case S_IFSOCK:
    1005             if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
     993            fd = socket(AF_UNIX, SOCK_STREAM, 0);
     994            if (fd < 0)
    1006995                break;
    1007996            un_addr.sun_family = AF_UNIX;
    1008997            snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath);
    1009             val = bind(fd,(struct sockaddr *) &un_addr,(int) sizeof un_addr);
     998            val = bind(fd, (struct sockaddr *) &un_addr, (int) sizeof un_addr);
    1010999            close(fd);
    10111000            if (val != 0 || chmod(destpath, new_mode & ~S_IFMT) != 0)
     
    10131002            goto do_chown;
    10141003        case S_IFLNK:
    1015             if ((val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1)) < 0)
     1004            val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1);
     1005            if (val < 0)
    10161006                break;
    10171007            symlink_val[val] = '\0';
     
    10201010            break;
    10211011        case S_IFREG:
    1022             if ((fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT)) < 0)
     1012            fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT);
     1013            if (fd < 0)
    10231014                break;
    10241015            close(fd);
     
    10861077        return atoi(string);
    10871078
    1088     if (flag == UID && (pw_ent  = getpwnam(string)) != NULL)
     1079    if (flag == UID && (pw_ent = getpwnam(string)) != NULL)
    10891080        return pw_ent->pw_uid;
    10901081
     
    10951086
    10961087    if (ENABLE_DEVFSD_VERBOSE)
    1097         msg_logger(LOG_ERR,"unknown %s: %s, defaulting to %cid=0",  msg, string, msg[0]);
     1088        msg_logger(LOG_ERR, "unknown %s: %s, defaulting to %cid=0",  msg, string, msg[0]);
    10981089    return 0;
    10991090}/*  End Function get_uid_gid  */
     
    11361127{
    11371128    static char sbuf[sizeof(int)*3 + 2]; /* sign and NUL */
    1138 
    1139     char hostname[STRING_LENGTH];
     1129    static char *hostname;
     1130
    11401131    struct get_variable_info *gv_info = info;
    11411132    const char *field_names[] = {
     
    11461137    int i;
    11471138
    1148     if (gethostname(hostname, STRING_LENGTH - 1) != 0)
    1149         /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
    1150         error_logger_and_die(LOG_ERR, "gethostname");
    1151 
    1152     hostname[STRING_LENGTH - 1] = '\0';
    1153 
     1139    if (!hostname)
     1140        hostname = safe_gethostname();
    11541141    /* index_in_str_array returns i>=0  */
    11551142    i = index_in_str_array(field_names, variable);
     
    12011188    char *path;
    12021189
    1203     if ((dp = warn_opendir(dir_name)) == NULL)
     1190    dp = warn_opendir(dir_name);
     1191    if (dp == NULL)
    12041192        return;
    12051193
     
    13431331/* from compat_name.c */
    13441332
    1345 struct translate_struct
    1346 {
     1333struct translate_struct {
    13471334    const char *match;    /*  The string to match to(up to length)                */
    13481335    const char *format;   /*  Format of output, "%s" takes data past match string,
     
    14461433    /* 2 ==scsi/disc, 4 == scsi/part */
    14471434    if (i == 2 || i == 4)
    1448         compat_name = write_old_sd_name(buffer, major, minor,((i == 2) ? "" : (ptr + 4)));
     1435        compat_name = write_old_sd_name(buffer, major, minor, ((i == 2) ? "" : (ptr + 4)));
    14491436
    14501437    /* 5 == scsi/mt */
     
    15851572                if (isspace(ch) ||(ch == '/') ||(ch == '\0')) {
    15861573                    /* User's own home directory: leave separator for next time */
    1587                     if ((env = getenv("HOME")) == NULL) {
     1574                    env = getenv("HOME");
     1575                    if (env == NULL) {
    15881576                        info_logger(LOG_INFO, bb_msg_variable_not_found, "HOME");
    15891577                        return FALSE;
     
    16041592                safe_memcpy(tmp, input, len);
    16051593                input = ptr - 1;
    1606                 if ((pwent = getpwnam(tmp)) == NULL) {
     1594                pwent = getpwnam(tmp);
     1595                if (pwent == NULL) {
    16071596                    info_logger(LOG_INFO, "no pwent for: %s", tmp);
    16081597                    return FALSE;
     
    16641653    if (ch == '$') {
    16651654        /*  Special case for "$$": PID  */
    1666         sprintf(tmp, "%d",(int) getpid());
     1655        sprintf(tmp, "%d", (int) getpid());
    16671656        len = strlen(tmp);
    16681657        if (len + *out_pos >= length)
     
    16841673        safe_memcpy(tmp, input, len);
    16851674        input = ptr - 1;
    1686         if ((env = get_variable_v2(tmp, func, info)) == NULL) {
     1675        env = get_variable_v2(tmp, func, info);
     1676        if (env == NULL) {
    16871677            info_logger(LOG_INFO, bb_msg_variable_not_found, tmp);
    16881678            return NULL;
     
    17361726                break;
    17371727            case '\0':
    1738                 info_logger(LOG_INFO,"\"}\" not found in: %s", input);
     1728                info_logger(LOG_INFO, "\"}\" not found in: %s", input);
    17391729                return NULL;
    17401730            default:
     
    17441734    --ptr;
    17451735    /*  At this point ptr should point to closing brace of "${var:-word}"  */
    1746     if ((env = get_variable_v2(tmp, func, info)) != NULL) {
     1736    env = get_variable_v2(tmp, func, info);
     1737    if (env != NULL) {
    17471738        /*  Found environment variable, so skip the input to the closing brace
    17481739            and return the variable  */
Note: See TracChangeset for help on using the changeset viewer.