Mercurial > hg > Members > kono > nitros9-code
comparison level1/cmds/inetd.as @ 2783:03f26e88b809 lwtools-port
Renamed files and setup for lwasm/lwlink work
author | Boisy Pitre <boisy.pitre@nuance.com> |
---|---|
date | Sat, 26 Jan 2013 17:18:24 -0600 |
parents | level1/cmds/inetd.a@aaba193af04f |
children | 28b6ec8a14d5 |
comparison
equal
deleted
inserted
replaced
2782:aaba193af04f | 2783:03f26e88b809 |
---|---|
1 ******************************************************************** | |
2 * inetd - internet daemon | |
3 * | |
4 * $Id$ | |
5 * | |
6 * Edt/Rev YYYY/MM/DD Modified by | |
7 * Comment | |
8 * ------------------------------------------------------------------ | |
9 * 1 2010/01/08 Boisy G. Pitre | |
10 * Started. | |
11 * | |
12 * 2 2010/01/22 Boisy G. Pitre | |
13 * Now reads inetd.conf file. | |
14 * | |
15 * 3 2011/08/07 Boisy G. Pitre | |
16 * Fixed bug where conf file wasn't being processed correctly. | |
17 | |
18 nam inetd | |
19 ttl internet daemon | |
20 | |
21 tylg set $01 Prgrm+Objct | |
22 atrv set $80+rev ReEnt+rev | |
23 rev set $00 | |
24 edition set 3 | |
25 | |
26 section data | |
27 targetport rmb 2 | |
28 netdatardy rmb 1 | |
29 nbufferl equ 128 | |
30 nbuffer rmb nbufferl | |
31 lbufferl equ 128 | |
32 lbuffer rmb lbufferl | |
33 nnext rmb 2 | |
34 token rmb 2 | |
35 orgstdin rmb 1 | |
36 orgstdout rmb 1 | |
37 orgstderr rmb 1 | |
38 childnetpath rmb 1 | |
39 netpath rmb 1 | |
40 targetprog rmb 128 | |
41 targetparams rmb 128 | |
42 tmodeparamlen rmb 1 | |
43 tmodeparams rmb 128 | |
44 endsect | |
45 | |
46 * psect inetd_a,$01,$80,1,200,start | |
47 section text | |
48 | |
49 DEBUG equ 1 | |
50 | |
51 | |
52 NetSig equ 2 | |
53 | |
54 tmode fcs /tmode/ | |
55 | |
56 * signal intercept routine | |
57 sigint cmpb #NetSig | |
58 bne sigex | |
59 inc netdatardy,u | |
60 sigex rti | |
61 | |
62 **** Entry Point **** | |
63 start: | |
64 * setup signal intercept | |
65 leax sigint,pcr | |
66 os9 F$Icpt | |
67 | |
68 clr netdatardy,u | |
69 | |
70 leax nbuffer,u | |
71 stx nnext,u | |
72 | |
73 * Turn off pause in standard out | |
74 ldd #$01*256+SS.Opt | |
75 leas -32,s | |
76 tfr s,x | |
77 os9 I$GetStt | |
78 bcs opterr | |
79 clr PD.PAU-PD.OPT,x | |
80 os9 I$SetStt | |
81 opterr | |
82 leas 32,s | |
83 | |
84 * open the path to the control channel | |
85 lbsr TCPOpen | |
86 lbcs errex | |
87 sta netpath,u | |
88 leax SetupPorts,pcr | |
89 lbsr ProcInetd | |
90 lbcs errex | |
91 | |
92 IFNE DEBUG | |
93 lbsr PRINTS | |
94 fcc /Got netpath and setup ports/ | |
95 fcb C$CR | |
96 fcb $00 | |
97 ENDC | |
98 | |
99 ssignetpath | |
100 IFNE DEBUG | |
101 lbsr PRINTS | |
102 fcc /SS.SSig on NetPath/ | |
103 fcb C$CR | |
104 fcb $00 | |
105 ENDC | |
106 | |
107 lda netpath,u | |
108 ldb #SS.SSig send signal on data ready | |
109 ldx #NetSig | |
110 os9 I$SetStt | |
111 lbcs errex | |
112 | |
113 **** MAIN LOOP **** | |
114 mainloop | |
115 pshs cc | |
116 orcc #IntMasks | |
117 tst netdatardy,u | |
118 bne gotdata | |
119 | |
120 * wait for a child to die (or wake up via signal) | |
121 os9 F$Wait | |
122 bcc chkrdy | |
123 cmpb #E$NoChld | |
124 bne chkrdy got error other than "no children" | |
125 * if no children, go to sleep | |
126 ldx #$0000 | |
127 os9 F$Sleep | |
128 | |
129 chkrdy puls cc | |
130 bra ssignetpath | |
131 | |
132 gotdata puls cc | |
133 dec netdatardy,u | |
134 * read the data from netpath | |
135 IFNE DEBUG | |
136 lbsr PRINTS | |
137 fcc /Reading data from netpath/ | |
138 fcb C$CR | |
139 fcb $00 | |
140 ENDC | |
141 | |
142 lda netpath,u | |
143 ldb #SS.Ready | |
144 os9 I$GetStt | |
145 bcs ssignetpath | |
146 | |
147 clra | |
148 tfr d,y | |
149 lda netpath,u | |
150 ldx nnext,u | |
151 os9 I$Read | |
152 lbcs errex | |
153 tfr y,d | |
154 leax d,x | |
155 stx nnext,u | |
156 lda -1,x | |
157 cmpa #C$CR | |
158 lbne ssignetpath | |
159 | |
160 leax nbuffer,u | |
161 stx nnext,u | |
162 | |
163 lda #1 | |
164 ldy #256 | |
165 os9 I$WritLn | |
166 | |
167 * determine response | |
168 lda ,x | |
169 cmpa #'9 | |
170 ble incoming | |
171 | |
172 cmpa #'F | |
173 lbra ssignetpath | |
174 | |
175 * get token number | |
176 incoming | |
177 lbsr DEC_BIN | |
178 std token,u | |
179 IFNE DEBUG | |
180 pshs d | |
181 lbsr PRINTS | |
182 fcc /Got token / | |
183 fcb $00 | |
184 puls d | |
185 lbsr PRINT_DEC | |
186 lbsr PRINTS | |
187 fcb C$CR | |
188 fcb $00 | |
189 ENDC | |
190 | |
191 * skip over token number | |
192 IFNE DEBUG | |
193 lbsr PRINTS | |
194 fcc /To Space.../ | |
195 fcb C$CR | |
196 fcb $00 | |
197 ENDC | |
198 lbsr TO_SP | |
199 IFNE DEBUG | |
200 lbsr PRINTS | |
201 fcc /To Non-Space.../ | |
202 fcb C$CR | |
203 fcb $00 | |
204 ENDC | |
205 lbsr TO_NON_SP | |
206 | |
207 * get port number | |
208 lbsr DEC_BIN | |
209 std targetport,u | |
210 | |
211 IFNE DEBUG | |
212 pshs d | |
213 lbsr PRINTS | |
214 fcc /Got request for port / | |
215 fcb $00 | |
216 ldd ,s | |
217 lbsr PRINT_DEC | |
218 lbsr PRINTS | |
219 fcb C$CR | |
220 fcb $00 | |
221 puls d | |
222 ENDC | |
223 | |
224 leax ForkProcForPort,pcr | |
225 lbsr ProcInetd | |
226 lbra ssignetpath we may want to tell server we have no app | |
227 | |
228 errex os9 F$Exit | |
229 | |
230 | |
231 * Process inetd.conf file | |
232 * | |
233 * Entry: X = processor routine | |
234 * | |
235 * - open conf file | |
236 * - read each line and get first parameter (port number) | |
237 * - send it to the processor routine at x | |
238 * - if error or end of file, close and return | |
239 ProcInetd pshs x | |
240 leax inetdconf,pcr | |
241 lda #READ. | |
242 os9 I$Open | |
243 bcs adex | |
244 IFNE DEBUG | |
245 pshs d | |
246 lbsr PRINTS | |
247 fcc /Opened inetd.conf ok/ | |
248 fcb C$CR | |
249 fcb $00 | |
250 puls d | |
251 ENDC | |
252 nextline leax lbuffer,u | |
253 ldy #lbufferl-1 | |
254 lbsr FGETS | |
255 bcs closeup | |
256 lbsr TO_NON_SP skip any leading spaces | |
257 ldb ,x check for EOL or comment | |
258 cmpb #C$CR | |
259 beq nextline | |
260 cmpb #'# | |
261 beq nextline | |
262 IFNE DEBUG | |
263 pshs d,x | |
264 lbsr PRINTS | |
265 fcc /Reading line: / | |
266 fcb $00 | |
267 ldx 2,s | |
268 lbsr PUTS | |
269 puls d,x | |
270 ENDC | |
271 pshs a | |
272 jsr [1,s] | |
273 puls a | |
274 bcc nextline | |
275 closeup cmpb #E$EOF | |
276 bne closeandex | |
277 clrb | |
278 closeandex pshs b,cc | |
279 os9 I$Close | |
280 puls b,cc | |
281 adex puls x,pc | |
282 | |
283 | |
284 * Setup ports | |
285 * Extract first parameter at X and send to server | |
286 SetupPorts lbsr DEC_BIN | |
287 cmpd #0 | |
288 beq ret0 | |
289 * find comma and change it to nul | |
290 tfr x,y | |
291 setuploop lda ,y+ | |
292 cmpa #C$CR | |
293 beq ret0 | |
294 cmpa #', | |
295 bne setuploop | |
296 setuplisten | |
297 clr -1,y | |
298 IFNE DEBUG | |
299 pshs d,x | |
300 lbsr PRINTS | |
301 fcc /Send listen/ | |
302 fcb C$CR | |
303 fcb $00 | |
304 puls d,x | |
305 ENDC | |
306 lda netpath,u | |
307 lbsr TCPListen | |
308 ret0 rts | |
309 | |
310 retcc clrb | |
311 rts | |
312 | |
313 * Fork Proccess that matches target port | |
314 * Extract first parameter at X and see if it matches target port | |
315 * if so, read rest of line and fork the process | |
316 * Line looks like this: portnumberplusoptions,prog,params,path opts | |
317 ForkProcForPort | |
318 * get port number | |
319 lbsr DEC_BIN | |
320 IFNE DEBUG | |
321 pshs d | |
322 lbsr PRINTS | |
323 fcc /Reading port / | |
324 fcb $00 | |
325 ldd ,s | |
326 lbsr PRINT_DEC | |
327 lbsr PRINTS | |
328 fcb C$CR | |
329 fcb $00 | |
330 lbsr PRINTS | |
331 fcc /Comparing to port / | |
332 fcb $00 | |
333 ldd targetport,u | |
334 lbsr PRINT_DEC | |
335 lbsr PRINTS | |
336 fcb C$CR | |
337 fcb $00 | |
338 puls d | |
339 ENDC | |
340 cmpd targetport,u | |
341 lbne retcc | |
342 * point Y to byte after comma | |
343 portloop lda ,y+ | |
344 cmpa #C$CR | |
345 beq ret0 | |
346 cmpa #', | |
347 bne portloop | |
348 tfr y,x | |
349 * copy bytes up to comma at X | |
350 leay targetprog,u | |
351 prgloop lda ,x+ | |
352 cmpa #', | |
353 beq sethi | |
354 cmpa #C$CR | |
355 lbeq ret | |
356 sta ,y+ | |
357 bra prgloop | |
358 sethi lda -1,y | |
359 ora #$80 | |
360 sta -1,y | |
361 copypar clr tmodeparamlen,u | |
362 leay targetparams,u | |
363 parloop lda ,x+ | |
364 sta ,y+ | |
365 cmpa #', | |
366 beq procopts | |
367 cmpa #C$CR | |
368 beq gotprocparms | |
369 | |
370 procopts | |
371 leay tmodeparams,u | |
372 procoptsloop lda ,x+ | |
373 sta ,y+ | |
374 inc targetparams,u | |
375 cmpa #C$CR | |
376 beq procoptsloop | |
377 | |
378 gotprocparms | |
379 IFNE DEBUG | |
380 pshs d | |
381 lbsr PRINTS | |
382 fcc /Got proc and params to fork/ | |
383 fcb C$CR | |
384 fcb $00 | |
385 puls d | |
386 ENDC | |
387 | |
388 * ignore client port number and hostname for now | |
389 lbsr TCPOpen | |
390 bcc savechild | |
391 | |
392 ldd token,u | |
393 leas -8,s | |
394 leax ,s | |
395 lbsr BIN_DEC | |
396 lda netpath,u | |
397 tfr x,y | |
398 lbsr TCPKill | |
399 leas 8,s | |
400 lbra forkex | |
401 | |
402 savechild | |
403 sta childnetpath,u | |
404 ldd token,u | |
405 leas -8,s | |
406 leax ,s | |
407 lbsr BIN_DEC | |
408 lda childnetpath,u | |
409 tfr x,y | |
410 lbsr TCPJoin | |
411 leas 8,s | |
412 bcc turnonechoalf | |
413 os9 I$Close | |
414 lbra forkex | |
415 | |
416 turnonechoalf | |
417 IFNE DEBUG | |
418 pshs d | |
419 lbsr PRINTS | |
420 fcc /Turning on PD.EKO and PD.ALF/ | |
421 fcb C$CR | |
422 fcb $00 | |
423 puls d | |
424 ENDC | |
425 lbsr SetEchoOn | |
426 lbcs ret | |
427 lbsr SetAutoLFOn | |
428 lbcs ret | |
429 | |
430 * dup paths | |
431 duper | |
432 IFNE DEBUG | |
433 pshs d | |
434 lbsr PRINTS | |
435 fcc /Duping paths/ | |
436 fcb C$CR | |
437 fcb $00 | |
438 puls d | |
439 ENDC | |
440 | |
441 clra | |
442 os9 I$Dup | |
443 lbcs errex | |
444 sta orgstdin,u | |
445 lda #1 | |
446 os9 I$Dup | |
447 lbcs errex | |
448 sta orgstdout,u | |
449 lda #2 | |
450 os9 I$Dup | |
451 lbcs errex | |
452 sta orgstderr,u | |
453 | |
454 * close original stdin/out/err paths | |
455 clra | |
456 os9 I$Close | |
457 inca | |
458 os9 I$Close | |
459 inca | |
460 os9 I$Close | |
461 | |
462 * Dup child net path to stdin/stdout/stderr | |
463 lda childnetpath,u | |
464 os9 I$Dup | |
465 lbcs errex | |
466 os9 I$Dup | |
467 lbcs errex | |
468 os9 I$Dup | |
469 lbcs errex | |
470 | |
471 * fork tmode process if tmode param length > 0 | |
472 tst tmodeparamlen,u | |
473 beq forkchild | |
474 pshs u | |
475 leax tmode,pcr | |
476 leau tmodeparams,u | |
477 lda #Objct | |
478 clrb | |
479 ldy #256 | |
480 os9 F$Fork | |
481 puls u | |
482 os9 F$Wait | |
483 | |
484 * fork child process | |
485 forkchild | |
486 pshs u | |
487 leax targetprog,u | |
488 leau targetparams,u | |
489 lda #Objct | |
490 clrb | |
491 ldy #256 | |
492 os9 F$Fork | |
493 puls u | |
494 * If our F$Fork fails, do not error out... | |
495 * bcs ret2 | |
496 | |
497 * restore orginal paths | |
498 clra | |
499 os9 I$Close | |
500 inca | |
501 os9 I$Close | |
502 inca | |
503 os9 I$Close | |
504 | |
505 lda orgstdin,u | |
506 os9 I$Dup | |
507 lbcs errex | |
508 lda orgstdout,u | |
509 os9 I$Dup | |
510 lbcs errex | |
511 lda orgstderr,u | |
512 os9 I$Dup | |
513 lbcs errex | |
514 lda orgstdin,u | |
515 os9 I$Close | |
516 lda orgstdout,u | |
517 os9 I$Close | |
518 lda orgstderr,u | |
519 os9 I$Close | |
520 lda childnetpath,u | |
521 os9 I$Close | |
522 | |
523 IFNE DEBUG | |
524 pshs d | |
525 lbsr PRINTS | |
526 fcc /Proc forked/ | |
527 fcb C$CR | |
528 fcb $00 | |
529 puls d | |
530 ENDC | |
531 | |
532 forkex comb | |
533 ldb #E$EOF | |
534 ret rts | |
535 | |
536 inetdconf fcc "....../SYS/inetd.conf" | |
537 fcb C$CR | |
538 endsect |