Package: irssi-plugin-xmpp / 0.54-3

singpolyma-0019-Forgot-these-files.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From eb08b8579355c6962e187f27e6c69a8e5e837d2c Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Mon, 7 Oct 2013 13:31:29 -0500
Subject: [PATCH] Forgot these files

---
 src/core/popenRWE.c | 93 ++++++++++++++++++++++++++++++++++++++++++
 src/core/popenRWE.h |  7 ++++
 2 files changed, 100 insertions(+)
 create mode 100644 src/core/popenRWE.c
 create mode 100644 src/core/popenRWE.h

--- /dev/null
+++ b/src/core/popenRWE.c
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2009-2010 Bart Trojanowski <bart@jukie.net>
+ * Licensed under GPLv2, or later, at your choosing.
+ *
+ * bidirectional popen() call
+ *
+ * @param rwepipe - int array of size three
+ * @param exe - program to run
+ * @param argv - argument list
+ * @return pid or -1 on error
+ *
+ * The caller passes in an array of three integers (rwepipe), on successful
+ * execution it can then write to element 0 (stdin of exe), and read from
+ * element 1 (stdout) and 2 (stderr).
+ */
+
+/* Modified by Stephen Paul Weber to take a path and pass it to sh -c */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
+#include "popenRWE.h"
+
+int popenRWE(int *rwepipe, const char *path) {
+	int in[2];
+	int out[2];
+	int err[2];
+	int pid;
+	int rc;
+	const char *argv[4] = {"sh", "-c", NULL, NULL};
+	argv[2] = path;
+
+	rc = pipe(in);
+	if (rc<0)
+		goto error_in;
+
+	rc = pipe(out);
+	if (rc<0)
+		goto error_out;
+
+	rc = pipe(err);
+	if (rc<0)
+		goto error_err;
+
+	pid = fork();
+	if (pid > 0) { /* parent */
+		close(in[0]);
+		close(out[1]);
+		close(err[1]);
+		rwepipe[0] = in[1];
+		rwepipe[1] = out[0];
+		rwepipe[2] = err[0];
+		return pid;
+	} else if (pid == 0) { /* child */
+		close(in[1]);
+		close(out[0]);
+		close(err[0]);
+		close(0);
+		dup(in[0]);
+		close(1);
+		dup(out[1]);
+		close(2);
+		dup(err[1]);
+
+		execvp(argv[0], (char**)argv);
+		exit(1);
+	} else
+		goto error_fork;
+
+	return pid;
+
+error_fork:
+	close(err[0]);
+	close(err[1]);
+error_err:
+	close(out[0]);
+	close(out[1]);
+error_out:
+	close(in[0]);
+	close(in[1]);
+error_in:
+	return -1;
+}
+
+int pcloseRWE(int pid, int *rwepipe) {
+	int rc, status;
+	close(rwepipe[0]);
+	close(rwepipe[1]);
+	close(rwepipe[2]);
+	rc = waitpid(pid, &status, 0);
+	return status;
+}
--- /dev/null
+++ b/src/core/popenRWE.h
@@ -0,0 +1,7 @@
+#ifndef __POPEN_RWE
+#define __POPEN_RWE
+
+int popenRWE(int *rwepipe, const char *path);
+int pcloseRWE(int pid, int *rwepipe);
+
+#endif