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