aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2021-03-19 13:46:01 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2021-03-19 13:46:01 +0100
commit679e1d9a2266328b00e2d4909c38a52c35794bd0 (patch)
tree675101dd31b7cb621191146341e3a1725bc71b44
parentaee602ea2fd23dd34fa88d74ceb3d6441c88ef72 (diff)
downloadlite-xl-popen-light.tar.gz
lite-xl-popen-light.zip
Factor xrdb function into a popen-like functionpopen-light
-rw-r--r--src/xrdb_parse.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/xrdb_parse.c b/src/xrdb_parse.c
index 47018106..8304b24b 100644
--- a/src/xrdb_parse.c
+++ b/src/xrdb_parse.c
@@ -23,7 +23,9 @@ static int join_path(char buf[], int buf_size, const char *path, const char *nam
}
-static int xrdb_popen (int *pid_ptr) {
+/* Lauch a child process using execve and pipe its output into a file
+ descriptor (returned by the function). */
+static int process_open_output(char * const argv[], int *pid_ptr) {
int fd[2];
if (pipe(fd) != 0) return -1;
@@ -36,11 +38,10 @@ static int xrdb_popen (int *pid_ptr) {
dup2(write_fd, STDOUT_FILENO);
close(write_fd);
char *path = getenv("PATH");
- char xrdb_filename[256];
+ char exec_filename[256];
while (path) {
- char *xrgb_argv[3] = {"xrdb", "-query", NULL};
- if (join_path(xrdb_filename, 256, path, "xrdb") == 0) {
- execve(xrdb_filename, xrgb_argv, environ);
+ if (join_path(exec_filename, 256, path, argv[0]) == 0) {
+ execve(exec_filename, argv, environ);
}
path = strchr(path, ':');
if (path) {
@@ -125,7 +126,7 @@ static int xrdb_parse_for_dpi(int read_fd) {
int xrdb_find_dpi() {
int xrdb_pid;
- int read_fd = xrdb_popen(&xrdb_pid);
+ int read_fd = process_open_output((char *[]) {"xrdb", "-query", NULL}, &xrdb_pid);
if (read_fd >= 0) {
int dpi_read = xrdb_parse_for_dpi(read_fd);
int child_status;