Patchwork [5,of,5,V2] chg: forward umask from client to server

login
register
mail settings
Submitter Jun Wu
Date Feb. 16, 2016, 7:50 p.m.
Message ID <85f8838dcd9afd49b1a3.1455652226@x1c>
Download mbox | patch
Permalink /patch/13233/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Feb. 16, 2016, 7:50 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1455546926 0
#      Mon Feb 15 14:35:26 2016 +0000
# Node ID 85f8838dcd9afd49b1a3ded8fb8193b8126a3a04
# Parent  0e71344230a9d312b22fcb4a08c8da7399cd07b2
chg: forward umask from client to server

This is necessary to make chg test pass on test-inherit-mode.t.
Yuya Nishihara - Feb. 17, 2016, 1:46 p.m.
On Tue, 16 Feb 2016 19:50:26 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1455546926 0
> #      Mon Feb 15 14:35:26 2016 +0000
> # Node ID 85f8838dcd9afd49b1a3ded8fb8193b8126a3a04
> # Parent  0e71344230a9d312b22fcb4a08c8da7399cd07b2
> chg: forward umask from client to server

Pushed the series to the clowncopter, thanks!

> +static void forwardumask(hgclient_t *hgc)
> +{
> +	mode_t mask = umask(0);
> +	umask(mask);
> +
> +	const char command[] = "setumask\n";

Changed it to static const just for consistency.

Patch

diff --git a/contrib/chg/hgclient.c b/contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c
+++ b/contrib/chg/hgclient.c
@@ -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);
+
+	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;
 }