Introduction
Introduction Statistics Contact Development Disclaimer Help
Fix spawn*() so it can report errors to the caller - noice - small file browser…
git clone git://git.codemadness.org/noice
Log
Files
Refs
README
LICENSE
---
commit 58edea240e40eeb006923f012a6bb792fb8ef8a7
parent 784551aa55ff996e103443d1bbe65684fd4d7463
Author: sin <[email protected]>
Date: Thu, 22 Aug 2019 15:09:29 +0100
Fix spawn*() so it can report errors to the caller
If nopen is not in PATH, noice will briefly print a warning about it
so the user knows.
Also, add NOPENCMD define in noiceconf.def.h to specify the default
plumber program.
Diffstat:
A TODO | 1 +
M noice.c | 6 +++++-
M noiceconf.def.h | 2 ++
M nopen.c | 5 ++---
M spawn.c | 11 +++++++----
M util.h | 4 ++--
6 files changed, 19 insertions(+), 10 deletions(-)
---
diff --git a/TODO b/TODO
@@ -0,0 +1 @@
+- Support overriding plumber via environment variable
diff --git a/noice.c b/noice.c
@@ -650,8 +650,12 @@ nochange:
goto begin;
case S_IFREG:
exitcurses();
- spawnlp(path, "nopen", "nopen", newpath, (void…
+ r = spawnlp(path, NOPENCMD, NOPENCMD, newpath,…
initcurses();
+ if (r == -1) {
+ printmsg("failed to execute " NOPENCMD…
+ goto nochange;
+ }
continue;
default:
printmsg("Unsupported file");
diff --git a/noiceconf.def.h b/noiceconf.def.h
@@ -3,6 +3,8 @@
#define CURSR " > "
#define EMPTY " "
+#define NOPENCMD "nopen"
+
int dirorder = 0; /* Set to 1 to sort by directory first */
int mtimeorder = 0; /* Set to 1 to sort by time modified */
int icaseorder = 0; /* Set to 1 to sort by ignoring case */
diff --git a/nopen.c b/nopen.c
@@ -21,7 +21,7 @@ struct assoc {
#include "nopenconf.h"
void
-spawnassoc(struct assoc *assoc, char *arg)
+run(struct assoc *assoc, char *arg)
{
char *argv[NR_ARGS];
int i;
@@ -46,7 +46,6 @@ openwith(char *file)
if (regexec(&assocs[i].regcomp, file, 0, NULL, 0) == 0)
return &assocs[i];
}
-
return NULL;
}
@@ -88,7 +87,7 @@ main(int argc, char *argv[])
if ((assoc = openwith(argv[0])) == NULL)
continue;
- spawnassoc(assoc, argv[0]);
+ run(assoc, argv[0]);
}
return 0;
}
diff --git a/spawn.c b/spawn.c
@@ -9,7 +9,7 @@
#include "util.h"
-void
+int
spawnvp(char *dir, char *file, char *argv[])
{
pid_t pid;
@@ -18,7 +18,7 @@ spawnvp(char *dir, char *file, char *argv[])
pid = fork();
switch (pid) {
case -1:
- err(1, "fork");
+ return -1;
case 0:
if (dir != NULL)
chdir(dir);
@@ -27,10 +27,13 @@ spawnvp(char *dir, char *file, char *argv[])
default:
while (waitpid(pid, &status, 0) == -1 && errno == EINTR)
;
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+ return -1;
}
+ return 0;
}
-void
+int
spawnlp(char *dir, char *file, char *argv0, ...)
{
char *argv[NR_ARGS];
@@ -43,5 +46,5 @@ spawnlp(char *dir, char *file, char *argv0, ...)
;
argv[argc] = NULL;
va_end(ap);
- spawnvp(dir, file, argv);
+ return spawnvp(dir, file, argv);
}
diff --git a/util.h b/util.h
@@ -24,5 +24,5 @@ size_t strlcat(char *, const char *, size_t);
#undef strlcpy
size_t strlcpy(char *, const char *, size_t);
int strverscmp(const char *, const char *);
-void spawnvp(char *, char *, char *[]);
-void spawnlp(char *, char *, char *, ...);
+int spawnvp(char *, char *, char *[]);
+int spawnlp(char *, char *, char *, ...);
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.