Patchwork [01,of,14] chg: add fchdirx as a utility function

login
register
mail settings
Submitter Jun Wu
Date April 10, 2016, 11:57 p.m.
Message ID <cecc773636dcaeaf6d51.1460332638@x1c>
Download mbox | patch
Permalink /patch/14499/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - April 10, 2016, 11:57 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1460254472 -3600
#      Sun Apr 10 03:14:32 2016 +0100
# Node ID cecc773636dcaeaf6d5130831f400a77fb065a96
# Parent  99a2bdad0fda4fe16830376ad81c1065a5080cb9
chg: add fchdirx as a utility function

As part of the series to support long socket path, we need to use fchdir and
check its result in several places. Make it a utility function.

Patch

diff --git a/contrib/chg/util.c b/contrib/chg/util.c
--- a/contrib/chg/util.c
+++ b/contrib/chg/util.c
@@ -84,6 +84,13 @@ 
 	va_end(args);
 }
 
+void fchdirx(int dirfd)
+{
+	int r = fchdir(dirfd);
+	if (r == -1)
+		abortmsgerrno("failed to fchdir");
+}
+
 void *mallocx(size_t size)
 {
 	void *result = malloc(size);
diff --git a/contrib/chg/util.h b/contrib/chg/util.h
--- a/contrib/chg/util.h
+++ b/contrib/chg/util.h
@@ -23,6 +23,7 @@ 
 void enabledebugmsg(void);
 void debugmsg(const char *fmt, ...) PRINTF_FORMAT_;
 
+void fchdirx(int dirfd);
 void *mallocx(size_t size);
 void *reallocx(void *ptr, size_t size);