42 printf(
" buckets for pfile %d:",puploadtree->
pfile_fk);
43 for (rv=0;bucketList[rv];rv++) printf(
"%d ",bucketList[rv]);
72 char *fcnName =
"getLeafBuckets";
73 int *bucket_pk_list = 0;
74 int *bucket_pk_list_start;
81 int numBucketDefs = 0;
83 int foundmatch, foundmatch2;
98 if (
debug) printf(
"debug: %s pfile: %d\n", fcnName, puploadtree->
pfile_fk);
100 for (bucketDefArray = in_bucketDefArray; bucketDefArray->
bucket_pk; bucketDefArray++)
104 bucket_pk_list_start = calloc(numBucketDefs+1,
sizeof(
int));
105 if (bucket_pk_list_start == 0)
107 printf(
"FATAL: out of memory allocating int array of %d elements\n", numBucketDefs+1);
110 bucket_pk_list = bucket_pk_list_start;
113 bucketDefArray = in_bucketDefArray;
117 snprintf(sql,
sizeof(sql),
118 "SELECT distinct(rf_shortname) as rf_shortname, rf_pk \
119 from license_ref,license_file,\
120 (SELECT distinct(pfile_fk) as PF from uploadtree \
122 and uploadtree.lft BETWEEN %d and %d) as SS \
123 where PF=pfile_fk and agent_fk=%d and rf_fk=rf_pk",
127 result = PQexec(
pgConn, sql);
129 numLics = PQntuples(result);
132 pfile_rfpks = calloc(numLics+1,
sizeof(
int));
133 if (pfile_rfpks == 0)
135 printf(
"FATAL: out of memory allocating int array of %d rf_pk elements\n", numLics+1);
138 for (licNumb=0; licNumb < numLics; licNumb++)
139 pfile_rfpks[licNumb] = atoi(PQgetvalue(result, licNumb, 1));
143 printf(
"bobg: fileName: %s\n", puploadtree->
ufile_name);
145 isPkg = (ppackage->
pkgname[0]) ? 1 : 0;
147 for (bucketDefArray = in_bucketDefArray; bucketDefArray->
bucket_pk; bucketDefArray++)
155 if (!isPkg)
continue;
162 if ((!isPkg) && (IsContainer(puploadtree->
ufile_mode)))
167 *bucket_pk_list = bucketDefArray->
bucket_pk;
171 else if (rv == -1)
return 0;
177 printf(
"bobg: check bucket_pk: %d\n", bucketDefArray->
bucket_pk);
184 if (!ppmatch_array)
break;
185 while (*ppmatch_array)
188 if (
arrayAinB(*ppmatch_array, pfile_rfpks))
190 *bucket_pk_list = bucketDefArray->
bucket_pk;
201 if (numLics == 0)
break;
204 for (licNumb=0; licNumb < numLics; licNumb++)
209 while (*pmatch_array)
211 if (pfile_rfpks[licNumb] == *pmatch_array)
break;
223 *bucket_pk_list = bucketDefArray->
bucket_pk;
234 *bucket_pk_list = bucketDefArray->
bucket_pk;
258 snprintf(filepath,
sizeof(filepath),
"%s/bucketpools/%d/%s",
259 PROJECTSTATEDIR, bucketDefArray->bucketpool_pk, bucketDefArray->
dataFilename);
260 if ((pid = fork()) < 0)
262 printf(
"FATAL: fork failure, %s\n", strerror(errno));
269 if ((rv = chdir(
"/tmp")))
271 printf(
"FATAL: exec bucket couldn't cd to /tmp\n");
279 sprintf(envbuf,
"FILENAME=%s", puploadtree->
ufile_name);
280 envp[envnum++] = strdup(envbuf);
282 strcpy(envbuf,
"LICENSES=");
283 for (licNumb=0; licNumb < numLics; licNumb++)
285 if (envbuf[9]) strcat(envbuf,
"|");
286 strcat(envbuf, PQgetvalue(result, licNumb, 0));
288 envp[envnum++] = strdup(envbuf);
289 sprintf(envbuf,
"PKGVERS=%s", ppackage->
pkgvers);
290 envp[envnum++] = strdup(envbuf);
291 sprintf(envbuf,
"VENDOR=%s", ppackage->
vendor);
292 envp[envnum++] =strdup(envbuf);
293 sprintf(envbuf,
"PKGNAME=%s", ppackage->
pkgname);
294 envp[envnum++] =strdup(envbuf);
295 sprintf(envbuf,
"SRCPKGNAME=%s", ppackage->
srcpkgname);
296 envp[envnum++] =strdup(envbuf);
297 sprintf(envbuf,
"UPLOADTREE_PK=%d", puploadtree->
uploadtree_pk);
298 envp[envnum++] =strdup(envbuf);
299 sprintf(envbuf,
"PFILE_PK=%d", puploadtree->
pfile_fk);
300 envp[envnum++] =strdup(envbuf);
318 snprintf(sql,
sizeof(sql),
319 "select pfile_mimetypefk from pfile where pfile_pk=%d",
321 resultmime = PQexec(
pgConn, sql);
323 mimetype = *(PQgetvalue(resultmime, 0, 0));
326 else if (mimetype ==
DEB_BINARY) pkgtype =
'b';
330 sprintf(envbuf,
"PKGTYPE=%c", pkgtype);
331 envp[envnum++] =strdup(envbuf);
334 execve(filepath, argv, envp);
335 printf(
"FATAL: buckets execve (%s) failed, %s\n", filepath, strerror(errno));
340 if (waitpid(pid, &rv, 0) < 0)
342 printf(
"FATAL: waitpid, %s\n", strerror(errno));
347 printf(
"FATAL: child %d died from signal %d", pid, WTERMSIG(rv));
353 printf(
"FATAL: child %d stopped, signal %d", pid, WSTOPSIG(rv));
359 if (WEXITSTATUS(rv) == 0)
361 *bucket_pk_list = bucketDefArray->
bucket_pk;
386 switch (regex_row->
ftype1)
389 foundmatch = !regexec(®ex_row->compRegex1, puploadtree->
ufile_name, 0, 0, 0);
392 foundmatch =
matchAnyLic(result, numLics, ®ex_row->compRegex1);
399 if ((regex_row->
op == 2) || !foundmatch)
402 switch (regex_row->
ftype2)
405 foundmatch2 = !regexec(®ex_row->compRegex2, puploadtree->
ufile_name, 0, 0, 0);
408 foundmatch2 =
matchAnyLic(result, numLics, ®ex_row->compRegex2);
413 switch (regex_row->
op)
416 foundmatch = (foundmatch && foundmatch2) ? 1 : 0;
419 foundmatch = (foundmatch || foundmatch2) ? 1 : 0;
422 foundmatch = (foundmatch && !foundmatch2) ? 1 : 0;
428 *bucket_pk_list = bucketDefArray->
bucket_pk;
440 *bucket_pk_list = bucketDefArray->
bucket_pk;
448 printf(
"FATAL: Unknown bucket type %d, exiting...\n",
453 printf(
"bobg match: %d\n",
match);
459 printf(
"bobg exit GetLeafBuckets()\n");
463 return bucket_pk_list_start;
PGconn * pgConn
Database connection.
FUNCTION int matchAnyLic(PGresult *result, int numLics, regex_t *compRegex)
Does this regex match any license name for this pfile?
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.
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 * getLeafBuckets(PGconn *pgConn, pbucketdef_t in_bucketDefArray, puploadtree_t puploadtree, ppackage_t ppackage, int hasPrules)
Determine what buckets the pfile is in.
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.
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.