##// END OF EJS Templates
chg: upgrade client to use "setumask2" command...
Yuya Nishihara -
r40145:413b6b10 default
parent child Browse files
Show More
@@ -1,619 +1,620 b''
1 1 /*
2 2 * A command server client that uses Unix domain socket
3 3 *
4 4 * Copyright (c) 2011 Yuya Nishihara <yuya@tcha.org>
5 5 *
6 6 * This software may be used and distributed according to the terms of the
7 7 * GNU General Public License version 2 or any later version.
8 8 */
9 9
10 10 #include <arpa/inet.h> /* for ntohl(), htonl() */
11 11 #include <assert.h>
12 12 #include <ctype.h>
13 13 #include <errno.h>
14 14 #include <fcntl.h>
15 15 #include <signal.h>
16 16 #include <stdint.h>
17 17 #include <stdio.h>
18 18 #include <stdlib.h>
19 19 #include <string.h>
20 20 #include <sys/socket.h>
21 21 #include <sys/stat.h>
22 22 #include <sys/un.h>
23 23 #include <unistd.h>
24 24
25 25 #include "hgclient.h"
26 26 #include "procutil.h"
27 27 #include "util.h"
28 28
29 29 enum { CAP_GETENCODING = 0x0001,
30 30 CAP_RUNCOMMAND = 0x0002,
31 31 /* cHg extension: */
32 32 CAP_ATTACHIO = 0x0100,
33 33 CAP_CHDIR = 0x0200,
34 34 CAP_SETENV = 0x0800,
35 CAP_SETUMASK = 0x1000,
35 CAP_SETUMASK2 = 0x1000,
36 36 CAP_VALIDATE = 0x2000,
37 37 CAP_SETPROCNAME = 0x4000,
38 38 };
39 39
40 40 typedef struct {
41 41 const char *name;
42 42 unsigned int flag;
43 43 } cappair_t;
44 44
45 45 static const cappair_t captable[] = {
46 46 {"getencoding", CAP_GETENCODING},
47 47 {"runcommand", CAP_RUNCOMMAND},
48 48 {"attachio", CAP_ATTACHIO},
49 49 {"chdir", CAP_CHDIR},
50 50 {"setenv", CAP_SETENV},
51 {"setumask", CAP_SETUMASK},
51 {"setumask2", CAP_SETUMASK2},
52 52 {"validate", CAP_VALIDATE},
53 53 {"setprocname", CAP_SETPROCNAME},
54 54 {NULL, 0}, /* terminator */
55 55 };
56 56
57 57 typedef struct {
58 58 char ch;
59 59 char *data;
60 60 size_t maxdatasize;
61 61 size_t datasize;
62 62 } context_t;
63 63
64 64 struct hgclient_tag_ {
65 65 int sockfd;
66 66 pid_t pgid;
67 67 pid_t pid;
68 68 context_t ctx;
69 69 unsigned int capflags;
70 70 };
71 71
72 72 static const size_t defaultdatasize = 4096;
73 73
74 74 static void attachio(hgclient_t *hgc);
75 75
76 76 static void initcontext(context_t *ctx)
77 77 {
78 78 ctx->ch = '\0';
79 79 ctx->data = malloc(defaultdatasize);
80 80 ctx->maxdatasize = (ctx->data) ? defaultdatasize : 0;
81 81 ctx->datasize = 0;
82 82 debugmsg("initialize context buffer with size %zu", ctx->maxdatasize);
83 83 }
84 84
85 85 static void enlargecontext(context_t *ctx, size_t newsize)
86 86 {
87 87 if (newsize <= ctx->maxdatasize)
88 88 return;
89 89
90 90 newsize = defaultdatasize *
91 91 ((newsize + defaultdatasize - 1) / defaultdatasize);
92 92 ctx->data = reallocx(ctx->data, newsize);
93 93 ctx->maxdatasize = newsize;
94 94 debugmsg("enlarge context buffer to %zu", ctx->maxdatasize);
95 95 }
96 96
97 97 static void freecontext(context_t *ctx)
98 98 {
99 99 debugmsg("free context buffer");
100 100 free(ctx->data);
101 101 ctx->data = NULL;
102 102 ctx->maxdatasize = 0;
103 103 ctx->datasize = 0;
104 104 }
105 105
106 106 /* Read channeled response from cmdserver */
107 107 static void readchannel(hgclient_t *hgc)
108 108 {
109 109 assert(hgc);
110 110
111 111 ssize_t rsize = recv(hgc->sockfd, &hgc->ctx.ch, sizeof(hgc->ctx.ch), 0);
112 112 if (rsize != sizeof(hgc->ctx.ch)) {
113 113 /* server would have exception and traceback would be printed */
114 114 debugmsg("failed to read channel");
115 115 exit(255);
116 116 }
117 117
118 118 uint32_t datasize_n;
119 119 rsize = recv(hgc->sockfd, &datasize_n, sizeof(datasize_n), 0);
120 120 if (rsize != sizeof(datasize_n))
121 121 abortmsg("failed to read data size");
122 122
123 123 /* datasize denotes the maximum size to write if input request */
124 124 hgc->ctx.datasize = ntohl(datasize_n);
125 125 enlargecontext(&hgc->ctx, hgc->ctx.datasize);
126 126
127 127 if (isupper(hgc->ctx.ch) && hgc->ctx.ch != 'S')
128 128 return; /* assumes input request */
129 129
130 130 size_t cursize = 0;
131 131 while (cursize < hgc->ctx.datasize) {
132 132 rsize = recv(hgc->sockfd, hgc->ctx.data + cursize,
133 133 hgc->ctx.datasize - cursize, 0);
134 134 if (rsize < 1)
135 135 abortmsg("failed to read data block");
136 136 cursize += rsize;
137 137 }
138 138 }
139 139
140 140 static void sendall(int sockfd, const void *data, size_t datasize)
141 141 {
142 142 const char *p = data;
143 143 const char *const endp = p + datasize;
144 144 while (p < endp) {
145 145 ssize_t r = send(sockfd, p, endp - p, 0);
146 146 if (r < 0)
147 147 abortmsgerrno("cannot communicate");
148 148 p += r;
149 149 }
150 150 }
151 151
152 152 /* Write lengh-data block to cmdserver */
153 153 static void writeblock(const hgclient_t *hgc)
154 154 {
155 155 assert(hgc);
156 156
157 157 const uint32_t datasize_n = htonl(hgc->ctx.datasize);
158 158 sendall(hgc->sockfd, &datasize_n, sizeof(datasize_n));
159 159
160 160 sendall(hgc->sockfd, hgc->ctx.data, hgc->ctx.datasize);
161 161 }
162 162
163 163 static void writeblockrequest(const hgclient_t *hgc, const char *chcmd)
164 164 {
165 165 debugmsg("request %s, block size %zu", chcmd, hgc->ctx.datasize);
166 166
167 167 char buf[strlen(chcmd) + 1];
168 168 memcpy(buf, chcmd, sizeof(buf) - 1);
169 169 buf[sizeof(buf) - 1] = '\n';
170 170 sendall(hgc->sockfd, buf, sizeof(buf));
171 171
172 172 writeblock(hgc);
173 173 }
174 174
175 175 /* Build '\0'-separated list of args. argsize < 0 denotes that args are
176 176 * terminated by NULL. */
177 177 static void packcmdargs(context_t *ctx, const char *const args[],
178 178 ssize_t argsize)
179 179 {
180 180 ctx->datasize = 0;
181 181 const char *const *const end = (argsize >= 0) ? args + argsize : NULL;
182 182 for (const char *const *it = args; it != end && *it; ++it) {
183 183 const size_t n = strlen(*it) + 1; /* include '\0' */
184 184 enlargecontext(ctx, ctx->datasize + n);
185 185 memcpy(ctx->data + ctx->datasize, *it, n);
186 186 ctx->datasize += n;
187 187 }
188 188
189 189 if (ctx->datasize > 0)
190 190 --ctx->datasize; /* strip last '\0' */
191 191 }
192 192
193 193 /* Extract '\0'-separated list of args to new buffer, terminated by NULL */
194 194 static const char **unpackcmdargsnul(const context_t *ctx)
195 195 {
196 196 const char **args = NULL;
197 197 size_t nargs = 0, maxnargs = 0;
198 198 const char *s = ctx->data;
199 199 const char *e = ctx->data + ctx->datasize;
200 200 for (;;) {
201 201 if (nargs + 1 >= maxnargs) { /* including last NULL */
202 202 maxnargs += 256;
203 203 args = reallocx(args, maxnargs * sizeof(args[0]));
204 204 }
205 205 args[nargs] = s;
206 206 nargs++;
207 207 s = memchr(s, '\0', e - s);
208 208 if (!s)
209 209 break;
210 210 s++;
211 211 }
212 212 args[nargs] = NULL;
213 213 return args;
214 214 }
215 215
216 216 static void handlereadrequest(hgclient_t *hgc)
217 217 {
218 218 context_t *ctx = &hgc->ctx;
219 219 size_t r = fread(ctx->data, sizeof(ctx->data[0]), ctx->datasize, stdin);
220 220 ctx->datasize = r;
221 221 writeblock(hgc);
222 222 }
223 223
224 224 /* Read single-line */
225 225 static void handlereadlinerequest(hgclient_t *hgc)
226 226 {
227 227 context_t *ctx = &hgc->ctx;
228 228 if (!fgets(ctx->data, ctx->datasize, stdin))
229 229 ctx->data[0] = '\0';
230 230 ctx->datasize = strlen(ctx->data);
231 231 writeblock(hgc);
232 232 }
233 233
234 234 /* Execute the requested command and write exit code */
235 235 static void handlesystemrequest(hgclient_t *hgc)
236 236 {
237 237 context_t *ctx = &hgc->ctx;
238 238 enlargecontext(ctx, ctx->datasize + 1);
239 239 ctx->data[ctx->datasize] = '\0'; /* terminate last string */
240 240
241 241 const char **args = unpackcmdargsnul(ctx);
242 242 if (!args[0] || !args[1] || !args[2])
243 243 abortmsg("missing type or command or cwd in system request");
244 244 if (strcmp(args[0], "system") == 0) {
245 245 debugmsg("run '%s' at '%s'", args[1], args[2]);
246 246 int32_t r = runshellcmd(args[1], args + 3, args[2]);
247 247 free(args);
248 248
249 249 uint32_t r_n = htonl(r);
250 250 memcpy(ctx->data, &r_n, sizeof(r_n));
251 251 ctx->datasize = sizeof(r_n);
252 252 writeblock(hgc);
253 253 } else if (strcmp(args[0], "pager") == 0) {
254 254 setuppager(args[1], args + 3);
255 255 if (hgc->capflags & CAP_ATTACHIO)
256 256 attachio(hgc);
257 257 /* unblock the server */
258 258 static const char emptycmd[] = "\n";
259 259 sendall(hgc->sockfd, emptycmd, sizeof(emptycmd) - 1);
260 260 } else {
261 261 abortmsg("unknown type in system request: %s", args[0]);
262 262 }
263 263 }
264 264
265 265 /* Read response of command execution until receiving 'r'-esult */
266 266 static void handleresponse(hgclient_t *hgc)
267 267 {
268 268 for (;;) {
269 269 readchannel(hgc);
270 270 context_t *ctx = &hgc->ctx;
271 271 debugmsg("response read from channel %c, size %zu", ctx->ch,
272 272 ctx->datasize);
273 273 switch (ctx->ch) {
274 274 case 'o':
275 275 fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
276 276 stdout);
277 277 break;
278 278 case 'e':
279 279 fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
280 280 stderr);
281 281 break;
282 282 case 'd':
283 283 /* assumes last char is '\n' */
284 284 ctx->data[ctx->datasize - 1] = '\0';
285 285 debugmsg("server: %s", ctx->data);
286 286 break;
287 287 case 'r':
288 288 return;
289 289 case 'I':
290 290 handlereadrequest(hgc);
291 291 break;
292 292 case 'L':
293 293 handlereadlinerequest(hgc);
294 294 break;
295 295 case 'S':
296 296 handlesystemrequest(hgc);
297 297 break;
298 298 default:
299 299 if (isupper(ctx->ch))
300 300 abortmsg("cannot handle response (ch = %c)",
301 301 ctx->ch);
302 302 }
303 303 }
304 304 }
305 305
306 306 static unsigned int parsecapabilities(const char *s, const char *e)
307 307 {
308 308 unsigned int flags = 0;
309 309 while (s < e) {
310 310 const char *t = strchr(s, ' ');
311 311 if (!t || t > e)
312 312 t = e;
313 313 const cappair_t *cap;
314 314 for (cap = captable; cap->flag; ++cap) {
315 315 size_t n = t - s;
316 316 if (strncmp(s, cap->name, n) == 0 &&
317 317 strlen(cap->name) == n) {
318 318 flags |= cap->flag;
319 319 break;
320 320 }
321 321 }
322 322 s = t + 1;
323 323 }
324 324 return flags;
325 325 }
326 326
327 327 static void readhello(hgclient_t *hgc)
328 328 {
329 329 readchannel(hgc);
330 330 context_t *ctx = &hgc->ctx;
331 331 if (ctx->ch != 'o') {
332 332 char ch = ctx->ch;
333 333 if (ch == 'e') {
334 334 /* write early error and will exit */
335 335 fwrite(ctx->data, sizeof(ctx->data[0]), ctx->datasize,
336 336 stderr);
337 337 handleresponse(hgc);
338 338 }
339 339 abortmsg("unexpected channel of hello message (ch = %c)", ch);
340 340 }
341 341 enlargecontext(ctx, ctx->datasize + 1);
342 342 ctx->data[ctx->datasize] = '\0';
343 343 debugmsg("hello received: %s (size = %zu)", ctx->data, ctx->datasize);
344 344
345 345 const char *s = ctx->data;
346 346 const char *const dataend = ctx->data + ctx->datasize;
347 347 while (s < dataend) {
348 348 const char *t = strchr(s, ':');
349 349 if (!t || t[1] != ' ')
350 350 break;
351 351 const char *u = strchr(t + 2, '\n');
352 352 if (!u)
353 353 u = dataend;
354 354 if (strncmp(s, "capabilities:", t - s + 1) == 0) {
355 355 hgc->capflags = parsecapabilities(t + 2, u);
356 356 } else if (strncmp(s, "pgid:", t - s + 1) == 0) {
357 357 hgc->pgid = strtol(t + 2, NULL, 10);
358 358 } else if (strncmp(s, "pid:", t - s + 1) == 0) {
359 359 hgc->pid = strtol(t + 2, NULL, 10);
360 360 }
361 361 s = u + 1;
362 362 }
363 363 debugmsg("capflags=0x%04x, pid=%d", hgc->capflags, hgc->pid);
364 364 }
365 365
366 366 static void updateprocname(hgclient_t *hgc)
367 367 {
368 368 int r = snprintf(hgc->ctx.data, hgc->ctx.maxdatasize, "chg[worker/%d]",
369 369 (int)getpid());
370 370 if (r < 0 || (size_t)r >= hgc->ctx.maxdatasize)
371 371 abortmsg("insufficient buffer to write procname (r = %d)", r);
372 372 hgc->ctx.datasize = (size_t)r;
373 373 writeblockrequest(hgc, "setprocname");
374 374 }
375 375
376 376 static void attachio(hgclient_t *hgc)
377 377 {
378 378 debugmsg("request attachio");
379 379 static const char chcmd[] = "attachio\n";
380 380 sendall(hgc->sockfd, chcmd, sizeof(chcmd) - 1);
381 381 readchannel(hgc);
382 382 context_t *ctx = &hgc->ctx;
383 383 if (ctx->ch != 'I')
384 384 abortmsg("unexpected response for attachio (ch = %c)", ctx->ch);
385 385
386 386 static const int fds[3] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
387 387 struct msghdr msgh;
388 388 memset(&msgh, 0, sizeof(msgh));
389 389 struct iovec iov = {ctx->data, ctx->datasize}; /* dummy payload */
390 390 msgh.msg_iov = &iov;
391 391 msgh.msg_iovlen = 1;
392 392 char fdbuf[CMSG_SPACE(sizeof(fds))];
393 393 msgh.msg_control = fdbuf;
394 394 msgh.msg_controllen = sizeof(fdbuf);
395 395 struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msgh);
396 396 cmsg->cmsg_level = SOL_SOCKET;
397 397 cmsg->cmsg_type = SCM_RIGHTS;
398 398 cmsg->cmsg_len = CMSG_LEN(sizeof(fds));
399 399 memcpy(CMSG_DATA(cmsg), fds, sizeof(fds));
400 400 msgh.msg_controllen = cmsg->cmsg_len;
401 401 ssize_t r = sendmsg(hgc->sockfd, &msgh, 0);
402 402 if (r < 0)
403 403 abortmsgerrno("sendmsg failed");
404 404
405 405 handleresponse(hgc);
406 406 int32_t n;
407 407 if (ctx->datasize != sizeof(n))
408 408 abortmsg("unexpected size of attachio result");
409 409 memcpy(&n, ctx->data, sizeof(n));
410 410 n = ntohl(n);
411 411 if (n != sizeof(fds) / sizeof(fds[0]))
412 412 abortmsg("failed to send fds (n = %d)", n);
413 413 }
414 414
415 415 static void chdirtocwd(hgclient_t *hgc)
416 416 {
417 417 if (!getcwd(hgc->ctx.data, hgc->ctx.maxdatasize))
418 418 abortmsgerrno("failed to getcwd");
419 419 hgc->ctx.datasize = strlen(hgc->ctx.data);
420 420 writeblockrequest(hgc, "chdir");
421 421 }
422 422
423 423 static void forwardumask(hgclient_t *hgc)
424 424 {
425 425 mode_t mask = umask(0);
426 426 umask(mask);
427 427
428 static const char command[] = "setumask\n";
429 sendall(hgc->sockfd, command, sizeof(command) - 1);
430 428 uint32_t data = htonl(mask);
431 sendall(hgc->sockfd, &data, sizeof(data));
429 enlargecontext(&hgc->ctx, sizeof(data));
430 memcpy(hgc->ctx.data, &data, sizeof(data));
431 hgc->ctx.datasize = sizeof(data);
432 writeblockrequest(hgc, "setumask2");
432 433 }
433 434
434 435 /*!
435 436 * Open connection to per-user cmdserver
436 437 *
437 438 * If no background server running, returns NULL.
438 439 */
439 440 hgclient_t *hgc_open(const char *sockname)
440 441 {
441 442 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
442 443 if (fd < 0)
443 444 abortmsgerrno("cannot create socket");
444 445
445 446 /* don't keep fd on fork(), so that it can be closed when the parent
446 447 * process get terminated. */
447 448 fsetcloexec(fd);
448 449
449 450 struct sockaddr_un addr;
450 451 addr.sun_family = AF_UNIX;
451 452
452 453 /* use chdir to workaround small sizeof(sun_path) */
453 454 int bakfd = -1;
454 455 const char *basename = sockname;
455 456 {
456 457 const char *split = strrchr(sockname, '/');
457 458 if (split && split != sockname) {
458 459 if (split[1] == '\0')
459 460 abortmsg("sockname cannot end with a slash");
460 461 size_t len = split - sockname;
461 462 char sockdir[len + 1];
462 463 memcpy(sockdir, sockname, len);
463 464 sockdir[len] = '\0';
464 465
465 466 bakfd = open(".", O_DIRECTORY);
466 467 if (bakfd == -1)
467 468 abortmsgerrno("cannot open cwd");
468 469
469 470 int r = chdir(sockdir);
470 471 if (r != 0)
471 472 abortmsgerrno("cannot chdir %s", sockdir);
472 473
473 474 basename = split + 1;
474 475 }
475 476 }
476 477 if (strlen(basename) >= sizeof(addr.sun_path))
477 478 abortmsg("sockname is too long: %s", basename);
478 479 strncpy(addr.sun_path, basename, sizeof(addr.sun_path));
479 480 addr.sun_path[sizeof(addr.sun_path) - 1] = '\0';
480 481
481 482 /* real connect */
482 483 int r = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
483 484 if (r < 0) {
484 485 if (errno != ENOENT && errno != ECONNREFUSED)
485 486 abortmsgerrno("cannot connect to %s", sockname);
486 487 }
487 488 if (bakfd != -1) {
488 489 fchdirx(bakfd);
489 490 close(bakfd);
490 491 }
491 492 if (r < 0) {
492 493 close(fd);
493 494 return NULL;
494 495 }
495 496 debugmsg("connected to %s", addr.sun_path);
496 497
497 498 hgclient_t *hgc = mallocx(sizeof(hgclient_t));
498 499 memset(hgc, 0, sizeof(*hgc));
499 500 hgc->sockfd = fd;
500 501 initcontext(&hgc->ctx);
501 502
502 503 readhello(hgc);
503 504 if (!(hgc->capflags & CAP_RUNCOMMAND))
504 505 abortmsg("insufficient capability: runcommand");
505 506 if (hgc->capflags & CAP_SETPROCNAME)
506 507 updateprocname(hgc);
507 508 if (hgc->capflags & CAP_ATTACHIO)
508 509 attachio(hgc);
509 510 if (hgc->capflags & CAP_CHDIR)
510 511 chdirtocwd(hgc);
511 if (hgc->capflags & CAP_SETUMASK)
512 if (hgc->capflags & CAP_SETUMASK2)
512 513 forwardumask(hgc);
513 514
514 515 return hgc;
515 516 }
516 517
517 518 /*!
518 519 * Close connection and free allocated memory
519 520 */
520 521 void hgc_close(hgclient_t *hgc)
521 522 {
522 523 assert(hgc);
523 524 freecontext(&hgc->ctx);
524 525 close(hgc->sockfd);
525 526 free(hgc);
526 527 }
527 528
528 529 pid_t hgc_peerpgid(const hgclient_t *hgc)
529 530 {
530 531 assert(hgc);
531 532 return hgc->pgid;
532 533 }
533 534
534 535 pid_t hgc_peerpid(const hgclient_t *hgc)
535 536 {
536 537 assert(hgc);
537 538 return hgc->pid;
538 539 }
539 540
540 541 /*!
541 542 * Send command line arguments to let the server load the repo config and check
542 543 * whether it can process our request directly or not.
543 544 * Make sure hgc_setenv is called before calling this.
544 545 *
545 546 * @return - NULL, the server believes it can handle our request, or does not
546 547 * support "validate" command.
547 548 * - a list of strings, the server probably cannot handle our request
548 549 * and it sent instructions telling us what to do next. See
549 550 * chgserver.py for possible instruction formats.
550 551 * the list should be freed by the caller.
551 552 * the last string is guaranteed to be NULL.
552 553 */
553 554 const char **hgc_validate(hgclient_t *hgc, const char *const args[],
554 555 size_t argsize)
555 556 {
556 557 assert(hgc);
557 558 if (!(hgc->capflags & CAP_VALIDATE))
558 559 return NULL;
559 560
560 561 packcmdargs(&hgc->ctx, args, argsize);
561 562 writeblockrequest(hgc, "validate");
562 563 handleresponse(hgc);
563 564
564 565 /* the server returns '\0' if it can handle our request */
565 566 if (hgc->ctx.datasize <= 1)
566 567 return NULL;
567 568
568 569 /* make sure the buffer is '\0' terminated */
569 570 enlargecontext(&hgc->ctx, hgc->ctx.datasize + 1);
570 571 hgc->ctx.data[hgc->ctx.datasize] = '\0';
571 572 return unpackcmdargsnul(&hgc->ctx);
572 573 }
573 574
574 575 /*!
575 576 * Execute the specified Mercurial command
576 577 *
577 578 * @return result code
578 579 */
579 580 int hgc_runcommand(hgclient_t *hgc, const char *const args[], size_t argsize)
580 581 {
581 582 assert(hgc);
582 583
583 584 packcmdargs(&hgc->ctx, args, argsize);
584 585 writeblockrequest(hgc, "runcommand");
585 586 handleresponse(hgc);
586 587
587 588 int32_t exitcode_n;
588 589 if (hgc->ctx.datasize != sizeof(exitcode_n)) {
589 590 abortmsg("unexpected size of exitcode");
590 591 }
591 592 memcpy(&exitcode_n, hgc->ctx.data, sizeof(exitcode_n));
592 593 return ntohl(exitcode_n);
593 594 }
594 595
595 596 /*!
596 597 * (Re-)send client's stdio channels so that the server can access to tty
597 598 */
598 599 void hgc_attachio(hgclient_t *hgc)
599 600 {
600 601 assert(hgc);
601 602 if (!(hgc->capflags & CAP_ATTACHIO))
602 603 return;
603 604 attachio(hgc);
604 605 }
605 606
606 607 /*!
607 608 * Update server's environment variables
608 609 *
609 610 * @param envp list of environment variables in "NAME=VALUE" format,
610 611 * terminated by NULL.
611 612 */
612 613 void hgc_setenv(hgclient_t *hgc, const char *const envp[])
613 614 {
614 615 assert(hgc && envp);
615 616 if (!(hgc->capflags & CAP_SETENV))
616 617 return;
617 618 packcmdargs(&hgc->ctx, envp, /*argsize*/ -1);
618 619 writeblockrequest(hgc, "setenv");
619 620 }
General Comments 0
You need to be logged in to leave comments. Login now