commit - c47aa8f77728a25846c3e2055cb701fc4628526ea998271dfff97c98ee9545ad
commit + f227782da5439de8415e9ee711d22fbe93d101d780b74a0eafa6ee9f9d7c0c8d
blob - a84b37e006e1bc5b3eab23f3bf1f3fab23614f3b6bfa274ad84a511003ad0bc6
blob + 5379854236078b70a2a4c09e660ee253bd2921fb8a34a9f7f9f4ec9b088b812f
--- gotsys/gotsys.1
+++ gotsys/gotsys.1
.Nm
are as follows:
.Bl -tag -width Ds
-.It Cm apply Oo Fl c Ar commit Oc Oo Fl f Ar socket Oc Oo Fl r Ar repository-path Oc Oo Ar file Oc
+.It Cm apply Oo Fl c Ar commit Oc Oo Fl f Ar socket Oc Oo Fl r Ar repository-path Oc Oo Fl w Oc Oo Ar file Oc
Trigger system configuration tasks based on the
.Xr gotsys.conf 5
configuration
If not specified, the repository path
.Pa /git/gotsys.git
will be used.
+.It Fl w
+Wait until
+.Xr gotsysd 8
+is done trying to apply the configuration and report the result.
.El
.It Cm check Oo Fl q Oc Oo Fl f Ar file Oc
Read a
blob - 4121f9b246c4cd0e3fb0a74062b3e82a6144b8afc48d7e8a64247e745bd4f5fe
blob + 78445f8f21e3faadcf55634dcd6906d9ed31876dc1771175f46a7e3e6d64d0e0
--- gotsys/gotsys.c
+++ gotsys/gotsys.c
usage_apply(void)
{
fprintf(stderr, "usage: %s apply [-f socket] [-r repository] "
- "[-c commit] [filename]", getprogname());
+ "[-c commit] [-w] [filename]", getprogname());
exit(1);
}
const char *filename = GOTSYSD_SYSCONF_FILENAME;
const char *socket_path = GOTSYSD_UNIX_SOCKET;
struct got_commit_object *commit = NULL;
- int ch, ret, fd = -1, sysconf_fd = -1, gotsysd_sock = -1;
+ int ch, ret, fd = -1, sysconf_fd = -1, gotsysd_sock = -1, wait = 0;
FILE *sysconf_file = NULL;
struct got_object_id *commit_id = NULL;
struct gotsysd_imsg_cmd_sysconf sysconf_cmd;
memset(&ibuf, 0, sizeof(ibuf));
- while ((ch = getopt(argc, argv, "f:c:r:")) != -1) {
+ while ((ch = getopt(argc, argv, "f:c:r:w")) != -1) {
switch (ch) {
case 'c':
commit_id_str = optarg;
}
got_path_strip_trailing_slashes(repo_path);
break;
+ case 'w':
+ wait = 1;
+ break;
default:
usage_apply();
/* NOTREACHED */
goto done;
}
#endif
- n = imsgbuf_read(&ibuf);
- if (n == -1) {
- err = got_error_from_errno("imsgbuf_read");
- goto done;
- }
- if (n == 0) {
- err = got_error(GOT_ERR_EOF);
- goto done;
- }
+ do {
+ n = imsgbuf_read(&ibuf);
+ if (n == -1) {
+ err = got_error_from_errno("imsgbuf_read");
+ goto done;
+ }
+ if (n == 0) {
+ err = got_error(GOT_ERR_EOF);
+ goto done;
+ }
- n = imsg_get(&ibuf, &imsg);
- if (n == -1) {
- err = got_error_from_errno("imsg_get");
- goto done;
- }
- if (n == 0) {
- err = got_error(GOT_ERR_PRIVSEP_READ);
- goto done;
- }
+ n = imsg_get(&ibuf, &imsg);
+ if (n == -1) {
+ err = got_error_from_errno("imsg_get");
+ goto done;
+ }
+ if (n == 0) {
+ err = got_error(GOT_ERR_PRIVSEP_READ);
+ goto done;
+ }
- switch (imsg.hdr.type) {
- case GOTSYSD_IMSG_ERROR:
- err = recv_error(&imsg);
- break;
- case GOTSYSD_IMSG_SYSCONF_STARTED:
- break;
- default:
- err = got_error(GOT_ERR_PRIVSEP_MSG);
- break;
- }
+ switch (imsg.hdr.type) {
+ case GOTSYSD_IMSG_ERROR:
+ err = recv_error(&imsg);
+ break;
+ case GOTSYSD_IMSG_SYSCONF_STARTED:
+ break;
+ case GOTSYSD_IMSG_SYSCONF_SUCCESS:
+ printf("sysconf success\n");
+ wait = 0;
+ break;
+ case GOTSYSD_IMSG_SYSCONF_FAILURE:
+ err = got_error_fmt(GOT_ERR_ON_SERVER_SIDE,
+ "sysconf failure");
+ break;
+ default:
+ err = got_error(GOT_ERR_PRIVSEP_MSG);
+ break;
+ }
- imsg_free(&imsg);
+ imsg_free(&imsg);
+ } while (err == NULL && wait);
done:
imsgbuf_clear(&ibuf);
free(repo_path);
blob - 6889c91e6644ce5c044927933fbe45cfad67bc0c289df737ea0fa5f756b31f10
blob + 1f62383621d43dab535d4d92db8d5f29b867f16658ce3f402e5d8b1b9c545ee7
--- gotsysd/gotsysd.c
+++ gotsysd/gotsysd.c
int pipe[2];
struct gotsysd_imsgev iev;
struct event tmo;
+ uint32_t client_id;
TAILQ_ENTRY(gotsysd_child_proc) entry;
};
enum gotsysd_client_state {
GOTSYSD_CLIENT_STATE_NEW = -1,
GOTSYSD_CLIENT_STATE_ACCESS_GRANTED = 1,
+ GOTSYSD_CLIENT_STATE_SYSCONF_STARTED,
};
struct gotsysd_client {
}
static void
+client_sysconf_done(uint32_t client_id, int exit_status)
+{
+ struct gotsysd_client *client;
+ int imsg_code;
+
+ client = find_client(client_id);
+ if (client == NULL)
+ return;
+
+ if (client->state != GOTSYSD_CLIENT_STATE_SYSCONF_STARTED)
+ return;
+
+ if (exit_status == 0)
+ imsg_code = GOTSYSD_IMSG_SYSCONF_SUCCESS;
+ else
+ imsg_code = GOTSYSD_IMSG_SYSCONF_FAILURE;
+
+ if (gotsysd_imsg_compose_event(&client->iev, imsg_code,
+ GOTSYSD_PROC_GOTSYSD, -1, NULL, 0) == -1)
+ log_warn("imsg compose %d", imsg_code);
+}
+
+static void
disconnect(struct gotsysd_client *client)
{
struct gotsysd_imsg_disconnect idisconnect;
}
static const struct got_error *
-start_sysconf_child(int sysconf_fd, struct got_object_id *commit_id)
+start_sysconf_child(int sysconf_fd, struct got_object_id *commit_id,
+ uint32_t client_id)
{
const struct got_error *err = NULL;
struct gotsysd_child_proc *proc;
evtimer_set(&proc->tmo, kill_proc_timeout, proc);
proc->type = GOTSYSD_PROC_SYSCONF;
+ proc->client_id = client_id;
log_debug("running system configuration tasks for gotsys.conf from "
"gotsys.git commit %s", commit_id_str);
STAILQ_REMOVE_HEAD(&gotsysd.sysconf_pending, entry);
- err = start_sysconf_child(cmd->fd, &cmd->commit_id);
+ err = start_sysconf_child(cmd->fd, &cmd->commit_id, cmd->client_id);
if (err) {
log_warn("could not start sysconf child process: %s",
err->msg);
return got_error(GOT_ERR_PRIVSEP_MSG);
if (gotsysd.sysconf_proc == NULL) {
- err = start_sysconf_child(sysconf_fd, &sysconf_cmd.commit_id);
+ err = start_sysconf_child(sysconf_fd, &sysconf_cmd.commit_id,
+ client->id);
if (err) {
close(sysconf_fd);
return err;
cmd->fd = sysconf_fd;
memcpy(&cmd->commit_id, &sysconf_cmd.commit_id,
sizeof(cmd->commit_id));
+ cmd->client_id = client->id;
STAILQ_INSERT_TAIL(&gotsysd.sysconf_pending, cmd, entry);
evtimer_add(&gotsysd.sysconf_tmo, &tv);
}
GOTSYSD_IMSG_SYSCONF_STARTED,
GOTSYSD_PROC_GOTSYSD, -1, NULL, 0) == -1) {
err = got_error_from_errno("imsg compose SYSCONF_STARTED");
- }
+ } else
+ client->state = GOTSYSD_CLIENT_STATE_SYSCONF_STARTED;
return NULL;
}
" signal %d", pid, WTERMSIG(status));
}
+ if (proc->type == GOTSYSD_PROC_SYSCONF) {
+ client_sysconf_done(proc->client_id,
+ WEXITSTATUS(status));
+ }
+
if (proc == gotsysd.sysconf_proc) {
gotsysd.sysconf_proc = NULL;
if (gotsysd.sysconf_fd != -1) {
blob - ebcf973b8ff5c1b1bb2d23ddf650c37c67057d178fb64c04aa4a7e1784fc4e59
blob + 1c3bbe47e3922000a38b3f1b076b4225f524efcf488ff3546e088ce7d73f0ae5
--- gotsysd/gotsysd.h
+++ gotsysd/gotsysd.h
STAILQ_ENTRY(gotsysd_pending_sysconf_cmd) entry;
int fd;
struct got_object_id commit_id;
+ uint32_t client_id;
};
STAILQ_HEAD(gotsysd_pending_sysconf_cmd_list,
gotsysd_pending_sysconf_cmd);
GOTSYSD_IMSG_INFO,
GOTSYSD_IMSG_CMD_SYSCONF,
GOTSYSD_IMSG_SYSCONF_STARTED,
+ GOTSYSD_IMSG_SYSCONF_SUCCESS,
+ GOTSYSD_IMSG_SYSCONF_FAILURE,
/* Internal sysconf messages. */
GOTSYSD_IMSG_SYSCONF_READY,
GOTSYSD_IMSG_SYSCONF_FD,
- GOTSYSD_IMSG_SYSCONF_SUCCESS,
/* Child processes management. */
GOTSYSD_IMSG_CONNECT_PROC,
blob - d8b5c41f76d490ad677cf0bd331d8dc5f6d5631d292e2675e9248833cf0361b8
blob + 5eae740af7035feea6899f6918d3f7913d4be8a051e2a325134cd745a39dedbe
--- include/got_error.h
+++ include/got_error.h
#define GOT_ERR_GROUP_EXISTS 179
#define GOT_ERR_AUTHORIZED_KEY 180
#define GOT_ERR_CONNECTION_LIMIT 190
+#define GOT_ERR_ON_SERVER_SIDE 191
struct got_error {
int code;
blob - 9cbfc82bf95406c5f6bf0ffc48de50a9ea908ce36509473c65870ded2a90ad03
blob + a4cc1e868466853221008d463d499319c36161afec6cfbf795ba524a5f0f562b
--- lib/error.c
+++ lib/error.c
{ GOT_ERR_GROUP_EXISTS, "group already exists" },
{ GOT_ERR_AUTHORIZED_KEY, "no authorized key found" },
{ GOT_ERR_CONNECTION_LIMIT, "connection limit exceeded" },
+ { GOT_ERR_ON_SERVER_SIDE, "see server-side logs for error details" },
};
static struct got_custom_error {