Annotation of freem/src/ssvn_zprocess.c, revision 1.1.1.1
1.1 snw 1: /*
2: * *
3: * * *
4: * * *
5: * ***************
6: * * * * *
7: * * MUMPS *
8: * * * * *
9: * ***************
10: * * *
11: * * *
12: * *
13: *
14: * ssvn_zprocess.c
15: * ^$ZPROCESS ssv
16: *
17: *
18: * Author: Serena Willis <jpw@coherent-logic.com>
19: * Copyright (C) 1998 MUG Deutschland
20: * Copyright (C) 2020 Coherent Logic Development LLC
21: *
22: *
23: * This file is part of FreeM.
24: *
25: * FreeM is free software: you can redistribute it and/or modify
26: * it under the terms of the GNU Affero Public License as published by
27: * the Free Software Foundation, either version 3 of the License, or
28: * (at your option) any later version.
29: *
30: * FreeM is distributed in the hope that it will be useful,
31: * but WITHOUT ANY WARRANTY; without even the implied warranty of
32: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33: * GNU Affero Public License for more details.
34: *
35: * You should have received a copy of the GNU Affero Public License
36: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
37: *
38: **/
39:
40: #include <stdlib.h>
41: #include <stdio.h>
42: #include <string.h>
43: #include <dirent.h>
44:
45: #include "mpsdef.h"
46: #include "mref.h"
47: #include "iniconf.h"
48:
49: void ssvn_zprocess (short action, char *key, char *data)
50: {
51: freem_ref_t *ref = (freem_ref_t *) malloc (sizeof(freem_ref_t));
52:
53: char *kbuf = (char *) malloc (STRLEN * sizeof(char));
54: char *verb = (char *) malloc (STRLEN * sizeof(char));
55: char *proc_path = (char *) malloc (STRLEN * sizeof(char));
56:
57: pid_t t_pid;
58:
59: NULLPTRCHK(ref,"ssvn_zprocess");
60: NULLPTRCHK(kbuf,"ssvn_zprocess");
61: NULLPTRCHK(verb,"ssvn_zprocess");
62: NULLPTRCHK(proc_path,"ssvn_zprocess");
63:
64: mref_init (ref, MREF_RT_SSVN, "");
65: internal_to_mref (ref, key);
66:
67: if (ref->subscript_count < 2) {
68:
69: free (kbuf);
70: free (ref);
71: free (verb);
72: free (proc_path);
73:
74: merr_raise (INVREF);
75: return;
76: }
77:
78: t_pid = atol(ref->subscripts[0]);
79: snprintf (proc_path, STRLEN - 1, "/proc/%d", t_pid);
80:
81: strncpy (verb, ref->subscripts[1], STRLEN - 1);
82:
83:
84: stcpy (kbuf, key);
85:
86: switch (action) {
87:
88: case get_sym:
89:
90: if (strcmp (verb, "EXISTS") == 0) {
91:
92: if (kill (t_pid, 0) == 0) {
93: snprintf (data, STRLEN - 1, "%d\201", 1);
94: }
95: else {
96: snprintf (data, STRLEN - 1, "%d\201", 0);
97: }
98:
99: free (kbuf);
100: free (ref);
101: free (verb);
102: free (proc_path);
103:
104: merr_raise (OK);
105: return;
106:
107: }
108: else if (strcmp (verb, "ATTRIBUTE") == 0) {
109:
110: char attrib[256];
111: char fpath[4096];
112:
113: FILE *fp;
114:
115: strncpy (attrib, ref->subscripts[2], 255);
116:
117: snprintf (fpath, 4095, "/proc/%d/%s", t_pid, attrib);
118:
119: if ((fp = fopen (fpath, "r")) == NULL) {
120:
121: free (kbuf);
122: free (ref);
123: free (verb);
124: free (proc_path);
125:
126: merr_raise (INVREF);
127: return;
128: }
129:
130: fgets (data, 256, fp);
131: stcnv_c2m (data);
132:
133: fclose (fp);
134:
135: free (kbuf);
136: free (ref);
137: free (verb);
138: free (proc_path);
139:
140:
141: merr_raise (OK);
142: return;
143:
144: }
145:
146: free (kbuf);
147: free (ref);
148: free (verb);
149: free (proc_path);
150:
151: merr_raise (INVREF);
152: return;
153:
154: case set_sym:
155:
156: if (strcmp (verb, "SIGNAL") == 0) {
157:
158: int signum;
159:
160: stcnv_m2c (data);
161:
162: signum = atoi (data);
163: kill (t_pid, signum);
164:
165: stcnv_c2m (data);
166:
167: free (kbuf);
168: free (ref);
169: free (verb);
170: free (proc_path);
171:
172:
173: merr_raise (OK);
174: return;
175:
176:
177: }
178: else {
179:
180: free (kbuf);
181: free (ref);
182: free (verb);
183: free (proc_path);
184:
185: merr_raise (M29);
186: return;
187: }
188:
189: case killone:
190: case kill_sym:
191:
192: kill (t_pid, 15);
193:
194: free (kbuf);
195: free (ref);
196: free (verb);
197: free (proc_path);
198:
199: merr_raise (OK);
200: return;
201:
202: case dat:
203: case fra_order:
204: case fra_query:
205: case bigquery:
206: case getnext:
207: case m_alias:
208: case zdata:
209:
210: default:
211:
212: free (kbuf);
213: free (ref);
214: free (verb);
215: free (proc_path);
216:
217: merr_raise (INVREF);
218: return;
219:
220: }
221:
222: free (kbuf);
223: free (ref);
224: free (verb);
225: free (proc_path);
226:
227: *data = EOL;
228: return;
229: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>