chg: add procutil.h
This patch adds a formal header procutil.h for procutil.c, and changes
Makefile to build procutil.c independently.
--- a/contrib/chg/Makefile Mon Jan 02 14:43:37 2017 +0000
+++ b/contrib/chg/Makefile Mon Jan 02 14:57:14 2017 +0000
@@ -1,7 +1,7 @@
HG = $(CURDIR)/../../hg
TARGET = chg
-SRCS = chg.c hgclient.c util.c
+SRCS = chg.c hgclient.c procutil.c util.c
OBJS = $(SRCS:.c=.o)
CFLAGS ?= -O2 -Wall -Wextra -pedantic -g
@@ -24,8 +24,9 @@
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)
-chg.o: hgclient.h util.h
+chg.o: hgclient.h procutil.h util.h
hgclient.o: hgclient.h util.h
+procutil.o: procutil.h util.h
util.o: util.h
.PHONY: install
--- a/contrib/chg/chg.c Mon Jan 02 14:43:37 2017 +0000
+++ b/contrib/chg/chg.c Mon Jan 02 14:57:14 2017 +0000
@@ -23,6 +23,7 @@
#include <unistd.h>
#include "hgclient.h"
+#include "procutil.h"
#include "util.h"
#ifndef PATH_MAX
@@ -303,8 +304,6 @@
}
}
-#include "procutil.c"
-
/* Run instructions sent from the server like unlink and set redirect path
* Return 1 if reconnect is needed, otherwise 0 */
static int runinstructions(struct cmdserveropts *opts, const char **insts)
--- a/contrib/chg/procutil.c Mon Jan 02 14:43:37 2017 +0000
+++ b/contrib/chg/procutil.c Mon Jan 02 14:57:14 2017 +0000
@@ -7,6 +7,17 @@
* GNU General Public License version 2 or any later version.
*/
+#include <assert.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "procutil.h"
+#include "util.h"
+
static pid_t pagerpid = 0;
static pid_t peerpgid = 0;
static pid_t peerpid = 0;
@@ -71,7 +82,7 @@
kill(peerpid, SIGPIPE);
}
-static void setupsignalhandler(pid_t pid, pid_t pgid)
+void setupsignalhandler(pid_t pid, pid_t pgid)
{
if (pid <= 0)
return;
@@ -121,7 +132,7 @@
abortmsgerrno("failed to set up signal handlers");
}
-static void restoresignalhandler()
+void restoresignalhandler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
@@ -157,7 +168,7 @@
/* This implementation is based on hgext/pager.py (post 369741ef7253)
* Return 0 if pager is not started, or pid of the pager */
-static pid_t setuppager(const char *pagercmd)
+pid_t setuppager(const char *pagercmd)
{
assert(pagerpid == 0);
if (!pagercmd)
@@ -199,7 +210,7 @@
return 0;
}
-static void waitpager(void)
+void waitpager(void)
{
if (pagerpid == 0)
return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/contrib/chg/procutil.h Mon Jan 02 14:57:14 2017 +0000
@@ -0,0 +1,21 @@
+/*
+ * Utilities about process handling - signal and subprocess (ex. pager)
+ *
+ * Copyright (c) 2011 Yuya Nishihara <yuya@tcha.org>
+ *
+ * This software may be used and distributed according to the terms of the
+ * GNU General Public License version 2 or any later version.
+ */
+
+#ifndef PROCUTIL_H_
+#define PROCUTIL_H_
+
+#include <unistd.h>
+
+void restoresignalhandler(void);
+void setupsignalhandler(pid_t pid, pid_t pgid);
+
+pid_t setuppager(const char *pagercmd);
+void waitpager(void);
+
+#endif /* PROCUTIL_H_ */