rpmmen -> patch zmieniajacy tablice struktur na tablice wskaznikow
Wojtek Bojdol
wojboj w lp.net.pl
Pon, 17 Maj 1999, 08:46:22 CEST
daje w koncu ta late o ktorej mowilem ostatnio
zmienia tablice struktur na tablice wskaznikow do struktur co zmniejsza
uzycie realloc()a...
do tego przy okazji dolaczylem poprawki na uzywanie malloc'a do paru
zmiennych..:)
a tak poza tym pare pytan co do init'a
otoz musze wiedziec, w jakich sytuacjach bedzie on pracowal..:)
jesli tylko bedzie pracowal z bootdisca to spox...
ale jesli beda przypadki w stylu nfsroot, cdrom-root itp to mowcie
do tego mysle, czy by tak nie wpakowac srcow mount'a i umount'a do init'a
zysk: nie trzeba uzywac w inicie execve() przez co zmniejsza sie liczba
problemow jakie moga wystapic (przy kiepsko zrobionej plytce i roocie na
cdku mzoe nie byc atrybutu +x na mount)
jesli wpakujemy mounta i umounta do inita to robimy potem linki do inita
nazwane mount i umount i mamy 3 komendy w 1 binarce
straty: jesli uzyjemy mounta z bysuboxa to tam nie ma obslugi nfsa
mozemy obsluge nfsa, ncpfsa i smbfsa dac jako nfsmount, ncpmount i
smbmount -> osobne komendy :)
-------------- następna część ---------
--- rpmmenlib/rpmmen.cold Fri May 14 19:56:50 1999
+++ rpmmenlib/rpmmen.c Fri May 14 20:15:57 1999
@@ -36,7 +36,7 @@
static TPkgSet rpmmen_pkgs;
*/
-char dest[1000];
+char *dest;
int rpmpkgs_preparetoinstall(TPkgSet * pkgs);
int installrpm(char *name, int, rpmNotifyFunction);
@@ -64,10 +64,10 @@
while (!feof(f)) {
fscanf(f, "%s\n", tmp);
for (i = 0; i < pkgs->numPackages; i++)
- if (!strcmp(tmp, pkgs->packages[i].name)) {
+ if (!strcmp(tmp, pkgs->packages[i]->name)) {
log_debug_message("%s package %s", __FUNCTION__,
tmp);
- pkgs->packages[i].selected = RPMMEN_FROM_FILE;
+ pkgs->packages[i]->selected = RPMMEN_FROM_FILE;
}
}
ioi_close(fd);
@@ -82,9 +82,10 @@
void rpmpkgs_init(TPkgSet * pkgs, char *src, char *dest_)
{
/* rpmSetVerbosity(0); */
- pkgs->packages = NULL;
+ pkgs->packages = malloc(TPkgSetDefRoz*sizeof(void *));
pkgs->numPackages = 0;
pkgs->src = strdup(src);
+ dest=malloc(strlen(dest_));
strcpy(dest, dest_);
}
@@ -92,11 +93,12 @@
{
int i;
for (i = 0; i < pkgs->numPackages; i++) {
- headerFree(pkgs->packages[i].h);
- free(pkgs->packages[i].name);
- free(pkgs->packages[i].fname);
+ headerFree(pkgs->packages[i]->h);
+ free(pkgs->packages[i]->name);
+ free(pkgs->packages[i]->fname);
+ free(pkgs->packages[i]);
}
- free(pkgs->packages);
+/* free(pkgs->packages); */
pkgs->numPackages = 0;
}
@@ -128,9 +130,9 @@
int rpmmen_opendb()
{
int st, i;
- char tmp[1000];
- strcpy(tmp, dest);
- strcat(tmp, "/var");
+ char *tmp;
+ tmp=malloc(strlen(dest)+4+4+4+2);
+ sprintf(tmp,"%s/var");
if (!rpmmen_mkdir(tmp))
i = 0;
@@ -149,7 +151,7 @@
logDebugMessage("root: %s", dest);
rpmSetVar(RPMVAR_DBPATH, tmp);
rpmSetVar(RPMVAR_ROOT, dest);
-
+ free(tmp);
/* st=rpmdbOpen("",&rpmmen_db,O_RDWR, 0644);
if(!st)
return 0 ; *//* OK */
@@ -214,7 +216,7 @@
for (i = 0; i < pkgs->numPackages; i++) {
- pk = &(pkgs->packages[i]);
+ pk = pkgs->packages[i];
if (pk->hasHeader)
if (pk->selected) /*basesystem juz jest */
rpmdepAddPackage(rpmdep, pk->h, pk);
@@ -278,13 +280,13 @@
rpmorder = rpmdepDependencies(NULL);
for (i = 0; i < pkgs->numPackages; i++) {
- pk = &(pkgs->packages[i]);
+ pk = pkgs->packages[i];
if (strcmp(pk->name, RPMMEN_BASE_PKG) == 0)
rpmdepAddPackage(rpmorder, pk->h, pk);
}
for (i = 0; i < pkgs->numPackages; i++) {
- pk = &(pkgs->packages[i]);
+ pk = pkgs->packages[i];
if (pk->hasHeader && pk->selected)
if (strcmp(pk->name, RPMMEN_BASE_PKG) != 0)
if (pk->selected)
--- rpmmenlib/rpmmen.hold Fri May 14 20:01:05 1999
+++ rpmmenlib/rpmmen.h Fri May 14 20:02:01 1999
@@ -17,8 +17,9 @@
} TPkgInfo;
+#define TPkgSetDefRoz 200
typedef struct {
- TPkgInfo *packages;
+ TPkgInfo **packages;
int numPackages;
char *src;
} TPkgSet;
--- rpmmenlib/srcget.cold Fri May 14 20:27:47 1999
+++ rpmmenlib/srcget.c Fri May 14 20:27:36 1999
@@ -38,30 +38,33 @@
*/
void addPackage(TPkgSet * pkgs, char *fname, Header * h)
{
- TPkgInfo *pk;
+ TPkgInfo **pk,*pktmp;
int count, type;
char *tmp2;
- pk = (TPkgInfo *) realloc(pkgs->packages, \
- sizeof(TPkgInfo) * (++(pkgs->numPackages)));
- if (pk == NULL) {
+ if (pkgs->numPackages>TPkgSetDefRoz)
+ pk=realloc(pkgs->packages,pkgs->numPackages*sizeof(*pk));
+ pktmp=malloc(sizeof(TPkgInfo));
+ if ((pk == NULL)||(pktmp==NULL)) {
pkgs->numPackages--;
logMessage("Can't alloc more memory for packages list. %s", \
"Not good, next time try to make biger swap");
return;
}
- pkgs->packages = pk;
+
+ pkgs->packages[pkgs->numPackages-1] = pktmp;
+
if (h != NULL) {
- memcpy(&(pkgs->packages[pkgs->numPackages - 1].h), h, \
+ memcpy(&(pkgs->packages[pkgs->numPackages - 1]->h), h, \
sizeof(Header));
- h = &(pkgs->packages[pkgs->numPackages - 1].h);
+ h = &(pkgs->packages[pkgs->numPackages - 1]->h);
}
- pkgs->packages[pkgs->numPackages - 1].hasHeader = (h != NULL);
- pkgs->packages[pkgs->numPackages - 1].selected = 0;
+ pkgs->packages[pkgs->numPackages - 1]->hasHeader = (h != NULL);
+ pkgs->packages[pkgs->numPackages - 1]->selected = 0;
if (h != NULL)
headerGetEntry(*h, RPMTAG_NAME, &type, (void *) &tmp2, &count);
- pkgs->packages[pkgs->numPackages - 1].name = \
+ pkgs->packages[pkgs->numPackages - 1]->name = \
(h) ? strdup(tmp2) : strdup(fname);
- pkgs->packages[pkgs->numPackages - 1].fname = strdup(fname);
+ pkgs->packages[pkgs->numPackages - 1]->fname = strdup(fname);
logDebugMessage("%s : added package %s", __FUNCTION__, fname);
}
@@ -99,7 +102,7 @@
}
pkgs = (TPkgSet *) malloc(sizeof(TPkgSet));
pkgs->numPackages = 0;
- pkgs->packages = NULL;
+/* pkgs->packages = NULL; */
end = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
@@ -150,7 +153,7 @@
openLog(1);
pk = getPackagesList();
for (i = 0; i < pk->numPackages; i++)
- printf("iiiiii%s\n", pk->packages[i].fname);
+ printf("iiiiii%s\n", pk->packages[i]->fname);
closeLog();
}
#endif
Więcej informacji o liście dyskusyjnej pld-installer