-
Notifications
You must be signed in to change notification settings - Fork 2
/
share.c
120 lines (103 loc) · 1.93 KB
/
share.c
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
119
120
#include <mintbind.h>
#include <string.h>
#include <sys/ioctl.h>
#include "global.h"
#include "config.h"
#include "environ.h"
#include "proc.h"
#include "share.h"
#include "toswin2.h"
#include "window.h"
#undef DEBUG_SH
int env_bytes;
static void sendMsg(int id, int what)
{
short msg[8];
msg[0] = what;
msg[1] = gl_apid;
msg[2] = 0;
appl_write(id, sizeof(msg), msg);
}
void handle_share(int id)
{
int fd;
short msg[8], d;
SHAREDATA *blk;
TEXTWIN *t;
char name[80], *env;
char arg[125] = " ";
WINCFG *cfg;
int err, ev;
sendMsg(id, TWOK);
err = 0;
do
{
ev = evnt_multi((MU_MESAG|MU_TIMER), 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
msg, 5000L, &d, &d, &d, &d, &d, &d);
if ((ev & MU_MESAG) && (msg[0] == TWWRITE))
err = 1;
if (ev & MU_TIMER) /* Timeout, tw-call antwortet nicht */
err = -1;
}
while (err == 0);
if (err == -1)
{
alert(1, 0, NOTWCALL);
return ;
}
sprintf(name, SHARENAME, id);
#ifdef DEBUG_SH
debug("SHM-Name: %s\n", name);
#endif
fd = (int)Fopen(name, 2);
if (fd > 0)
{
blk = (SHAREDATA *)Fcntl(fd, 0L, SHMGETBLK);
#ifdef DEBUG_SH
debug("Name : %s\n", blk->name);
debug("Pfad : %s\n", blk->pfad);
debug("Arg : %s\n", blk->arg);
#endif
cfg = get_wincfg(blk->name);
env = share_env(cfg->col, cfg->row, cfg->vt_mode, blk->name, blk->arg, blk->env);
if (blk->arg[0] != '\0')
{
strcat(arg, blk->arg);
arg[0] = strlen(arg);
}
else
{
arg[0] = 127;
arg[1] = '\0';
}
t = new_proc(blk->name, arg, env, blk->pfad, cfg, id, NULL);
if (t)
open_window(t->win, cfg->iconified);
free(env);
Fclose(fd);
Mfree(blk);
Fdelete(name);
sendMsg(id, TWREAD);
}
else
{
#ifdef DEBUG_SH
debug("shared open failed (%d)!\n", fd);
#endif
sendMsg(id, TWERR);
}
}
void handle_exit(int id)
{
if (id != -1)
{
short msg[8];
msg[0] = CH_EXIT;
msg[1] = gl_apid;
msg[2] = 0;
msg[3] = id;
msg[4] = exit_code;
appl_write(id, (int)sizeof(msg), msg);
}
}