aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-06-27 23:13:13 +1200
committerDavid Phillips <david@sighup.nz>2018-06-27 23:13:13 +1200
commit8edfe990e819dcc1a951e9bf73c338a015cb6a6a (patch)
tree941c0673144c2ded9a99fcb90117bd27b7d5e5f1
parent48a94012fd2785d500c17e1f6f2315a13b2a0a2f (diff)
downloadalarmd-8edfe990e819dcc1a951e9bf73c338a015cb6a6a.tar.xz
Remove some magic constants
Also removes old debug print code
-rw-r--r--alarmd/alarmd.c8
-rw-r--r--lib/libalarm.c2
2 files changed, 4 insertions, 6 deletions
diff --git a/alarmd/alarmd.c b/alarmd/alarmd.c
index 4b3df78..9f2c254 100644
--- a/alarmd/alarmd.c
+++ b/alarmd/alarmd.c
@@ -68,12 +68,12 @@ int handle_register(int c_sock, pid_t owner)
}
new_alarm->name = strdup((const char*)buffer);
- memcpy(new_alarm->uuid, uuid, 16);
+ memcpy(new_alarm->uuid, uuid, sizeof(new_alarm->uuid));
new_alarm->is_raised = 0;
new_alarm->owner = owner;
/* LOCK */
- HASH_ADD(hh, alarms, uuid, 16, new_alarm);
+ HASH_ADD(hh, alarms, uuid, sizeof(uuid), new_alarm);
/* UNLOCK */
return 0;
}
@@ -108,7 +108,7 @@ int handle_set_raised_generic(int c_sock, int shall_raise)
size_t nread = 0;
struct alarm *target = NULL;
- if ((nread = recv(c_sock, &uuid, 16, 0)) < 16) {
+ if ((nread = recv(c_sock, &uuid, sizeof(uuid), 0)) < sizeof(uuid)) {
fprintf(stderr, "Received UUID too short\n");
return 1;
}
@@ -147,7 +147,6 @@ int handle_query(int c_sock)
}
HASH_ITER(hh, alarms, a, tmp) {
- fprintf(stderr, "DEBUG : [%s] %s\n", a->is_raised ? "RAISE" : "CLEAR" , a->name);
/* FIXME factor out, idiot. also bounds check on strlen */
length = strlen(a->name);
if (send(c_sock, &length, sizeof(length), 0) < sizeof(length)) {
@@ -162,7 +161,6 @@ int handle_query(int c_sock)
if (send(c_sock, &(a->owner), sizeof(a->owner), 0) < sizeof(a->owner)) {
perror("send");
}
- fprintf(stderr, "SENT.\n");
}
/* UNLOCK */
return 0;
diff --git a/lib/libalarm.c b/lib/libalarm.c
index 9dc9ae0..20448aa 100644
--- a/lib/libalarm.c
+++ b/lib/libalarm.c
@@ -58,7 +58,7 @@ int send_string(int sock, char *buffer)
int send_packet_uuid(int sock, uint32_t packet_type, uuid_t uuid)
{
return (send(sock, &packet_type, sizeof(packet_type), 0) != sizeof(packet_type)
- || send(sock, uuid, 16, 0) != 16);
+ || send(sock, uuid, sizeof(uuid_t), 0) != 16);
}
/** End helper functions ***********/