commit - 7b14cfd98d4c0900c1b3d8b95ef388d895a9f363
commit + ba522d3c85e14ed4626a823f0cef8d42aef9d0bc
blob - 700b931c36131a8b0513e60d55ab18b3a8da45d0
blob + d8d9e210e900e38322ae61e42335b5789eae6811
--- ctl.c
+++ ctl.c
edit_file(tmpfile, daemons2->mode, daemons2->propername, args);
}
-static void
+static int
provide_example_config(char *filename)
{
char *name;
char path[PATH_MAX];
char tmpprompt[sizeof(prompt)];
FILE *f = NULL, *example = NULL;
- int ret, num;
+ int ret = 0, n, num;
struct stat sb;
size_t len, remain;
f = fopen(filename, "a+");
if (f == NULL)
- return;
+ return 0;
if (fstat(fileno(f), &sb) == -1)
goto done;
if (name == NULL)
goto done;
- ret = snprintf(path, sizeof(path), "/etc/examples/%s", name);
- if (ret < 0 || (size_t)ret >= sizeof(path))
+ n = snprintf(path, sizeof(path), "/etc/examples/%s", name);
+ if (n < 0 || (size_t)n >= sizeof(path))
goto done;
/* Snip off rdomain trailer at end of filename. */
restoreprompt();
if (example)
fclose(example);
+ return ret;
}
int
char *editor;
int fd;
int ret = 0;
+ sig_t sigint;
/* acq lock, call editor, test config with cmd and args, release lock */
if ((editor = getenv("VISUAL")) == NULL) {
}
if ((fd = acq_lock(tmpfile)) > 0) {
char *argv[] = { editor, tmpfile, NULL };
- provide_example_config(tmpfile);
- ret = cmdargs(editor, argv);
+
+ /*
+ * Temporarily disable command.c intr() handler to ensure
+ * we tidy up the lock file when the user hits Ctrl-C at
+ * at prompt.
+ */
+ sigint = signal(SIGINT, SIG_IGN);
+
+ ret = provide_example_config(tmpfile);
+ if (ret == 0)
+ ret = cmdargs(editor, argv);
if (ret == 0 && chmod(tmpfile, mode) == -1) {
printf("%% chmod %o %s: %s\n",
mode, tmpfile, strerror(errno));
if (ret == 0 && args != NULL)
ret = cmdargs(args[0], args);
rls_lock(fd);
+ signal(SIGINT, sigint); /* Restore SIGINT handler. */
} else {
printf ("%% %s configuration is locked for editing\n",
propername);