1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#include "system.h"
#include <pthread.h>
#include <assert.h>
#include <rpmlib.h>
#include <rpmts.h>
#include <rpmsq.h> /* XXX for _rpmsq_debug */
#include <rpmio.h>
#include <rpmlog.h>
#include "debug.h"
extern int _psm_debug;
static void *other_notify(const void *h,
const rpmCallbackType what,
const unsigned long amount,
const unsigned long 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;
}
|