chg: add sockdirfd to cmdserveropts
authorJun Wu <quark@fb.com>
Sun, 10 Apr 2016 23:56:00 +0100
changeset 28852 7b5f5a1b4b41
parent 28851 584e0716c7af
child 28853 d11548b4ae45
chg: add sockdirfd to cmdserveropts As part of the series to support long socket paths, we need to add the fd of the directory to the cmdserveropts structure so we can use basenames instead of full paths for sockname, redirectsockname, and lockfile.
contrib/chg/chg.c
--- a/contrib/chg/chg.c	Sun Apr 10 21:56:05 2016 +0100
+++ b/contrib/chg/chg.c	Sun Apr 10 23:56:00 2016 +0100
@@ -36,17 +36,23 @@
 	size_t argsize;
 	const char **args;
 	int lockfd;
+	int sockdirfd;
 };
 
 static void initcmdserveropts(struct cmdserveropts *opts) {
 	memset(opts, 0, sizeof(struct cmdserveropts));
 	opts->lockfd = -1;
+	opts->sockdirfd = AT_FDCWD;
 }
 
 static void freecmdserveropts(struct cmdserveropts *opts) {
 	free(opts->args);
 	opts->args = NULL;
 	opts->argsize = 0;
+	if (opts->sockdirfd != AT_FDCWD) {
+		close(opts->sockdirfd);
+		opts->sockdirfd = AT_FDCWD;
+	}
 }
 
 /*