+static struct dep_t *depend;
+
+#define main_options "acdklnqrst:vVC:"
+#define INSERT_ALL 1 /* a */
+#define DUMP_CONF_EXIT 2 /* c */
+#define D_OPT_IGNORED 4 /* d */
+#define AUTOCLEAN_FLG 8 /* k */
+#define LIST_ALL 16 /* l */
+#define SHOW_ONLY 32 /* n */
+#define QUIET 64 /* q */
+#define REMOVE_OPT 128 /* r */
+#define DO_SYSLOG 256 /* s */
+#define RESTRICT_DIR 512 /* t */
+#define VERBOSE 1024 /* v */
+#define VERSION_ONLY 2048 /* V */
+#define CONFIG_FILE 4096 /* C */
+
+#define autoclean (main_opts & AUTOCLEAN_FLG)
+#define show_only (main_opts & SHOW_ONLY)
+#define quiet (main_opts & QUIET)
+#define remove_opt (main_opts & REMOVE_OPT)
+#define do_syslog (main_opts & DO_SYSLOG)
+#define verbose (main_opts & VERBOSE)
+
+static int main_opts;
+
+static int parse_tag_value ( char *buffer, char **ptag, char **pvalue )
+{
+ char *tag, *value;
+
+ while ( isspace ( *buffer ))
+ buffer++;
+ tag = value = buffer;
+ while ( !isspace ( *value ))
+ if (!*value) return 0;
+ else value++;
+ *value++ = 0;
+ while ( isspace ( *value ))
+ value++;
+ if (!*value) return 0;
+
+ *ptag = tag;
+ *pvalue = value;
+
+ return 1;
+}
+
+/* Jump through hoops to simulate how fgets() grabs just one line at a
+ * time... Don't use any stdio since modprobe gets called from a kernel
+ * thread and stdio junk can overflow the limited stack...
+ */
+static char *reads ( int fd, char *buffer, size_t len )
+{
+ int n = read ( fd, buffer, len );
+
+ if ( n > 0 ) {
+ char *p;
+
+ buffer [len-1] = 0;
+ p = strchr ( buffer, '\n' );
+
+ if ( p ) {
+ off_t offset;
+
+ offset = lseek ( fd, 0L, SEEK_CUR ); // Get the current file descriptor offset
+ lseek ( fd, offset-n + (p-buffer) + 1, SEEK_SET ); // Set the file descriptor offset to right after the \n
+
+ p[1] = 0;
+ }
+ return buffer;
+ }
+
+ else
+ return 0;
+}
+
+/*
+ * This function appends an option to a list
+ */
+static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt )
+{
+ struct mod_opt_t *ol = opt_list;
+
+ if( ol ) {
+ while( ol-> m_next ) {
+ ol = ol-> m_next;
+ }
+ ol-> m_next = xmalloc( sizeof( struct mod_opt_t ) );
+ ol = ol-> m_next;
+ } else {
+ ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) );
+ }
+
+ ol-> m_opt_val = bb_xstrdup( opt );
+ ol-> m_next = NULL;
+
+ return opt_list;
+}
+
+#if ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS
+/* static char* parse_command_string( char* src, char **dst );
+ * src: pointer to string containing argument
+ * dst: pointer to where to store the parsed argument
+ * return value: the pointer to the first char after the parsed argument,
+ * NULL if there was no argument parsed (only trailing spaces).
+ * Note that memory is allocated with bb_xstrdup when a new argument was
+ * parsed. Don't forget to free it!
+ */
+#define ARG_EMPTY 0x00
+#define ARG_IN_DQUOTES 0x01
+#define ARG_IN_SQUOTES 0x02
+static char *parse_command_string( char *src, char **dst )
+{
+ int opt_status = ARG_EMPTY;
+ char* tmp_str;
+
+ /* Dumb you, I have nothing to do... */
+ if( src == NULL ) return src;
+
+ /* Skip leading spaces */
+ while( *src == ' ' ) {
+ src++;
+ }
+ /* Is the end of string reached? */
+ if( *src == '\0' ) {
+ return NULL;
+ }
+ /* Reached the start of an argument
+ * By the way, we duplicate a little too much
+ * here but what is too much is freed later. */
+ *dst = tmp_str = bb_xstrdup( src );
+ /* Get to the end of that argument */
+ while( ( *tmp_str != '\0' )
+ && ( ( *tmp_str != ' ' )
+ || ( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) ) ) {
+ switch( *tmp_str ) {
+ case '\'':
+ if( opt_status & ARG_IN_DQUOTES ) {
+ /* Already in double quotes, keep current char as is */
+ } else {
+ /* shift left 1 char, until end of string: get rid of the opening/closing quotes */
+ memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) );
+ /* mark me: we enter or leave single quotes */
+ opt_status ^= ARG_IN_SQUOTES;
+ /* Back one char, as we need to re-scan the new char there. */
+ tmp_str--;
+ }
+ break;
+ case '"':
+ if( opt_status & ARG_IN_SQUOTES ) {
+ /* Already in single quotes, keep current char as is */
+ } else {
+ /* shift left 1 char, until end of string: get rid of the opening/closing quotes */
+ memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) );
+ /* mark me: we enter or leave double quotes */
+ opt_status ^= ARG_IN_DQUOTES;
+ /* Back one char, as we need to re-scan the new char there. */
+ tmp_str--;
+ }
+ break;
+ case '\\':
+ if( opt_status & ARG_IN_SQUOTES ) {
+ /* Between single quotes: keep as is. */
+ } else {
+ switch( *(tmp_str+1) ) {
+ case 'a':
+ case 'b':
+ case 't':
+ case 'n':
+ case 'v':
+ case 'f':
+ case 'r':
+ case '0':
+ /* We escaped a special character. For now, keep
+ * both the back-slash and the following char. */
+ tmp_str++; src++;
+ break;
+ default:
+ /* We escaped a space or a single or double quote,
+ * or a back-slash, or a non-escapable char. Remove
+ * the '\' and keep the new current char as is. */
+ memmove( tmp_str, tmp_str + 1, strlen( tmp_str ) );
+ break;
+ }
+ }
+ break;
+ /* Any other char that is special shall appear here.
+ * Example: $ starts a variable
+ case '$':
+ do_variable_expansion();
+ break;
+ * */
+ default:
+ /* any other char is kept as is. */
+ break;
+ }
+ tmp_str++; /* Go to next char */
+ src++; /* Go to next char to find the end of the argument. */
+ }
+ /* End of string, but still no ending quote */
+ if( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) {
+ bb_error_msg_and_die( "unterminated (single or double) quote in options list: %s", src );
+ }
+ *tmp_str++ = '\0';
+ *dst = xrealloc( *dst, (tmp_str - *dst ) );
+ return src;
+}
+#else
+#define parse_command_string(src, dst) (0)
+#endif /* ENABLE_FEATURE_MODPROBE_MULTIPLE_OPTIONS */
+
+/*
+ * This function reads aliases and default module options from a configuration file
+ * (/etc/modprobe.conf syntax). It supports includes (only files, no directories).
+ */
+static void include_conf ( struct dep_t **first, struct dep_t **current, char *buffer, int buflen, int fd )
+{
+ int continuation_line = 0;