changeset 28160:098cb7bd46a7

chg: forward umask from client to server This is necessary to make chg test pass on test-inherit-mode.t.
author Jun Wu <quark@fb.com>
date Mon, 15 Feb 2016 14:35:26 +0000
parents d2d04d1d2f92
children 3324345a498e
files contrib/chg/hgclient.c
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/chg/hgclient.c	Mon Feb 15 14:28:17 2016 +0000
+++ b/contrib/chg/hgclient.c	Mon Feb 15 14:35:26 2016 +0000
@@ -33,6 +33,7 @@
 	CAP_CHDIR = 0x0200,
 	CAP_GETPAGER = 0x0400,
 	CAP_SETENV = 0x0800,
+	CAP_SETUMASK = 0x1000,
 };
 
 typedef struct {
@@ -47,6 +48,7 @@
 	{"chdir", CAP_CHDIR},
 	{"getpager", CAP_GETPAGER},
 	{"setenv", CAP_SETENV},
+	{"setumask", CAP_SETUMASK},
 	{NULL, 0},  /* terminator */
 };
 
@@ -385,6 +387,17 @@
 	writeblockrequest(hgc, "chdir");
 }
 
+static void forwardumask(hgclient_t *hgc)
+{
+	mode_t mask = umask(0);
+	umask(mask);
+
+	static const char command[] = "setumask\n";
+	sendall(hgc->sockfd, command, sizeof(command) - 1);
+	uint32_t data = htonl(mask);
+	sendall(hgc->sockfd, &data, sizeof(data));
+}
+
 /*!
  * Open connection to per-user cmdserver
  *
@@ -433,6 +446,8 @@
 		attachio(hgc);
 	if (hgc->capflags & CAP_CHDIR)
 		chdirtocwd(hgc);
+	if (hgc->capflags & CAP_SETUMASK)
+		forwardumask(hgc);
 
 	return hgc;
 }