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