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