1 /* opkg_conf.c - the opkg package management system
5 Copyright (C) 2001 University of Southern California
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
19 #include "opkg_conf.h"
20 #include "opkg_error.h"
23 #include "sprintf_alloc.h"
25 #include "opkg_message.h"
26 #include "file_util.h"
28 #include "opkg_defines.h"
29 #include "libbb/libbb.h"
31 #include <sys/types.h>
37 static int opkg_conf_parse_file(opkg_conf_t
*conf
, const char *filename
,
38 pkg_src_list_t
*pkg_src_list
,
39 nv_pair_list_t
*tmp_dest_nv_pair_list
);
40 static int opkg_conf_set_option(const opkg_option_t
*options
,
41 const char *name
, const char *value
);
42 static int opkg_conf_set_default_dest(opkg_conf_t
*conf
,
43 const char *default_dest_name
);
44 static int set_and_load_pkg_src_list(opkg_conf_t
*conf
,
45 pkg_src_list_t
*nv_pair_list
);
46 static int set_and_load_pkg_dest_list(opkg_conf_t
*conf
,
47 nv_pair_list_t
*nv_pair_list
);
49 void opkg_init_options_array(const opkg_conf_t
*conf
, opkg_option_t
**options
)
51 opkg_option_t tmp
[] = {
52 { "cache", OPKG_OPT_TYPE_STRING
, &conf
->cache
},
53 { "force_defaults", OPKG_OPT_TYPE_BOOL
, &conf
->force_defaults
},
54 { "force_maintainer", OPKG_OPT_TYPE_BOOL
, &conf
->force_maintainer
},
55 { "force_depends", OPKG_OPT_TYPE_BOOL
, &conf
->force_depends
},
56 { "force_overwrite", OPKG_OPT_TYPE_BOOL
, &conf
->force_overwrite
},
57 { "force_downgrade", OPKG_OPT_TYPE_BOOL
, &conf
->force_downgrade
},
58 { "force_reinstall", OPKG_OPT_TYPE_BOOL
, &conf
->force_reinstall
},
59 { "force_space", OPKG_OPT_TYPE_BOOL
, &conf
->force_space
},
60 { "check_signature", OPKG_OPT_TYPE_INT
, &conf
->check_signature
},
61 { "ftp_proxy", OPKG_OPT_TYPE_STRING
, &conf
->ftp_proxy
},
62 { "http_proxy", OPKG_OPT_TYPE_STRING
, &conf
->http_proxy
},
63 { "no_proxy", OPKG_OPT_TYPE_STRING
, &conf
->no_proxy
},
64 { "test", OPKG_OPT_TYPE_INT
, &conf
->noaction
},
65 { "noaction", OPKG_OPT_TYPE_INT
, &conf
->noaction
},
66 { "nodeps", OPKG_OPT_TYPE_BOOL
, &conf
->nodeps
},
67 { "offline_root", OPKG_OPT_TYPE_STRING
, &conf
->offline_root
},
68 { "offline_root_path", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_path
},
69 { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_post_script_cmd
},
70 { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_pre_script_cmd
},
71 { "proxy_passwd", OPKG_OPT_TYPE_STRING
, &conf
->proxy_passwd
},
72 { "proxy_user", OPKG_OPT_TYPE_STRING
, &conf
->proxy_user
},
73 { "query-all", OPKG_OPT_TYPE_BOOL
, &conf
->query_all
},
74 { "verbosity", OPKG_OPT_TYPE_BOOL
, &conf
->verbosity
},
75 #if defined(HAVE_OPENSSL)
76 { "signature_ca_file", OPKG_OPT_TYPE_STRING
, &conf
->signature_ca_file
},
77 { "signature_ca_path", OPKG_OPT_TYPE_STRING
, &conf
->signature_ca_path
},
79 #if defined(HAVE_PATHFINDER)
80 { "check_x509_path", OPKG_OPT_TYPE_INT
, &conf
->check_x509_path
},
82 #if defined(HAVE_SSLCURL) && defined(HAVE_CURL)
83 { "ssl_engine", OPKG_OPT_TYPE_STRING
, &conf
->ssl_engine
},
84 { "ssl_cert", OPKG_OPT_TYPE_STRING
, &conf
->ssl_cert
},
85 { "ssl_cert_type", OPKG_OPT_TYPE_STRING
, &conf
->ssl_cert_type
},
86 { "ssl_key", OPKG_OPT_TYPE_STRING
, &conf
->ssl_key
},
87 { "ssl_key_type", OPKG_OPT_TYPE_STRING
, &conf
->ssl_key_type
},
88 { "ssl_key_passwd", OPKG_OPT_TYPE_STRING
, &conf
->ssl_key_passwd
},
89 { "ssl_ca_file", OPKG_OPT_TYPE_STRING
, &conf
->ssl_ca_file
},
90 { "ssl_ca_path", OPKG_OPT_TYPE_STRING
, &conf
->ssl_ca_path
},
91 { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL
, &conf
->ssl_dont_verify_peer
},
96 *options
= xcalloc(1, sizeof(tmp
));
97 memcpy(*options
, tmp
, sizeof(tmp
));
100 static void opkg_conf_override_string(char **conf_str
, char *arg_str
)
106 *conf_str
= xstrdup(arg_str
);
110 static void opkg_conf_free_string(char **conf_str
)
118 int opkg_conf_init(opkg_conf_t
*conf
, const args_t
*args
)
123 nv_pair_list_t tmp_dest_nv_pair_list
;
124 char *lock_file
= NULL
;
126 char *etc_opkg_conf_pattern
;
127 char *offline_root
= NULL
;
129 memset(conf
, 0, sizeof(opkg_conf_t
));
131 #if defined(HAVE_PATHFINDER)
132 conf
->check_x509_path
= 1;
135 pkg_src_list_init(&conf
->pkg_src_list
);
137 nv_pair_list_init(&tmp_dest_nv_pair_list
);
138 pkg_dest_list_init(&conf
->pkg_dest_list
);
140 nv_pair_list_init(&conf
->arch_list
);
142 conf
->restrict_to_default_dest
= 0;
143 conf
->default_dest
= NULL
;
145 if (args
->conf_file
) {
146 struct stat stat_buf
;
147 err
= stat(args
->conf_file
, &stat_buf
);
149 if (opkg_conf_parse_file(conf
, args
->conf_file
,
150 &conf
->pkg_src_list
, &tmp_dest_nv_pair_list
)<0) {
151 /* Memory leakage from opkg_conf_parse-file */
152 return OPKG_CONF_ERR_PARSE
;
156 opkg_conf_override_string(&conf
->offline_root
, args
->offline_root
);
157 offline_root
= conf
->offline_root
;
159 if (conf
->offline_root
)
160 sprintf_alloc(&etc_opkg_conf_pattern
, "%s/etc/opkg/*.conf", conf
->offline_root
);
162 char *conf_file_dir
= getenv("OPKG_CONF_DIR");
163 if (conf_file_dir
== NULL
)
164 conf_file_dir
= ARGS_DEFAULT_CONF_FILE_DIR
;
165 sprintf_alloc(&etc_opkg_conf_pattern
, "%s/*.conf", conf_file_dir
);
167 memset(&globbuf
, 0, sizeof(globbuf
));
168 err
= glob(etc_opkg_conf_pattern
, 0, NULL
, &globbuf
);
169 free (etc_opkg_conf_pattern
);
172 for (i
= 0; i
< globbuf
.gl_pathc
; i
++) {
173 if (globbuf
.gl_pathv
[i
])
174 if (args
->conf_file
&&
175 !strcmp(args
->conf_file
, globbuf
.gl_pathv
[i
]))
177 if ( opkg_conf_parse_file(conf
, globbuf
.gl_pathv
[i
],
178 &conf
->pkg_src_list
, &tmp_dest_nv_pair_list
)<0) {
179 /* Memory leakage from opkg_conf_parse-file */
180 return OPKG_CONF_ERR_PARSE
;
182 if (offline_root
!= conf
->offline_root
) {
183 opkg_message(conf
, OPKG_ERROR
,
184 "Config file %s, within an offline "
185 "root contains option offline_root.\n",
186 globbuf
.gl_pathv
[i
]);
187 return OPKG_CONF_ERR_PARSE
;
193 opkg_conf_override_string(&conf
->offline_root_path
,
194 args
->offline_root_path
);
195 opkg_conf_override_string(&conf
->offline_root_pre_script_cmd
,
196 args
->offline_root_pre_script_cmd
);
197 opkg_conf_override_string(&conf
->offline_root_post_script_cmd
,
198 args
->offline_root_post_script_cmd
);
200 opkg_conf_override_string(&conf
->cache
, args
->cache
);
202 /* check for lock file */
203 if (conf
->offline_root
)
204 sprintf_alloc (&lock_file
, "%s/%s/lock", conf
->offline_root
, OPKG_STATE_DIR_PREFIX
);
206 sprintf_alloc (&lock_file
, "%s/lock", OPKG_STATE_DIR_PREFIX
);
208 err
= conf
->lock_fd
= creat (lock_file
, S_IRUSR
| S_IWUSR
| S_IRGRP
);
210 err
= lockf (conf
->lock_fd
, F_TLOCK
, 0);
214 opkg_message (conf
, OPKG_ERROR
, "Could not lock %s: %s\n",
215 lock_file
, strerror(errno_copy
));
217 return OPKG_CONF_ERR_LOCK
;
222 tmp_dir_base
= args
->tmp_dir
;
224 tmp_dir_base
= getenv("TMPDIR");
225 sprintf_alloc(&conf
->tmp_dir
, "%s/%s",
226 tmp_dir_base
? tmp_dir_base
: OPKG_CONF_DEFAULT_TMP_DIR_BASE
,
227 OPKG_CONF_TMP_DIR_SUFFIX
);
228 conf
->tmp_dir
= mkdtemp(conf
->tmp_dir
);
229 if (conf
->tmp_dir
== NULL
) {
230 opkg_message(conf
, OPKG_ERROR
,
231 "%s: Creating temp dir %s failed: %s\n",
232 conf
->tmp_dir
, strerror(errno
));
233 return OPKG_CONF_ERR_TMP_DIR
;
236 pkg_hash_init("pkg-hash", &conf
->pkg_hash
, OPKG_CONF_DEFAULT_HASH_LEN
);
237 hash_table_init("file-hash", &conf
->file_hash
, OPKG_CONF_DEFAULT_HASH_LEN
);
238 hash_table_init("obs-file-hash", &conf
->obs_file_hash
, OPKG_CONF_DEFAULT_HASH_LEN
);
240 if (conf
->lists_dir
== NULL
)
241 conf
->lists_dir
= xstrdup(OPKG_CONF_LISTS_DIR
);
243 if (conf
->offline_root
) {
245 sprintf_alloc(&tmp
, "%s/%s", conf
->offline_root
, conf
->lists_dir
);
246 free(conf
->lists_dir
);
247 conf
->lists_dir
= tmp
;
250 sprintf_alloc(&conf
->pending_dir
, "%s/pending", conf
->lists_dir
);
252 /* if no architectures were defined, then default all, noarch, and host architecture */
253 if (nv_pair_list_empty(&conf
->arch_list
)) {
254 nv_pair_list_append(&conf
->arch_list
, "all", "1");
255 nv_pair_list_append(&conf
->arch_list
, "noarch", "1");
256 nv_pair_list_append(&conf
->arch_list
, HOST_CPU_STR
, "10");
259 /* Even if there is no conf file, we'll need at least one dest. */
260 if (nv_pair_list_empty(&tmp_dest_nv_pair_list
)) {
261 nv_pair_list_append(&tmp_dest_nv_pair_list
,
262 OPKG_CONF_DEFAULT_DEST_NAME
,
263 OPKG_CONF_DEFAULT_DEST_ROOT_DIR
);
266 /* After parsing the file, set options from command-line, (so that
267 command-line arguments take precedence) */
268 /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c
269 really needs to be cleaned up. There is so much duplication
270 right now it is ridiculous. Maybe opkg_conf_t should just save
271 a pointer to args_t (which could then not be freed), rather
272 than duplicating every field here? */
273 if (args
->autoremove
) {
274 conf
->autoremove
= 1;
276 if (args
->force_depends
) {
277 conf
->force_depends
= 1;
279 if (args
->force_defaults
) {
280 conf
->force_defaults
= 1;
282 if (args
->force_maintainer
) {
283 conf
->force_maintainer
= 1;
285 if (args
->force_overwrite
) {
286 conf
->force_overwrite
= 1;
288 if (args
->force_downgrade
) {
289 conf
->force_downgrade
= 1;
291 if (args
->force_space
) {
292 conf
->force_space
= 1;
294 if (args
->force_reinstall
) {
295 conf
->force_reinstall
= 1;
297 if (args
->force_removal_of_dependent_packages
) {
298 conf
->force_removal_of_dependent_packages
= 1;
300 if (args
->force_removal_of_essential_packages
) {
301 conf
->force_removal_of_essential_packages
= 1;
306 if (args
->noaction
) {
309 if (args
->query_all
) {
312 if (args
->verbosity
!= conf
->verbosity
) {
313 conf
->verbosity
= args
->verbosity
;
316 /* Pigi: added a flag to disable the checking of structures if the command does not need to
317 read anything from there.
319 if ( !(args
->nocheckfordirorfile
)){
320 /* need to run load the source list before dest list -Jamey */
321 if ( !(args
->noreadfeedsfile
))
322 set_and_load_pkg_src_list(conf
, &conf
->pkg_src_list
);
324 /* Now that we have resolved conf->offline_root, we can commit to
325 the directory names for the dests and load in all the package
327 set_and_load_pkg_dest_list(conf
, &tmp_dest_nv_pair_list
);
330 err
= opkg_conf_set_default_dest(conf
, args
->dest
);
332 return OPKG_CONF_ERR_DEFAULT_DEST
;
336 nv_pair_list_deinit(&tmp_dest_nv_pair_list
);
341 void opkg_conf_deinit(opkg_conf_t
*conf
)
346 free(conf
->lists_dir
);
347 free(conf
->pending_dir
);
349 pkg_src_list_deinit(&conf
->pkg_src_list
);
350 pkg_dest_list_deinit(&conf
->pkg_dest_list
);
351 nv_pair_list_deinit(&conf
->arch_list
);
353 opkg_conf_free_string(&conf
->cache
);
355 opkg_conf_free_string(&conf
->ftp_proxy
);
356 opkg_conf_free_string(&conf
->http_proxy
);
357 opkg_conf_free_string(&conf
->no_proxy
);
359 opkg_conf_free_string(&conf
->offline_root
);
360 opkg_conf_free_string(&conf
->offline_root_path
);
361 opkg_conf_free_string(&conf
->offline_root_pre_script_cmd
);
362 opkg_conf_free_string(&conf
->offline_root_post_script_cmd
);
364 opkg_conf_free_string(&conf
->proxy_passwd
);
365 opkg_conf_free_string(&conf
->proxy_user
);
367 #if defined(HAVE_OPENSSL)
368 opkg_conf_free_string(&conf
->signature_ca_file
);
369 opkg_conf_free_string(&conf
->signature_ca_path
);
372 #if defined(HAVE_SSLCURL)
373 opkg_conf_free_string(&conf
->ssl_engine
);
374 opkg_conf_free_string(&conf
->ssl_cert
);
375 opkg_conf_free_string(&conf
->ssl_cert_type
);
376 opkg_conf_free_string(&conf
->ssl_key
);
377 opkg_conf_free_string(&conf
->ssl_key_type
);
378 opkg_conf_free_string(&conf
->ssl_key_passwd
);
379 opkg_conf_free_string(&conf
->ssl_ca_file
);
380 opkg_conf_free_string(&conf
->ssl_ca_path
);
383 if (conf
->verbosity
>= OPKG_DEBUG
) {
385 hash_table_t
*hashes
[] = {
388 &conf
->obs_file_hash
};
389 for (i
= 0; i
< 3; i
++) {
390 hash_table_t
*hash
= hashes
[i
];
394 for (j
= 0; j
< hash
->n_entries
; j
++) {
396 hash_entry_t
*e
= &hash
->entries
[j
];
399 while (e
&& e
->key
) {
406 opkg_message(conf
, OPKG_DEBUG
, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n",
407 hash
->name
, hash
->n_entries
, hash
->n_elements
, c
, n_conflicts
);
412 pkg_hash_deinit(&conf
->pkg_hash
);
413 if (&conf
->file_hash
)
414 hash_table_deinit(&conf
->file_hash
);
415 if (&conf
->obs_file_hash
)
416 hash_table_deinit(&conf
->obs_file_hash
);
418 lockf(conf
->lock_fd
, F_ULOCK
, 0);
419 close(conf
->lock_fd
);
422 static int opkg_conf_set_default_dest(opkg_conf_t
*conf
,
423 const char *default_dest_name
)
425 pkg_dest_list_elt_t
*iter
;
428 for (iter
= void_list_first(&conf
->pkg_dest_list
); iter
; iter
= void_list_next(&conf
->pkg_dest_list
, iter
)) {
429 dest
= (pkg_dest_t
*)iter
->data
;
430 if (strcmp(dest
->name
, default_dest_name
) == 0) {
431 conf
->default_dest
= dest
;
432 conf
->restrict_to_default_dest
= 1;
437 fprintf(stderr
, "ERROR: Unknown dest name: `%s'\n", default_dest_name
);
442 static int set_and_load_pkg_src_list(opkg_conf_t
*conf
, pkg_src_list_t
*pkg_src_list
)
444 pkg_src_list_elt_t
*iter
;
448 for (iter
= void_list_first(pkg_src_list
); iter
; iter
= void_list_next(pkg_src_list
, iter
)) {
449 src
= (pkg_src_t
*)iter
->data
;
454 sprintf_alloc(&list_file
, "%s/%s",
455 conf
->restrict_to_default_dest
? conf
->default_dest
->lists_dir
: conf
->lists_dir
,
458 if (file_exists(list_file
)) {
459 pkg_hash_add_from_file(conf
, list_file
, src
, NULL
, 0);
467 static int set_and_load_pkg_dest_list(opkg_conf_t
*conf
, nv_pair_list_t
*nv_pair_list
)
469 nv_pair_list_elt_t
*iter
;
474 for (iter
= nv_pair_list_first(nv_pair_list
); iter
; iter
= nv_pair_list_next(nv_pair_list
, iter
)) {
475 nv_pair
= (nv_pair_t
*)iter
->data
;
477 if (conf
->offline_root
) {
478 sprintf_alloc(&root_dir
, "%s%s", conf
->offline_root
, nv_pair
->value
);
480 root_dir
= xstrdup(nv_pair
->value
);
482 dest
= pkg_dest_list_append(&conf
->pkg_dest_list
, nv_pair
->name
, root_dir
, conf
->lists_dir
);
487 if (conf
->default_dest
== NULL
) {
488 conf
->default_dest
= dest
;
490 if (file_exists(dest
->status_file_name
)) {
491 pkg_hash_add_from_file(conf
, dest
->status_file_name
,
499 static int opkg_conf_parse_file(opkg_conf_t
*conf
, const char *filename
,
500 pkg_src_list_t
*pkg_src_list
,
501 nv_pair_list_t
*tmp_dest_nv_pair_list
)
504 opkg_option_t
* options
;
506 regex_t valid_line_re
, comment_re
;
507 #define regmatch_size 12
508 regmatch_t regmatch
[regmatch_size
];
510 opkg_init_options_array(conf
, &options
);
512 file
= fopen(filename
, "r");
514 fprintf(stderr
, "%s: failed to open %s: %s\n",
515 __FUNCTION__
, filename
, strerror(errno
));
519 opkg_message(conf
, OPKG_NOTICE
, "loading conf file %s\n", filename
);
521 err
= xregcomp(&comment_re
,
522 "^[[:space:]]*(#.*|[[:space:]]*)$",
528 err
= xregcomp(&valid_line_re
, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED
);
537 char *type
, *name
, *value
, *extra
;
539 line
= file_read_line_alloc(file
);
547 if (regexec(&comment_re
, line
, 0, 0, 0) == 0) {
551 if (regexec(&valid_line_re
, line
, regmatch_size
, regmatch
, 0) == REG_NOMATCH
) {
553 fprintf(stderr
, "%s:%d: Ignoring invalid line: `%s'\n",
554 filename
, line_num
, line
);
558 /* This has to be so ugly to deal with optional quotation marks */
559 if (regmatch
[2].rm_so
> 0) {
560 type
= xstrndup(line
+ regmatch
[2].rm_so
,
561 regmatch
[2].rm_eo
- regmatch
[2].rm_so
);
563 type
= xstrndup(line
+ regmatch
[3].rm_so
,
564 regmatch
[3].rm_eo
- regmatch
[3].rm_so
);
566 if (regmatch
[5].rm_so
> 0) {
567 name
= xstrndup(line
+ regmatch
[5].rm_so
,
568 regmatch
[5].rm_eo
- regmatch
[5].rm_so
);
570 name
= xstrndup(line
+ regmatch
[6].rm_so
,
571 regmatch
[6].rm_eo
- regmatch
[6].rm_so
);
573 if (regmatch
[8].rm_so
> 0) {
574 value
= xstrndup(line
+ regmatch
[8].rm_so
,
575 regmatch
[8].rm_eo
- regmatch
[8].rm_so
);
577 value
= xstrndup(line
+ regmatch
[9].rm_so
,
578 regmatch
[9].rm_eo
- regmatch
[9].rm_so
);
581 if (regmatch
[11].rm_so
> 0) {
582 extra
= xstrndup (line
+ regmatch
[11].rm_so
,
583 regmatch
[11].rm_eo
- regmatch
[11].rm_so
);
586 /* We use the tmp_dest_nv_pair_list below instead of
587 conf->pkg_dest_list because we might encounter an
588 offline_root option later and that would invalidate the
589 directories we would have computed in
590 pkg_dest_list_init. (We do a similar thing with
591 tmp_src_nv_pair_list for sake of symmetry.) */
592 if (strcmp(type
, "option") == 0) {
593 opkg_conf_set_option(options
, name
, value
);
594 } else if (strcmp(type
, "src") == 0) {
595 if (!nv_pair_list_find((nv_pair_list_t
*) pkg_src_list
, name
)) {
596 pkg_src_list_append (pkg_src_list
, name
, value
, extra
, 0);
598 opkg_message(conf
, OPKG_ERROR
, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
601 } else if (strcmp(type
, "src/gz") == 0) {
602 if (!nv_pair_list_find((nv_pair_list_t
*) pkg_src_list
, name
)) {
603 pkg_src_list_append (pkg_src_list
, name
, value
, extra
, 1);
605 opkg_message(conf
, OPKG_ERROR
, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
608 } else if (strcmp(type
, "dest") == 0) {
609 nv_pair_list_append(tmp_dest_nv_pair_list
, name
, value
);
610 } else if (strcmp(type
, "lists_dir") == 0) {
611 conf
->lists_dir
= xstrdup(value
);
612 } else if (strcmp(type
, "arch") == 0) {
613 opkg_message(conf
, OPKG_INFO
, "supported arch %s priority (%s)\n", name
, value
);
615 opkg_message(conf
, OPKG_NOTICE
, "defaulting architecture %s priority to 10\n", name
);
616 value
= xstrdup("10");
618 nv_pair_list_append(&conf
->arch_list
, name
, value
);
620 fprintf(stderr
, "WARNING: Ignoring unknown configuration "
621 "parameter: %s %s %s\n", type
, name
, value
);
637 regfree(&comment_re
);
638 regfree(&valid_line_re
);
644 static int opkg_conf_set_option(const opkg_option_t
*options
,
645 const char *name
, const char *value
)
648 while (options
[i
].name
) {
649 if (strcmp(options
[i
].name
, name
) == 0) {
650 switch (options
[i
].type
) {
651 case OPKG_OPT_TYPE_BOOL
:
652 *((int *)options
[i
].value
) = 1;
654 case OPKG_OPT_TYPE_INT
:
656 *((int *)options
[i
].value
) = atoi(value
);
659 printf("%s: Option %s need an argument\n",
663 case OPKG_OPT_TYPE_STRING
:
665 *((char **)options
[i
].value
) = xstrdup(value
);
668 printf("%s: Option %s need an argument\n",
677 fprintf(stderr
, "%s: Unrecognized option: %s=%s\n",
678 __FUNCTION__
, name
, value
);
682 int opkg_conf_write_status_files(opkg_conf_t
*conf
)
684 pkg_dest_list_elt_t
*iter
;
693 list_for_each_entry(iter
, &conf
->pkg_dest_list
.head
, node
) {
694 dest
= (pkg_dest_t
*)iter
->data
;
696 dest
->status_fp
= fopen(dest
->status_file_name
, "w");
697 if (dest
->status_fp
== NULL
) {
698 fprintf(stderr
, "%s: Can't open status file: %s: %s\n",
699 __FUNCTION__
, dest
->status_file_name
, strerror(errno
));
704 all
= pkg_vec_alloc();
705 pkg_hash_fetch_available(&conf
->pkg_hash
, all
);
707 for(i
= 0; i
< all
->len
; i
++) {
709 /* We don't need most uninstalled packages in the status file */
710 if (pkg
->state_status
== SS_NOT_INSTALLED
711 && (pkg
->state_want
== SW_UNKNOWN
712 || pkg
->state_want
== SW_DEINSTALL
713 || pkg
->state_want
== SW_PURGE
)) {
716 if (pkg
->dest
== NULL
) {
717 fprintf(stderr
, "%s: ERROR: Can't write status for "
718 "package %s since it has a NULL dest\n",
719 __FUNCTION__
, pkg
->name
);
722 if (pkg
->dest
->status_fp
)
723 pkg_print_status(pkg
, pkg
->dest
->status_fp
);
728 list_for_each_entry(iter
, &conf
->pkg_dest_list
.head
, node
) {
729 dest
= (pkg_dest_t
*)iter
->data
;
730 fclose(dest
->status_fp
);
737 char *root_filename_alloc(opkg_conf_t
*conf
, char *filename
)
740 sprintf_alloc(&root_filename
, "%s%s", (conf
->offline_root
? conf
->offline_root
: ""), filename
);
741 return root_filename
;