410c8acf |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: util.c,v 1.1 2001/02/03 20:26:37 mdw Exp $ |
4 | * |
5 | * Utilities for the client and the server |
6 | * |
7 | * (c) 2001 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Trivial IP Encryption (TrIPE). |
13 | * |
14 | * TrIPE is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2 of the License, or |
17 | * (at your option) any later version. |
18 | * |
19 | * TrIPE is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License |
25 | * along with TrIPE; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | */ |
28 | |
29 | /*----- Revision history --------------------------------------------------* |
30 | * |
31 | * $Log: util.c,v $ |
32 | * Revision 1.1 2001/02/03 20:26:37 mdw |
33 | * Initial checkin. |
34 | * |
35 | */ |
36 | |
37 | /*----- Header files ------------------------------------------------------*/ |
38 | |
39 | #include <errno.h> |
40 | #include <stdio.h> |
41 | #include <stdlib.h> |
42 | #include <string.h> |
43 | |
44 | #include <sys/types.h> |
45 | #include <unistd.h> |
46 | #include <fcntl.h> |
47 | |
48 | #include "util.h" |
49 | |
50 | #include <sys/ioctl.h> |
51 | |
52 | /*----- Main code ---------------------------------------------------------*/ |
53 | |
54 | /* --- @u_daemon@ --- * |
55 | * |
56 | * Arguments: --- |
57 | * |
58 | * Returns: Zero if OK, nonzero on failure. |
59 | * |
60 | * Use: Becomes a daemon. |
61 | */ |
62 | |
63 | int u_daemon(void) |
64 | { |
65 | pid_t kid; |
66 | |
67 | if ((kid = fork()) < 0) |
68 | return (-1); |
69 | if (kid) |
70 | _exit(0); |
71 | #ifdef TIOCNOTTY |
72 | { |
73 | int fd; |
74 | if ((fd = open("/dev/tty", O_RDONLY)) >= 0) { |
75 | ioctl(fd, TIOCNOTTY); |
76 | close(fd); |
77 | } |
78 | } |
79 | #endif |
80 | setsid(); |
81 | |
82 | if (fork() > 0) |
83 | _exit(0); |
84 | return (0); |
85 | } |
86 | |
87 | /*----- That's all, folks -------------------------------------------------*/ |