Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/cs/vcs_src/mnt_vcs.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "mnt_imount.h"
21
22
int vcs_write(buf)
23
char* buf;
24
{
25
int ret;
26
27
if ((istate.fd == -1) && ((istate.fd = csopen(istate.cs_svc, CS_OPEN_READ)) < 0))
28
{
29
printf("cannot connect cs server %s\n", istate.cs_svc);
30
return (-1);
31
}
32
if ((ret = write(istate.fd, buf, strlen(buf))) < 0)
33
{
34
printf("cannot write to cs server %s\n", istate.cs_svc);
35
istate.fd = -1;
36
return (-1);
37
}
38
return (ret);
39
}
40
41
int vcs_read(buf, bufsize)
42
char* buf;
43
int bufsize;
44
{
45
int ret;
46
Cs_poll_t ack;
47
if ((istate.fd == -1) && ((istate.fd = csopen(istate.cs_svc, CS_OPEN_READ)) < 0))
48
{
49
printf("cannot connect cs server %s\n", istate.cs_svc);
50
return (-1);
51
}
52
ack.fd = istate.fd;
53
ack.events = CS_POLL_READ;
54
if (cspoll(&ack, 1, -1) != 1)
55
{
56
printf("no msg from server\n");
57
close(istate.fd);
58
istate.fd = -1;
59
return (-1);
60
}
61
ret = read(istate.fd, buf, bufsize);
62
if (ret <= 0)
63
{
64
printf("read error\n");
65
close(istate.fd);
66
istate.fd = -1;
67
}
68
else
69
buf[ret] = '\0';
70
return (ret);
71
}
72
73
int im_vcs_help(s)
74
register char* s;
75
{
76
if (strcmp(s, "cs") == 0)
77
printf("\tcs commands\n");
78
else if (strcmp(s, "version") == 0)
79
printf("\tversion # display server's ID\n");
80
else if (strcmp(s, "kill") == 0)
81
printf("\tkill # kill server \n");
82
else if (strcmp(s, "connect") == 0)
83
printf("\tconnect [server] # connect server \n");
84
else if (strcmp(s, "log") == 0)
85
printf("\tlog [file] # log server messages\n");
86
return (0);
87
}
88
89
int im_vcs_main(argc, argv)
90
int argc;
91
char** argv;
92
{
93
register char* s;
94
register char* cmd;
95
char reply[1024];
96
int fd;
97
char buf[2048];
98
int len;
99
100
cmd = error_info.id = argv[0];
101
opt_info.index = 1;
102
103
memset(buf, 0, sizeof(buf));
104
memset(reply, 0, sizeof(reply));
105
argc -= opt_info.index;
106
argv += opt_info.index;
107
108
if(strcmp(cmd, "kill") == 0)
109
{
110
sfsprintf(buf, 2048, "%s\n", cmd);
111
(void)vcs_write(buf);
112
close(istate.fd);
113
istate.fd = -1;
114
return (0);
115
}
116
else if ((strcmp(cmd, "connect") == 0) || (strncmp(cmd, "version", 4) == 0))
117
{
118
if (argc > 0)
119
{
120
s = *argv;
121
if ((fd = csopen(s, CS_OPEN_READ)) < 0)
122
{
123
printf("cannot connect cs server %s\n", s);
124
return (-1);
125
}
126
istate.cs_svc = strdup(s);
127
istate.fd = fd;
128
argc--;
129
argv++;
130
}
131
cmd = "version";
132
}
133
else if (strcmp(cmd, "log") == 0)
134
{
135
cmd = "r";
136
}
137
else if (strcmp(cmd, "cs") == 0)
138
{
139
cmd = NULL;
140
141
}
142
143
if (cmd != NULL)
144
{
145
len = sfsprintf(buf, 2048, "%s ", cmd);
146
s = buf + len;
147
}
148
else
149
s = buf;
150
151
if (argc > 0)
152
{
153
argv[argc] = NULL;
154
arr2str(s, argv, ' ');
155
}
156
strcat(buf, "\n");
157
if (vcs_write(buf) <=0 || vcs_read(reply, 1024) <=0)
158
{
159
printf("cannot connect cs server\n");
160
return (-1);
161
}
162
if (strncmp(reply, "I ", 2) == 0)
163
s = reply + 2;
164
else
165
s = reply;
166
printf("%s", s);
167
return (0);
168
}
169
170
171
void printmtmsg(buf)
172
char* buf;
173
{
174
register char* url;
175
register char* mnt;
176
177
if( !strncmp( buf, "I 0 ok 0 ", 9 ) &&
178
(url = strtok( buf+9, " \t\r\n" )) &&
179
(mnt = strtok( NULL, " \t\r\n" )) ) {
180
printf("%s -> %s\n", mnt, url);
181
} else {
182
printf( "%s", buf );
183
}
184
}
185
186