IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
| Source at commit cec05a0f5ea2fb4ff5637d418c7f5dae196abda8 created 6 years 9 months ago. By Werner Almesberger, atusb/atusb.pro: we don't use power.lib anymore | |
|---|---|
| 1 | /* |
| 2 | * lib/daemon.c - Helper functions for proper daemonification |
| 3 | * |
| 4 | * Written 2011 by Werner Almesberger |
| 5 | * Copyright 2011 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <stdlib.h> |
| 15 | #include <stdio.h> |
| 16 | #include <unistd.h> |
| 17 | |
| 18 | #include "daemon.h" |
| 19 | |
| 20 | |
| 21 | pid_t daemonize(void) |
| 22 | { |
| 23 | pid_t pid; |
| 24 | int i; |
| 25 | |
| 26 | pid = fork(); |
| 27 | if (pid < 0) { |
| 28 | perror("fork"); |
| 29 | exit(1); |
| 30 | } |
| 31 | if (pid) |
| 32 | return pid; |
| 33 | if (setsid() < 0) { |
| 34 | perror("setsid"); |
| 35 | exit(1); |
| 36 | } |
| 37 | for (i = 0; i <= 2; i++) |
| 38 | (void) close(i); |
| 39 | (void) chdir("/"); |
| 40 | return 0; |
| 41 | } |
| 42 | |
