forgot about avn add... :(
[oweals/busybox.git] / miscutils / devfsd.c
index 62d217345743d24cde0530bbd5221dad433547c6..de046e818cc96ae23d4e329bb149cb54c0acc684 100644 (file)
@@ -1,3 +1,8 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
 /*
        devfsd implementation for busybox
 
@@ -57,7 +62,6 @@
 #include <stdarg.h>
 #include <string.h>
 #include <ctype.h>
-#include <sys/time.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -121,7 +125,7 @@ struct devfsd_notify_struct
 #define BUFFER_SIZE 16384
 #define DEVFSD_VERSION "1.3.25"
 #define CONFIG_FILE  "/etc/devfsd.conf"
-#define MODPROBE               "/sbin/modprobe"
+#define MODPROBE               "/sbin/modprobe"
 #define MODPROBE_SWITCH_1 "-k"
 #define MODPROBE_SWITCH_2 "-C"
 #define CONFIG_MODULES_DEVFS "/etc/modules.devfs"
@@ -289,7 +293,7 @@ static struct event_type
 /* Busybox messages */
 
 static const char * const bb_msg_proto_rev                     = "protocol revision";
-static const char * const bb_msg_bad_config            = "bad %s config file: %s";
+static const char * const bb_msg_bad_config            = "bad %s config file: %s";
 static const char * const bb_msg_small_buffer          = "buffer too small";
 static const char * const bb_msg_variable_not_found = "variable: %s not found";
 
@@ -297,16 +301,16 @@ static const char * const bb_msg_variable_not_found = "variable: %s not found";
 static void msg_logger(int pri, const char * fmt, ... )
 {
        va_list ap;
-       int ret; 
-       
+       int ret;
+
        va_start(ap, fmt);
-       ret = access ("/dev/log", F_OK); 
+       ret = access ("/dev/log", F_OK);
        if (ret == 0) {
-               openlog(bb_applet_name, 0, LOG_DAEMON);
+               openlog(applet_name, 0, LOG_DAEMON);
                vsyslog( pri , fmt, ap);
                /* Man: A trailing newline is added when needed. */
                closelog();
-       } 
+       }
        /* ENABLE_DEVFSD_VERBOSE is always enabled if msg_logger is used */
        if ((ENABLE_DEVFSD_VERBOSE && ret) || ENABLE_DEBUG) {
                bb_error_msg(fmt, ap);
@@ -319,28 +323,28 @@ static void msg_logger_and_die(int pri, const char* fmt, ...)
        va_list ap;
 
        va_start(ap, fmt);
-       msg_logger(pri, fmt, ap);
+       msg_logger(pri, fmt, ap);
        va_end(ap);
        exit(EXIT_FAILURE);
 }
 
 /* Busybox stuff */
 #if defined(CONFIG_DEVFSD_VERBOSE) || defined(CONFIG_DEBUG)
-#define devfsd_error_msg(fmt, args...)                bb_error_msg(fmt, ## args)  
-#define devfsd_perror_msg_and_die(fmt, args...)       bb_perror_msg_and_die(fmt, ## args)  
-#define devfsd_error_msg_and_die(fmt, args...)        bb_error_msg_and_die(fmt, ## args)  
+#define devfsd_error_msg(fmt, args...)                bb_error_msg(fmt, ## args)
+#define devfsd_perror_msg_and_die(fmt, args...)       bb_perror_msg_and_die(fmt, ## args)
+#define devfsd_error_msg_and_die(fmt, args...)        bb_error_msg_and_die(fmt, ## args)
 #if defined(CONFIG_DEBUG)
 #define debug_msg_logger(x, fmt, args...)             msg_logger(x, fmt, ## args)
 #else
-#define debug_msg_logger(x, fmt, args...)    
+#define debug_msg_logger(x, fmt, args...)
 #endif
 #else
 #define debug_msg_logger(x, fmt, args...)
-#define msg_logger(p, fmt, args...) 
+#define msg_logger(p, fmt, args...)
 #define msg_logger_and_die(p, fmt, args...)           exit(1)
 #define devfsd_perror_msg_and_die(fmt, args...)       exit(1)
 #define devfsd_error_msg_and_die(fmt, args...)        exit(1)
-#define devfsd_error_msg(fmt, args...)   
+#define devfsd_error_msg(fmt, args...)
 #endif
 
 static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag)
@@ -451,10 +455,10 @@ int devfsd_main (int argc, char **argv)
                {
                        if(argv[count][1]=='v' && !argv[count][2]) /* -v */
                                        print_version = TRUE;
-                       else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='f' 
+                       else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='f'
                                        && argv[count][2]=='g' && !argv[count][3]) /* -fg */
                                        do_daemon = FALSE;
-                       else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='n' 
+                       else if(ENABLE_DEVFSD_FG_NP && argv[count][1]=='n'
                                        && argv[count][2]=='p' && !argv[count][3]) /* -np */
                                        no_polling = TRUE;
                        else
@@ -470,13 +474,14 @@ int devfsd_main (int argc, char **argv)
 
        if (chdir (mount_point) != 0)
                devfsd_perror_msg_and_die(mount_point);
-       
-       fd = bb_xopen (".devfsd", O_RDONLY);
+
+       fd = xopen (".devfsd", O_RDONLY);
 
        if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0)
                devfsd_perror_msg_and_die("FD_CLOEXEC");
 
-       do_ioctl_and_die(fd, DEVFSDIOC_GET_PROTO_REV,(int )&proto_rev);
+       if (ioctl (fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev) == -1)
+               msg_logger_and_die(LOG_ERR, "ioctl");
 
        /*setup initial entries */
     for (curr = initial_symlinks; curr->dest != NULL; ++curr)
@@ -486,9 +491,9 @@ int devfsd_main (int argc, char **argv)
 
        if ( print_version  || (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev) )
        {
-               bb_printf( "%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n",
-                                        bb_applet_name,DEVFSD_VERSION,bb_msg_proto_rev,
-                                        DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev);
+               printf( "%s v%s\nDaemon %s:\t%d\nKernel-side %s:\t%d\n",
+                               applet_name,DEVFSD_VERSION,bb_msg_proto_rev,
+                               DEVFSD_PROTOCOL_REVISION_DAEMON,bb_msg_proto_rev, proto_rev);
                if (DEVFSD_PROTOCOL_REVISION_DAEMON != proto_rev)
                        bb_error_msg_and_die( "%s mismatch!",bb_msg_proto_rev);
                exit(EXIT_SUCCESS); /* -v */
@@ -503,15 +508,15 @@ int devfsd_main (int argc, char **argv)
        new_action.sa_handler = signal_handler;
        if (sigaction (SIGHUP, &new_action, NULL) != 0 || sigaction (SIGUSR1, &new_action, NULL) != 0 )
                devfsd_error_msg_and_die( "sigaction");
-       
-       bb_printf("%s v%s  started for %s\n",bb_applet_name, DEVFSD_VERSION, mount_point);
 
-       /*  Set umask so that mknod(2), open(2) and mkdir(2) have complete control      over permissions  */
+       printf("%s v%s  started for %s\n",applet_name, DEVFSD_VERSION, mount_point);
+
+       /*  Set umask so that mknod(2), open(2) and mkdir(2) have complete control over permissions  */
        umask (0);
        read_config_file (CONFIG_FILE, FALSE, &event_mask);
        /*  Do the scan before forking, so that boot scripts see the finished product  */
        dir_operation(SERVICE,mount_point,0,NULL);
-       
+
        if (ENABLE_DEVFSD_FG_NP && no_polling)
                exit (0);
        if (do_daemon)
@@ -553,7 +558,7 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas
        char *line=NULL;
 
        debug_msg_logger(LOG_INFO, "%s: %s", __FUNCTION__, path);
-       
+
        if (stat (path, &statbuf) == 0 )
        {
                /* Don't read 0 length files: ignored */
@@ -564,7 +569,7 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas
                        /* strip last / from dirname so we don't need to check for it later */
                        while( path  && path[1]!='\0' && path[strlen(path)-1] == '/')
                                path[strlen(path) -1] = '\0';
-       
+
                        dir_operation(READ_CONFIG, path, 0, event_mask);
                        return;
                }
@@ -586,7 +591,7 @@ static void read_config_file (char *path, int optional, unsigned long *event_mas
        } else {
 read_config_file_err:
        if(optional ==  0  && errno == ENOENT)
-               msg_logger_and_die(LOG_ERR, "read config file: %s: %m", path);  
+               msg_logger_and_die(LOG_ERR, "read config file: %s: %m", path);
        }
        return;
 }   /*  End Function read_config_file   */
@@ -605,23 +610,24 @@ static void process_config_line (const char *line, unsigned long *event_mask)
        char name[STRING_LENGTH];
        char * msg="";
        char *ptr;
+       int i;
 
        /* !!!! Only Uppercase Keywords in devsfd.conf */
-       const char *options[] = {       "CLEAR_CONFIG", "INCLUDE", "OPTIONAL_INCLUDE", "RESTORE",
-                                                               "PERMISSIONS", "MODLOAD", "EXECUTE", "COPY", "IGNORE",
-                                                               "MKOLDCOMPAT", "MKNEWCOMPAT","RMOLDCOMPAT", "RMNEWCOMPAT", 0 };
-
-       int i;
+       static const char *const options[] = {
+               "CLEAR_CONFIG", "INCLUDE", "OPTIONAL_INCLUDE",
+               "RESTORE", "PERMISSIONS", "MODLOAD", "EXECUTE",
+               "COPY", "IGNORE", "MKOLDCOMPAT", "MKNEWCOMPAT",
+               "RMOLDCOMPAT", "RMNEWCOMPAT", 0
+       };
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
 
-
        for (count = 0; count < MAX_ARGS; ++count) p[count][0] = '\0';
        num_args = sscanf (line, "%s %s %s %s %s %s %s %s %s %s",
                        when, name, what,
                        p[0], p[1], p[2], p[3], p[4], p[5], p[6]);
 
-       i = compare_string_array(options, when );
+       i = index_in_str_array(options, when );
 
        /*"CLEAR_CONFIG"*/
        if( i == 0)
@@ -667,7 +673,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
                goto process_config_line_err;
        }
 
-       i = compare_string_array(options, what );
+       i = index_in_str_array(options, what );
 
        switch(i)
        {
@@ -677,7 +683,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
                        if ( ( ptr = strchr (p[0], '.') ) == NULL )
                        {
                                msg="UID.GID";
-                               goto process_config_line_err; /*"missing '.' in UID.GID */
+                               goto process_config_line_err; /*"missing '.' in UID.GID"*/
                        }
 
                        *ptr++ = '\0';
@@ -691,14 +697,14 @@ static void process_config_line (const char *line, unsigned long *event_mask)
                        the device name) to the module loading  facility.  In  addition,
                        the /etc/modules.devfs configuration file is used.*/
                         if (ENABLE_DEVFSD_MODLOAD)
-                               new->action.what = AC_MODLOAD;
+                               new->action.what = AC_MODLOAD;
                         break;
                case 6: /* EXECUTE */
                        new->action.what = AC_EXECUTE;
                        num_args -= 3;
 
                        for (count = 0; count < num_args; ++count)
-                               new->u.execute.argv[count] = bb_xstrdup (p[count]);
+                               new->u.execute.argv[count] = xstrdup (p[count]);
 
                        new->u.execute.argv[num_args] = NULL;
                        break;
@@ -708,8 +714,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
                        if (num_args != 2)
                                goto process_config_line_err; /* missing path and function in line */
 
-                       new->u.copy.source = bb_xstrdup (p[0]);
-                       new->u.copy.destination = bb_xstrdup (p[1]);
+                       new->u.copy.source = xstrdup (p[0]);
+                       new->u.copy.destination = xstrdup (p[1]);
                        break;
                case 8: /* IGNORE */
                /* FALLTROUGH */
@@ -759,7 +765,7 @@ static int do_servicing (int fd, unsigned long event_mask)
        unsigned long tmp_event_mask;
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
-       
+
        /*  Tell devfs what events we care about  */
        tmp_event_mask = event_mask;
        do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask);
@@ -816,9 +822,9 @@ static void service_name (const struct devfsd_notify_struct *info)
                        continue;
                for (n = 0; (n < MAX_SUBEXPR) && (mbuf[n].rm_so != -1); ++n)
                        /* VOID */;
-               
+
                debug_msg_logger(LOG_INFO, "%s: action.what %d", __FUNCTION__, entry->action.what);
-               
+
                switch (entry->action.what)
                {
                        case AC_PERMISSIONS:
@@ -870,7 +876,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)
+                           const struct config_entry_struct *entry ATTRIBUTE_UNUSED)
 /*  [SUMMARY] Load a module.
     <info> The devfs change.
     <entry> The config file entry.
@@ -928,7 +934,7 @@ static void action_execute (const struct devfsd_notify_struct *info,
 
 static void action_copy (const struct devfsd_notify_struct *info,
                         const struct config_entry_struct *entry,
-                         const regmatch_t *regexpr, unsigned int numexpr)
+                        const regmatch_t *regexpr, unsigned int numexpr)
 /*  [SUMMARY] Copy permissions.
     <info> The devfs change.
     <entry> The config file entry.
@@ -945,9 +951,9 @@ static void action_copy (const struct devfsd_notify_struct *info,
        int ret = 0;
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
-       
+
        dest_stat.st_mode = 0;
-       
+
        if ( (info->type == DEVFSD_NOTIFY_CHANGE) && S_ISLNK (info->mode) )
                return;
        gv_info.info = info;
@@ -970,7 +976,7 @@ static void action_copy (const struct devfsd_notify_struct *info,
                new_mode |= S_ISVTX;
        else if ( (info->type == DEVFSD_NOTIFY_CHANGE) && (dest_stat.st_mode & S_ISVTX) )
                new_mode |= S_ISVTX;
-       ret = copy_inode (destination, &dest_stat, new_mode, source, &source_stat); 
+       ret = copy_inode (destination, &dest_stat, new_mode, source, &source_stat);
        if (ENABLE_DEBUG && ret && (errno != EEXIST))
                debug_msg_logger(LOG_ERR, "copy_inode: %s to %s: %m", source, destination);
        return;
@@ -992,17 +998,19 @@ static void action_compat (const struct devfsd_notify_struct *info, unsigned int
        unsigned int i;
        char rewind_;
        /* 1 to 5  "scsi/" , 6 to 9 "ide/host" */
-       const char *fmt[] = {   NULL ,
-                                                       "sg/c%db%dt%du%d",                      /* scsi/generic */
-                                                       "sd/c%db%dt%du%d",                      /* scsi/disc */
-                                                       "sr/c%db%dt%du%d",                      /* scsi/cd */
-                                                       "sd/c%db%dt%du%dp%d",           /* scsi/part */
-                                                       "st/c%db%dt%du%dm%d%c",         /* scsi/mt */
-                                                       "ide/hd/c%db%dt%du%d",          /* ide/host/disc */
-                                                       "ide/cd/c%db%dt%du%d",          /* ide/host/cd */
-                                                       "ide/hd/c%db%dt%du%dp%d",       /* ide/host/part */
-                                                       "ide/mt/c%db%dt%du%d%s",        /* ide/host/mt */
-                                                       NULL };
+       static const char *const fmt[] = {
+               NULL ,
+               "sg/c%db%dt%du%d",              /* scsi/generic */
+               "sd/c%db%dt%du%d",              /* scsi/disc */
+               "sr/c%db%dt%du%d",              /* scsi/cd */
+               "sd/c%db%dt%du%dp%d",           /* scsi/part */
+               "st/c%db%dt%du%dm%d%c",         /* scsi/mt */
+               "ide/hd/c%db%dt%du%d",          /* ide/host/disc */
+               "ide/cd/c%db%dt%du%d",          /* ide/host/cd */
+               "ide/hd/c%db%dt%du%dp%d",       /* ide/host/part */
+               "ide/mt/c%db%dt%du%d%s",        /* ide/host/mt */
+               NULL
+       };
 
        /*  First construct compatibility name  */
        switch (action)
@@ -1126,7 +1134,7 @@ static int copy_inode (const char *destpath, const struct stat *dest_stat,
                                ( dest_len   = readlink (destpath  , dest_link  , STRING_LENGTH - 1) ) < 0 )
                                return (FALSE);
                        source_link[source_len] = '\0';
-                       dest_link[dest_len]     = '\0';
+                       dest_link[dest_len]     = '\0';
                        if ( (source_len != dest_len) || (strcmp (source_link, dest_link) != 0) )
                        {
                                unlink (destpath);
@@ -1183,7 +1191,7 @@ do_chown:
        return (FALSE);
 }   /*  End Function copy_inode  */
 
-static void free_config ()
+static void free_config (void)
 /*  [SUMMARY] Free the configuration information.
     [RETURNS] Nothing.
 */
@@ -1224,12 +1232,12 @@ static int get_uid_gid (int flag, const char *string)
        struct passwd *pw_ent;
        struct group *grp_ent;
        static char *msg;
-       
+
        if (ENABLE_DEVFSD_VERBOSE)
                msg="user";
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
-       
+
        if(ENABLE_DEBUG && flag != UID && flag != GID)
                msg_logger_and_die(LOG_ERR,"%s: flag != UID && flag != GID", __FUNCTION__);
 
@@ -1241,7 +1249,7 @@ static int get_uid_gid (int flag, const char *string)
 
        if ( flag == GID && ( grp_ent = getgrnam (string) ) != NULL )
                return (grp_ent->gr_gid);
-       else if(ENABLE_DEVFSD_VERBOSE) 
+       else if(ENABLE_DEVFSD_VERBOSE)
                msg="group";
 
        if(ENABLE_DEVFSD_VERBOSE)
@@ -1264,7 +1272,7 @@ static mode_t get_mode (const char *string)
                return strtoul (string, NULL, 8);
        if (strlen (string) != 9)
                msg_logger_and_die(LOG_ERR, "bad mode: %s", string);
-       
+
        mode = 0;
        i= S_IRUSR;
        while(i>0)
@@ -1280,7 +1288,7 @@ static mode_t get_mode (const char *string)
 static void signal_handler (int sig)
 {
        debug_msg_logger(LOG_INFO, __FUNCTION__);
-       
+
        caught_signal = TRUE;
        if (sig == SIGHUP)
                caught_sighup = TRUE;
@@ -1301,16 +1309,16 @@ static const char *get_variable (const char *variable, void *info)
 
        if (gethostname (hostname, STRING_LENGTH - 1) != 0)
                msg_logger_and_die(LOG_ERR, "gethostname: %m");
-               
+
                /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */
                hostname[STRING_LENGTH - 1] = '\0';
 
-       /* compare_string_array returns i>=0  */
-       i=compare_string_array(field_names, variable);
+       /* index_in_str_array returns i>=0  */
+       i=index_in_str_array(field_names, variable);
 
-       if ( i > 6 && (i > 1 && gv_info == NULL))
+       if ( i > 6 || i < 0 || (i > 1 && gv_info == NULL))
                        return (NULL);
-       if( i >= 0 || i <= 3)
+       if( i >= 0 && i <= 3)
        {
                debug_msg_logger(LOG_INFO, "%s: i=%d %s", __FUNCTION__, i ,field_names[i+7]);
                return(field_names[i+7]);
@@ -1442,9 +1450,9 @@ static int make_dir_tree (const char *path)
 static int expand_expression(char *output, unsigned int outsize,
                              const char *input,
                              const char *(*get_variable_func)(const char *variable, void *info),
-                              void *info,
-                              const char *devname,
-                              const regmatch_t *ex, unsigned int numexp)
+                             void *info,
+                             const char *devname,
+                             const regmatch_t *ex, unsigned int numexp)
 /*  [SUMMARY] Expand environment variables and regular subexpressions in string.
     <output> The output expanded expression is written here.
     <length> The size of the output buffer.
@@ -1595,20 +1603,22 @@ const char *get_old_name (const char *devname, unsigned int namelen,
        const char *pty2;
        size_t len;
        /* 1 to 5  "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */
-       const char *fmt[] = {   NULL ,
-                                                       "sg%u",                 /* scsi/generic */
-                                                       NULL,                   /* scsi/disc */
-                                                       "sr%u",                 /* scsi/cd */
-                                                       NULL,                   /* scsi/part */
-                                                       "nst%u%c",              /* scsi/mt */
-                                                       "hd%c"  ,               /* ide/host/disc */
-                                                       "hd%c"  ,               /* ide/host/cd */
-                                                       "hd%c%s",               /* ide/host/part */
-                                                       "%sht%d",               /* ide/host/mt */
-                                                       "sbpcd%u",              /* sbp/ */
-                                                       "vcs%s",                /* vcc/ */
-                                                       "%cty%c%c",             /* pty/ */
-                                                       NULL };
+       static const char *const fmt[] = {
+               NULL ,
+               "sg%u",                 /* scsi/generic */
+               NULL,                   /* scsi/disc */
+               "sr%u",                 /* scsi/cd */
+               NULL,                   /* scsi/part */
+               "nst%u%c",              /* scsi/mt */
+               "hd%c"  ,               /* ide/host/disc */
+               "hd%c"  ,               /* ide/host/cd */
+               "hd%c%s",               /* ide/host/part */
+               "%sht%d",               /* ide/host/mt */
+               "sbpcd%u",              /* sbp/ */
+               "vcs%s",                /* vcc/ */
+               "%cty%c%c",             /* pty/ */
+               NULL
+       };
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
 
@@ -1632,7 +1642,7 @@ const char *get_old_name (const char *devname, unsigned int namelen,
                compat_name = buffer;
        else
                return NULL;
-               
+
        debug_msg_logger(LOG_INFO, "%s: scan_dev_name = %d", __FUNCTION__, i);
 
        /* 1 == scsi/generic, 3 == scsi/cd, 10 == sbp/ */
@@ -1677,10 +1687,10 @@ const char *get_old_name (const char *devname, unsigned int namelen,
                indexx = atoi (devname + 5);
                sprintf (buffer, fmt[i], (devname[4] == 'm') ? 'p' : 't', pty1[indexx >> 4], pty2[indexx & 0x0f]);
        }
-       
+
        if(ENABLE_DEBUG && compat_name!=NULL)
                msg_logger(LOG_INFO, "%s: compat_name  %s", __FUNCTION__, compat_name);
-               
+
        return (compat_name);
 }   /*  End Function get_old_name  */
 
@@ -1692,7 +1702,7 @@ static char get_old_ide_name (unsigned int major, unsigned int minor)
 */
 {
        char letter='y';        /* 121 */
-       char c='a';             /*  97 */
+       char c='a';             /*  97 */
        int i=IDE0_MAJOR;
 
        debug_msg_logger(LOG_INFO, __FUNCTION__);
@@ -1704,7 +1714,7 @@ static char get_old_ide_name (unsigned int major, unsigned int minor)
                        i==IDE6_MAJOR || i==IDE7_MAJOR || i==IDE8_MAJOR ||
                        i==IDE9_MAJOR )
                {
-                       if(i==major)
+                       if((unsigned int)i==major)
                        {
                                letter=c;
                                break;
@@ -1900,7 +1910,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
                for (ptr = input; isalnum (ch) || (ch == '_') || (ch == ':');ch = *++ptr)
                        /* VOID */ ;
                len = ptr - input;
-               if (len >= sizeof tmp)
+               if ((size_t)len >= sizeof tmp)
                        goto expand_variable_out;
 
                safe_memcpy (tmp, input, len);
@@ -1926,7 +1936,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
        {
                /*  Must be simple variable expansion with "${var}"  */
                len = ptr - input;
-               if (len >= sizeof tmp)
+               if ((size_t)len >= sizeof tmp)
                        goto expand_variable_out;
 
                safe_memcpy (tmp, input, len);
@@ -1942,7 +1952,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
        }
        /*  It's that handy "${var:-word}" expression. Check if var is defined  */
        len = ptr - input;
-       if (len >= sizeof tmp)
+       if ((size_t)len >= sizeof tmp)
                goto expand_variable_out;
 
        safe_memcpy (tmp, input, len);
@@ -1987,7 +1997,7 @@ static const char *expand_variable (char *buffer, unsigned int length,
        pointer to start of word in "${var:-word}"  */
        input += 2;
        len = ptr - input;
-       if (len >= sizeof tmp)
+       if ((size_t)len >= sizeof tmp)
                goto expand_variable_out;
 
        safe_memcpy (tmp, input, len);