static void trk_explicit_activate_awaiter(struct pkginfo *aw) { char buf[1024]; const char *emsg; struct pkginfo *pend; if (!trk_explicit_f) return; if (fseek(trk_explicit_f, 0, SEEK_SET)) ohshite(_("failed to rewind trigger interest file `%.250s'"), trk_explicit_fn.buf); while (trk_explicit_fgets(buf, sizeof(buf)) >= 0) { char *slash; bool noawait = false; slash = strchr(buf, '/'); if (slash && strcmp("/noawait", slash) == 0) { noawait = true; *slash = '\0'; } emsg = pkg_name_is_illegal(buf, NULL); if (emsg) ohshit(_("trigger interest file `%.250s' syntax error; " "illegal package name `%.250s': %.250s"), trk_explicit_fn.buf, buf, emsg); pend = pkg_db_find(buf); trig_record_activation(pend, noawait ? NULL : aw, trk_explicit_trig); } }
static void trk_explicit_interest_change(const char *trig, struct pkginfo *pkg, int signum, enum trig_options opts) { static struct varbuf newfn; char buf[1024]; FILE *nf; bool empty = true; trk_explicit_start(trig); varbuf_reset(&newfn); varbuf_printf(&newfn, "%s/%s.new", triggersdir, trig); nf = fopen(newfn.buf, "w"); if (!nf) ohshite(_("unable to create new trigger interest file `%.250s'"), newfn.buf); push_cleanup(cu_closestream, ~ehflag_normaltidy, NULL, 0, 1, nf); while (trk_explicit_f && trk_explicit_fgets(buf, sizeof(buf)) >= 0) { int len = strlen(pkg->name); if (strncmp(buf, pkg->name, len) == 0 && (buf[len] == '\0' || buf[len] == '/')) continue; fprintf(nf, "%s\n", buf); empty = false; } if (signum > 0) { fprintf(nf, "%s%s\n", pkg->name, (opts == trig_noawait) ? "/noawait" : ""); empty = false; } if (!empty) trk_explicit_interest_flush(newfn.buf, nf); pop_cleanup(ehflag_normaltidy); if (fclose(nf)) ohshite(_("unable to close new trigger interest file `%.250s'"), newfn.buf); if (empty) trk_explicit_interest_remove(newfn.buf); else trk_explicit_interest_commit(newfn.buf); dir_sync_path(triggersdir); }
static void trk_explicit_interest_change(const char *trig, struct pkginfo *pkg, struct pkgbin *pkgbin, int signum, enum trig_options opts) { char buf[1024]; struct atomic_file *file; bool empty = true; trk_explicit_start(trig); file = atomic_file_new(trk_explicit_fn.buf, 0); atomic_file_open(file); while (trk_explicit_f && trk_explicit_fgets(buf, sizeof(buf)) >= 0) { const char *pkgname = pkgbin_name(pkg, pkgbin, pnaw_nonambig); size_t len = strlen(pkgname); if (strncmp(buf, pkgname, len) == 0 && len < sizeof(buf) && (buf[len] == '\0' || buf[len] == '/')) continue; fprintf(file->fp, "%s\n", buf); empty = false; } if (signum > 0) { fprintf(file->fp, "%s%s\n", pkgbin_name(pkg, pkgbin, pnaw_nonambig), (opts == TRIG_NOAWAIT) ? "/noawait" : ""); empty = false; } if (!empty) atomic_file_sync(file); atomic_file_close(file); if (empty) atomic_file_remove(file); else atomic_file_commit(file); atomic_file_free(file); dir_sync_path(triggersdir); }
static void trk_explicit_activate_awaiter(struct pkginfo *aw) { char buf[1024]; struct pkginfo *pend; if (!trk_explicit_f) return; if (fseek(trk_explicit_f, 0, SEEK_SET)) ohshite(_("failed to rewind trigger interest file '%.250s'"), trk_explicit_fn.buf); while (trk_explicit_fgets(buf, sizeof(buf)) >= 0) { struct dpkg_error err; char *slash; bool noawait = false; slash = strchr(buf, '/'); if (slash && strcmp("/noawait", slash) == 0) { noawait = true; *slash = '\0'; } if (slash && strcmp("/await", slash) == 0) { noawait = false; *slash = '\0'; } pend = pkg_spec_parse_pkg(buf, &err); if (pend == NULL) ohshit(_("trigger interest file '%.250s' syntax error; " "illegal package name '%.250s': %.250s"), trk_explicit_fn.buf, buf, err.str); trig_record_activation(pend, noawait ? NULL : aw, trk_explicit_trig); } }