~ubuntu-branches/ubuntu/precise/rpm/precise-proposed

« back to all changes in this revision

Viewing changes to build/rpmfc.c

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-06-28 11:12:30 UTC
  • mfrom: (17.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100628111230-8ggjjhgpvrnr3ybx
Tags: 4.8.1-5
Fix compilation on hurd and kfreebsd (Closes: #587366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "system.h"
2
2
 
3
3
#include <signal.h>
 
4
#include <magic.h>
 
5
 
4
6
#if HAVE_GELF_H
5
7
#include <gelf.h>
6
8
 
45
47
 
46
48
    rpmds provides;     /*!< (no. provides) package provides */
47
49
    rpmds requires;     /*!< (no. requires) package requires */
48
 
 
49
 
    StringBuf sb_java;  /*!< concatenated list of java colored files. */
50
 
    StringBuf sb_perl;  /*!< concatenated list of perl colored files. */
51
 
    StringBuf sb_python;/*!< concatenated list of python colored files. */
52
 
 
53
50
};
54
51
 
55
52
/**
331
328
{
332
329
    const char * fn = fc->fn[fc->ix];
333
330
    char *buf = NULL;
 
331
    char *mname = NULL;
334
332
    StringBuf sb_stdout = NULL;
335
333
    StringBuf sb_stdin;
336
334
    char *av[2];
352
350
    case 'P':
353
351
        if (fc->skipProv)
354
352
            return 0;
355
 
        rasprintf(&buf, "%%{?__%s_provides}", nsdep);
 
353
        mname = rstrscat(NULL, "__", nsdep, "_provides", NULL);
356
354
        depsp = &fc->provides;
357
355
        dsContext = RPMSENSE_FIND_PROVIDES;
358
356
        tagN = RPMTAG_PROVIDENAME;
360
358
    case 'R':
361
359
        if (fc->skipReq)
362
360
            return 0;
363
 
        rasprintf(&buf, "%%{?__%s_requires}", nsdep);
 
361
        mname = rstrscat(NULL, "__", nsdep, "_requires", NULL);
364
362
        depsp = &fc->requires;
365
363
        dsContext = RPMSENSE_FIND_REQUIRES;
366
364
        tagN = RPMTAG_REQUIRENAME;
367
365
        break;
368
366
    }
 
367
    rasprintf(&buf, "%%{?%s:%%{%s} %%{?%s_opts}}", mname, mname, mname);
369
368
    av[0] = buf;
370
369
    av[1] = NULL;
371
370
 
433
432
    }
434
433
    sb_stdout = freeStringBuf(sb_stdout);
435
434
    free(buf);
 
435
    free(mname);
436
436
 
437
437
    return 0;
438
438
}
471
471
  { "libtool library ",         RPMFC_LIBTOOL|RPMFC_INCLUDE },
472
472
  { "pkgconfig ",               RPMFC_PKGCONFIG|RPMFC_INCLUDE },
473
473
 
 
474
  { "Objective caml ",          RPMFC_OCAML|RPMFC_INCLUDE },
 
475
 
474
476
  /* XXX .NET executables and libraries.  file(1) cannot differ from win32 
475
477
   * executables unfortunately :( */
476
478
  { "Mono/.Net assembly",       RPMFC_MONO|RPMFC_INCLUDE },
484
486
  { "RPM v4",                   RPMFC_ARCHIVE|RPMFC_INCLUDE },
485
487
 
486
488
  { " image",                   RPMFC_IMAGE|RPMFC_INCLUDE },
 
489
  { " font metrics",            RPMFC_WHITE|RPMFC_INCLUDE },
487
490
  { " font",                    RPMFC_FONT|RPMFC_INCLUDE },
488
491
  { " Font",                    RPMFC_FONT|RPMFC_INCLUDE },
489
492
 
496
499
  { "SGML",                     RPMFC_WHITE|RPMFC_INCLUDE },
497
500
  { "XML",                      RPMFC_WHITE|RPMFC_INCLUDE },
498
501
 
499
 
  { " program text",            RPMFC_WHITE|RPMFC_INCLUDE },
500
502
  { " source",                  RPMFC_WHITE|RPMFC_INCLUDE },
501
503
  { "GLS_BINARY_LSB_FIRST",     RPMFC_WHITE|RPMFC_INCLUDE },
502
504
  { " DB ",                     RPMFC_WHITE|RPMFC_INCLUDE },
503
505
 
504
 
  { "ASCII English text",       RPMFC_WHITE|RPMFC_INCLUDE },
505
 
  { "ASCII text",               RPMFC_WHITE|RPMFC_INCLUDE },
506
 
  { "ISO-8859 text",            RPMFC_WHITE|RPMFC_INCLUDE },
507
 
 
508
506
  { "symbolic link to",         RPMFC_SYMLINK },
509
507
  { "socket",                   RPMFC_DEVICE },
510
508
  { "special",                  RPMFC_DEVICE },
511
 
  { " text",                    RPMFC_TEXT },
 
509
  { " text",                    RPMFC_TEXT|RPMFC_INCLUDE },
512
510
 
513
511
  { "ASCII",                    RPMFC_WHITE },
514
512
  { "ISO-8859",                 RPMFC_WHITE },
639
637
 
640
638
        fc->provides = rpmdsFree(fc->provides);
641
639
        fc->requires = rpmdsFree(fc->requires);
642
 
 
643
 
        fc->sb_java = freeStringBuf(fc->sb_java);
644
 
        fc->sb_perl = freeStringBuf(fc->sb_perl);
645
 
        fc->sb_python = freeStringBuf(fc->sb_python);
646
 
 
647
640
    }
648
641
    fc = _free(fc);
649
642
    return NULL;
733
726
 
734
727
        /* Set color based on interpreter name. */
735
728
        bn = basename(s);
736
 
        if (!strcmp(bn, "perl"))
 
729
        if (rstreq(bn, "perl"))
737
730
            fc->fcolor->vals[fc->ix] |= RPMFC_PERL;
738
 
        else if (!strncmp(bn, "python", sizeof("python")-1))
 
731
        else if (rstreqn(bn, "python", sizeof("python")-1))
739
732
            fc->fcolor->vals[fc->ix] |= RPMFC_PYTHON;
740
733
 
741
734
        break;
774
767
        xx = rpmfcHelper(fc, 'P', "mono");
775
768
        if (is_executable)
776
769
            xx = rpmfcHelper(fc, 'R', "mono");
 
770
    } else
 
771
    if (fc->fcolor->vals[fc->ix] & RPMFC_OCAML) {
 
772
        xx = rpmfcHelper(fc, 'P', "ocaml");
 
773
        xx = rpmfcHelper(fc, 'R', "ocaml");
777
774
    }
778
775
 
779
776
    return 0;
883
880
                        } else
884
881
                        if (soname != NULL
885
882
                         && !(filter_GLIBC_PRIVATE != 0
886
 
                                && !strcmp(s, "GLIBC_PRIVATE")))
 
883
                                && rstreq(s, "GLIBC_PRIVATE")))
887
884
                        {
888
885
                            rasprintf(&buf, "%s(%s)%s", soname, s,
889
886
#if !defined(__alpha__)
940
937
                        /* Filter dependencies that contain GLIBC_PRIVATE */
941
938
                        if (soname != NULL
942
939
                         && !(filter_GLIBC_PRIVATE != 0
943
 
                                && !strcmp(s, "GLIBC_PRIVATE")))
 
940
                                && rstreq(s, "GLIBC_PRIVATE")))
944
941
                        {
945
942
                            rasprintf(&buf, "%s(%s)%s", soname, s,
946
943
#if !defined(__alpha__)
1056
1053
        else
1057
1054
            s = fn;
1058
1055
 
1059
 
/* LCL: s is not null. */
1060
1056
        rasprintf(&buf, "%s%s", s,
1061
1057
#if !defined(__alpha__)
1062
1058
                                isElf64 ? "()(64bit)" : "");
1085
1081
#endif
1086
1082
}
1087
1083
 
 
1084
static int rpmfcMISC(rpmfc fc)
 
1085
{
 
1086
    struct stat st;
 
1087
    int rc = -1;
 
1088
    const char *what = NULL;
 
1089
    const char * fn = fc->fn[fc->ix];
 
1090
    /* this part is enumerated, compare equality not bit flags */
 
1091
    int ftype = fc->fcolor->vals[fc->ix] & 0x000F0000;
 
1092
 
 
1093
    if (ftype == RPMFC_FONT) {
 
1094
        what = "fontconfig";
 
1095
    } else if (ftype == RPMFC_TEXT && rpmFileHasSuffix(fn, ".desktop")) {
 
1096
        what = "desktop";
 
1097
    }
 
1098
 
 
1099
    if (what == NULL || stat(fn, &st) < 0 || !S_ISREG(st.st_mode)) {
 
1100
        goto exit;
 
1101
    }
 
1102
 
 
1103
    (void) rpmfcHelper(fc, 'P', what);
 
1104
    rc = 0;
 
1105
 
 
1106
exit:
 
1107
    return rc;
 
1108
}
1088
1109
typedef const struct rpmfcApplyTbl_s {
1089
1110
    int (*func) (rpmfc fc);
1090
1111
    int colormask;
1095
1116
static const struct rpmfcApplyTbl_s const rpmfcApplyTable[] = {
1096
1117
    { rpmfcELF,         RPMFC_ELF },
1097
1118
    { rpmfcSCRIPT,      (RPMFC_SCRIPT|RPMFC_BOURNE|
1098
 
                         RPMFC_PERL|RPMFC_PYTHON|RPMFC_MONO|
 
1119
                         RPMFC_PERL|RPMFC_PYTHON|RPMFC_MONO|RPMFC_OCAML|
1099
1120
                         RPMFC_PKGCONFIG|RPMFC_LIBTOOL) },
 
1121
    { rpmfcMISC,        RPMFC_FONT|RPMFC_TEXT },
1100
1122
    { NULL, 0 }
1101
1123
};
1102
1124
 
1128
1150
                fn += sizeof("/usr/lib")-1;
1129
1151
                if (fn[0] == '6' && fn[1] == '4')
1130
1152
                    fn += 2;
1131
 
                if (!strncmp(fn, "/python", sizeof("/python")-1))
 
1153
                if (rstreqn(fn, "/python", sizeof("/python")-1))
1132
1154
                    fc->fcolor->vals[fc->ix] |= RPMFC_PYTHON;
1133
1155
            }
1134
1156
        }
1212
1234
    size_t slen;
1213
1235
    int fcolor;
1214
1236
    int xx;
1215
 
    int msflags = MAGIC_CHECK;  /* XXX MAGIC_COMPRESS flag? */
 
1237
    int msflags = MAGIC_CHECK | MAGIC_COMPRESS | MAGIC_NO_CHECK_TOKENS;
1216
1238
    magic_t ms = NULL;
1217
1239
 
1218
1240
    if (fc == NULL || argv == NULL)
1245
1267
    for (fc->ix = 0; fc->ix < fc->nfiles; fc->ix++) {
1246
1268
        const char * ftype;
1247
1269
        rpm_mode_t mode = (fmode ? fmode[fc->ix] : 0);
 
1270
        int is_executable = (mode & (S_IXUSR|S_IXGRP|S_IXOTH));
1248
1271
 
1249
1272
        s = argv[fc->ix];
1250
1273
        slen = strlen(s);
1271
1294
                ftype = "pkgconfig file";
1272
1295
 
1273
1296
            /* XXX skip all files in /dev/ which are (or should be) %dev dummies. */
1274
 
            else if (slen >= fc->brlen+sizeof("/dev/") && !strncmp(s+fc->brlen, "/dev/", sizeof("/dev/")-1))
 
1297
            else if (slen >= fc->brlen+sizeof("/dev/") && rstreqn(s+fc->brlen, "/dev/", sizeof("/dev/")-1))
1275
1298
                ftype = "";
1276
1299
            else
1277
1300
                ftype = magic_file(ms, s);
1278
1301
 
1279
1302
            if (ftype == NULL) {
1280
 
                rpmlog(RPMLOG_ERR, 
 
1303
                rpmlog(is_executable ? RPMLOG_ERR : RPMLOG_WARNING, 
1281
1304
                       _("Recognition of file \"%s\" failed: mode %06o %s\n"),
1282
1305
                       s, mode, magic_error(ms));
1283
 
                magic_close(ms);
1284
 
                return RPMRC_FAIL;
 
1306
                /* only executable files are critical to dep extraction */
 
1307
                if (is_executable) {
 
1308
                    magic_close(ms);
 
1309
                    return RPMRC_FAIL;
 
1310
                }
 
1311
                /* unrecognized non-executables get treated as "data" */
 
1312
                ftype = "data";
1285
1313
            }
1286
1314
        }
1287
1315
 
1445
1473
        appendLineStringBuf(sb_stdin, rpmfiFN(fi));
1446
1474
 
1447
1475
    for (dm = DepMsgs; dm->msg != NULL; dm++) {
1448
 
        rpmTag tag;
 
1476
        rpmTag tag = (dm->ftag > 0) ? dm->ftag : dm->ntag;
1449
1477
        rpmsenseFlags tagflags;
1450
 
        char * s;
1451
 
        int xx;
1452
 
 
1453
 
        tag = (dm->ftag > 0) ? dm->ftag : dm->ntag;
1454
 
        tagflags = 0;
1455
 
        s = NULL;
 
1478
        char * s = NULL;
1456
1479
 
1457
1480
        switch(tag) {
1458
1481
        case RPMTAG_PROVIDEFLAGS:
1472
1495
            break;
1473
1496
        }
1474
1497
 
1475
 
        xx = rpmfcExec(dm->argv, sb_stdin, &sb_stdout, failnonzero);
1476
 
        if (xx == -1)
 
1498
        if (rpmfcExec(dm->argv, sb_stdin, &sb_stdout, failnonzero) == -1)
1477
1499
            continue;
1478
1500
 
1479
1501
        s = rpmExpand(dm->argv[0], NULL);
1480
 
        rpmlog(RPMLOG_NOTICE, _("Finding  %s: %s\n"), dm->msg,
1481
 
                (s ? s : ""));
1482
 
        s = _free(s);
 
1502
        rpmlog(RPMLOG_NOTICE, _("Finding  %s: %s\n"), dm->msg, (s ? s : ""));
 
1503
        free(s);
1483
1504
 
1484
1505
        if (sb_stdout == NULL) {
1485
1506
            rc = RPMRC_FAIL;
1514
1535
    const char * N;
1515
1536
    const char * EVR;
1516
1537
    int genConfigDeps;
1517
 
    rpm_count_t c;
1518
1538
    int rc = RPMRC_OK;
1519
1539
    int xx;
1520
1540
    int idx;
1667
1687
    }
1668
1688
 
1669
1689
    /* Add Provides: */
1670
 
    if (fc->provides != NULL && (c = rpmdsCount(fc->provides)) > 0 && !fc->skipProv) {
 
1690
    if (fc->provides != NULL && rpmdsCount(fc->provides) > 0 && !fc->skipProv) {
1671
1691
        rpmds pi = rpmdsInit(fc->provides);
1672
1692
        while (rpmdsNext(pi) >= 0) {
1673
1693
            const char *name = rpmdsN(pi);
1681
1701
    }
1682
1702
 
1683
1703
    /* Add Requires: */
1684
 
    if (fc->requires != NULL && (c = rpmdsCount(fc->requires)) > 0 && !fc->skipReq) {
 
1704
    if (fc->requires != NULL && rpmdsCount(fc->requires) > 0 && !fc->skipReq) {
1685
1705
        rpmds pi = rpmdsInit(fc->requires);
1686
1706
        while (rpmdsNext(pi) >= 0) {
1687
1707
            const char *name = rpmdsN(pi);