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