diff options
author | root <root@ka-ata-killa.panaceas.james.internal> | 2022-04-09 11:57:42 +0100 |
---|---|---|
committer | root <root@ka-ata-killa.panaceas.james.internal> | 2022-04-09 11:57:42 +0100 |
commit | 338dcccc8d8532a446fa60dc65092b5510c06e3a (patch) | |
tree | 85c40cfec1a44b43a278d164f6a6c20576fd8aba /util.c | |
parent | c44cf3a3f0a73ad276c0316759fcb0d8a0d22032 (diff) | |
download | galaxy_sia-338dcccc8d8532a446fa60dc65092b5510c06e3a.tar.gz galaxy_sia-338dcccc8d8532a446fa60dc65092b5510c06e3a.tar.bz2 galaxy_sia-338dcccc8d8532a446fa60dc65092b5510c06e3a.zip |
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 66 |
1 files changed, 66 insertions, 0 deletions
@@ -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; +} + + + + |