49 bucketList =
getLeafBuckets(pgConn, bucketDefArray, puploadtree, ppackage, hasPrules);
54 printf(
" buckets for pfile %d:",puploadtree->
pfile_fk);
55 for (rv=0;bucketList[rv];rv++) printf(
"%d ",bucketList[rv]);
84 char *fcnName =
"getLeafBuckets";
85 int *bucket_pk_list = 0;
86 int *bucket_pk_list_start;
93 int numBucketDefs = 0;
95 int foundmatch, foundmatch2;
110 if (
debug) printf(
"debug: %s pfile: %d\n", fcnName, puploadtree->
pfile_fk);
112 for (bucketDefArray = in_bucketDefArray; bucketDefArray->
bucket_pk; bucketDefArray++)
116 bucket_pk_list_start = calloc(numBucketDefs+1,
sizeof(
int));
117 if (bucket_pk_list_start == 0)
119 printf(
"FATAL: out of memory allocating int array of %d elements\n", numBucketDefs+1);
122 bucket_pk_list = bucket_pk_list_start;
125 bucketDefArray = in_bucketDefArray;
129 snprintf(sql,
sizeof(sql),
130 "SELECT distinct(rf_shortname) as rf_shortname, rf_pk \ 131 from license_ref,license_file,\ 132 (SELECT distinct(pfile_fk) as PF from uploadtree \ 134 and uploadtree.lft BETWEEN %d and %d) as SS \ 135 where PF=pfile_fk and agent_fk=%d and rf_fk=rf_pk",
139 result = PQexec(pgConn, sql);
141 numLics = PQntuples(result);
144 pfile_rfpks = calloc(numLics+1,
sizeof(
int));
145 if (pfile_rfpks == 0)
147 printf(
"FATAL: out of memory allocating int array of %d rf_pk elements\n", numLics+1);
150 for (licNumb=0; licNumb < numLics; licNumb++)
151 pfile_rfpks[licNumb] = atoi(PQgetvalue(result, licNumb, 1));
155 printf(
"bobg: fileName: %s\n", puploadtree->
ufile_name);
157 isPkg = (ppackage->
pkgname[0]) ? 1 : 0;
159 for (bucketDefArray = in_bucketDefArray; bucketDefArray->
bucket_pk; bucketDefArray++)
167 if (!isPkg)
continue;
174 if ((!isPkg) && (IsContainer(puploadtree->
ufile_mode)))
179 *bucket_pk_list = bucketDefArray->
bucket_pk;
183 else if (rv == -1)
return 0;
189 printf(
"bobg: check bucket_pk: %d\n", bucketDefArray->
bucket_pk);
196 if (!ppmatch_array)
break;
197 while (*ppmatch_array)
200 if (
arrayAinB(*ppmatch_array, pfile_rfpks))
202 *bucket_pk_list = bucketDefArray->
bucket_pk;
213 if (numLics == 0)
break;
216 for (licNumb=0; licNumb < numLics; licNumb++)
221 while (*pmatch_array)
223 if (pfile_rfpks[licNumb] == *pmatch_array)
break;
235 *bucket_pk_list = bucketDefArray->
bucket_pk;
243 if (matchAnyLic(result, numLics, &bucketDefArray->
compRegex))
246 *bucket_pk_list = bucketDefArray->
bucket_pk;
270 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
271 PROJECTSTATEDIR, bucketDefArray->bucketpool_pk, bucketDefArray->
dataFilename);
272 if ((pid = fork()) < 0)
274 printf(
"FATAL: fork failure, %s\n", strerror(errno));
281 if ((rv = chdir(
"/tmp")))
283 printf(
"FATAL: exec bucket couldn't cd to /tmp\n");
291 sprintf(envbuf,
"FILENAME=%s", puploadtree->
ufile_name);
292 envp[envnum++] = strdup(envbuf);
294 strcpy(envbuf,
"LICENSES=");
295 for (licNumb=0; licNumb < numLics; licNumb++)
297 if (envbuf[9]) strcat(envbuf,
"|");
298 strcat(envbuf, PQgetvalue(result, licNumb, 0));
300 envp[envnum++] = strdup(envbuf);
301 sprintf(envbuf,
"PKGVERS=%s", ppackage->
pkgvers);
302 envp[envnum++] = strdup(envbuf);
303 sprintf(envbuf,
"VENDOR=%s", ppackage->
vendor);
304 envp[envnum++] =strdup(envbuf);
305 sprintf(envbuf,
"PKGNAME=%s", ppackage->
pkgname);
306 envp[envnum++] =strdup(envbuf);
307 sprintf(envbuf,
"SRCPKGNAME=%s", ppackage->
srcpkgname);
308 envp[envnum++] =strdup(envbuf);
309 sprintf(envbuf,
"UPLOADTREE_PK=%d", puploadtree->
uploadtree_pk);
310 envp[envnum++] =strdup(envbuf);
311 sprintf(envbuf,
"PFILE_PK=%d", puploadtree->
pfile_fk);
312 envp[envnum++] =strdup(envbuf);
330 snprintf(sql,
sizeof(sql),
331 "select pfile_mimetypefk from pfile where pfile_pk=%d",
333 resultmime = PQexec(pgConn, sql);
335 mimetype = *(PQgetvalue(resultmime, 0, 0));
338 else if (mimetype ==
DEB_BINARY) pkgtype =
'b';
342 sprintf(envbuf,
"PKGTYPE=%c", pkgtype);
343 envp[envnum++] =strdup(envbuf);
346 execve(filepath, argv, envp);
347 printf(
"FATAL: buckets execve (%s) failed, %s\n", filepath, strerror(errno));
352 if (waitpid(pid, &rv, 0) < 0)
354 printf(
"FATAL: waitpid, %s\n", strerror(errno));
359 printf(
"FATAL: child %d died from signal %d", pid, WTERMSIG(rv));
365 printf(
"FATAL: child %d stopped, signal %d", pid, WSTOPSIG(rv));
371 if (WEXITSTATUS(rv) == 0)
373 *bucket_pk_list = bucketDefArray->
bucket_pk;
398 switch (regex_row->
ftype1)
401 foundmatch = !regexec(®ex_row->compRegex1, puploadtree->
ufile_name, 0, 0, 0);
404 foundmatch = matchAnyLic(result, numLics, ®ex_row->compRegex1);
411 if ((regex_row->
op == 2) || !foundmatch)
414 switch (regex_row->
ftype2)
417 foundmatch2 = !regexec(®ex_row->compRegex2, puploadtree->
ufile_name, 0, 0, 0);
420 foundmatch2 = matchAnyLic(result, numLics, ®ex_row->compRegex2);
425 switch (regex_row->
op)
428 foundmatch = (foundmatch && foundmatch2) ? 1 : 0;
431 foundmatch = (foundmatch || foundmatch2) ? 1 : 0;
434 foundmatch = (foundmatch && !foundmatch2) ? 1 : 0;
440 *bucket_pk_list = bucketDefArray->
bucket_pk;
452 *bucket_pk_list = bucketDefArray->
bucket_pk;
460 printf(
"FATAL: Unknown bucket type %d, exiting...\n",
465 printf(
"bobg match: %d\n", match);
467 if (match && bucketDefArray->
stopon ==
'Y')
break;
471 printf(
"bobg exit GetLeafBuckets()\n");
475 return bucket_pk_list_start;
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Store the results of a regex match.
FUNCTION int arrayAinB(int *arrayA, int *arrayB)
Verify that all the values in array A are also in B.
PGconn * pgConn
Database connection.
FUNCTION int * getLeafBuckets(PGconn *pgConn, pbucketdef_t in_bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int hasPrules)
Determine what buckets the pfile is in.
FUNCTION int writeBuckets(PGconn *pgConn, int pfile_pk, int uploadtree_pk, int *bucketList, int agent_pk, int nomosagent_pk, int bucketpool_pk)
Write bucket results to either db (bucket_file, bucket_container) or stdout.
FUNCTION int processLeaf(PGconn *pgConn, pbucketdef_t bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int agent_pk, int hasPrules)
Determine which bucket(s) a leaf node is in and write results.
FUNCTION int childInBucket(PGconn *pgConn, pbucketdef_t bucketDef, puploadtree_t puploadtree)
Given a container uploadtree_pk and bucketdef, determine if any child is in this bucket.