commit - 7074d57878cd47e8ccaaf14d6ccb3c27cc5a4741
commit + 851cc2028301bdc7297fa1b1392abe502bddf4b5
blob - 4ce0a0931df0eff3514a34017c6e52d0312cac1d
blob + 1dfd1185ad1066e85310298b11c6567a84d3ecf8
--- gotd/gotd.c
+++ gotd/gotd.c
if (repo == NULL)
fatalx("no repository for path %s", repo_path);
session_main(title, repo_path, pack_fds, temp_fds,
- &gotd.request_timeout,
- &repo->notification_refs,
- &repo->notification_ref_namespaces,
- repo->summarize_notifications,
- &repo->notification_targets,
- proc_id);
+ &gotd.request_timeout, repo, proc_id);
/* NOTREACHED */
break;
case PROC_REPO_READ:
blob - 6bad495759fd5455d3e40a25cf588583054b3baa
blob + 3949efc5f4e975965c68cb4d8c928551cba2602e
--- gotd/session.c
+++ gotd/session.c
pid_t pid;
const char *title;
struct got_repository *repo;
+ struct gotd_repo *repo_cfg;
int *pack_fds;
int *temp_fds;
struct gotd_imsgev parent_iev;
static const struct got_error *
send_notification(struct got_object_id *old_id, struct got_object_id *new_id,
- struct got_reference *ref)
+ struct got_repository *repo, struct got_reference *ref)
{
const struct got_error *err = NULL;
+ struct gotd_session_client *client = &gotd_session_client;
struct gotd_imsgev *iev = &gotd_session.notifier_iev;
struct got_pathlist_entry *pe;
+ struct gotd_imsg_notify inotify;
int fd = -1;
+ char hostname[HOST_NAME_MAX + 1];
+ const char *action = "";
if (iev->ibuf.fd == -1)
return NULL; /* notifications unused */
+
+ memset(&inotify, 0, sizeof(inotify));
TAILQ_FOREACH(pe, gotd_session.notification_refs, entry) {
const char *refname = pe->path;
if (pe == NULL && !TAILQ_EMPTY(gotd_session.notification_refs))
return NULL;
+ if (gethostname(hostname, sizeof(hostname)) == -1)
+ return got_error_from_errno("gethostname");
+
TAILQ_FOREACH(pe, gotd_session.notification_ref_namespaces, entry) {
const char *namespace = pe->path;
if (fd == -1)
return got_error_from_errno("got_opentempfd");
- if (old_id == NULL) {
- dprintf(fd, "created %s\n", got_ref_get_name(ref));
- } else if (new_id == NULL) {
- dprintf(fd, "deleted %s\n", got_ref_get_name(ref));
- } else {
- dprintf(fd, "modified %s\n", got_ref_get_name(ref));
- }
+ if (old_id == NULL)
+ action = "created";
+ else if (new_id == NULL)
+ action = "removed";
+ else
+ action = "changed";
- /* TODO: send imsg */
+ strlcpy(inotify.repo_name, gotd_session.repo_cfg->name,
+ sizeof(inotify.repo_name));
- if (fd != -1 && close(fd) == -1 && err == NULL)
- err = got_error_from_errno("close");
- return err;
+ snprintf(inotify.subject_line, sizeof(inotify.subject_line),
+ "%s: %s: UID %d %s %s", hostname, gotd_session.repo_cfg->name,
+ client->euid, action, got_ref_get_name(ref));
+
+ dprintf(fd, "%s %s\n", action, got_ref_get_name(ref));
+
+ if (gotd_imsg_compose_event(iev, GOTD_IMSG_NOTIFY, PROC_SESSION_WRITE,
+ fd, &inotify, sizeof(inotify)) == -1) {
+ err = got_error_from_errno("imsg compose NOTIFY");
+ close(fd);
+ return err;
+ }
+
+ return NULL;
}
static const struct got_error *
err = got_ref_write(ref, repo); /* will lock/unlock */
if (err)
goto done;
- err = send_notification(NULL, &new_id, ref);
+ err = send_notification(NULL, &new_id, repo, ref);
if (err)
goto done;
} else {
err = got_ref_delete(ref, repo);
if (err)
goto done;
- err = send_notification(&old_id, NULL, ref);
+ err = send_notification(&old_id, NULL, repo, ref);
if (err)
goto done;
free(id);
err = got_ref_write(ref, repo);
if (err)
goto done;
- err = send_notification(&old_id, &new_id, ref);
+ err = send_notification(&old_id, &new_id, repo, ref);
if (err)
goto done;
}
void
session_main(const char *title, const char *repo_path,
int *pack_fds, int *temp_fds, struct timeval *request_timeout,
- struct got_pathlist_head *notification_refs,
- struct got_pathlist_head *notification_ref_namespaces,
- int summarize_notifications,
- struct gotd_notification_targets *notification_targets,
- enum gotd_procid proc_id)
+ struct gotd_repo *repo_cfg, enum gotd_procid proc_id)
{
const struct got_error *err = NULL;
struct event evsigint, evsigterm, evsighup, evsigusr1;
gotd_session.temp_fds = temp_fds;
memcpy(&gotd_session.request_timeout, request_timeout,
sizeof(gotd_session.request_timeout));
+ gotd_session.repo_cfg = repo_cfg;
gotd_session.proc_id = proc_id;
- gotd_session.notification_refs = notification_refs;
- gotd_session.notification_ref_namespaces = notification_ref_namespaces;
- gotd_session.summarize_notifications = summarize_notifications;
- gotd_session.notification_targets = notification_targets;
imsg_init(&gotd_session.notifier_iev.ibuf, -1);
blob - f98879f84ca1815ba0e760a8995524e6205f7a7b
blob + 624f7bb81035da8f1d5293bcbcdf72cd6f064102
--- gotd/session.h
+++ gotd/session.h
*/
void session_main(const char *, const char *, int *, int *, struct timeval *,
- struct got_pathlist_head *, struct got_pathlist_head *, int,
- struct gotd_notification_targets *, enum gotd_procid);
+ struct gotd_repo *, enum gotd_procid);