summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorroot <root@ka-ata-killa.panaceas.james.internal>2022-04-09 11:57:42 +0100
committerroot <root@ka-ata-killa.panaceas.james.internal>2022-04-09 11:57:42 +0100
commit338dcccc8d8532a446fa60dc65092b5510c06e3a (patch)
tree85c40cfec1a44b43a278d164f6a6c20576fd8aba /util.c
parentc44cf3a3f0a73ad276c0316759fcb0d8a0d22032 (diff)
downloadgalaxy_tools-master.tar.gz
galaxy_tools-master.tar.bz2
galaxy_tools-master.zip
various improvementsHEADmaster
Diffstat (limited to 'util.c')
-rw-r--r--util.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/util.c b/util.c
index 21c1eb9..052b382 100644
--- a/util.c
+++ b/util.c
@@ -8,6 +8,7 @@
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
+#include <sys/wait.h>
@@ -296,6 +297,7 @@ int open_tcp_client (const char *host, unsigned port)
if (fd < 0) return -1;
+
sin.sin_port = htons (port);
if (connect (fd, (struct sockaddr *)&sin, sizeof (sin))) {
@@ -339,3 +341,67 @@ int open_tcp_server (unsigned port)
+int daemonish (int nochdir, int noclose)
+{
+ pid_t pid;
+ int status;
+
+ if (!nochdir && chdir ("/"))
+ return -1;
+
+ if (!noclose) {
+ int fd, failed = 0;
+
+ if ((fd = open ("/dev/null", O_RDWR)) < 0) return -1;
+
+ if (dup2 (fd, 0) < 0 || dup2 (fd, 1) < 0 || dup2 (fd, 2) < 0)
+ failed++;
+
+ if (fd > 2) close (fd);
+
+ if (failed) return -1;
+ }
+
+ switch ((pid = fork())) {
+ case 0:
+ break;
+
+ case -1:
+ return -1;
+
+ default:
+ waitpid (pid, &status, 0);
+ return 1;;
+ }
+
+ if (setsid() < 0) return -1;
+
+ switch (fork()) {
+ case 0:
+ break;
+
+ case -1:
+ return -1;
+
+ default:
+ _exit (0);
+ }
+
+ return 0;
+}
+
+
+int local_isalnum (char c)
+{
+ if ((c >= '0') && (c <= '9')) return 1;
+
+ if ((c >= 'A') && (c <= 'Z')) return 1;
+
+ if ((c >= 'a') && (c <= 'z')) return 1;
+
+ return 0;
+}
+
+
+
+