dhcp: typo fix: UPD_DHCP_SIZE -> UDP_DHCP_SIZE
[oweals/busybox.git] / miscutils / devfsd.c
index 50c8203cb693843dad77b5216eae98aaea97f71f..8f19288cc32f5e955e240847c0688f1c932cec11 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  */
 
 /*
 #define DEVFS_PATHLEN               1024
 /*  Never change this otherwise the binary interface will change   */
 
-struct devfsd_notify_struct
-{   /*  Use native C types to ensure same types in kernel and user space     */
-    unsigned int type;           /*  DEVFSD_NOTIFY_* value                   */
-    unsigned int mode;           /*  Mode of the inode or device entry       */
-    unsigned int major;          /*  Major number of device entry            */
-    unsigned int minor;          /*  Minor number of device entry            */
-    unsigned int uid;            /*  Uid of process, inode or device entry   */
-    unsigned int gid;            /*  Gid of process, inode or device entry   */
-    unsigned int overrun_count;  /*  Number of lost events                   */
-    unsigned int namelen;        /*  Number of characters not including '\0' */
-    /*  The device name MUST come last                                       */
-    char devname[DEVFS_PATHLEN]; /*  This will be '\0' terminated            */
+struct devfsd_notify_struct {
+       /*  Use native C types to ensure same types in kernel and user space     */
+       unsigned int type;           /*  DEVFSD_NOTIFY_* value                   */
+       unsigned int mode;           /*  Mode of the inode or device entry       */
+       unsigned int major;          /*  Major number of device entry            */
+       unsigned int minor;          /*  Minor number of device entry            */
+       unsigned int uid;            /*  Uid of process, inode or device entry   */
+       unsigned int gid;            /*  Gid of process, inode or device entry   */
+       unsigned int overrun_count;  /*  Number of lost events                   */
+       unsigned int namelen;        /*  Number of characters not including '\0' */
+       /*  The device name MUST come last                                       */
+       char devname[DEVFS_PATHLEN]; /*  This will be '\0' terminated            */
 };
 
 #define BUFFER_SIZE 16384
@@ -151,32 +151,27 @@ struct devfsd_notify_struct
 #define AC_RMNEWCOMPAT                         10
 #define AC_RESTORE                                     11
 
-struct permissions_type
-{
+struct permissions_type {
        mode_t mode;
        uid_t uid;
        gid_t gid;
 };
 
-struct execute_type
-{
+struct execute_type {
        char *argv[MAX_ARGS + 1];  /*  argv[0] must always be the programme  */
 };
 
-struct copy_type
-{
+struct copy_type {
        const char *source;
        const char *destination;
 };
 
-struct action_type
-{
+struct action_type {
        unsigned int what;
        unsigned int when;
 };
 
-struct config_entry_struct
-{
+struct config_entry_struct {
        struct action_type action;
        regex_t preg;
        union
@@ -189,8 +184,7 @@ struct config_entry_struct
        struct config_entry_struct *next;
 };
 
-struct get_variable_info
-{
+struct get_variable_info {
        const struct devfsd_notify_struct *info;
        const char *devname;
        char devpath[STRING_LENGTH];
@@ -283,9 +277,9 @@ static const char bb_msg_variable_not_found[] ALIGN1 = "variable: %s not found";
 #else
 #define info_logger(p, fmt, args...)
 #define msg_logger(p, fmt, args...)
-#define msg_logger_and_die(p, fmt, args...)           exit(1)
+#define msg_logger_and_die(p, fmt, args...)           exit(EXIT_FAILURE)
 #define error_logger(p, fmt, args...)
-#define error_logger_and_die(p, fmt, args...)         exit(1)
+#define error_logger_and_die(p, fmt, args...)         exit(EXIT_FAILURE)
 #endif
 
 static void safe_memcpy(char *dest, const char *src, int len)
@@ -390,8 +384,8 @@ int devfsd_main(int argc, char **argv)
        sigemptyset(&new_action.sa_mask);
        new_action.sa_flags = 0;
        new_action.sa_handler = signal_handler;
-       sigaction(SIGHUP, &new_action, NULL);
-       sigaction(SIGUSR1, &new_action, NULL);
+       sigaction_set(SIGHUP, &new_action);
+       sigaction_set(SIGUSR1, &new_action);
 
        printf("%s v%s started for %s\n", applet_name, DEVFSD_VERSION, mount_point);
 
@@ -402,7 +396,7 @@ int devfsd_main(int argc, char **argv)
        dir_operation(SERVICE, mount_point, 0, NULL);
 
        if (ENABLE_DEVFSD_FG_NP && no_polling)
-               exit(0);
+               exit(EXIT_SUCCESS);
 
        if (ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG)
                logmode = LOGMODE_BOTH;
@@ -459,7 +453,7 @@ static void read_config_file(char *path, int optional, unsigned long *event_mask
                        free(p);
                        return;
                }
-               fp = fopen(path, "r");
+               fp = fopen_for_read(path);
                if (fp != NULL) {
                        while (fgets(buf, STRING_LENGTH, fp) != NULL) {
                                /*  Skip whitespace  */
@@ -643,7 +637,7 @@ static int do_servicing(int fd, unsigned long event_mask)
        xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, (void*)event_mask);
        while (!caught_signal) {
                errno = 0;
-               bytes = read(fd,(char *) &info, sizeof info);
+               bytes = read(fd, (char *) &info, sizeof info);
                if (caught_signal)
                        break;      /*  Must test for this first     */
                if (errno == EINTR)
@@ -741,7 +735,7 @@ static void action_permissions(const struct devfsd_notify_struct *info,
 }   /*  End Function action_permissions  */
 
 static void action_modload(const struct devfsd_notify_struct *info,
-                           const struct config_entry_struct *entry ATTRIBUTE_UNUSED)
+                           const struct config_entry_struct *entry UNUSED_PARAM)
 /*  [SUMMARY] Load a module.
     <info> The devfs change.
     <entry> The config file entry.
@@ -757,7 +751,7 @@ static void action_modload(const struct devfsd_notify_struct *info,
        argv[4] = concat_path_file("/dev", info->devname); /* device */
        argv[5] = NULL;
 
-       wait4pid(xspawn(argv));
+       spawn_and_wait(argv);
        free(argv[4]);
 }  /*  End Function action_modload  */
 
@@ -789,7 +783,7 @@ static void action_execute(const struct devfsd_notify_struct *info,
                argv[count] = largv[count];
        }
        argv[count] = NULL;
-       wait4pid(spawn(argv));
+       spawn_and_wait(argv);
 }   /*  End Function action_execute  */
 
 
@@ -947,10 +941,10 @@ static void restore(char *spath, struct stat source_stat, int rootlen)
        lstat(dpath, &dest_stat);
        free(dpath);
        if (S_ISLNK(source_stat.st_mode) || (source_stat.st_mode & S_ISVTX))
-               copy_inode(dpath, &dest_stat,(source_stat.st_mode & ~S_ISVTX) , spath, &source_stat);
+               copy_inode(dpath, &dest_stat, (source_stat.st_mode & ~S_ISVTX), spath, &source_stat);
 
        if (S_ISDIR(source_stat.st_mode))
-               dir_operation(RESTORE, spath, rootlen,NULL);
+               dir_operation(RESTORE, spath, rootlen, NULL);
 }
 
 
@@ -1001,7 +995,7 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
                                break;
                        un_addr.sun_family = AF_UNIX;
                        snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath);
-                       val = bind(fd,(struct sockaddr *) &un_addr,(int) sizeof un_addr);
+                       val = bind(fd, (struct sockaddr *) &un_addr, (int) sizeof un_addr);
                        close(fd);
                        if (val != 0 || chmod(destpath, new_mode & ~S_IFMT) != 0)
                                break;
@@ -1091,7 +1085,7 @@ static int get_uid_gid(int flag, const char *string)
                msg = "group";
 
        if (ENABLE_DEVFSD_VERBOSE)
-               msg_logger(LOG_ERR,"unknown %s: %s, defaulting to %cid=0",  msg, string, msg[0]);
+               msg_logger(LOG_ERR, "unknown %s: %s, defaulting to %cid=0",  msg, string, msg[0]);
        return 0;
 }/*  End Function get_uid_gid  */
 
@@ -1336,8 +1330,7 @@ static void expand_regexp(char *output, size_t outsize, const char *input,
 
 /* from compat_name.c */
 
-struct translate_struct
-{
+struct translate_struct {
        const char *match;    /*  The string to match to(up to length)                */
        const char *format;   /*  Format of output, "%s" takes data past match string,
                        NULL is effectively "%s"(just more efficient)       */
@@ -1439,7 +1432,7 @@ const char *get_old_name(const char *devname, unsigned int namelen,
 
        /* 2 ==scsi/disc, 4 == scsi/part */
        if (i == 2 || i == 4)
-               compat_name = write_old_sd_name(buffer, major, minor,((i == 2) ? "" : (ptr + 4)));
+               compat_name = write_old_sd_name(buffer, major, minor, ((i == 2) ? "" : (ptr + 4)));
 
        /* 5 == scsi/mt */
        if (i == 5) {
@@ -1659,7 +1652,7 @@ static const char *expand_variable(char *buffer, unsigned int length,
        ch = input[0];
        if (ch == '$') {
                /*  Special case for "$$": PID  */
-               sprintf(tmp, "%d",(int) getpid());
+               sprintf(tmp, "%d", (int) getpid());
                len = strlen(tmp);
                if (len + *out_pos >= length)
                        goto expand_variable_out;
@@ -1732,7 +1725,7 @@ static const char *expand_variable(char *buffer, unsigned int length,
                                --open_braces;
                                break;
                        case '\0':
-                               info_logger(LOG_INFO,"\"}\" not found in: %s", input);
+                               info_logger(LOG_INFO, "\"}\" not found in: %s", input);
                                return NULL;
                        default:
                                break;