commit c42b7609faa2e9d1f7c0a1b59fe2303f05ddaa22 from: Stefan Sperling date: Mon Mar 11 10:23:58 2024 UTC queue notification info without an open file commit - 9d88153b9f990652b2dd274efb7b561fc1446708 commit + c42b7609faa2e9d1f7c0a1b59fe2303f05ddaa22 blob - 8427fbb413b6a974cd738fd557463719005ebac9 blob + 00e51397517abfc6beb72abdf282b49321818416 --- gotd/session.c +++ gotd/session.c @@ -59,7 +59,6 @@ struct gotd_session_notif { char *refname; struct got_object_id old_id; struct got_object_id new_id; - int fd; }; STAILQ_HEAD(gotd_session_notifications, gotd_session_notif) notifications; @@ -429,18 +428,12 @@ prepare_notification(struct got_object_id *old_id, str struct gotd_session_client *client = &gotd_session_client; struct gotd_repo *repo_cfg = gotd_session.repo_cfg; struct gotd_imsgev *iev = &client->repo_child_iev; - struct gotd_imsg_notification_content req; struct got_pathlist_entry *pe; struct gotd_session_notif *notif; - struct ibuf *wbuf; - size_t len, refname_len; - int fd = -1; if (iev->ibuf.fd == -1) return NULL; /* notifications unused */ - memset(&req, 0, sizeof(req)); - TAILQ_FOREACH(pe, &repo_cfg->notification_refs, entry) { const char *refname = pe->path; if (strcmp(got_ref_get_name(ref), refname) == 0) @@ -463,73 +456,32 @@ prepare_notification(struct got_object_id *old_id, str !TAILQ_EMPTY(&repo_cfg->notification_ref_namespaces)) return NULL; - fd = got_opentempfd(); - if (fd == -1) - return got_error_from_errno("got_opentempfd"); + notif = calloc(1, sizeof(*notif)); + if (notif == NULL) + return got_error_from_errno("calloc"); - if (old_id) - memcpy(req.old_id, old_id->sha1, sizeof(req.old_id)); - if (new_id) - memcpy(req.new_id, new_id->sha1, sizeof(req.new_id)); - if (old_id == NULL) - req.action = GOTD_NOTIF_ACTION_CREATED; + notif->action = GOTD_NOTIF_ACTION_CREATED; else if (new_id == NULL) - req.action = GOTD_NOTIF_ACTION_REMOVED; + notif->action = GOTD_NOTIF_ACTION_REMOVED; else - req.action = GOTD_NOTIF_ACTION_CHANGED; - - notif = calloc(1, sizeof(*notif)); - if (notif == NULL) { - err = got_error_from_errno("calloc"); - close(fd); - return err; - } - notif->fd = dup(fd); - if (notif->fd == -1) { - err = got_error_from_errno("dup"); - goto done; - } - notif->action = req.action; + notif->action = GOTD_NOTIF_ACTION_CHANGED; + + memcpy(¬if->old_id, old_id, sizeof(notif->old_id)); + memcpy(¬if->new_id, new_id, sizeof(notif->new_id)); + notif->refname = strdup(got_ref_get_name(ref)); if (notif->refname == NULL) { err = got_error_from_errno("strdup"); - goto done; - } - - refname_len = strlen(got_ref_get_name(ref)); - len = sizeof(struct gotd_session_notif) + refname_len; - wbuf = imsg_create(&iev->ibuf, GOTD_IMSG_NOTIFY, gotd_session.proc_id, - gotd_session.pid, len); - if (wbuf == NULL) { - err = got_error_from_errno("imsg_create NOTIFY"); - goto done; - } - - if (imsg_add(wbuf, &req, sizeof(req)) == -1) { - err = got_error_from_errno("imsg_add NOTIFY"); goto done; } - if (imsg_add(wbuf, got_ref_get_name(ref), refname_len) == -1) { - err = got_error_from_errno("imsg_add NOTIFY"); - goto done; - } STAILQ_INSERT_TAIL(¬ifications, notif, entry); - - wbuf->fd = fd; - fd = -1; - imsg_close(&iev->ibuf, wbuf); - gotd_imsg_event_add(iev); done: if (err && notif) { - if (notif->fd != -1 && close(notif->fd) == -1 && err == NULL) - err = got_error_from_errno("close"); free(notif->refname); free(notif); } - if (fd != -1 && close(fd) == -1 && err == NULL) - err = got_error_from_errno("close"); return err; } @@ -1887,8 +1839,6 @@ gotd_session_shutdown(void) while (!STAILQ_EMPTY(¬ifications)) { notif = STAILQ_FIRST(¬ifications); STAILQ_REMOVE_HEAD(¬ifications, entry); - if (notif->fd != -1) - close(notif->fd); free(notif->refname); free(notif); }