X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_cmd.c;h=f5d78da6970fd2d77d89700324fba4762fc83083;hp=fcf74f6910026b4930e82a272cfbbd1ebdad0a85;hb=fe09abec099fb3ab0e8c21f6ba90de8ecc6a016e;hpb=9514ede74ec0bcb994a6f6dae3676accaff6cd97 diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index fcf74f6..f5d78da 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -55,6 +55,7 @@ static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_install_pending_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv); +static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_purge_cmd(opkg_conf_t *conf, int argc, char **argv); static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv); @@ -81,6 +82,7 @@ static opkg_cmd_t cmds[] = { {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd}, {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd}, {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd}, + {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd}, {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd}, {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd}, {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd}, @@ -151,7 +153,7 @@ void opkg_print_error_list (opkg_conf_t *conf) error_list = error_list->next; } - free_error_list(&error_list); + free_error_list(); } } @@ -288,7 +290,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) free (tmp_file_name); free (url); #else - opkg_message (conf, OPKG_NOTICE, "Signiture check for %s skipped " + opkg_message (conf, OPKG_NOTICE, "Signature check for %s skipped " "because GPG support was not enabled in this build\n", src->name); #endif free(list_file_name); @@ -312,11 +314,18 @@ typedef struct opkg_intercept *opkg_intercept_t; static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf) { opkg_intercept_t ctx; + char *oldpath; char *newpath; int gen; - ctx = malloc (sizeof (*ctx)); - ctx->oldpath = strdup (getenv ("PATH")); + ctx = calloc (1, sizeof (*ctx)); + oldpath = getenv ("PATH"); + if (oldpath) { + ctx->oldpath = strdup (oldpath); + } else { + ctx->oldpath = 0; + } + sprintf_alloc (&newpath, "%s/opkg/intercept:%s", DATADIR, ctx->oldpath); setenv ("PATH", newpath, 1); @@ -344,8 +353,12 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx) DIR *dir; int err = 0; - setenv ("PATH", ctx->oldpath, 1); - free (ctx->oldpath); + if (ctx->oldpath) { + setenv ("PATH", ctx->oldpath, 1); + free (ctx->oldpath); + } else { + unsetenv("PATH"); + } dir = opendir (ctx->statedir); if (dir) { @@ -369,7 +382,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx) perror (ctx->statedir); sprintf_alloc (&cmd, "rm -rf %s", ctx->statedir); - system (cmd); + err = system (cmd); free (cmd); free (ctx->statedir); @@ -771,6 +784,26 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } +static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv) +{ + pkg_vec_t *all = opkg_upgrade_all_list_get(conf); + pkg_t *_old_pkg, *_new_pkg; + char *old_v, *new_v; + int i; + for (i=0;ilen;i++) { + _old_pkg = all->pkgs[i]; + _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name, NULL); + old_v = pkg_version_str_alloc(_old_pkg); + new_v = pkg_version_str_alloc(_new_pkg); + if (opkg_cb_list) + opkg_cb_list(_old_pkg->name, new_v, old_v, _old_pkg->state_status, p_userdata); + free(old_v); + free(new_v); + } + pkg_vec_free(all); + return 0; +} + static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int installed_only) { int i; @@ -914,7 +947,7 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv) available = pkg_vec_alloc(); pkg_hash_fetch_all_installed(&conf->pkg_hash, available); for (i=0; i < argc; i++) { - pkg_name = malloc(strlen(argv[i])+2); + pkg_name = calloc(1, strlen(argv[i])+2); strcpy(pkg_name,argv[i]); for (a=0; a < available->len; a++) { pkg = available->pkgs[a]; @@ -1075,7 +1108,7 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv) size_t used_len; char *buff ; - buff = (char *)malloc(buff_len); + buff = (char *)calloc(1, buff_len); if ( buff == NULL ) { fprintf( stderr,"%s: Unable to allocate memory \n",__FUNCTION__); return ENOMEM;