summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-08-27 21:38:36 +0200
committerTom Gundersen <teg@jklm.no>2015-08-27 21:38:36 +0200
commit4a316c44aa6222f3abc7ed2d50d00a0817cd4466 (patch)
treea66424ffac18c715c70fce1484366cd3c7a9415d /src/basic
parentd56cc298808b2dbfa28ae893d6f47f34df3196b1 (diff)
parentc2c940bda03a07fbacfa3df2590ed865ec3dcc22 (diff)
Merge pull request #1055 from poettering/dhcp-updates
Various networkd and dhcp updates
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/refcnt.h4
-rw-r--r--src/basic/ring.h3
-rw-r--r--src/basic/time-util.c33
-rw-r--r--src/basic/time-util.h2
4 files changed, 38 insertions, 4 deletions
diff --git a/src/basic/refcnt.h b/src/basic/refcnt.h
index 0502c20a2e..8a39d69fe4 100644
--- a/src/basic/refcnt.h
+++ b/src/basic/refcnt.h
@@ -21,7 +21,9 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-/* A type-safe atomic refcounter */
+/* A type-safe atomic refcounter.
+ *
+ * DO NOT USE THIS UNLESS YOU ACTUALLY CARE ABOUT THREAD SAFETY! */
typedef struct {
volatile unsigned _value;
diff --git a/src/basic/ring.h b/src/basic/ring.h
index a7c44d1b56..dbd6296384 100644
--- a/src/basic/ring.h
+++ b/src/basic/ring.h
@@ -50,7 +50,6 @@ int ring_push(Ring *r, const void *u8, size_t size);
void ring_pull(Ring *r, size_t size);
/* return size of occupied buffer in bytes */
-static inline size_t ring_get_size(Ring *r)
-{
+static inline size_t ring_get_size(Ring *r) {
return r->used;
}
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index e278196c90..3d8d5d7568 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -26,6 +26,7 @@
#include "util.h"
#include "time-util.h"
+#include "path-util.h"
#include "strv.h"
usec_t now(clockid_t clock_id) {
@@ -971,7 +972,10 @@ bool timezone_is_valid(const char *name) {
const char *p, *t;
struct stat st;
- if (!name || *name == 0 || *name == '/')
+ if (isempty(name))
+ return false;
+
+ if (name[0] == '/')
return false;
for (p = name; *p; p++) {
@@ -1021,3 +1025,30 @@ clockid_t clock_boottime_or_monotonic(void) {
return clock;
}
+
+int get_timezone(char **timezone) {
+ _cleanup_free_ char *t = NULL;
+ const char *e;
+ char *z;
+ int r;
+
+ r = readlink_malloc("/etc/localtime", &t);
+ if (r < 0)
+ return r; /* returns EINVAL if not a symlink */
+
+ e = path_startswith(t, "/usr/share/zoneinfo/");
+ if (!e)
+ e = path_startswith(t, "../usr/share/zoneinfo/");
+ if (!e)
+ return -EINVAL;
+
+ if (!timezone_is_valid(e))
+ return -EINVAL;
+
+ z = strdup(e);
+ if (!z)
+ return -ENOMEM;
+
+ *timezone = z;
+ return 0;
+}
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 2aba042217..03a47f310d 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -110,3 +110,5 @@ bool timezone_is_valid(const char *name);
clockid_t clock_boottime_or_monotonic(void);
#define xstrftime(buf, fmt, tm) assert_se(strftime(buf, ELEMENTSOF(buf), fmt, tm) > 0)
+
+int get_timezone(char **timezone);