From 962c7b49d2c290678afad9a9893f76450e655108 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 12 May 2008 10:45:33 +0300 Subject: [PATCH] Rip old, bit-rotten librpm test programs --- lib/Makefile.am | 24 -------- lib/tcpu.c | 184 -------------------------------------------------------- lib/tds.c | 38 ------------ lib/tgi.c | 172 ---------------------------------------------------- lib/tplatform.c | 123 ------------------------------------- lib/tsystem.c | 38 ------------ lib/tthread.c | 93 ---------------------------- 7 files changed, 672 deletions(-) delete mode 100644 lib/tcpu.c delete mode 100644 lib/tds.c delete mode 100644 lib/tgi.c delete mode 100644 lib/tplatform.c delete mode 100644 lib/tsystem.c delete mode 100644 lib/tthread.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 85a58dd..4f5e193 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -36,27 +36,3 @@ librpm_la_LIBADD = \ @WITH_SELINUX_LIB@ \ @LIBINTL@ -check_PROGRAMS += tds -tds_SOURCES = tds.c -tds_LDADD = librpm.la - -check_PROGRAMS += tthread -tthread_SOURCES = tthread.c -tthread_LDADD = librpm.la @WITH_LIBELF_LIB@ - -check_PROGRAMS += tsystem -tsystem_SOURCES = tsystem.c -tsystem_LDADD = ../rpmio/librpmio.la @WITH_POPT_LIB@ - -check_PROGRAMS += tcpu -tcpu_SOURCES = tcpu.c -tcpu_LDADD = librpm.la - -check_PROGRAMS += tplatform -tplatform_SOURCES = tplatform.c -tplatform_LDADD = librpm.la - -check_PROGRAMS += tgi -tgi_SOURCES = tgi.c -tgi_LDADD = librpm.la - diff --git a/lib/tcpu.c b/lib/tcpu.c deleted file mode 100644 index cc503d9..0000000 --- a/lib/tcpu.c +++ /dev/null @@ -1,184 +0,0 @@ -#include "system.h" - -#include - -#include -#include -#include "debug.h" - -#define _PROC_CPUINFO "/proc/cpuinfo" -static const char * cpuinfo = _PROC_CPUINFO; - -#define _isspace(_c) \ - ((_c) == ' ' || (_c) == '\t' || (_c) == '\r' || (_c) == '\n') - -/* - * processor : 0 - * vendor_id : GenuineIntel - * cpu family : 6 - * model : 8 - * model name : Pentium III (Coppermine) - * stepping : 1 - * cpu MHz : 664.597 - * cache size : 256 KB - * physical id : 0 - * siblings : 1 - * fdiv_bug : no - * hlt_bug : no - * f00f_bug : no - * coma_bug : no - * fpu : yes - * fpu_exception : yes - * cpuid level : 2 - * wp : yes - * flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse - * bogomips : 1327.10 -*/ - -struct cpuinfo_s { - const char *name; - int done; - int flags; -}; - -struct cpuinfo_s ctags[] = { - { "processor", 0, 0 }, - { "vendor_id", 0, 0 }, - { "cpu_family", 0, 1 }, - { "model", 0, 1 }, - { "model_name", 0, 2 }, - { "stepping", 0, 1 }, - { "cpu_MHz", 0, 0 }, - { "cache_size", 0, 2 }, - { "physical_id", 0, 0 }, - { "siblings", 0, 0 }, - { "fdiv_bug", 0, 3 }, - { "hlt_bug", 0, 3 }, - { "f00f_bug", 0, 3 }, - { "coma_bug", 0, 3 }, - { "fpu", 0, 0 }, /* XXX flags attribute instead. */ - { "fpu_exception", 0, 3 }, - { "cpuid_level", 0, 0 }, - { "wp", 0, 3 }, - { "flags", 0, 4 }, - { "bogomips", 0, 0 }, - { NULL, 0, -1 } -}; - -static int rpmCtagFlags(char * name) -{ - struct cpuinfo_s * ct; - int flags = -1; - - for (ct = ctags; ct->name != NULL; ct++) { - if (strcmp(ct->name, name)) - continue; - if (ct->done) - continue; - ct->done = 1; - flags = ct->flags; - break; - } - return flags; -} - -static int rpmCpuinfo(void) -{ - char buf[BUFSIZ]; - char * f, * fe; - char * g, * ge; - char * t; - FD_t fd = NULL; - FILE * fp; - - int rc = -1; - - fd = Fopen(cpuinfo, "r.fpio"); - if (fd == NULL || Ferror(fd)) - goto exit; - fp = fdGetFILE(fd); - - while((f = fgets(buf, sizeof(buf), fp)) != NULL) { - /* rtrim on line. */ - ge = f + strlen(f); - while (--ge > f && _isspace(*ge)) - *ge = '\0'; - - /* ltrim on line. */ - while (*f && _isspace(*f)) - f++; - - /* split on ':' */ - fe = f; - while (*fe && *fe != ':') - fe++; - if (*fe == '\0') - continue; - g = fe + 1; - - /* rtrim on field 1. */ - *fe = '\0'; - while (--fe > f && _isspace(*fe)) - *fe = '\0'; - if (*f == '\0') - continue; - - /* ltrim on field 2. */ - while (*g && _isspace(*g)) - g++; - if (*g == '\0') - continue; - - for (t = f; *t != '\0'; t++) { - if (_isspace(*t)) - *t = '_'; - } - - switch (rpmCtagFlags(f)) { - case -1: /* not found */ - case 0: /* ignore */ - default: - continue; - break; - case 1: /* Provides: cpuinfo(f) = g */ -fprintf(stderr, "Provides: cpuinfo(%s) = %s\n", f, g); - break; - case 2: /* Provides: cpuinfo(g) */ - for (t = g; *t != '\0'; t++) { - if (_isspace(*t) || *t == '(' || *t == ')') - *t = '_'; - } -fprintf(stderr, "Provides: cpuinfo(%s)\n", g); - break; - case 3: /* if ("yes") Provides: cpuinfo(f) */ - if (strcmp(g, "yes")) - break; -fprintf(stderr, "Provides: cpuinfo(%s)\n", f); - break; - case 4: /* Provides: cpuinfo(g[i]) */ - { char ** av = NULL; - rc = poptParseArgvString(g, NULL, (const char ***)&av); - if (!rc && av != NULL) - while ((f = *av++) != NULL) { -fprintf(stderr, "Provides: cpuinfo(%s)\n", f); - } - if (av != NULL) - free(av); - } break; - } - } - -exit: - if (fd) (void) Fclose(fd); - return rc; -} - -int main (int argc, char *argv[]) -{ - - int rc; - - rc = rpmCpuinfo(); - - return rc; -} diff --git a/lib/tds.c b/lib/tds.c deleted file mode 100644 index 2f25b71..0000000 --- a/lib/tds.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "system.h" - -#include -#include - -#include "debug.h" - -extern int _rpmds_debug; - -int main(int argc, char *argv[]) -{ - rpmTag tagN = RPMTAG_REQUIRENAME; - rpmds ds = NULL; - rpmds dsA; - rpmds dsA1; - rpmds dsA2; - rpmds dsB; - rpmds dsC; - - _rpmds_debug = 0; - dsA = rpmdsSingle(tagN, "A", "0", RPMSENSE_EQUAL); - dsA1 = rpmdsSingle(tagN, "A", "0", RPMSENSE_LESS); - dsA2 = rpmdsSingle(tagN, "A", "0", RPMSENSE_GREATER); - dsB = rpmdsSingle(tagN, "B", "1", RPMSENSE_LESS); - dsC = rpmdsSingle(tagN, "C", "2", RPMSENSE_GREATER); - - rpmdsMerge(&ds, dsA2); - rpmdsMerge(&ds, dsA); - rpmdsMerge(&ds, dsC); - rpmdsMerge(&ds, dsB); - rpmdsMerge(&ds, dsA1); - - ds = rpmdsInit(ds); - while (rpmdsNext(ds) >= 0) - fprintf(stderr, "%d %s\n", rpmdsIx(ds), rpmdsDNEVR(ds)+2); - - return 0; -} diff --git a/lib/tgi.c b/lib/tgi.c deleted file mode 100644 index 6449e86..0000000 --- a/lib/tgi.c +++ /dev/null @@ -1,172 +0,0 @@ -#include "system.h" - -#include - -#include -#include -#include -#include -#include - -#include "debug.h" - -static const char * gitagstr = "packages"; -static const char * gikeystr = NULL; -static rpmtransFlags transFlags = 0; -#ifdef DYING -static rpmgiFlags giFlags = 0; -#endif - -static const char * queryFormat = NULL; -static const char * defaultQueryFormat = - "%{name}-%{version}-%{release}.%|SOURCERPM?{%{arch}.rpm}:{%|ARCH?{src.rpm}:{pubkey}|}|"; - -static const char * rpmgiPathOrQF(const rpmgi gi) -{ - const char * fmt = ((queryFormat != NULL) - ? queryFormat : defaultQueryFormat); - const char * val = NULL; - Header h = rpmgiHeader(gi); - - if (h != NULL) - val = headerSprintf(h, fmt, rpmTagTable, rpmHeaderFormats, NULL); - else { - const char * fn = rpmgiHdrPath(gi); - val = (fn != NULL ? xstrdup(fn) : NULL); - } - - return val; -} - -static struct poptOption optionsTable[] = { - { "rpmgidebug", 'd', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmgi_debug, -1, - N_("debug generalized iterator"), NULL}, - - { "tag", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gitagstr, 0, - N_("iterate tag index"), NULL }, - { "key", '\0', POPT_ARG_STRING|POPT_ARGFLAG_SHOW_DEFAULT, &gikeystr, 0, - N_("tag value key"), NULL }, - - { "transaction", 'T', POPT_BIT_SET, &giFlags, (RPMGI_TSADD|RPMGI_TSORDER), - N_("create transaction set"), NULL}, - { "noorder", '\0', POPT_BIT_CLR, &giFlags, RPMGI_TSORDER, - N_("do not order transaction set"), NULL}, - { "noglob", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOGLOB, - N_("do not glob arguments"), NULL}, - { "nomanifest", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOMANIFEST, - N_("do not process non-package files as manifests"), NULL}, - { "noheader", '\0', POPT_BIT_SET, &giFlags, RPMGI_NOHEADER, - N_("do not read headers"), NULL}, - - { "qf", '\0', POPT_ARG_STRING, &queryFormat, 0, - N_("use the following query format"), "QUERYFORMAT" }, - { "queryformat", '\0', POPT_ARG_STRING, &queryFormat, 0, - N_("use the following query format"), "QUERYFORMAT" }, - - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliFtsPoptTable, 0, - N_("File tree walk options for fts(3):"), - NULL }, - - { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmcliAllPoptTable, 0, - N_("Common options for all rpm modes and executables:"), - NULL }, - - POPT_AUTOALIAS - POPT_AUTOHELP - POPT_TABLEEND -}; - -int -main(int argc, char *argv[]) -{ - poptContext optCon; - rpmts ts = NULL; - rpmVSFlags vsflags; - rpmgi gi = NULL; - rpmTag gitag = RPMDBI_PACKAGES; - const char ** av; - int ac; - int rc = 0; - - optCon = rpmcliInit(argc, argv, optionsTable); - if (optCon == NULL) - exit(EXIT_FAILURE); - - if (ftsOpts == 0) - ftsOpts = (RPMGI_COMFOLLOW | RPMGI_LOGICAL | RPMGI_NOSTAT); - - if (gitagstr != NULL) { - gitag = rpmTagGetValue(gitagstr); - if (gitag == RPMTAG_NOT_FOUND) { - fprintf(stderr, _("unknown --tag argument: %s\n"), gitagstr); - exit(EXIT_FAILURE); - } - } - - /* XXX ftswalk segfault with no args. */ - - ts = rpmtsCreate(); - (void) rpmtsSetFlags(ts, transFlags); - - vsflags = rpmExpandNumeric("%{?_vsflags_query}"); - if (rpmcliQueryFlags & VERIFY_DIGEST) - vsflags |= _RPMVSF_NODIGESTS; - if (rpmcliQueryFlags & VERIFY_SIGNATURE) - vsflags |= _RPMVSF_NOSIGNATURES; - if (rpmcliQueryFlags & VERIFY_HDRCHK) - vsflags |= RPMVSF_NOHDRCHK; - (void) rpmtsSetVSFlags(ts, vsflags); - - { rpm_tid_t tid = (rpm_tid_t) time(NULL); - (void) rpmtsSetTid(ts, tid); - } - - gi = rpmgiNew(ts, gitag, gikeystr, 0); - - av = poptGetArgs(optCon); - (void) rpmgiSetArgs(gi, av, ftsOpts, giFlags); - - ac = 0; - while (rpmgiNext(gi) == RPMRC_OK) { - if (!(giFlags & RPMGI_TSADD)) { - const char * arg = rpmgiPathOrQF(gi); - - fprintf(stdout, "%5d %s\n", ac, arg); - arg = _free(arg); - } - ac++; - } - - if (giFlags & RPMGI_TSORDER) { - rpmtsi tsi; - rpmte q; - int i; - -fprintf(stdout, "======================= %d transaction elements\n\ - # Tree Depth Degree Package\n\ -=======================\n", rpmtsNElements(ts)); - - i = 0; - tsi = rpmtsiInit(ts); - while((q = rpmtsiNext(tsi, 0)) != NULL) { - char deptypechar; - - if (i == rpmtsUnorderedSuccessors(ts, -1)) - fprintf(stdout, "======================= leaf nodes only:\n"); - - deptypechar = (rpmteType(q) == TR_REMOVED ? '-' : '+'); - fprintf(stdout, "%5d%5d%6d%7d %*s%c%s\n", - i, rpmteTree(q), rpmteDepth(q), rpmteDegree(q), - (2 * rpmteDepth(q)), "", - deptypechar, rpmteNEVRA(q)); - i++; - } - tsi = rpmtsiFree(tsi); - } - - gi = rpmgiFree(gi); - ts = rpmtsFree(ts); - optCon = rpmcliFini(optCon); - - return rc; -} diff --git a/lib/tplatform.c b/lib/tplatform.c deleted file mode 100644 index 905f0a6..0000000 --- a/lib/tplatform.c +++ /dev/null @@ -1,123 +0,0 @@ -#include "system.h" - -#include -#include - -#include "rpmio/rpmio_internal.h" /* XXX rpmioSlurp */ - -#include "debug.h" - -#define _ETC_RPM_PLATFORM "/etc/rpm/platform" -static const char * platform = _ETC_RPM_PLATFORM; - -static const char ** platpat = NULL; -static int nplatpat = 0; - -static int rpmPlatform(void) -{ - char *cpu = NULL, *vendor = NULL, *os = NULL, *gnu = NULL; - uint8_t * b = NULL; - ssize_t blen = 0; - int init_platform = 0; - char * p, * pe; - int rc; - - rc = rpmioSlurp(platform, &b, &blen); - - if (rc || b == NULL || blen <= 0) { - rc = -1; - goto exit; - } - - p = (char *) b; - for (pe = p; p && *p; p = pe) { - pe = strchr(p, '\n'); - if (pe) - *pe++ = '\0'; - -fprintf(stderr, "--- %s\n", p); - - while (*p && isspace(*p)) - p++; - if (*p == '\0' || *p == '#') - continue; - - if (init_platform) { - char * t = p + strlen(p); - - while (--t > p && isspace(*t)) - *t = '\0'; - if (t > p) { - platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat)); - platpat[nplatpat] = xstrdup(p); -fprintf(stderr, "\tplatpat[%d] \"%s\"\n", nplatpat, platpat[nplatpat]); - nplatpat++; - platpat[nplatpat] = NULL; - } - continue; - } - - cpu = p; - vendor = "unknown"; - os = "unknown"; - gnu = NULL; - while (*p && !(*p == '-' || isspace(*p))) - p++; - if (*p != '\0') *p++ = '\0'; -fprintf(stderr, "--- cpu \"%s\"\n", cpu); - - vendor = p; - while (*p && !(*p == '-' || isspace(*p))) - p++; - if (*p != '-') { - if (*p != '\0') *p++ = '\0'; - os = vendor; - vendor = "unknown"; - } else { - if (*p != '\0') *p++ = '\0'; - - os = p; - while (*p && !(*p == '-' || isspace(*p))) - p++; - if (*p == '-') { - *p++ = '\0'; - - gnu = p; - while (*p && !(*p == '-' || isspace(*p))) - p++; - } - if (*p != '\0') *p++ = '\0'; - } -fprintf(stderr, "--- vendor \"%s\"\n", vendor); -fprintf(stderr, "--- os \"%s\"\n", os); -fprintf(stderr, "--- gnu \"%s\"\n", gnu); - - addMacro(NULL, "_host_cpu", NULL, cpu, -1); - addMacro(NULL, "_host_vendor", NULL, vendor, -1); - addMacro(NULL, "_host_os", NULL, os, -1); - - platpat = xrealloc(platpat, (nplatpat + 2) * sizeof(*platpat)); - platpat[nplatpat] = rpmExpand("%{_host_cpu}-%{_host_vendor}-%{_host_os}", (gnu && *gnu ? "-" : NULL), gnu, NULL); -fprintf(stderr, "\tplatpat[%d] \"%s\"\n", nplatpat, platpat[nplatpat]); - nplatpat++; - platpat[nplatpat] = NULL; - - init_platform++; - } - rc = (init_platform ? 0 : -1); - -exit: - b = _free(b); - return rc; -} - -int main (int argc, char *argv[]) -{ - - int rc; - -_rpmio_debug = 0; - rc = rpmPlatform(); - - return rc; -} diff --git a/lib/tsystem.c b/lib/tsystem.c deleted file mode 100644 index 5c7057d..0000000 --- a/lib/tsystem.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "system.h" - -#include -#include - -#include - -#include "debug.h" - -static void * -other_thread(void *dat) -{ - const char * cmd = (const char *)dat; - const char ** av = NULL; - int ac = 0; - int xx = poptParseArgvString(cmd, &ac, &av); - if (xx) - return ((void *)xx); -fprintf(stderr, "thread(%lu): pid %u %s\n", pthread_self(), getpid(), cmd); - return ((void *) rpmsqExecve(av)); -} - -int main(int argc, char *argv[]) -{ - pthread_t pth; - const char * cmd = argv[1]; - - if (cmd == NULL) - cmd = "/bin/sleep 30"; - pthread_create(&pth, NULL, other_thread, (void *)cmd); -fprintf(stderr, " main(%lu): pid %u other(%lu)\n", pthread_self(), getpid(), pth); - - sleep(2); - pthread_cancel(pth); - - pthread_join(pth, NULL); - return 0; -} diff --git a/lib/tthread.c b/lib/tthread.c deleted file mode 100644 index b20d03d..0000000 --- a/lib/tthread.c +++ /dev/null @@ -1,93 +0,0 @@ -#include "system.h" - -#include -#include - -#include /* rpmReadConfigFiles, rpmReadPackageFile */ -#include -#include /* XXX for _rpmsq_debug */ -#include -#include - -#include "debug.h" - -extern int _psm_debug; - -static void *other_notify(const void *h, - const rpmCallbackType what, - const rpm_off_t amount, - const rpm_off_t total, - fnpyKey key, - rpmCallbackData data) -{ - static FD_t fd; - - fprintf(stderr, "notify %d %ld %ld\n", what, amount, total); - - switch (what) { - case RPMCALLBACK_INST_OPEN_FILE: - fd = Fopen(key, "r"); - return fd; - break; - case RPMCALLBACK_INST_CLOSE_FILE: - if (fd != NULL) { - (void) Fclose(fd); - fd = NULL; - } - break; - default: - break; - } - return NULL; -} - -static void * -other_thread(void *dat) -{ - rpmts ts; - int err; - FD_t fd; - Header h = NULL; - - rpmReadConfigFiles(NULL, NULL); - ts = rpmtsCreate(); - assert(ts); - (void) rpmtsSetRootDir(ts, "/"); - - rpmIncreaseVerbosity(); - rpmIncreaseVerbosity(); - - fd = Fopen(dat, "r.ufdio"); - assert(fd != NULL); - rpmReadPackageFile(ts, fd, "other_thread", &h); - Fclose(fd); - - err = rpmtsAddInstallElement(ts, h, dat, 1, NULL); - - err = rpmtsSetNotifyCallback(ts, other_notify, NULL); - assert(!err); - - err = rpmtsRun(ts, NULL, RPMPROB_FILTER_REPLACEPKG); - if(err) - fprintf(stderr, "Run failed: %d\n", err); - - return NULL; -} - -int main(int argc, char *argv[]) -{ - pthread_t pth; - - _psm_debug = 1; - _rpmsq_debug = 1; - - rpmsqEnable(SIGINT, NULL); - rpmsqEnable(SIGQUIT, NULL); - rpmsqEnable(SIGCHLD, NULL); - - pthread_create(&pth, NULL, other_thread, argv[1]); - - pthread_join(pth, NULL); - - return 0; -} -- 2.7.4