diff options
| author | Roy Marples <roy@marples.name> | 2006-11-27 20:23:22 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2006-11-27 20:23:22 +0000 |
| commit | cced195e703c548e7375727ea91bbdcd76aae517 (patch) | |
| tree | 6c97679eedd1d687263f7d65742b02bedd93895f /common.c | |
| download | dhcpcd-cced195e703c548e7375727ea91bbdcd76aae517.tar.xz | |
Add dhcpcd-3 re-write
Diffstat (limited to 'common.c')
| -rw-r--r-- | common.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/common.c b/common.c new file mode 100644 index 00000000..c3203b9c --- /dev/null +++ b/common.c @@ -0,0 +1,64 @@ +/* + * dhcpcd - DHCP client daemon - + * Copyright (C) 2006 Roy Marples <uberlord@gentoo.org> + * + * dhcpcd is an RFC2131 compliant DHCP client daemon. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <sys/time.h> +#include <stdlib.h> +#include <string.h> + +#include "logger.h" + +/* This requires us to link to rt on glibc, so we use sysinfo instead */ +#ifdef __linux__ +#include <sys/sysinfo.h> +long uptime (void) +{ + struct sysinfo info; + + sysinfo (&info); + return info.uptime; +} +#else +#include <time.h> +long uptime (void) +{ + struct timespec tp; + + if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1) + { + logger (LOG_ERR, "Unable to get uptime: %m"); + return -1; + } + + return tp.tv_sec; +} +#endif /* __linux__ */ + +void *xmalloc (size_t size) +{ + register void *value = malloc (size); + + if (value) + return value; + + logger (LOG_ERR, "memory exhausted"); + exit (1); +} + |
