Patchwork [5,of,5] chg: add procutil.h

login
register
mail settings
Submitter Jun Wu
Date Jan. 2, 2017, 3:09 p.m.
Message ID <7a7681e4ab86597232eb.1483369767@x1c>
Download mbox | patch
Permalink /patch/18067/
State Accepted
Headers show

Comments

Jun Wu - Jan. 2, 2017, 3:09 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1483369034 0
#      Mon Jan 02 14:57:14 2017 +0000
# Node ID 7a7681e4ab86597232eb147ebc1bcaa322a92067
# Parent  73378fbef0fe54376ecfcb0009f0b7924d3a245b
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 7a7681e4ab86
# Note  runshellcmd (in util.c) will be moved to procutil.c later.
chg: add procutil.h

This patch adds a formal header procutil.h for procutil.c, and changes
Makefile to build procutil.c independently.
Yuya Nishihara - Jan. 4, 2017, 1:39 p.m.
On Mon, 2 Jan 2017 15:09:27 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1483369034 0
> #      Mon Jan 02 14:57:14 2017 +0000
> # Node ID 7a7681e4ab86597232eb147ebc1bcaa322a92067
> # Parent  73378fbef0fe54376ecfcb0009f0b7924d3a245b
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 7a7681e4ab86
> # Note  runshellcmd (in util.c) will be moved to procutil.c later.
> chg: add procutil.h

Nice module separation. Queued the series, thanks.

> --- a/contrib/chg/Makefile
> +++ b/contrib/chg/Makefile
> @@ -2,5 +2,5 @@ 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)
>  
> @@ -25,6 +25,7 @@ all: $(TARGET)
>  	$(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: util.h

Fixed as "procutil.o: procutil.h util.h".

Patch

diff --git a/contrib/chg/Makefile b/contrib/chg/Makefile
--- a/contrib/chg/Makefile
+++ b/contrib/chg/Makefile
@@ -2,5 +2,5 @@  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)
 
@@ -25,6 +25,7 @@  all: $(TARGET)
 	$(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: util.h
 util.o: util.h
 
diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -24,4 +24,5 @@ 
 
 #include "hgclient.h"
+#include "procutil.h"
 #include "util.h"
 
@@ -304,6 +305,4 @@  static void killcmdserver(const struct c
 }
 
-#include "procutil.c"
-
 /* Run instructions sent from the server like unlink and set redirect path
  * Return 1 if reconnect is needed, otherwise 0 */
diff --git a/contrib/chg/procutil.c b/contrib/chg/procutil.c
--- a/contrib/chg/procutil.c
+++ b/contrib/chg/procutil.c
@@ -8,4 +8,15 @@ 
  */
 
+#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;
@@ -72,5 +83,5 @@  static void handlechildsignal(int sig UN
 }
 
-static void setupsignalhandler(pid_t pid, pid_t pgid)
+void setupsignalhandler(pid_t pid, pid_t pgid)
 {
 	if (pid <= 0)
@@ -122,5 +133,5 @@  error:
 }
 
-static void restoresignalhandler()
+void restoresignalhandler(void)
 {
 	struct sigaction sa;
@@ -158,5 +169,5 @@  error:
 /* 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);
@@ -200,5 +211,5 @@  error:
 }
 
-static void waitpager(void)
+void waitpager(void)
 {
 	if (pagerpid == 0)
diff --git a/contrib/chg/procutil.h b/contrib/chg/procutil.h
new file mode 100644
--- /dev/null
+++ b/contrib/chg/procutil.h
@@ -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_ */