[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnunet] 16/30: Add helper lib "gnunet-qr-utils.h".
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnunet] 16/30: Add helper lib "gnunet-qr-utils.h". |
Date: |
Wed, 03 Apr 2019 13:53:57 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
commit 6f4f14aa56a879587ae731751d51ea062e3d0956
Author: Hartmut Goebel <address@hidden>
AuthorDate: Sat Mar 2 17:26:35 2019 +0100
Add helper lib "gnunet-qr-utils.h".
These functions are copied from dns/gnunet-helper-dns.c,
move them into a common library.
Or think about implementing a even more elaborate version.
---
src/util/gnunet-qr-utils.h | 111 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 111 insertions(+)
diff --git a/src/util/gnunet-qr-utils.h b/src/util/gnunet-qr-utils.h
new file mode 100644
index 000000000..6d821633c
--- /dev/null
+++ b/src/util/gnunet-qr-utils.h
@@ -0,0 +1,111 @@
+/*
+ This file is part of GNUnet.
+ Copyright (C) 2010, 2011, 2012 Christian Grothoff
+ Copyright (C) 2019 GNUnet e.V.
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet 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
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+*/
+
+#include "platform.h"
+
+//
+// FIXME: These functions are copied from dns/gnunet-helper-dns.c,
+// move them into a common library. Or think about implementing a even
+// more elaborate version.
+//
+
+/**
+ * Open '/dev/null' and make the result the given
+ * file descriptor.
+ *
+ * @param target_fd desired FD to point to /dev/null
+ * @param flags open flags (O_RDONLY, O_WRONLY)
+ */
+static void
+open_dev_null (int target_fd,
+ int flags)
+{
+ int fd;
+
+ fd = open ("/dev/null", flags);
+ if (-1 == fd)
+ abort ();
+ if (fd == target_fd)
+ return;
+ if (-1 == dup2 (fd, target_fd))
+ {
+ (void) close (fd);
+ abort ();
+ }
+ (void) close (fd);
+}
+
+/**
+ * Run the given command and wait for it to complete.
+ *
+ * @param file name of the binary to run
+ * @param cmd command line arguments (as given to 'execv')
+ * @return 0 on success, 1 on any error
+ */
+static int
+fork_and_exec (const char *file,
+ char *const cmd[])
+{
+ int status;
+ pid_t pid;
+ pid_t ret;
+
+ pid = fork ();
+ if (-1 == pid)
+ {
+ fprintf (stderr,
+ "fork failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+ if (0 == pid)
+ {
+ /* we are the child process */
+ /* close stdin/stdout to not cause interference
+ with the helper's main protocol! */
+ (void) close (0);
+ open_dev_null (0, O_RDONLY);
+ (void) close (1);
+ open_dev_null (1, O_WRONLY);
+ (void) execv (file, cmd);
+ /* can only get here on error */
+ fprintf (stderr,
+ "exec `%s' failed: %s\n",
+ file,
+ strerror (errno));
+ _exit (1);
+ }
+ /* keep running waitpid as long as the only error we get is 'EINTR' */
+ while ( (-1 == (ret = waitpid (pid, &status, 0))) &&
+ (errno == EINTR) );
+ if (-1 == ret)
+ {
+ fprintf (stderr,
+ "waitpid failed: %s\n",
+ strerror (errno));
+ return 1;
+ }
+ if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status))))
+ return 1;
+ /* child process completed and returned success, we're happy */
+ return 0;
+}
+
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnunet] 01/30: gnunet-qr: Reimplement in C - yet only a proof of concept., (continued)
- [GNUnet-SVN] [gnunet] 01/30: gnunet-qr: Reimplement in C - yet only a proof of concept., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 25/30: contrib/guix: Add zbar as dependency for package gnunet., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 17/30: gnunet-qr: Actually run gnunet-uri., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 15/30: gnunet-qr: Simplify verbose messaging., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 18/30: Add Hartmut Goebel to the AUTHORS file., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 08/30: gnunet-qr: Use the `gnunet-uri` binary installed into PREFIX., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 12/30: contrib/guix: Add zbar as dependency for package gnunet., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 09/30: gnunet-qr: Update documentation and scripts to changed dependencies., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 19/30: configure.ac: Add check for libzbar (using pkgconfig)., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 20/30: gnunet-qr: Add into Makefile.am and pofiles,, gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 16/30: Add helper lib "gnunet-qr-utils.h".,
gnunet <=
- [GNUnet-SVN] [gnunet] 11/30: contrib/guix: Add package zbar (for gnunet-qr)., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 26/30: gnunet-qr: Implement functionality of gnunet-uri, don't spawn., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 23/30: gnunet-qr: Use GNUNET_PROGRAM_run to simplify the code., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 24/30: contrib/guix: Add package zbar (for gnunet-qr)., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 13/30: gnunet-qr: Implement functionality of gnunet-uri, don't spawn., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 21/30: gnunet-qr: Use the `gnunet-uri` binary installed into PREFIX., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 22/30: gnunet-qr: Update documentation and scripts to changed dependencies., gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 28/30: merge conflict resolution, gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 29/30: fix libzbar detection, gnunet, 2019/04/03
- [GNUnet-SVN] [gnunet] 14/30: gnunet-qr: Reimplement in C - yet only a proof of concept., gnunet, 2019/04/03