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"
27 #include "opkg_defines.h"
28 #include "libbb/libbb.h"
30 #include <sys/types.h>
36 static int opkg_conf_parse_file(opkg_conf_t
*conf
, const char *filename
,
37 pkg_src_list_t
*pkg_src_list
,
38 nv_pair_list_t
*tmp_dest_nv_pair_list
);
39 static int opkg_conf_set_option(const opkg_option_t
*options
,
40 const char *name
, const char *value
);
41 static int opkg_conf_set_default_dest(opkg_conf_t
*conf
,
42 const char *default_dest_name
);
43 static int set_and_load_pkg_src_list(opkg_conf_t
*conf
,
44 pkg_src_list_t
*nv_pair_list
);
45 static int set_and_load_pkg_dest_list(opkg_conf_t
*conf
,
46 nv_pair_list_t
*nv_pair_list
);
48 void opkg_init_options_array(const opkg_conf_t
*conf
, opkg_option_t
**options
)
50 opkg_option_t tmp
[] = {
51 { "cache", OPKG_OPT_TYPE_STRING
, &conf
->cache
},
52 { "force_defaults", OPKG_OPT_TYPE_BOOL
, &conf
->force_defaults
},
53 { "force_maintainer", OPKG_OPT_TYPE_BOOL
, &conf
->force_maintainer
},
54 { "force_depends", OPKG_OPT_TYPE_BOOL
, &conf
->force_depends
},
55 { "force_overwrite", OPKG_OPT_TYPE_BOOL
, &conf
->force_overwrite
},
56 { "force_downgrade", OPKG_OPT_TYPE_BOOL
, &conf
->force_downgrade
},
57 { "force_reinstall", OPKG_OPT_TYPE_BOOL
, &conf
->force_reinstall
},
58 { "force_space", OPKG_OPT_TYPE_BOOL
, &conf
->force_space
},
59 { "check_signature", OPKG_OPT_TYPE_INT
, &conf
->check_signature
},
60 { "ftp_proxy", OPKG_OPT_TYPE_STRING
, &conf
->ftp_proxy
},
61 { "http_proxy", OPKG_OPT_TYPE_STRING
, &conf
->http_proxy
},
62 { "no_proxy", OPKG_OPT_TYPE_STRING
, &conf
->no_proxy
},
63 { "test", OPKG_OPT_TYPE_INT
, &conf
->noaction
},
64 { "noaction", OPKG_OPT_TYPE_INT
, &conf
->noaction
},
65 { "nodeps", OPKG_OPT_TYPE_BOOL
, &conf
->nodeps
},
66 { "offline_root", OPKG_OPT_TYPE_STRING
, &conf
->offline_root
},
67 { "offline_root_path", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_path
},
68 { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_post_script_cmd
},
69 { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING
, &conf
->offline_root_pre_script_cmd
},
70 { "proxy_passwd", OPKG_OPT_TYPE_STRING
, &conf
->proxy_passwd
},
71 { "proxy_user", OPKG_OPT_TYPE_STRING
, &conf
->proxy_user
},
72 { "query-all", OPKG_OPT_TYPE_BOOL
, &conf
->query_all
},
73 { "tmp_dir", OPKG_OPT_TYPE_STRING
, &conf
->tmp_dir
},
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
)
122 char *tmp_dir_base
, *tmp2
;
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 */
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 */
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
]);
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
);
201 opkg_conf_override_string(&conf
->tmp_dir
, args
->tmp_dir
);
203 /* check for lock file */
204 if (conf
->offline_root
)
205 sprintf_alloc (&lock_file
, "%s/%s/lock", conf
->offline_root
, OPKG_STATE_DIR_PREFIX
);
207 sprintf_alloc (&lock_file
, "%s/lock", OPKG_STATE_DIR_PREFIX
);
209 err
= conf
->lock_fd
= creat (lock_file
, S_IRUSR
| S_IWUSR
| S_IRGRP
);
211 err
= lockf (conf
->lock_fd
, F_TLOCK
, 0);
215 opkg_message (conf
, OPKG_ERROR
, "Could not lock %s: %s\n",
216 lock_file
, strerror(errno_copy
));
223 tmp_dir_base
= conf
->tmp_dir
;
225 tmp_dir_base
= getenv("TMPDIR");
226 sprintf_alloc(&tmp2
, "%s/%s",
227 tmp_dir_base
? tmp_dir_base
: OPKG_CONF_DEFAULT_TMP_DIR_BASE
,
228 OPKG_CONF_TMP_DIR_SUFFIX
);
231 conf
->tmp_dir
= mkdtemp(tmp2
);
232 if (conf
->tmp_dir
== NULL
) {
233 opkg_message(conf
, OPKG_ERROR
,
234 "%s: Creating temp dir %s failed: %s\n",
235 __FUNCTION__
, tmp2
, strerror(errno
));
239 pkg_hash_init("pkg-hash", &conf
->pkg_hash
, OPKG_CONF_DEFAULT_HASH_LEN
);
240 hash_table_init("file-hash", &conf
->file_hash
, OPKG_CONF_DEFAULT_HASH_LEN
);
241 hash_table_init("obs-file-hash", &conf
->obs_file_hash
, OPKG_CONF_DEFAULT_HASH_LEN
/16);
243 if (conf
->lists_dir
== NULL
)
244 conf
->lists_dir
= xstrdup(OPKG_CONF_LISTS_DIR
);
246 if (conf
->offline_root
) {
248 sprintf_alloc(&tmp
, "%s/%s", conf
->offline_root
, conf
->lists_dir
);
249 free(conf
->lists_dir
);
250 conf
->lists_dir
= tmp
;
253 /* if no architectures were defined, then default all, noarch, and host architecture */
254 if (nv_pair_list_empty(&conf
->arch_list
)) {
255 nv_pair_list_append(&conf
->arch_list
, "all", "1");
256 nv_pair_list_append(&conf
->arch_list
, "noarch", "1");
257 nv_pair_list_append(&conf
->arch_list
, HOST_CPU_STR
, "10");
260 /* Even if there is no conf file, we'll need at least one dest. */
261 if (nv_pair_list_empty(&tmp_dest_nv_pair_list
)) {
262 nv_pair_list_append(&tmp_dest_nv_pair_list
,
263 OPKG_CONF_DEFAULT_DEST_NAME
,
264 OPKG_CONF_DEFAULT_DEST_ROOT_DIR
);
267 /* After parsing the file, set options from command-line, (so that
268 command-line arguments take precedence) */
269 /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c
270 really needs to be cleaned up. There is so much duplication
271 right now it is ridiculous. Maybe opkg_conf_t should just save
272 a pointer to args_t (which could then not be freed), rather
273 than duplicating every field here? */
274 if (args
->autoremove
) {
275 conf
->autoremove
= 1;
277 if (args
->force_depends
) {
278 conf
->force_depends
= 1;
280 if (args
->force_defaults
) {
281 conf
->force_defaults
= 1;
283 if (args
->force_maintainer
) {
284 conf
->force_maintainer
= 1;
286 if (args
->force_overwrite
) {
287 conf
->force_overwrite
= 1;
289 if (args
->force_downgrade
) {
290 conf
->force_downgrade
= 1;
292 if (args
->force_space
) {
293 conf
->force_space
= 1;
295 if (args
->force_reinstall
) {
296 conf
->force_reinstall
= 1;
298 if (args
->force_removal_of_dependent_packages
) {
299 conf
->force_removal_of_dependent_packages
= 1;
301 if (args
->force_removal_of_essential_packages
) {
302 conf
->force_removal_of_essential_packages
= 1;
307 if (args
->noaction
) {
310 if (args
->query_all
) {
313 if (args
->verbosity
!= conf
->verbosity
) {
314 conf
->verbosity
= args
->verbosity
;
317 /* Pigi: added a flag to disable the checking of structures if the command does not need to
318 read anything from there.
320 if (!(args
->nocheckfordirorfile
)) {
322 if (!(args
->noreadfeedsfile
)) {
323 if (set_and_load_pkg_src_list(conf
, &conf
->pkg_src_list
)) {
324 nv_pair_list_deinit(&tmp_dest_nv_pair_list
);
329 /* Now that we have resolved conf->offline_root, we can commit to
330 the directory names for the dests and load in all the package
332 if (set_and_load_pkg_dest_list(conf
, &tmp_dest_nv_pair_list
)) {
333 nv_pair_list_deinit(&tmp_dest_nv_pair_list
);
338 err
= opkg_conf_set_default_dest(conf
, args
->dest
);
340 nv_pair_list_deinit(&tmp_dest_nv_pair_list
);
345 nv_pair_list_deinit(&tmp_dest_nv_pair_list
);
350 void opkg_conf_deinit(opkg_conf_t
*conf
)
355 free(conf
->lists_dir
);
357 pkg_src_list_deinit(&conf
->pkg_src_list
);
358 pkg_dest_list_deinit(&conf
->pkg_dest_list
);
359 nv_pair_list_deinit(&conf
->arch_list
);
361 opkg_conf_free_string(&conf
->cache
);
363 opkg_conf_free_string(&conf
->ftp_proxy
);
364 opkg_conf_free_string(&conf
->http_proxy
);
365 opkg_conf_free_string(&conf
->no_proxy
);
367 opkg_conf_free_string(&conf
->offline_root
);
368 opkg_conf_free_string(&conf
->offline_root_path
);
369 opkg_conf_free_string(&conf
->offline_root_pre_script_cmd
);
370 opkg_conf_free_string(&conf
->offline_root_post_script_cmd
);
372 opkg_conf_free_string(&conf
->proxy_passwd
);
373 opkg_conf_free_string(&conf
->proxy_user
);
375 #if defined(HAVE_OPENSSL)
376 opkg_conf_free_string(&conf
->signature_ca_file
);
377 opkg_conf_free_string(&conf
->signature_ca_path
);
380 #if defined(HAVE_SSLCURL)
381 opkg_conf_free_string(&conf
->ssl_engine
);
382 opkg_conf_free_string(&conf
->ssl_cert
);
383 opkg_conf_free_string(&conf
->ssl_cert_type
);
384 opkg_conf_free_string(&conf
->ssl_key
);
385 opkg_conf_free_string(&conf
->ssl_key_type
);
386 opkg_conf_free_string(&conf
->ssl_key_passwd
);
387 opkg_conf_free_string(&conf
->ssl_ca_file
);
388 opkg_conf_free_string(&conf
->ssl_ca_path
);
391 if (conf
->verbosity
>= OPKG_DEBUG
) {
392 hash_print_stats(&conf
->pkg_hash
);
393 hash_print_stats(&conf
->file_hash
);
394 hash_print_stats(&conf
->obs_file_hash
);
398 pkg_hash_deinit(&conf
->pkg_hash
);
399 if (&conf
->file_hash
)
400 hash_table_deinit(&conf
->file_hash
);
401 if (&conf
->obs_file_hash
)
402 hash_table_deinit(&conf
->obs_file_hash
);
404 /* lockf maybe defined with warn_unused_result */
405 if(lockf(conf
->lock_fd
, F_ULOCK
, 0) != 0){
406 opkg_message(conf
, OPKG_DEBUG
, "%s: unlock failed: %s\n",
410 close(conf
->lock_fd
);
413 static int opkg_conf_set_default_dest(opkg_conf_t
*conf
,
414 const char *default_dest_name
)
416 pkg_dest_list_elt_t
*iter
;
419 for (iter
= void_list_first(&conf
->pkg_dest_list
); iter
; iter
= void_list_next(&conf
->pkg_dest_list
, iter
)) {
420 dest
= (pkg_dest_t
*)iter
->data
;
421 if (strcmp(dest
->name
, default_dest_name
) == 0) {
422 conf
->default_dest
= dest
;
423 conf
->restrict_to_default_dest
= 1;
428 fprintf(stderr
, "ERROR: Unknown dest name: `%s'\n", default_dest_name
);
434 set_and_load_pkg_src_list(opkg_conf_t
*conf
, pkg_src_list_t
*pkg_src_list
)
436 pkg_src_list_elt_t
*iter
;
440 for (iter
= void_list_first(pkg_src_list
); iter
; iter
= void_list_next(pkg_src_list
, iter
)) {
441 src
= (pkg_src_t
*)iter
->data
;
446 sprintf_alloc(&list_file
, "%s/%s",
447 conf
->restrict_to_default_dest
? conf
->default_dest
->lists_dir
: conf
->lists_dir
,
450 if (file_exists(list_file
)) {
451 if (pkg_hash_add_from_file(conf
, list_file
, src
, NULL
, 0)) {
463 set_and_load_pkg_dest_list(opkg_conf_t
*conf
, nv_pair_list_t
*nv_pair_list
)
465 nv_pair_list_elt_t
*iter
;
470 for (iter
= nv_pair_list_first(nv_pair_list
); iter
; iter
= nv_pair_list_next(nv_pair_list
, iter
)) {
471 nv_pair
= (nv_pair_t
*)iter
->data
;
473 if (conf
->offline_root
) {
474 sprintf_alloc(&root_dir
, "%s%s", conf
->offline_root
, nv_pair
->value
);
476 root_dir
= xstrdup(nv_pair
->value
);
478 dest
= pkg_dest_list_append(&conf
->pkg_dest_list
, nv_pair
->name
, root_dir
, conf
->lists_dir
);
483 if (conf
->default_dest
== NULL
) {
484 conf
->default_dest
= dest
;
486 if (file_exists(dest
->status_file_name
)) {
487 if (pkg_hash_add_from_file(conf
, dest
->status_file_name
,
496 static int opkg_conf_parse_file(opkg_conf_t
*conf
, const char *filename
,
497 pkg_src_list_t
*pkg_src_list
,
498 nv_pair_list_t
*tmp_dest_nv_pair_list
)
501 opkg_option_t
* options
;
503 regex_t valid_line_re
, comment_re
;
504 #define regmatch_size 12
505 regmatch_t regmatch
[regmatch_size
];
507 opkg_init_options_array(conf
, &options
);
509 file
= fopen(filename
, "r");
511 fprintf(stderr
, "%s: failed to open %s: %s\n",
512 __FUNCTION__
, filename
, strerror(errno
));
516 opkg_message(conf
, OPKG_NOTICE
, "loading conf file %s\n", filename
);
518 err
= xregcomp(&comment_re
,
519 "^[[:space:]]*(#.*|[[:space:]]*)$",
525 err
= xregcomp(&valid_line_re
, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED
);
534 char *type
, *name
, *value
, *extra
;
536 line
= file_read_line_alloc(file
);
542 if (regexec(&comment_re
, line
, 0, 0, 0) == 0) {
546 if (regexec(&valid_line_re
, line
, regmatch_size
, regmatch
, 0) == REG_NOMATCH
) {
547 fprintf(stderr
, "%s:%d: Ignoring invalid line: `%s'\n",
548 filename
, line_num
, line
);
552 /* This has to be so ugly to deal with optional quotation marks */
553 if (regmatch
[2].rm_so
> 0) {
554 type
= xstrndup(line
+ regmatch
[2].rm_so
,
555 regmatch
[2].rm_eo
- regmatch
[2].rm_so
);
557 type
= xstrndup(line
+ regmatch
[3].rm_so
,
558 regmatch
[3].rm_eo
- regmatch
[3].rm_so
);
560 if (regmatch
[5].rm_so
> 0) {
561 name
= xstrndup(line
+ regmatch
[5].rm_so
,
562 regmatch
[5].rm_eo
- regmatch
[5].rm_so
);
564 name
= xstrndup(line
+ regmatch
[6].rm_so
,
565 regmatch
[6].rm_eo
- regmatch
[6].rm_so
);
567 if (regmatch
[8].rm_so
> 0) {
568 value
= xstrndup(line
+ regmatch
[8].rm_so
,
569 regmatch
[8].rm_eo
- regmatch
[8].rm_so
);
571 value
= xstrndup(line
+ regmatch
[9].rm_so
,
572 regmatch
[9].rm_eo
- regmatch
[9].rm_so
);
575 if (regmatch
[11].rm_so
> 0) {
576 extra
= xstrndup (line
+ regmatch
[11].rm_so
,
577 regmatch
[11].rm_eo
- regmatch
[11].rm_so
);
580 /* We use the tmp_dest_nv_pair_list below instead of
581 conf->pkg_dest_list because we might encounter an
582 offline_root option later and that would invalidate the
583 directories we would have computed in
584 pkg_dest_list_init. (We do a similar thing with
585 tmp_src_nv_pair_list for sake of symmetry.) */
586 if (strcmp(type
, "option") == 0) {
587 opkg_conf_set_option(options
, name
, value
);
588 } else if (strcmp(type
, "src") == 0) {
589 if (!nv_pair_list_find((nv_pair_list_t
*) pkg_src_list
, name
)) {
590 pkg_src_list_append (pkg_src_list
, name
, value
, extra
, 0);
592 opkg_message(conf
, OPKG_ERROR
, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
595 } else if (strcmp(type
, "src/gz") == 0) {
596 if (!nv_pair_list_find((nv_pair_list_t
*) pkg_src_list
, name
)) {
597 pkg_src_list_append (pkg_src_list
, name
, value
, extra
, 1);
599 opkg_message(conf
, OPKG_ERROR
, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n",
602 } else if (strcmp(type
, "dest") == 0) {
603 nv_pair_list_append(tmp_dest_nv_pair_list
, name
, value
);
604 } else if (strcmp(type
, "lists_dir") == 0) {
605 conf
->lists_dir
= xstrdup(value
);
606 } else if (strcmp(type
, "arch") == 0) {
607 opkg_message(conf
, OPKG_INFO
, "supported arch %s priority (%s)\n", name
, value
);
609 opkg_message(conf
, OPKG_NOTICE
, "defaulting architecture %s priority to 10\n", name
);
610 value
= xstrdup("10");
612 nv_pair_list_append(&conf
->arch_list
, name
, value
);
614 fprintf(stderr
, "WARNING: Ignoring unknown configuration "
615 "parameter: %s %s %s\n", type
, name
, value
);
631 regfree(&comment_re
);
632 regfree(&valid_line_re
);
638 static int opkg_conf_set_option(const opkg_option_t
*options
,
639 const char *name
, const char *value
)
642 while (options
[i
].name
) {
643 if (strcmp(options
[i
].name
, name
) == 0) {
644 switch (options
[i
].type
) {
645 case OPKG_OPT_TYPE_BOOL
:
646 *((int *)options
[i
].value
) = 1;
648 case OPKG_OPT_TYPE_INT
:
650 *((int *)options
[i
].value
) = atoi(value
);
653 printf("%s: Option %s need an argument\n",
657 case OPKG_OPT_TYPE_STRING
:
659 *((char **)options
[i
].value
) = xstrdup(value
);
662 printf("%s: Option %s need an argument\n",
671 fprintf(stderr
, "%s: Unrecognized option: %s=%s\n",
672 __FUNCTION__
, name
, value
);
676 int opkg_conf_write_status_files(opkg_conf_t
*conf
)
678 pkg_dest_list_elt_t
*iter
;
687 list_for_each_entry(iter
, &conf
->pkg_dest_list
.head
, node
) {
688 dest
= (pkg_dest_t
*)iter
->data
;
690 dest
->status_fp
= fopen(dest
->status_file_name
, "w");
691 if (dest
->status_fp
== NULL
) {
692 fprintf(stderr
, "%s: Can't open status file: %s: %s\n",
693 __FUNCTION__
, dest
->status_file_name
, strerror(errno
));
698 all
= pkg_vec_alloc();
699 pkg_hash_fetch_available(&conf
->pkg_hash
, all
);
701 for(i
= 0; i
< all
->len
; i
++) {
703 /* We don't need most uninstalled packages in the status file */
704 if (pkg
->state_status
== SS_NOT_INSTALLED
705 && (pkg
->state_want
== SW_UNKNOWN
706 || pkg
->state_want
== SW_DEINSTALL
707 || pkg
->state_want
== SW_PURGE
)) {
710 if (pkg
->dest
== NULL
) {
711 fprintf(stderr
, "%s: ERROR: Can't write status for "
712 "package %s since it has a NULL dest\n",
713 __FUNCTION__
, pkg
->name
);
716 if (pkg
->dest
->status_fp
)
717 pkg_print_status(pkg
, pkg
->dest
->status_fp
);
722 list_for_each_entry(iter
, &conf
->pkg_dest_list
.head
, node
) {
723 dest
= (pkg_dest_t
*)iter
->data
;
724 fclose(dest
->status_fp
);
731 char *root_filename_alloc(opkg_conf_t
*conf
, char *filename
)
734 sprintf_alloc(&root_filename
, "%s%s", (conf
->offline_root
? conf
->offline_root
: ""), filename
);
735 return root_filename
;