[PATCH] libhurdutil: New library containing utils to be used by Guix.

2016-05-25 Thread manolis837
From: Manolis Ragkousis 

* libhurdutil/hurdutil.h: New file.
* libhurdutil/settrans.c: New file.
* libhurdutil/Makefile: New file.
* utils/Makefile (HURDLIBS, settrans): Use the new library.
* utils/settrans.c: Update to use the new library.
* Makefile: (lib-subdirs): Add library.
---
 Makefile   |   2 +-
 libhurdutil/Makefile   |  28 +++
 libhurdutil/hurdutil.h |  78 
 libhurdutil/settrans.c | 377 +++
 utils/Makefile |   4 +-
 utils/settrans.c   | 475 +++--
 6 files changed, 594 insertions(+), 370 deletions(-)
 create mode 100644 libhurdutil/Makefile
 create mode 100644 libhurdutil/hurdutil.h
 create mode 100644 libhurdutil/settrans.c

diff --git a/Makefile b/Makefile
index d48baaa..e712767 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ include ./Makeconf
 lib-subdirs = libshouldbeinlibc libihash libiohelp libports libthreads \
  libpager libfshelp libdiskfs libtrivfs libps \
  libnetfs libpipe libstore libhurdbugaddr libftpconn libcons \
- libhurd-slab
+ libhurd-slab libhurdutil
 
 # Hurd programs
 prog-subdirs = auth proc exec term \
diff --git a/libhurdutil/Makefile b/libhurdutil/Makefile
new file mode 100644
index 000..2e0e642
--- /dev/null
+++ b/libhurdutil/Makefile
@@ -0,0 +1,28 @@
+#   Copyright (C) 2016 Free Software Foundation, Inc.
+#
+#   This file is part of the GNU Hurd.
+#
+#   The GNU Hurd is free software; you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation; either version 2, or (at
+#   your option) any later version.
+#
+#   The GNU Hurd is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#   General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := libhurdutil
+makemode := library
+
+libname := libhurdutil
+SRCS = settrans.c
+installhdrs = hurdutil.h
+
+OBJS = $(SRCS:.c=.o)
+
+include ../Makeconf
diff --git a/libhurdutil/hurdutil.h b/libhurdutil/hurdutil.h
new file mode 100644
index 000..5786cff
--- /dev/null
+++ b/libhurdutil/hurdutil.h
@@ -0,0 +1,78 @@
+/* hurdutil.h - Hurd utils interface.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   Written by Manolis Fragkiskos Ragkousis .
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   The GNU Hurd is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with the GNU Hurd; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+
+#ifndef _HURD_UTIL_H
+#define _HURD_UTIL_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+struct settrans_flags
+{
+  /* The name of the node we're putting the translator on. */
+  char *node_name;
+
+  /* Flags to pass to file_set_translator.  */
+  int lookup_flags;
+  int goaway_flags;
+
+  /* Various option flags.  */
+  int passive;
+  int active;
+  int keep_active;
+  int pause;
+  int kill_active;
+  int orphan;
+  int start;
+  int stack;
+  int excl;
+  int timeout;
+  char *pid_file;
+  char *underlying_node_name;
+  int underlying_lookup_flags;
+  char **chroot_command;
+  char *chroot_chdir;
+
+  /* The translator's arg vector, in '\0' separated format.  */
+  char *argz;
+  size_t argz_len;
+};
+typedef struct settrans_flags *settrans_flags_t;
+
+/* Initialize the flags to be used. */
+void settrans_flags_init (settrans_flags_t flags);
+
+/* Release the memory allocated. */
+void settrans_flags_cleanup (settrans_flags_t flags);
+
+/* Create the struct containing the flags and initialize them.
+   If a memory allocation error occurs, ENOMEM is returned,
+   otherwise 0.*/
+error_t settrans_flags_create (settrans_flags_t *flags);
+
+/* Set a translator according to the flags passed. On success return 0. */
+error_t settrans(settrans_flags_t flags);
+
+#endif /* _HURD_UTIL_H */
diff --git a/libhurdutil/settrans.c b/libhurdutil/settrans.c
new file mode 100644
index 000..eeaa964
--- /dev/null
+++ b/libhurdutil/settrans.c
@@ -0,0 +1,377 @@
+/* settrans.c - Set a file's translator.
+
+   Copyright 

[PATCH] libhurdutil: New library containing utils to be used by Guix.

2016-05-25 Thread manolis837

I am resending the patch from 
https://lists.gnu.org/archive/html/bug-hurd/2016-05/msg00040.html modified to 
apply on master. 

Manolis



[PATCH] libhurdutil: New library containing utils to be used by Guix.

2016-05-25 Thread Manolis Ragkousis
Hello everyone,

This is the library Justus suggested some time ago and it contains the
implementation of settrans. This patch actually does three things.

1) It creates libhurdutil/hurdutil.h which exposes the interface and a
struct called settrans_flags_t which contains all the flags to be used
by settrans.
2) It creates libhurdutil/settrans.c which includes the c implementation
of utils/settrans.c without the arguments parsing.
3) It modifies utils/settrans.c to use the new library. The arguments
parsing of the settrans binary happens here.

Whoever uses the library directly will modify the flags accordingly and
pass them to settrans() from the library.

In order to use it you first have to declare a variable settrans_flags_t
flags, initialize it with settrans_flags_create(), change the
flags inside settrans_flags_t, pass it to settrans() and when you are
done call settrans_flags_cleanup(flags).

I have tested it and it works. I am currently using it in my vm. But I
have some questions.

Implementation questions:
1) How should I handle errors of settrans inside the library? Normally
utils/settrans.c used error() to report any problems. But settrans()
should return error_t codes. Should I define a list of errors for
settrans() and use them accordingly? (e.g TRANS_NOT_SET etc.)
2) Do you agree with the way I handle arguments? Should I do it in a
different way?

Code indentations questions:
1) I am using emacs and I have configured it to automatically indent
code according to the gnu style. But I noticed that this causes changes
from the original. For example in the original, some '{'  are not being
tabbed 4 spaces to the right. Why? Is this a special case?

This is my first serious c library so I am sure there will be many
things that need to be changed. settrans_flags_cleanup() needs some work
and I need to add more comments. It's still work in progress so please
feel free to correct/suggest anything. :-)

Thank you,
Manolis

From 4fe21e255e483a711f898227b90b130afd969b33 Mon Sep 17 00:00:00 2001
From: Manolis Ragkousis 
Date: Thu, 12 May 2016 15:08:36 +0300
Subject: [PATCH] libhurdutil: New library containing utils to be used by Guix.

* libhurdutil/hurdutil.h: New file.
* libhurdutil/settrans.c: New file.
* libhurdutil/Makefile: New file.
* utils/Makefile (HURDLIBS, settrans): Use the new library.
* utils/settrans.c: Update to use the new library.
* Makefile: (lib-subdirs): Add library.
---
 Makefile   |   2 +-
 libhurdutil/Makefile   |  28 +++
 libhurdutil/hurdutil.h |  78 +++
 libhurdutil/settrans.c | 377 ++
 utils/Makefile |   4 +-
 utils/settrans.c   | 536 ++---
 6 files changed, 633 insertions(+), 392 deletions(-)
 create mode 100644 libhurdutil/Makefile
 create mode 100644 libhurdutil/hurdutil.h
 create mode 100644 libhurdutil/settrans.c

diff --git a/Makefile b/Makefile
index d48baaa..e712767 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ include ./Makeconf
 lib-subdirs = libshouldbeinlibc libihash libiohelp libports libthreads \
 	  libpager libfshelp libdiskfs libtrivfs libps \
 	  libnetfs libpipe libstore libhurdbugaddr libftpconn libcons \
-	  libhurd-slab
+	  libhurd-slab libhurdutil
 
 # Hurd programs
 prog-subdirs = auth proc exec term \
diff --git a/libhurdutil/Makefile b/libhurdutil/Makefile
new file mode 100644
index 000..2e0e642
--- /dev/null
+++ b/libhurdutil/Makefile
@@ -0,0 +1,28 @@
+#   Copyright (C) 2016 Free Software Foundation, Inc.
+#
+#   This file is part of the GNU Hurd.
+#
+#   The GNU Hurd is free software; you can redistribute it and/or
+#   modify it under the terms of the GNU General Public License as
+#   published by the Free Software Foundation; either version 2, or (at
+#   your option) any later version.
+#
+#   The GNU Hurd is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#   General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+dir := libhurdutil
+makemode := library
+
+libname := libhurdutil
+SRCS = settrans.c
+installhdrs = hurdutil.h
+
+OBJS = $(SRCS:.c=.o)
+
+include ../Makeconf
diff --git a/libhurdutil/hurdutil.h b/libhurdutil/hurdutil.h
new file mode 100644
index 000..5786cff
--- /dev/null
+++ b/libhurdutil/hurdutil.h
@@ -0,0 +1,78 @@
+/* hurdutil.h - Hurd utils interface.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   Written by Manolis Fragkiskos Ragkousis .
+
+   This file is part of the GNU Hurd.
+
+   The GNU Hurd is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+