summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-01-03 20:58:07 +0100
committerLennart Poettering <lennart@poettering.net>2012-01-03 21:08:58 +0100
commit000a2c98860e4c1de7e1477bedf6ad216f8c5854 (patch)
treea22d4c8fbd85629d4b0533acc0c0460eccf0155c
parenta5344d2c3b0f14e954ce1c0ef905c5b44bc5bf0a (diff)
sd-id128: add _public_ to all exports, and add validity checks for all parameters
-rw-r--r--Makefile.am2
-rw-r--r--src/sd-id128.c30
2 files changed, 21 insertions, 11 deletions
diff --git a/Makefile.am b/Makefile.am
index 651b37df0c..1af9cbc5a5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1925,7 +1925,7 @@ man/sd_login_monitor_get_fd.3: man/sd_login_monitor_new.3
man/sd_session_get_uid.3: man/sd_session_is_active.3
man/sd_session_get_seat.3: man/sd_session_is_active.3
man/sd_pid_get_owner_uid.3: man/sd_pid_get_session.3
-man/sd_pid_get_session.3: man/sd_pid_get_session.3
+man/sd_pid_get_service.3: man/sd_pid_get_session.3
man/sd_uid_is_on_seat.3: man/sd_uid_get_state.3
man/sd_uid_get_sessions.3: man/sd_uid_get_state.3
man/sd_uid_get_seats.3: man/sd_uid_get_state.3
diff --git a/src/sd-id128.c b/src/sd-id128.c
index f5e0432a3f..387cf919b0 100644
--- a/src/sd-id128.c
+++ b/src/sd-id128.c
@@ -27,10 +27,11 @@
#include "util.h"
#include "macro.h"
-char *sd_id128_to_string(sd_id128_t id, char s[33]) {
+_public_ char *sd_id128_to_string(sd_id128_t id, char s[33]) {
unsigned n;
- assert(s);
+ if (!s)
+ return NULL;
for (n = 0; n < 16; n++) {
s[n*2] = hexchar(id.bytes[n] >> 4);
@@ -42,12 +43,14 @@ char *sd_id128_to_string(sd_id128_t id, char s[33]) {
return s;
}
-int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
+_public_ int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
unsigned n;
sd_id128_t t;
- assert(s);
- assert(ret);
+ if (!s)
+ return -EINVAL;
+ if (!ret)
+ return -EINVAL;
for (n = 0; n < 16; n++) {
int a, b;
@@ -70,7 +73,7 @@ int sd_id128_from_string(const char s[33], sd_id128_t *ret) {
return 0;
}
-sd_id128_t sd_id128_make_v4_uuid(sd_id128_t id) {
+_public_ sd_id128_t sd_id128_make_v4_uuid(sd_id128_t id) {
/* Stolen from generate_random_uuid() of drivers/char/random.c
* in the kernel sources */
@@ -83,7 +86,7 @@ sd_id128_t sd_id128_make_v4_uuid(sd_id128_t id) {
return id;
}
-int sd_id128_get_machine(sd_id128_t *ret) {
+_public_ int sd_id128_get_machine(sd_id128_t *ret) {
static __thread sd_id128_t saved_machine_id;
static __thread bool saved_machine_id_valid = false;
int fd;
@@ -92,6 +95,9 @@ int sd_id128_get_machine(sd_id128_t *ret) {
unsigned j;
sd_id128_t t;
+ if (!ret)
+ return -EINVAL;
+
if (saved_machine_id_valid) {
*ret = saved_machine_id;
return 0;
@@ -129,7 +135,7 @@ int sd_id128_get_machine(sd_id128_t *ret) {
return 0;
}
-int sd_id128_get_boot(sd_id128_t *ret) {
+_public_ int sd_id128_get_boot(sd_id128_t *ret) {
static __thread sd_id128_t saved_boot_id;
static __thread bool saved_boot_id_valid = false;
int fd;
@@ -139,6 +145,9 @@ int sd_id128_get_boot(sd_id128_t *ret) {
sd_id128_t t;
char *p;
+ if (!ret)
+ return -EINVAL;
+
if (saved_boot_id_valid) {
*ret = saved_boot_id;
return 0;
@@ -181,12 +190,13 @@ int sd_id128_get_boot(sd_id128_t *ret) {
return 0;
}
-int sd_id128_randomize(sd_id128_t *ret) {
+_public_ int sd_id128_randomize(sd_id128_t *ret) {
int fd;
ssize_t k;
sd_id128_t t;
- assert(ret);
+ if (!ret)
+ return -EINVAL;
fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
if (fd < 0)