00001 #include "system.h"
00002
00003 #include <signal.h>
00004
00005 #include <rpmbuild.h>
00006 #include <argv.h>
00007 #include <rpmfc.h>
00008
00009 #define _RPMDS_INTERNAL
00010 #include <rpmds.h>
00011 #include <rpmfi.h>
00012
00013 #if HAVE_GELF_H
00014 #include <gelf.h>
00015 #endif
00016
00017 #include "debug.h"
00018
00019
00020
00021
00024 static int rpmfcExpandAppend( ARGV_t * argvp, const ARGV_t av)
00025
00026
00027
00028 {
00029 ARGV_t argv = *argvp;
00030 int argc = argvCount(argv);
00031 int ac = argvCount(av);
00032 int i;
00033
00034
00035 argv = xrealloc(argv, (argc + ac + 1) * sizeof(*argv));
00036
00037 for (i = 0; i < ac; i++)
00038 argv[argc + i] = rpmExpand(av[i], NULL);
00039 argv[argc + ac] = NULL;
00040 *argvp = argv;
00041 return 0;
00042 }
00043
00053
00054 static StringBuf getOutputFrom( const char * dir, ARGV_t argv,
00055 const char * writePtr, int writeBytesLeft,
00056 int failNonZero)
00057
00058
00059 {
00060 pid_t child, reaped;
00061 int toProg[2];
00062 int fromProg[2];
00063 int status;
00064 void *oldhandler;
00065 StringBuf readBuff;
00066 int done;
00067
00068
00069 oldhandler = signal(SIGPIPE, SIG_IGN);
00070
00071
00072 toProg[0] = toProg[1] = 0;
00073 (void) pipe(toProg);
00074 fromProg[0] = fromProg[1] = 0;
00075 (void) pipe(fromProg);
00076
00077 if (!(child = fork())) {
00078 (void) close(toProg[1]);
00079 (void) close(fromProg[0]);
00080
00081 (void) dup2(toProg[0], STDIN_FILENO);
00082 (void) dup2(fromProg[1], STDOUT_FILENO);
00083
00084 (void) close(toProg[0]);
00085 (void) close(fromProg[1]);
00086
00087 if (dir) {
00088 (void) chdir(dir);
00089 }
00090
00091 rpmMessage(RPMMESS_DEBUG, _("\texecv(%s) pid %d\n"),
00092 argv[0], (unsigned)getpid());
00093
00094 unsetenv("MALLOC_CHECK_");
00095 (void) execvp(argv[0], (char *const *)argv);
00096
00097 rpmError(RPMERR_EXEC, _("Couldn't exec %s: %s\n"),
00098 argv[0], strerror(errno));
00099 _exit(RPMERR_EXEC);
00100 }
00101 if (child < 0) {
00102 rpmError(RPMERR_FORK, _("Couldn't fork %s: %s\n"),
00103 argv[0], strerror(errno));
00104 return NULL;
00105 }
00106
00107 (void) close(toProg[0]);
00108 (void) close(fromProg[1]);
00109
00110
00111 (void) fcntl(fromProg[0], F_SETFL, O_NONBLOCK);
00112 (void) fcntl(toProg[1], F_SETFL, O_NONBLOCK);
00113
00114 readBuff = newStringBuf();
00115
00116 do {
00117 fd_set ibits, obits;
00118 struct timeval tv;
00119 int nfd, nbw, nbr;
00120 int rc;
00121
00122 done = 0;
00123 top:
00124 FD_ZERO(&ibits);
00125 FD_ZERO(&obits);
00126 if (fromProg[0] >= 0) {
00127 FD_SET(fromProg[0], &ibits);
00128 }
00129 if (toProg[1] >= 0) {
00130 FD_SET(toProg[1], &obits);
00131 }
00132
00133 tv.tv_sec = 0;
00134 tv.tv_usec = 10000;
00135 nfd = ((fromProg[0] > toProg[1]) ? fromProg[0] : toProg[1]);
00136 if ((rc = select(nfd, &ibits, &obits, NULL, &tv)) < 0) {
00137 if (errno == EINTR)
00138 goto top;
00139 break;
00140 }
00141
00142
00143 if (toProg[1] >= 0 && FD_ISSET(toProg[1], &obits)) {
00144 if (writePtr && writeBytesLeft > 0) {
00145 if ((nbw = write(toProg[1], writePtr,
00146 (1024<writeBytesLeft) ? 1024 : writeBytesLeft)) < 0) {
00147 if (errno != EAGAIN) {
00148 perror("getOutputFrom()");
00149 exit(EXIT_FAILURE);
00150 }
00151 nbw = 0;
00152 }
00153 writeBytesLeft -= nbw;
00154 writePtr += nbw;
00155 } else if (toProg[1] >= 0) {
00156 (void) close(toProg[1]);
00157 toProg[1] = -1;
00158 }
00159 }
00160
00161
00162
00163 { char buf[BUFSIZ+1];
00164 while ((nbr = read(fromProg[0], buf, sizeof(buf)-1)) > 0) {
00165 buf[nbr] = '\0';
00166 appendStringBuf(readBuff, buf);
00167 }
00168 }
00169
00170
00171
00172 done = (nbr == 0 || (nbr < 0 && errno != EAGAIN));
00173
00174 } while (!done);
00175
00176
00177 if (toProg[1] >= 0)
00178 (void) close(toProg[1]);
00179 if (fromProg[0] >= 0)
00180 (void) close(fromProg[0]);
00181
00182 (void) signal(SIGPIPE, oldhandler);
00183
00184
00185
00186 reaped = waitpid(child, &status, 0);
00187 rpmMessage(RPMMESS_DEBUG, _("\twaitpid(%d) rc %d status %x\n"),
00188 (unsigned)child, (unsigned)reaped, status);
00189
00190 if (failNonZero && (!WIFEXITED(status) || WEXITSTATUS(status))) {
00191 rpmError(RPMERR_EXEC, _("%s failed\n"), argv[0]);
00192 return NULL;
00193 }
00194 if (writeBytesLeft) {
00195 rpmError(RPMERR_EXEC, _("failed to write all data to %s\n"), argv[0]);
00196 return NULL;
00197 }
00198 return readBuff;
00199 }
00200
00201 int rpmfcExec(ARGV_t av, StringBuf sb_stdin, StringBuf * sb_stdoutp,
00202 int failnonzero)
00203 {
00204 const char * s = NULL;
00205 ARGV_t xav = NULL;
00206 ARGV_t pav = NULL;
00207 int pac = 0;
00208 int ec = -1;
00209 StringBuf sb = NULL;
00210 const char * buf_stdin = NULL;
00211 int buf_stdin_len = 0;
00212 int xx;
00213
00214 if (sb_stdoutp)
00215 *sb_stdoutp = NULL;
00216 if (!(av && *av))
00217 goto exit;
00218
00219
00220 s = rpmExpand(av[0], NULL);
00221 if (!(s && *s))
00222 goto exit;
00223
00224
00225 pac = 0;
00226 xx = poptParseArgvString(s, &pac, (const char ***)&pav);
00227 if (!(xx == 0 && pac > 0 && pav != NULL))
00228 goto exit;
00229
00230
00231 xav = NULL;
00232
00233 xx = argvAppend(&xav, pav);
00234 if (av[1])
00235 xx = rpmfcExpandAppend(&xav, av + 1);
00236
00237
00238 if (sb_stdin != NULL) {
00239 buf_stdin = getStringBuf(sb_stdin);
00240 buf_stdin_len = strlen(buf_stdin);
00241 }
00242
00243
00244 sb = getOutputFrom(NULL, xav, buf_stdin, buf_stdin_len, failnonzero);
00245
00246
00247 if (sb_stdoutp != NULL) {
00248 *sb_stdoutp = sb;
00249 sb = NULL;
00250 }
00251
00252
00253 ec = 0;
00254
00255 exit:
00256 sb = freeStringBuf(sb);
00257 xav = argvFree(xav);
00258 pav = _free(pav);
00259 s = _free(s);
00260 return ec;
00261 }
00262
00265 static int rpmfcSaveArg( ARGV_t * argvp, const char * key)
00266
00267
00268 {
00269 int rc = 0;
00270
00271 if (argvSearch(*argvp, key, NULL) == NULL) {
00272 rc = argvAdd(argvp, key);
00273 rc = argvSort(*argvp, NULL);
00274 }
00275 return rc;
00276 }
00277
00278 static char * rpmfcFileDep( char * buf, int ix,
00279 rpmds ds)
00280
00281
00282
00283 {
00284 int_32 tagN = rpmdsTagN(ds);
00285 char deptype = 'X';
00286
00287 buf[0] = '\0';
00288 switch (tagN) {
00289 case RPMTAG_PROVIDENAME:
00290 deptype = 'P';
00291 break;
00292 case RPMTAG_REQUIRENAME:
00293 deptype = 'R';
00294 break;
00295 }
00296
00297 if (ds != NULL)
00298 sprintf(buf, "%08d%c %s %s 0x%08x", ix, deptype,
00299 rpmdsN(ds), rpmdsEVR(ds), rpmdsFlags(ds));
00300
00301 return buf;
00302 };
00303
00311 static int rpmfcHelper(rpmfc fc, unsigned char deptype, const char * nsdep)
00312
00313
00314 {
00315 const char * fn = fc->fn[fc->ix];
00316 char buf[BUFSIZ];
00317 StringBuf sb_stdout = NULL;
00318 StringBuf sb_stdin;
00319 const char *av[2];
00320 rpmds * depsp, ds;
00321 const char * N;
00322 const char * EVR;
00323 int_32 Flags, dsContext, tagN;
00324 ARGV_t pav;
00325 const char * s;
00326 int pac;
00327 int xx;
00328 int i;
00329
00330 switch (deptype) {
00331 default:
00332 return -1;
00333 break;
00334 case 'P':
00335 if (fc->skipProv)
00336 return 0;
00337 xx = snprintf(buf, sizeof(buf), "%%{?__%s_provides}", nsdep);
00338 depsp = &fc->provides;
00339 dsContext = RPMSENSE_FIND_PROVIDES;
00340 tagN = RPMTAG_PROVIDENAME;
00341 break;
00342 case 'R':
00343 if (fc->skipReq)
00344 return 0;
00345 xx = snprintf(buf, sizeof(buf), "%%{?__%s_requires}", nsdep);
00346 depsp = &fc->requires;
00347 dsContext = RPMSENSE_FIND_REQUIRES;
00348 tagN = RPMTAG_REQUIRENAME;
00349 break;
00350 }
00351 buf[sizeof(buf)-1] = '\0';
00352 av[0] = buf;
00353 av[1] = NULL;
00354
00355 sb_stdin = newStringBuf();
00356 appendLineStringBuf(sb_stdin, fn);
00357 sb_stdout = NULL;
00358
00359 xx = rpmfcExec(av, sb_stdin, &sb_stdout, 0);
00360
00361 sb_stdin = freeStringBuf(sb_stdin);
00362
00363 if (xx == 0 && sb_stdout != NULL) {
00364 pav = NULL;
00365 xx = argvSplit(&pav, getStringBuf(sb_stdout), " \t\n\r");
00366 pac = argvCount(pav);
00367 if (pav)
00368 for (i = 0; i < pac; i++) {
00369 N = pav[i];
00370 EVR = "";
00371 Flags = dsContext;
00372
00373 if (pav[i+1] && strchr("=<>", *pav[i+1])) {
00374 i++;
00375 for (s = pav[i]; *s; s++) {
00376 switch(*s) {
00377 default:
00378 assert(*s != '\0');
00379 break;
00380 case '=':
00381 Flags |= RPMSENSE_EQUAL;
00382 break;
00383 case '<':
00384 Flags |= RPMSENSE_LESS;
00385 break;
00386 case '>':
00387 Flags |= RPMSENSE_GREATER;
00388 break;
00389 }
00390 }
00391 i++;
00392 EVR = pav[i];
00393 assert(EVR != NULL);
00394 }
00395
00396
00397
00398
00399 if (!fc->tracked && deptype == 'P' && *EVR != '\0') {
00400 ds = rpmdsSingle(RPMTAG_REQUIRENAME,
00401 "rpmlib(VersionedDependencies)", "3.0.3-1",
00402 RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL));
00403 xx = rpmdsMerge(&fc->requires, ds);
00404 ds = rpmdsFree(ds);
00405 fc->tracked = 1;
00406 }
00407
00408 ds = rpmdsSingle(tagN, N, EVR, Flags);
00409
00410
00411 xx = rpmdsMerge(depsp, ds);
00412
00413
00414
00415 xx = rpmfcSaveArg(&fc->ddict, rpmfcFileDep(buf, fc->ix, ds));
00416
00417
00418 ds = rpmdsFree(ds);
00419 }
00420
00421 pav = argvFree(pav);
00422 }
00423 sb_stdout = freeStringBuf(sb_stdout);
00424
00425 return 0;
00426 }
00427
00430
00431 static struct rpmfcTokens_s rpmfcTokens[] = {
00432 { "directory", RPMFC_DIRECTORY|RPMFC_INCLUDE },
00433
00434 { " shared object", RPMFC_LIBRARY },
00435 { " executable", RPMFC_EXECUTABLE },
00436 { " statically linked", RPMFC_STATIC },
00437 { " not stripped", RPMFC_NOTSTRIPPED },
00438 { " archive", RPMFC_ARCHIVE },
00439
00440 { "ELF 32-bit", RPMFC_ELF32|RPMFC_INCLUDE },
00441 { "ELF 64-bit", RPMFC_ELF64|RPMFC_INCLUDE },
00442
00443 { " script", RPMFC_SCRIPT },
00444 { " text", RPMFC_TEXT },
00445 { " document", RPMFC_DOCUMENT },
00446
00447 { " compressed", RPMFC_COMPRESSED },
00448
00449 { "troff or preprocessor input", RPMFC_MANPAGE },
00450
00451 { "perl script text", RPMFC_PERL|RPMFC_INCLUDE },
00452 { "Perl5 module source text", RPMFC_PERL|RPMFC_MODULE|RPMFC_INCLUDE },
00453
00454 { "current ar archive", RPMFC_STATIC|RPMFC_LIBRARY|RPMFC_ARCHIVE|RPMFC_INCLUDE },
00455
00456 { "Zip archive data", RPMFC_COMPRESSED|RPMFC_ARCHIVE|RPMFC_INCLUDE },
00457 { "tar archive", RPMFC_ARCHIVE|RPMFC_INCLUDE },
00458 { "cpio archive", RPMFC_ARCHIVE|RPMFC_INCLUDE },
00459 { "RPM v3", RPMFC_ARCHIVE|RPMFC_INCLUDE },
00460
00461 { " image", RPMFC_IMAGE|RPMFC_INCLUDE },
00462 { " font", RPMFC_FONT|RPMFC_INCLUDE },
00463 { " Font", RPMFC_FONT|RPMFC_INCLUDE },
00464
00465 { " commands", RPMFC_SCRIPT|RPMFC_INCLUDE },
00466 { " script", RPMFC_SCRIPT|RPMFC_INCLUDE },
00467
00468 { "python compiled", RPMFC_WHITE|RPMFC_INCLUDE },
00469
00470 { "empty", RPMFC_WHITE|RPMFC_INCLUDE },
00471
00472 { "HTML", RPMFC_WHITE|RPMFC_INCLUDE },
00473 { "SGML", RPMFC_WHITE|RPMFC_INCLUDE },
00474 { "XML", RPMFC_WHITE|RPMFC_INCLUDE },
00475
00476 { " program text", RPMFC_WHITE|RPMFC_INCLUDE },
00477 { " source", RPMFC_WHITE|RPMFC_INCLUDE },
00478 { "GLS_BINARY_LSB_FIRST", RPMFC_WHITE|RPMFC_INCLUDE },
00479 { " DB ", RPMFC_WHITE|RPMFC_INCLUDE },
00480
00481 { "ASCII English text", RPMFC_WHITE|RPMFC_INCLUDE },
00482 { "ASCII text", RPMFC_WHITE|RPMFC_INCLUDE },
00483 { "ISO-8859 text", RPMFC_WHITE|RPMFC_INCLUDE },
00484
00485 { "symbolic link to", RPMFC_SYMLINK },
00486 { "socket", RPMFC_DEVICE },
00487 { "special", RPMFC_DEVICE },
00488
00489 { "ASCII", RPMFC_WHITE },
00490 { "ISO-8859", RPMFC_WHITE },
00491
00492 { "data", RPMFC_WHITE },
00493
00494 { "application", RPMFC_WHITE },
00495 { "boot", RPMFC_WHITE },
00496 { "catalog", RPMFC_WHITE },
00497 { "code", RPMFC_WHITE },
00498 { "file", RPMFC_WHITE },
00499 { "format", RPMFC_WHITE },
00500 { "message", RPMFC_WHITE },
00501 { "program", RPMFC_WHITE },
00502
00503 { "broken symbolic link to ", RPMFC_WHITE|RPMFC_ERROR },
00504 { "can't read", RPMFC_WHITE|RPMFC_ERROR },
00505 { "can't stat", RPMFC_WHITE|RPMFC_ERROR },
00506 { "executable, can't read", RPMFC_WHITE|RPMFC_ERROR },
00507 { "core file", RPMFC_WHITE|RPMFC_ERROR },
00508
00509 { NULL, RPMFC_BLACK }
00510 };
00511
00512 int rpmfcColoring(const char * fmstr)
00513 {
00514 rpmfcToken fct;
00515 int fcolor = RPMFC_BLACK;
00516
00517 for (fct = rpmfcTokens; fct->token != NULL; fct++) {
00518 if (strstr(fmstr, fct->token) == NULL)
00519 continue;
00520 fcolor |= fct->colors;
00521 if (fcolor & RPMFC_INCLUDE)
00522 return fcolor;
00523 }
00524 return fcolor;
00525 }
00526
00527 void rpmfcPrint(const char * msg, rpmfc fc, FILE * fp)
00528 {
00529 int fcolor;
00530 int ndx;
00531 int cx;
00532 int dx;
00533 int fx;
00534
00535 int nprovides;
00536 int nrequires;
00537
00538 if (fp == NULL) fp = stderr;
00539
00540 if (msg)
00541 fprintf(fp, "===================================== %s\n", msg);
00542
00543 nprovides = rpmdsCount(fc->provides);
00544 nrequires = rpmdsCount(fc->requires);
00545
00546 if (fc)
00547 for (fx = 0; fx < fc->nfiles; fx++) {
00548 assert(fx < fc->fcdictx->nvals);
00549 cx = fc->fcdictx->vals[fx];
00550 assert(fx < fc->fcolor->nvals);
00551 fcolor = fc->fcolor->vals[fx];
00552
00553 fprintf(fp, "%3d %s", fx, fc->fn[fx]);
00554 if (fcolor != RPMFC_BLACK)
00555 fprintf(fp, "\t0x%x", fc->fcolor->vals[fx]);
00556 else
00557 fprintf(fp, "\t%s", fc->cdict[cx]);
00558 fprintf(fp, "\n");
00559
00560 if (fc->fddictx == NULL || fc->fddictn == NULL)
00561 continue;
00562
00563 assert(fx < fc->fddictx->nvals);
00564 dx = fc->fddictx->vals[fx];
00565 assert(fx < fc->fddictn->nvals);
00566 ndx = fc->fddictn->vals[fx];
00567
00568 while (ndx-- > 0) {
00569 const char * depval;
00570 unsigned char deptype;
00571 unsigned ix;
00572
00573 ix = fc->ddictx->vals[dx++];
00574 deptype = ((ix >> 24) & 0xff);
00575 ix &= 0x00ffffff;
00576 depval = NULL;
00577 switch (deptype) {
00578 default:
00579 assert(depval != NULL);
00580 break;
00581 case 'P':
00582 if (nprovides > 0) {
00583 assert(ix < nprovides);
00584 (void) rpmdsSetIx(fc->provides, ix-1);
00585 if (rpmdsNext(fc->provides) >= 0)
00586 depval = rpmdsDNEVR(fc->provides);
00587 }
00588 break;
00589 case 'R':
00590 if (nrequires > 0) {
00591 assert(ix < nrequires);
00592 (void) rpmdsSetIx(fc->requires, ix-1);
00593 if (rpmdsNext(fc->requires) >= 0)
00594 depval = rpmdsDNEVR(fc->requires);
00595 }
00596 break;
00597 }
00598 if (depval)
00599 fprintf(fp, "\t%s\n", depval);
00600 }
00601 }
00602 }
00603
00604 rpmfc rpmfcFree(rpmfc fc)
00605 {
00606 if (fc) {
00607 fc->fn = argvFree(fc->fn);
00608 fc->fcolor = argiFree(fc->fcolor);
00609 fc->fcdictx = argiFree(fc->fcdictx);
00610 fc->fddictx = argiFree(fc->fddictx);
00611 fc->fddictn = argiFree(fc->fddictn);
00612 fc->cdict = argvFree(fc->cdict);
00613 fc->ddict = argvFree(fc->ddict);
00614 fc->ddictx = argiFree(fc->ddictx);
00615
00616 fc->provides = rpmdsFree(fc->provides);
00617 fc->requires = rpmdsFree(fc->requires);
00618
00619 fc->sb_java = freeStringBuf(fc->sb_java);
00620 fc->sb_perl = freeStringBuf(fc->sb_perl);
00621 fc->sb_python = freeStringBuf(fc->sb_python);
00622
00623 }
00624 fc = _free(fc);
00625 return NULL;
00626 }
00627
00628 rpmfc rpmfcNew(void)
00629 {
00630 rpmfc fc = xcalloc(1, sizeof(*fc));
00631 return fc;
00632 }
00633
00639 static int rpmfcSCRIPT(rpmfc fc)
00640
00641
00642 {
00643 const char * fn = fc->fn[fc->ix];
00644 const char * bn;
00645 rpmds ds;
00646 char buf[BUFSIZ];
00647 FILE * fp;
00648 char * s, * se;
00649 int i;
00650 struct stat sb, * st = &sb;
00651 int is_executable;
00652 int xx;
00653
00654
00655 if (stat(fn, st) < 0)
00656 return -1;
00657 is_executable = (st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH));
00658
00659 fp = fopen(fn, "r");
00660 if (fp == NULL || ferror(fp)) {
00661 if (fp) (void) fclose(fp);
00662 return -1;
00663 }
00664
00665
00666
00667 for (i = 0; i < 10; i++) {
00668
00669 s = fgets(buf, sizeof(buf) - 1, fp);
00670 if (s == NULL || ferror(fp) || feof(fp))
00671 break;
00672 s[sizeof(buf)-1] = '\0';
00673 if (!(s[0] == '#' && s[1] == '!'))
00674 continue;
00675 s += 2;
00676
00677 while (*s && strchr(" \t\n\r", *s) != NULL)
00678 s++;
00679 if (*s == '\0')
00680 continue;
00681 if (*s != '/')
00682 continue;
00683
00684 for (se = s+1; *se; se++) {
00685 if (strchr(" \t\n\r", *se) != NULL)
00686 break;
00687 }
00688 *se = '\0';
00689 se++;
00690
00691 if (is_executable) {
00692
00693 ds = rpmdsSingle(RPMTAG_REQUIRENAME, s, "", RPMSENSE_FIND_REQUIRES);
00694 xx = rpmdsMerge(&fc->requires, ds);
00695
00696
00697 xx = rpmfcSaveArg(&fc->ddict, rpmfcFileDep(se, fc->ix, ds));
00698
00699 ds = rpmdsFree(ds);
00700 }
00701
00702
00703 bn = basename(s);
00704 if (!strcmp(bn, "perl"))
00705 fc->fcolor->vals[fc->ix] |= RPMFC_PERL;
00706 else if (!strcmp(bn, "python"))
00707 fc->fcolor->vals[fc->ix] |= RPMFC_PYTHON;
00708
00709 break;
00710 }
00711
00712
00713 (void) fclose(fp);
00714
00715 if (fc->fcolor->vals[fc->ix] & RPMFC_PERL) {
00716 if (fc->fcolor->vals[fc->ix] & RPMFC_MODULE)
00717 xx = rpmfcHelper(fc, 'P', "perl");
00718 if (is_executable || (fc->fcolor->vals[fc->ix] & RPMFC_MODULE))
00719 xx = rpmfcHelper(fc, 'R', "perl");
00720 }
00721 if (fc->fcolor->vals[fc->ix] & RPMFC_PYTHON) {
00722 xx = rpmfcHelper(fc, 'P', "python");
00723 if (is_executable)
00724 xx = rpmfcHelper(fc, 'R', "python");
00725 }
00726
00727 return 0;
00728 }
00729
00735 static int rpmfcELF(rpmfc fc)
00736
00737
00738 {
00739 #if HAVE_GELF_H && HAVE_LIBELF
00740 const char * fn = fc->fn[fc->ix];
00741 Elf * elf;
00742 Elf_Scn * scn;
00743 Elf_Data * data;
00744 GElf_Ehdr ehdr_mem, * ehdr;
00745 GElf_Shdr shdr_mem, * shdr;
00746 GElf_Verdef def_mem, * def;
00747 GElf_Verneed need_mem, * need;
00748 GElf_Dyn dyn_mem, * dyn;
00749 unsigned int auxoffset;
00750 unsigned int offset;
00751 int fdno;
00752 int cnt2;
00753 int cnt;
00754 char buf[BUFSIZ];
00755 const char * s;
00756 struct stat sb, * st = &sb;
00757 const char * soname = NULL;
00758 rpmds * depsp, ds;
00759 int_32 tagN, dsContext;
00760 char * t;
00761 int xx;
00762 int isElf64;
00763 int isDSO;
00764 int gotSONAME = 0;
00765 static int filter_GLIBC_PRIVATE = 0;
00766 static int oneshot = 0;
00767
00768 if (oneshot == 0) {
00769 oneshot = 1;
00770 filter_GLIBC_PRIVATE = rpmExpandNumeric("%{?_filter_GLIBC_PRIVATE}");
00771 }
00772
00773
00774 if (stat(fn, st) != 0)
00775 return(-1);
00776
00777 fdno = open(fn, O_RDONLY);
00778 if (fdno < 0)
00779 return fdno;
00780
00781 (void) elf_version(EV_CURRENT);
00782
00783
00784 elf = NULL;
00785 if ((elf = elf_begin (fdno, ELF_C_READ, NULL)) == NULL
00786 || elf_kind(elf) != ELF_K_ELF
00787 || (ehdr = gelf_getehdr(elf, &ehdr_mem)) == NULL
00788 || !(ehdr->e_type == ET_DYN || ehdr->e_type == ET_EXEC))
00789 goto exit;
00790
00791
00792 isElf64 = ehdr->e_ident[EI_CLASS] == ELFCLASS64;
00793 isDSO = ehdr->e_type == ET_DYN;
00794
00795
00796 scn = NULL;
00797 while ((scn = elf_nextscn(elf, scn)) != NULL) {
00798 shdr = gelf_getshdr(scn, &shdr_mem);
00799 if (shdr == NULL)
00800 break;
00801
00802 soname = _free(soname);
00803 switch (shdr->sh_type) {
00804 default:
00805 continue;
00806 break;
00807 case SHT_GNU_verdef:
00808 data = NULL;
00809 if (!fc->skipProv)
00810 while ((data = elf_getdata (scn, data)) != NULL) {
00811 offset = 0;
00812 for (cnt = shdr->sh_info; --cnt >= 0; ) {
00813
00814 def = gelf_getverdef (data, offset, &def_mem);
00815 if (def == NULL)
00816 break;
00817 auxoffset = offset + def->vd_aux;
00818 for (cnt2 = def->vd_cnt; --cnt2 >= 0; ) {
00819 GElf_Verdaux aux_mem, * aux;
00820
00821 aux = gelf_getverdaux (data, auxoffset, &aux_mem);
00822 if (aux == NULL)
00823 break;
00824
00825 s = elf_strptr(elf, shdr->sh_link, aux->vda_name);
00826 if (s == NULL)
00827 break;
00828 if (def->vd_flags & VER_FLG_BASE) {
00829 soname = _free(soname);
00830 soname = xstrdup(s);
00831 auxoffset += aux->vda_next;
00832 continue;
00833 } else
00834 if (soname != NULL
00835 && !(filter_GLIBC_PRIVATE != 0
00836 && !strcmp(s, "GLIBC_PRIVATE")))
00837 {
00838 buf[0] = '\0';
00839 t = buf;
00840 t = stpcpy( stpcpy( stpcpy( stpcpy(t, soname), "("), s), ")");
00841
00842 #if !defined(__alpha__)
00843 if (isElf64)
00844 t = stpcpy(t, "(64bit)");
00845 #endif
00846 t++;
00847
00848
00849 ds = rpmdsSingle(RPMTAG_PROVIDES,
00850 buf, "", RPMSENSE_FIND_PROVIDES);
00851 xx = rpmdsMerge(&fc->provides, ds);
00852
00853
00854 xx = rpmfcSaveArg(&fc->ddict,
00855 rpmfcFileDep(t, fc->ix, ds));
00856
00857 ds = rpmdsFree(ds);
00858 }
00859 auxoffset += aux->vda_next;
00860 }
00861 offset += def->vd_next;
00862 }
00863 }
00864 break;
00865 case SHT_GNU_verneed:
00866 data = NULL;
00867
00868 if (!fc->skipReq && (st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
00869 while ((data = elf_getdata (scn, data)) != NULL) {
00870 offset = 0;
00871 for (cnt = shdr->sh_info; --cnt >= 0; ) {
00872 need = gelf_getverneed (data, offset, &need_mem);
00873 if (need == NULL)
00874 break;
00875
00876 s = elf_strptr(elf, shdr->sh_link, need->vn_file);
00877 if (s == NULL)
00878 break;
00879 soname = _free(soname);
00880 soname = xstrdup(s);
00881 auxoffset = offset + need->vn_aux;
00882 for (cnt2 = need->vn_cnt; --cnt2 >= 0; ) {
00883 GElf_Vernaux aux_mem, * aux;
00884
00885 aux = gelf_getvernaux (data, auxoffset, &aux_mem);
00886 if (aux == NULL)
00887 break;
00888
00889 s = elf_strptr(elf, shdr->sh_link, aux->vna_name);
00890 if (s == NULL)
00891 break;
00892
00893
00894 if (soname != NULL
00895 && !(filter_GLIBC_PRIVATE != 0
00896 && !strcmp(s, "GLIBC_PRIVATE")))
00897 {
00898 buf[0] = '\0';
00899 t = buf;
00900 t = stpcpy( stpcpy( stpcpy( stpcpy(t, soname), "("), s), ")");
00901
00902 #if !defined(__alpha__)
00903 if (isElf64)
00904 t = stpcpy(t, "(64bit)");
00905 #endif
00906 t++;
00907
00908
00909 ds = rpmdsSingle(RPMTAG_REQUIRENAME,
00910 buf, "", RPMSENSE_FIND_REQUIRES);
00911 xx = rpmdsMerge(&fc->requires, ds);
00912
00913
00914 xx = rpmfcSaveArg(&fc->ddict,
00915 rpmfcFileDep(t, fc->ix, ds));
00916 ds = rpmdsFree(ds);
00917 }
00918 auxoffset += aux->vna_next;
00919 }
00920 offset += need->vn_next;
00921 }
00922 }
00923 break;
00924 case SHT_DYNAMIC:
00925 data = NULL;
00926 while ((data = elf_getdata (scn, data)) != NULL) {
00927
00928 for (cnt = 0; cnt < (shdr->sh_size / shdr->sh_entsize); ++cnt) {
00929 dyn = gelf_getdyn (data, cnt, &dyn_mem);
00930 if (dyn == NULL)
00931 break;
00932 s = NULL;
00933 switch (dyn->d_tag) {
00934 default:
00935 continue;
00936 break;
00937 case DT_NEEDED:
00938
00939 if (fc->skipReq || !(st->st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
00940 continue;
00941
00942 depsp = &fc->requires;
00943 tagN = RPMTAG_REQUIRENAME;
00944 dsContext = RPMSENSE_FIND_REQUIRES;
00945 s = elf_strptr(elf, shdr->sh_link, dyn->d_un.d_val);
00946 assert(s != NULL);
00947 break;
00948 case DT_SONAME:
00949 gotSONAME = 1;
00950
00951 if (fc->skipProv)
00952 continue;
00953 depsp = &fc->provides;
00954 tagN = RPMTAG_PROVIDENAME;
00955 dsContext = RPMSENSE_FIND_PROVIDES;
00956 s = elf_strptr(elf, shdr->sh_link, dyn->d_un.d_val);
00957 assert(s != NULL);
00958 break;
00959 }
00960 if (s == NULL)
00961 continue;
00962
00963 buf[0] = '\0';
00964 t = buf;
00965 t = stpcpy(t, s);
00966
00967 #if !defined(__alpha__)
00968 if (isElf64)
00969 t = stpcpy(t, "()(64bit)");
00970 #endif
00971 t++;
00972
00973
00974 ds = rpmdsSingle(tagN, buf, "", dsContext);
00975 xx = rpmdsMerge(depsp, ds);
00976
00977
00978 xx = rpmfcSaveArg(&fc->ddict,
00979 rpmfcFileDep(t, fc->ix, ds));
00980
00981 ds = rpmdsFree(ds);
00982 }
00983
00984 }
00985 break;
00986 }
00987 }
00988
00989
00990
00991 if (!fc->skipProv && isDSO && !gotSONAME) {
00992 depsp = &fc->provides;
00993 tagN = RPMTAG_PROVIDENAME;
00994 dsContext = RPMSENSE_FIND_PROVIDES;
00995
00996 s = strrchr(fn, '/');
00997 if (s)
00998 s++;
00999 else
01000 s = fn;
01001
01002
01003 buf[0] = '\0';
01004 t = buf;
01005
01006 t = stpcpy(t, s);
01007
01008
01009 #if !defined(__alpha__)
01010 if (isElf64)
01011 t = stpcpy(t, "()(64bit)");
01012 #endif
01013
01014 t++;
01015
01016
01017 ds = rpmdsSingle(tagN, buf, "", dsContext);
01018 xx = rpmdsMerge(depsp, ds);
01019
01020
01021
01022 xx = rpmfcSaveArg(&fc->ddict, rpmfcFileDep(t, fc->ix, ds));
01023
01024
01025 ds = rpmdsFree(ds);
01026 }
01027
01028 exit:
01029 soname = _free(soname);
01030 if (elf) (void) elf_end(elf);
01031 xx = close(fdno);
01032 return 0;
01033 #else
01034 return -1;
01035 #endif
01036 }
01037
01038 typedef struct rpmfcApplyTbl_s {
01039 int (*func) (rpmfc fc);
01040 int colormask;
01041 } * rpmfcApplyTbl;
01042
01045
01046 static struct rpmfcApplyTbl_s rpmfcApplyTable[] = {
01047 { rpmfcELF, RPMFC_ELF },
01048 { rpmfcSCRIPT, (RPMFC_SCRIPT|RPMFC_PERL) },
01049 { NULL, 0 }
01050 };
01051
01052 int rpmfcApply(rpmfc fc)
01053 {
01054 rpmfcApplyTbl fcat;
01055 const char * s;
01056 char * se;
01057 rpmds ds;
01058 const char * N;
01059 const char * EVR;
01060 int_32 Flags;
01061 unsigned char deptype;
01062 int nddict;
01063 int previx;
01064 unsigned int val;
01065 int dix;
01066 int ix;
01067 int i;
01068 int xx;
01069
01070
01071 for (fc->ix = 0; fc->fn[fc->ix] != NULL; fc->ix++) {
01072
01073 for (fcat = rpmfcApplyTable; fcat->func != NULL; fcat++) {
01074 if (!(fc->fcolor->vals[fc->ix] & fcat->colormask))
01075 continue;
01076 xx = (*fcat->func) (fc);
01077 }
01078 }
01079
01080
01081
01082 nddict = argvCount(fc->ddict);
01083 previx = -1;
01084 for (i = 0; i < nddict; i++) {
01085 s = fc->ddict[i];
01086
01087
01088 ix = strtol(s, &se, 10);
01089 assert(se != NULL);
01090 deptype = *se++;
01091 se++;
01092 N = se;
01093 while (*se && *se != ' ')
01094 se++;
01095 *se++ = '\0';
01096 EVR = se;
01097 while (*se && *se != ' ')
01098 se++;
01099 *se++ = '\0';
01100 Flags = strtol(se, NULL, 16);
01101
01102 dix = -1;
01103 switch (deptype) {
01104 default:
01105 break;
01106 case 'P':
01107 ds = rpmdsSingle(RPMTAG_PROVIDENAME, N, EVR, Flags);
01108 dix = rpmdsFind(fc->provides, ds);
01109 ds = rpmdsFree(ds);
01110 break;
01111 case 'R':
01112 ds = rpmdsSingle(RPMTAG_REQUIRENAME, N, EVR, Flags);
01113 dix = rpmdsFind(fc->requires, ds);
01114 ds = rpmdsFree(ds);
01115 break;
01116 }
01117
01118
01119 #if 0
01120 assert(dix >= 0);
01121 #else
01122 if (dix < 0)
01123 continue;
01124 #endif
01125
01126 val = (deptype << 24) | (dix & 0x00ffffff);
01127 xx = argiAdd(&fc->ddictx, -1, val);
01128
01129 if (previx != ix) {
01130 previx = ix;
01131 xx = argiAdd(&fc->fddictx, ix, argiCount(fc->ddictx)-1);
01132 }
01133 if (fc->fddictn && fc->fddictn->vals)
01134 fc->fddictn->vals[ix]++;
01135 }
01136
01137
01138 return 0;
01139 }
01140
01141 int rpmfcClassify(rpmfc fc, ARGV_t argv)
01142 {
01143 ARGV_t fcav = NULL;
01144 ARGV_t dav;
01145 const char * s, * se;
01146 size_t slen;
01147 int fcolor;
01148 int xx;
01149 fmagic fm = global_fmagic;
01150 int action = 0;
01151 int wid = 0;
01152
01153 if (fc == NULL || argv == NULL)
01154 return 0;
01155
01156 fc->nfiles = argvCount(argv);
01157
01158
01159 xx = argiAdd(&fc->fddictx, fc->nfiles-1, 0);
01160 xx = argiAdd(&fc->fddictn, fc->nfiles-1, 0);
01161
01162
01163 xx = argvAdd(&fc->cdict, "");
01164 xx = argvAdd(&fc->cdict, "directory");
01165
01166
01167 fm->magicfile = default_magicfile;
01168
01169
01170
01171 xx = fmagicSetup(fm, fm->magicfile, action);
01172 for (fc->ix = 0; fc->ix < fc->nfiles; fc->ix++) {
01173 s = argv[fc->ix];
01174 assert(s != NULL);
01175 slen = strlen(s);
01176
01177 fm->obp = fm->obuf;
01178 *fm->obp = '\0';
01179 fm->nob = sizeof(fm->obuf);
01180 xx = fmagicProcess(fm, s, wid);
01181
01182
01183 if (slen >= sizeof(".pm") && !strcmp(s+slen-(sizeof(".pm")-1), ".pm"))
01184 strcpy(fm->obuf, "Perl5 module source text");
01185
01186 se = fm->obuf;
01187 rpmMessage(RPMMESS_DEBUG, "%s: %s\n", s, se);
01188
01189 xx = argvAdd(&fc->fn, s);
01190 xx = argvAdd(&fcav, se);
01191
01192
01193 fcolor = rpmfcColoring(se);
01194 xx = argiAdd(&fc->fcolor, fc->ix, fcolor);
01195
01196
01197 if (fcolor != RPMFC_WHITE && (fcolor & RPMFC_INCLUDE))
01198 xx = rpmfcSaveArg(&fc->cdict, se);
01199
01200 }
01201
01202
01203 fc->fknown = 0;
01204 for (fc->ix = 0; fc->ix < fc->nfiles; fc->ix++) {
01205 se = fcav[fc->ix];
01206 assert(se != NULL);
01207
01208 dav = argvSearch(fc->cdict, se, NULL);
01209 if (dav) {
01210 xx = argiAdd(&fc->fcdictx, fc->ix, (dav - fc->cdict));
01211 fc->fknown++;
01212 } else {
01213 xx = argiAdd(&fc->fcdictx, fc->ix, 0);
01214 fc->fwhite++;
01215 }
01216 }
01217
01218 fcav = argvFree(fcav);
01219
01220
01221
01222 return 0;
01223 }
01224
01227 typedef struct DepMsg_s * DepMsg_t;
01228
01231 struct DepMsg_s {
01232
01233 const char * msg;
01234
01235 const char * argv[4];
01236 rpmTag ntag;
01237 rpmTag vtag;
01238 rpmTag ftag;
01239 int mask;
01240 int xor;
01241 };
01242
01245
01246 static struct DepMsg_s depMsgs[] = {
01247 { "Provides", { "%{?__find_provides}", NULL, NULL, NULL },
01248 RPMTAG_PROVIDENAME, RPMTAG_PROVIDEVERSION, RPMTAG_PROVIDEFLAGS,
01249 0, -1 },
01250 #ifdef DYING
01251 { "PreReq", { NULL, NULL, NULL, NULL },
01252 RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_REQUIREFLAGS,
01253 RPMSENSE_PREREQ, 0 },
01254 { "Requires(interp)", { NULL, "interp", NULL, NULL },
01255 -1, -1, RPMTAG_REQUIREFLAGS,
01256 _notpre(RPMSENSE_INTERP), 0 },
01257 #else
01258 { "Requires(interp)", { NULL, "interp", NULL, NULL },
01259 RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_REQUIREFLAGS,
01260 _notpre(RPMSENSE_INTERP), 0 },
01261 #endif
01262 { "Requires(rpmlib)", { NULL, "rpmlib", NULL, NULL },
01263 -1, -1, RPMTAG_REQUIREFLAGS,
01264 _notpre(RPMSENSE_RPMLIB), 0 },
01265 { "Requires(verify)", { NULL, "verify", NULL, NULL },
01266 -1, -1, RPMTAG_REQUIREFLAGS,
01267 RPMSENSE_SCRIPT_VERIFY, 0 },
01268 { "Requires(pre)", { NULL, "pre", NULL, NULL },
01269 -1, -1, RPMTAG_REQUIREFLAGS,
01270 _notpre(RPMSENSE_SCRIPT_PRE), 0 },
01271 { "Requires(post)", { NULL, "post", NULL, NULL },
01272 -1, -1, RPMTAG_REQUIREFLAGS,
01273 _notpre(RPMSENSE_SCRIPT_POST), 0 },
01274 { "Requires(preun)", { NULL, "preun", NULL, NULL },
01275 -1, -1, RPMTAG_REQUIREFLAGS,
01276 _notpre(RPMSENSE_SCRIPT_PREUN), 0 },
01277 { "Requires(postun)", { NULL, "postun", NULL, NULL },
01278 -1, -1, RPMTAG_REQUIREFLAGS,
01279 _notpre(RPMSENSE_SCRIPT_POSTUN), 0 },
01280 { "Requires", { "%{?__find_requires}", NULL, NULL, NULL },
01281 -1, -1, RPMTAG_REQUIREFLAGS,
01282 RPMSENSE_PREREQ, RPMSENSE_PREREQ },
01283 { "Conflicts", { "%{?__find_conflicts}", NULL, NULL, NULL },
01284 RPMTAG_CONFLICTNAME, RPMTAG_CONFLICTVERSION, RPMTAG_CONFLICTFLAGS,
01285 0, -1 },
01286 { "Obsoletes", { "%{?__find_obsoletes}", NULL, NULL, NULL },
01287 RPMTAG_OBSOLETENAME, RPMTAG_OBSOLETEVERSION, RPMTAG_OBSOLETEFLAGS,
01288 0, -1 },
01289 { NULL, { NULL, NULL, NULL, NULL }, 0, 0, 0, 0, 0 }
01290 };
01291
01292
01293 static DepMsg_t DepMsgs = depMsgs;
01294
01297 static void printDeps(Header h)
01298
01299 {
01300 DepMsg_t dm;
01301 rpmds ds = NULL;
01302 int scareMem = 0;
01303 const char * DNEVR;
01304 int_32 Flags;
01305 int bingo = 0;
01306
01307 for (dm = DepMsgs; dm->msg != NULL; dm++) {
01308 if (dm->ntag != -1) {
01309 ds = rpmdsFree(ds);
01310 ds = rpmdsNew(h, dm->ntag, scareMem);
01311 }
01312 if (dm->ftag == 0)
01313 continue;
01314
01315 ds = rpmdsInit(ds);
01316 if (ds == NULL)
01317 continue;
01318
01319 bingo = 0;
01320 while (rpmdsNext(ds) >= 0) {
01321
01322 Flags = rpmdsFlags(ds);
01323
01324 if (!((Flags & dm->mask) ^ dm->xor))
01325 continue;
01326 if (bingo == 0) {
01327 rpmMessage(RPMMESS_NORMAL, "%s:", (dm->msg ? dm->msg : ""));
01328 bingo = 1;
01329 }
01330 if ((DNEVR = rpmdsDNEVR(ds)) == NULL)
01331 continue;
01332 rpmMessage(RPMMESS_NORMAL, " %s", DNEVR+2);
01333 }
01334 if (bingo)
01335 rpmMessage(RPMMESS_NORMAL, "\n");
01336 }
01337 ds = rpmdsFree(ds);
01338 }
01339
01342 static int rpmfcGenerateDependsHelper(const Spec spec, Package pkg, rpmfi fi)
01343
01344
01345 {
01346 StringBuf sb_stdin;
01347 StringBuf sb_stdout;
01348 DepMsg_t dm;
01349 int failnonzero = 0;
01350 int rc = 0;
01351
01352
01353
01354
01355 sb_stdin = newStringBuf();
01356 fi = rpmfiInit(fi, 0);
01357 if (fi != NULL)
01358 while (rpmfiNext(fi) >= 0)
01359 appendLineStringBuf(sb_stdin, rpmfiFN(fi));
01360
01361 for (dm = DepMsgs; dm->msg != NULL; dm++) {
01362 int tag, tagflags;
01363 char * s;
01364 int xx;
01365
01366 tag = (dm->ftag > 0) ? dm->ftag : dm->ntag;
01367 tagflags = 0;
01368 s = NULL;
01369
01370 switch(tag) {
01371 case RPMTAG_PROVIDEFLAGS:
01372 if (!pkg->autoProv)
01373 continue;
01374 failnonzero = 1;
01375 tagflags = RPMSENSE_FIND_PROVIDES;
01376 break;
01377 case RPMTAG_REQUIREFLAGS:
01378 if (!pkg->autoReq)
01379 continue;
01380 failnonzero = 0;
01381 tagflags = RPMSENSE_FIND_REQUIRES;
01382 break;
01383 default:
01384 continue;
01385 break;
01386 }
01387
01388
01389 xx = rpmfcExec(dm->argv, sb_stdin, &sb_stdout, failnonzero);
01390
01391 if (xx == -1)
01392 continue;
01393
01394 s = rpmExpand(dm->argv[0], NULL);
01395 rpmMessage(RPMMESS_NORMAL, _("Finding %s: %s\n"), dm->msg,
01396 (s ? s : ""));
01397 s = _free(s);
01398
01399 if (sb_stdout == NULL) {
01400 rc = RPMERR_EXEC;
01401 rpmError(rc, _("Failed to find %s:\n"), dm->msg);
01402 break;
01403 }
01404
01405
01406 rc = parseRCPOT(spec, pkg, getStringBuf(sb_stdout), tag, 0, tagflags);
01407 sb_stdout = freeStringBuf(sb_stdout);
01408
01409 if (rc) {
01410 rpmError(rc, _("Failed to find %s:\n"), dm->msg);
01411 break;
01412 }
01413 }
01414
01415 sb_stdin = freeStringBuf(sb_stdin);
01416
01417 return rc;
01418 }
01419
01420 int rpmfcGenerateDepends(const Spec spec, Package pkg)
01421 {
01422 rpmfi fi = pkg->cpioList;
01423 rpmfc fc = NULL;
01424 rpmds ds;
01425 int scareMem = 0;
01426 ARGV_t av;
01427 int ac = rpmfiFC(fi);
01428 const void ** p;
01429 char buf[BUFSIZ];
01430 const char * N;
01431 const char * EVR;
01432 int genConfigDeps;
01433 int c;
01434 int rc = 0;
01435 int xx;
01436
01437
01438 if (ac <= 0)
01439 return 0;
01440
01441
01442 if (! (pkg->autoReq || pkg->autoProv))
01443 return 0;
01444
01445
01446 if (!rpmExpandNumeric("%{?_use_internal_dependency_generator}")) {
01447
01448 rc = rpmfcGenerateDependsHelper(spec, pkg, fi);
01449 printDeps(pkg->header);
01450 return rc;
01451 }
01452
01453
01454 av = xcalloc(ac+1, sizeof(*av));
01455
01456
01457 genConfigDeps = 0;
01458 fi = rpmfiInit(fi, 0);
01459 if (fi != NULL)
01460 while ((c = rpmfiNext(fi)) >= 0) {
01461 rpmfileAttrs fileAttrs;
01462
01463
01464 fileAttrs = rpmfiFFlags(fi);
01465 genConfigDeps |= (fileAttrs & RPMFILE_CONFIG);
01466
01467 av[c] = xstrdup(rpmfiFN(fi));
01468 }
01469 av[ac] = NULL;
01470
01471
01472 fc = rpmfcNew();
01473 fc->skipProv = !pkg->autoProv;
01474 fc->skipReq = !pkg->autoReq;
01475 fc->tracked = 0;
01476
01477
01478 if (!fc->skipProv) {
01479 ds = rpmdsNew(pkg->header, RPMTAG_PROVIDENAME, scareMem);
01480 xx = rpmdsMerge(&fc->provides, ds);
01481 ds = rpmdsFree(ds);
01482 xx = headerRemoveEntry(pkg->header, RPMTAG_PROVIDENAME);
01483 xx = headerRemoveEntry(pkg->header, RPMTAG_PROVIDEVERSION);
01484 xx = headerRemoveEntry(pkg->header, RPMTAG_PROVIDEFLAGS);
01485
01486
01487 if (genConfigDeps) {
01488 N = rpmdsN(pkg->ds);
01489 assert(N != NULL);
01490 EVR = rpmdsEVR(pkg->ds);
01491 assert(EVR != NULL);
01492 sprintf(buf, "config(%s)", N);
01493 ds = rpmdsSingle(RPMTAG_PROVIDENAME, buf, EVR,
01494 (RPMSENSE_EQUAL|RPMSENSE_CONFIG));
01495 xx = rpmdsMerge(&fc->provides, ds);
01496 ds = rpmdsFree(ds);
01497 }
01498 }
01499
01500 if (!fc->skipReq) {
01501 ds = rpmdsNew(pkg->header, RPMTAG_REQUIRENAME, scareMem);
01502 xx = rpmdsMerge(&fc->requires, ds);
01503 ds = rpmdsFree(ds);
01504 xx = headerRemoveEntry(pkg->header, RPMTAG_REQUIRENAME);
01505 xx = headerRemoveEntry(pkg->header, RPMTAG_REQUIREVERSION);
01506 xx = headerRemoveEntry(pkg->header, RPMTAG_REQUIREFLAGS);
01507
01508
01509 if (genConfigDeps) {
01510 N = rpmdsN(pkg->ds);
01511 assert(N != NULL);
01512 EVR = rpmdsEVR(pkg->ds);
01513 assert(EVR != NULL);
01514 sprintf(buf, "config(%s)", N);
01515 ds = rpmdsSingle(RPMTAG_REQUIRENAME, buf, EVR,
01516 (RPMSENSE_EQUAL|RPMSENSE_CONFIG));
01517 xx = rpmdsMerge(&fc->requires, ds);
01518 ds = rpmdsFree(ds);
01519 }
01520 }
01521
01522
01523 xx = rpmfcClassify(fc, av);
01524
01525
01526 xx = rpmfcApply(fc);
01527
01528
01529 p = (const void **) argiData(fc->fcolor);
01530 c = argiCount(fc->fcolor);
01531 assert(ac == c);
01532 if (p != NULL && c > 0) {
01533 int_32 * fcolors = (int_32 *)p;
01534 int i;
01535
01536
01537 for (i = 0; i < c; i++)
01538 fcolors[i] &= 0x0f;
01539 xx = headerAddEntry(pkg->header, RPMTAG_FILECOLORS, RPM_INT32_TYPE,
01540 p, c);
01541 }
01542
01543
01544 p = (const void **) argvData(fc->cdict);
01545 c = argvCount(fc->cdict);
01546 if (p != NULL && c > 0)
01547 xx = headerAddEntry(pkg->header, RPMTAG_CLASSDICT, RPM_STRING_ARRAY_TYPE,
01548 p, c);
01549
01550
01551 p = (const void **) argiData(fc->fcdictx);
01552 c = argiCount(fc->fcdictx);
01553 assert(ac == c);
01554 if (p != NULL && c > 0)
01555 xx = headerAddEntry(pkg->header, RPMTAG_FILECLASS, RPM_INT32_TYPE,
01556 p, c);
01557
01558
01559
01560 if (fc->provides != NULL && (c = rpmdsCount(fc->provides)) > 0 && !fc->skipProv) {
01561 p = (const void **) fc->provides->N;
01562 xx = headerAddEntry(pkg->header, RPMTAG_PROVIDENAME, RPM_STRING_ARRAY_TYPE,
01563 p, c);
01564
01565
01566 p = (const void **) fc->provides->EVR;
01567 assert(p != NULL);
01568 xx = headerAddEntry(pkg->header, RPMTAG_PROVIDEVERSION, RPM_STRING_ARRAY_TYPE,
01569 p, c);
01570 p = (const void **) fc->provides->Flags;
01571 assert(p != NULL);
01572 xx = headerAddEntry(pkg->header, RPMTAG_PROVIDEFLAGS, RPM_INT32_TYPE,
01573 p, c);
01574
01575 }
01576
01577
01578
01579
01580 if (fc->requires != NULL && (c = rpmdsCount(fc->requires)) > 0 && !fc->skipReq) {
01581 p = (const void **) fc->requires->N;
01582 xx = headerAddEntry(pkg->header, RPMTAG_REQUIRENAME, RPM_STRING_ARRAY_TYPE,
01583 p, c);
01584
01585
01586 p = (const void **) fc->requires->EVR;
01587 assert(p != NULL);
01588 xx = headerAddEntry(pkg->header, RPMTAG_REQUIREVERSION, RPM_STRING_ARRAY_TYPE,
01589 p, c);
01590 p = (const void **) fc->requires->Flags;
01591 assert(p != NULL);
01592 xx = headerAddEntry(pkg->header, RPMTAG_REQUIREFLAGS, RPM_INT32_TYPE,
01593 p, c);
01594
01595 }
01596
01597
01598
01599 p = (const void **) argiData(fc->ddictx);
01600 c = argiCount(fc->ddictx);
01601 if (p != NULL)
01602 xx = headerAddEntry(pkg->header, RPMTAG_DEPENDSDICT, RPM_INT32_TYPE,
01603 p, c);
01604
01605
01606 p = (const void **) argiData(fc->fddictx);
01607 c = argiCount(fc->fddictx);
01608 assert(ac == c);
01609 if (p != NULL)
01610 xx = headerAddEntry(pkg->header, RPMTAG_FILEDEPENDSX, RPM_INT32_TYPE,
01611 p, c);
01612
01613 p = (const void **) argiData(fc->fddictn);
01614 c = argiCount(fc->fddictn);
01615 assert(ac == c);
01616 if (p != NULL)
01617 xx = headerAddEntry(pkg->header, RPMTAG_FILEDEPENDSN, RPM_INT32_TYPE,
01618 p, c);
01619
01620 printDeps(pkg->header);
01621
01622 if (fc != NULL && _rpmfc_debug) {
01623 char msg[BUFSIZ];
01624 sprintf(msg, "final: files %d cdict[%d] %d%% ddictx[%d]", fc->nfiles, argvCount(fc->cdict), ((100 * fc->fknown)/fc->nfiles), argiCount(fc->ddictx));
01625 rpmfcPrint(msg, fc, NULL);
01626 }
01627
01628
01629 fc = rpmfcFree(fc);
01630 av = argvFree(av);
01631
01632 return rc;
01633 }