[linux-merge]linux integration; annotated tag, v4.0-rc6, created. v4.0-rc6
by postmaster@open-mesh.org
The annotated tag, v4.0-rc6 has been created
at 560a83984c7d32dd40027c9920d3997d519e94a7 (tag)
tagging e42391cd048809d903291d07f86ed3934ce138e9 (commit)
replaces v4.0-rc5
tagged by Linus Torvalds
on Sun Mar 29 15:26:43 2015 -0700
- Shortlog ------------------------------------------------------------
Linux 4.0-rc6
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJVGHwjAAoJEHm+PkMAQRiG8rcIAJ6cEJ6mbqLpyz5XrGf4yNp0
+wG/QlEpT8rgrxe9wSjB3lfW3kR2Pe69b9fVVCdiklygdkmva5vfmDrVGGzYfe3M
QrFSSlMVBplvh6IiM/L1mVMtr3DSmCO23YZZ9R5b7FoEYatNHRpNWBCBpuXpd4aD
sLuIvO3L/S7LqeOAFkkYWv6AuL9umicmjR8u+nsmCSRJom7At/aJ6R66WIp9vxho
Rn7r6wcUk6B2Q/gYNjdSE8SIwdyKhuBGyvqQ9U9s6Btg9DQfM/b0vG5kw9hqeAq/
9445jqVDP1whA2vz6GjnvltidxrqRvuDPBwzOnFmY5U+KZz4lS3x2mnWAAJ3xWs=
=TqVJ
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------
--
linux integration
7 years, 10 months
[linux-merge]linux integration; annotated tag, v4.0-rc5, created. v4.0-rc5
by postmaster@open-mesh.org
The annotated tag, v4.0-rc5 has been created
at 44138dfa09632152f3f52720bc07158d74949414 (tag)
tagging bc465aa9d045feb0e13b4a8f32cc33c1943f62d6 (commit)
replaces v4.0-rc4
tagged by Linus Torvalds
on Sun Mar 22 16:50:30 2015 -0700
- Shortlog ------------------------------------------------------------
Linux 4.0-rc5
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJVD1VGAAoJEHm+PkMAQRiG7yoH/juKOQ1zbxi5M+mleDEEJtA0
RxQSojqEMWIKrWi8PNZxjENn1OZB6XOLIXOhlyAZBrmgsjO34p1DyXlZMznr/R8W
kQ2Xxs061hRtB3OuruMIqOApUrjuqsaCwgbgUS1qWmqZcoyZN4oELyZMP6OOlqv5
UUBZm8MfyXGyxrCcg39mjct3VEOhiuEcvL6SUxOC380CdSVAnyqHFPcz0JVqMUn9
9RUBs0T9cMdhb0mZ2bfXzt6AKArj63G2nXOum+VzFcvspSm2U+MPIDCuoE+ZbTPS
jqIAgG0rj1ezRyb5oeJrvlU0Yy3u/cXoMPs9+kORvpladooYNLti8ovh6qllm0I=
=d/ye
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------
--
linux integration
7 years, 10 months
[alfred] master: alfred: Add "--update-command" parameter (4ae4c74)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 4ae4c749c0a4fe01e77590fef5421e0e78f1fe61
Author: Anatoliy Lapitskiy <anatoliy.lapitskiy(a)gmail.com>
Date: Tue Mar 17 10:11:15 2015 +0200
alfred: Add "--update-command" parameter
The "--update-command" parameter is created for adding a hook to run when
new information is received.
At the moment "alfred-facters" are run by cron once per every 5 minutes.
For some tasks (like sharing dhcp leases) it can be too slow.
Signed-off-by: Anatoliy Lapitskiy <anatoliy.lapitskiy(a)gmail.com>
Reviewed-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
4ae4c749c0a4fe01e77590fef5421e0e78f1fe61
alfred.h | 11 +++++++++
main.c | 12 +++++++++-
man/alfred.8 | 4 ++++
recv.c | 10 ++++++++
server.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/alfred.h b/alfred.h
index f26c80c..621805d 100644
--- a/alfred.h
+++ b/alfred.h
@@ -55,6 +55,11 @@ struct dataset {
uint8_t local_data;
};
+struct changed_data_type {
+ uint8_t data_type;
+ struct list_head list;
+};
+
struct transaction_packet {
struct alfred_push_data_v0 *push;
struct list_head list;
@@ -118,6 +123,10 @@ struct globals {
int unix_sock;
const char *unix_path;
+ const char *update_command;
+ struct list_head changed_data_types;
+ uint16_t changed_data_type_count; /* maximum is 256 */
+
struct timespec if_check;
struct hashtable_t *data_hash;
@@ -134,6 +143,8 @@ extern const struct in6_addr in6addr_localmcast;
/* server.c */
int alfred_server(struct globals *globals);
int set_best_server(struct globals *globals);
+void changed_data_type(struct globals *globals, uint8_t arg);
+
/* client.c */
int alfred_client_request_data(struct globals *globals);
int alfred_client_set_data(struct globals *globals);
diff --git a/main.c b/main.c
index 02553c0..db1f8b0 100644
--- a/main.c
+++ b/main.c
@@ -61,6 +61,7 @@ static void alfred_usage(void)
printf("\n");
printf(" -u, --unix-path [path] path to unix socket used for client-server\n");
printf(" communication (default: \""ALFRED_SOCK_PATH_DEFAULT"\")\n");
+ printf(" -c, --update-command command to call on data change\n");
printf(" -v, --version print the version\n");
printf(" -h, --help this help\n");
printf("\n");
@@ -153,6 +154,7 @@ static struct globals *alfred_init(int argc, char *argv[])
{"modeswitch", required_argument, NULL, 'M'},
{"change-interface", required_argument, NULL, 'I'},
{"unix-path", required_argument, NULL, 'u'},
+ {"update-command", required_argument, NULL, 'c'},
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, NULL, 'd'},
{NULL, 0, NULL, 0},
@@ -174,10 +176,13 @@ static struct globals *alfred_init(int argc, char *argv[])
globals->mesh_iface = "bat0";
globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
globals->verbose = 0;
+ globals->update_command = NULL;
+ INIT_LIST_HEAD(&globals->changed_data_types);
+ globals->changed_data_type_count = 0;
time_random_seed();
- while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:d", long_options,
+ while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:dc:", long_options,
&opt_ind)) != -1) {
switch (opt) {
case 'r':
@@ -237,6 +242,9 @@ static struct globals *alfred_init(int argc, char *argv[])
case 'd':
globals->verbose++;
break;
+ case 'c':
+ globals->update_command = optarg;
+ break;
case 'v':
printf("%s %s\n", argv[0], SOURCE_VERSION);
printf("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n");
@@ -250,6 +258,8 @@ static struct globals *alfred_init(int argc, char *argv[])
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
perror("could not register SIGPIPE handler");
+ if (signal(SIGCHLD, SIG_IGN) == SIG_ERR)
+ perror("could not register SIGCHLD handler");
return globals;
}
diff --git a/man/alfred.8 b/man/alfred.8
index a8050ab..e21bb55 100644
--- a/man/alfred.8
+++ b/man/alfred.8
@@ -114,6 +114,10 @@ still keeping redundancy (by having multiple masters). Obviously, at least one
master must be present in the network to let any data exchange happen. Also
having all nodes in master mode is possible (for maximum decentrality and
overhead).
+.TP
+\fB\-c\fP, \fB\-\-update-command\fP \fIcommand\fP
+Specify command to execute on data change. It will be called with data-type list
+as arguments.
.
.SH EXAMPLES
Start an alfred server listening on bridge br0 (assuming that this bridge
diff --git a/recv.c b/recv.c
index 02d96c9..59c69b4 100644
--- a/recv.c
+++ b/recv.c
@@ -22,6 +22,7 @@
#include <errno.h>
#include <net/ethernet.h>
#include <netinet/in.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -41,6 +42,7 @@ static int finish_alfred_push_data(struct globals *globals,
struct alfred_push_data_v0 *push)
{
int len, data_len;
+ bool new_entry_created;
struct alfred_data *data;
struct dataset *dataset;
uint8_t *pos;
@@ -57,6 +59,7 @@ static int finish_alfred_push_data(struct globals *globals,
if ((int)(data_len + sizeof(*data)) > len)
break;
+ new_entry_created = false;
dataset = hash_find(globals->data_hash, data);
if (!dataset) {
dataset = malloc(sizeof(*dataset));
@@ -71,6 +74,7 @@ static int finish_alfred_push_data(struct globals *globals,
free(dataset);
goto err;
}
+ new_entry_created = true;
}
/* don't overwrite our own data */
if (dataset->data_source == SOURCE_LOCAL)
@@ -78,6 +82,12 @@ static int finish_alfred_push_data(struct globals *globals,
clock_gettime(CLOCK_MONOTONIC, &dataset->last_seen);
+ /* check that data was changed */
+ if (new_entry_created ||
+ dataset->data.header.length != data_len ||
+ memcmp(dataset->buf, data->data, data_len) != 0)
+ changed_data_type(globals, data->header.type);
+
/* free old buffer */
if (dataset->buf) {
free(dataset->buf);
diff --git a/server.c b/server.c
index 83dfc9b..c9c77b9 100644
--- a/server.c
+++ b/server.c
@@ -23,6 +23,7 @@
#include <inttypes.h>
#include <net/ethernet.h>
#include <net/if.h>
+#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -136,6 +137,27 @@ int set_best_server(struct globals *globals)
return 0;
}
+void changed_data_type(struct globals *globals, uint8_t arg)
+{
+ struct changed_data_type *data_type = NULL;
+
+ if (!globals->update_command)
+ return;
+
+ list_for_each_entry(data_type, &globals->changed_data_types, list) {
+ if (data_type->data_type == arg)
+ return;
+ }
+
+ data_type = malloc(sizeof(*data_type));
+ if (!data_type)
+ return;
+
+ data_type->data_type = arg;
+ list_add(&data_type->list, &globals->changed_data_types);
+ globals->changed_data_type_count++;
+}
+
static int purge_data(struct globals *globals)
{
struct hash_it_t *hashit = NULL;
@@ -151,6 +173,8 @@ static int purge_data(struct globals *globals)
if (diff.tv_sec < ALFRED_DATA_TIMEOUT)
continue;
+ changed_data_type(globals, dataset->data.header.type);
+
hash_remove_bucket(globals->data_hash, hashit);
free(dataset->buf);
free(dataset);
@@ -259,6 +283,55 @@ static void check_if_sockets(struct globals *globals)
check_if_socket(interface);
}
+static void execute_update_command(struct globals *globals)
+{
+ pid_t script_pid;
+ size_t command_len;
+ char *command;
+ struct changed_data_type *data_type, *is;
+ /* data type is uint8_t, so 255 is maximum (3 chars)
+ * space for appending + terminating null byte
+ */
+ char buf[5];
+
+ if (!globals->update_command || !globals->changed_data_type_count)
+ return;
+
+ /* length of script + 4 bytes per data type (space +3 chars)
+ * + 1 for terminating null byte
+ */
+ command_len = strlen(globals->update_command);
+ command_len += 4 * globals->changed_data_type_count + 1;
+ command = malloc(command_len);
+ if (!command)
+ return;
+
+ strncpy(command, globals->update_command, command_len - 1);
+ command[command_len - 1] = '\0';
+
+ list_for_each_entry_safe(data_type, is, &globals->changed_data_types,
+ list) {
+ /* append the datatype to command line */
+ snprintf(buf, sizeof(buf), " %d", data_type->data_type);
+ strncat(command, buf, command_len - strlen(command) - 1);
+
+ /* clean the list */
+ list_del(&data_type->list);
+ free(data_type);
+ }
+ globals->changed_data_type_count = 0;
+
+ printf("executing: %s\n", command);
+
+ script_pid = fork();
+ if (script_pid == 0) {
+ system(command);
+ exit(0);
+ }
+
+ free(command);
+}
+
int alfred_server(struct globals *globals)
{
int maxsock, ret, recvs;
@@ -343,6 +416,7 @@ int alfred_server(struct globals *globals)
}
purge_data(globals);
check_if_sockets(globals);
+ execute_update_command(globals);
}
netsock_close_all(globals);
7 years, 10 months
[alfred] master: alfred: Remove manual \0 terminator after snprintf (f7914a8)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit f7914a86dbf72aa03ac89cba1490c9d6ff770c33
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Tue Mar 17 08:47:29 2015 +0100
alfred: Remove manual \0 terminator after snprintf
snprintf already guarantees \0 terminated strings for size arguments is > 0.
Reported-by: Anatoliy Lapitskiy <anatoliy.lapitskiy(a)gmail.com>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
f7914a86dbf72aa03ac89cba1490c9d6ff770c33
debugfs.c | 1 -
vis/vis.c | 3 ---
2 files changed, 4 deletions(-)
diff --git a/debugfs.c b/debugfs.c
index fbf992e..6404b49 100644
--- a/debugfs.c
+++ b/debugfs.c
@@ -58,7 +58,6 @@ int debugfs_make_path(const char *fmt, const char *mesh_iface, char *buffer,
return len+1;
snprintf(buffer, size-1, fmt, debugfs_mountpoint, mesh_iface);
- buffer[size - 1] = '\0';
return 0;
}
diff --git a/vis/vis.c b/vis/vis.c
index 4a14e66..c1f8dad 100644
--- a/vis/vis.c
+++ b/vis/vis.c
@@ -274,7 +274,6 @@ static int register_interfaces(struct globals *globals)
while ((iface_dir = readdir(iface_base_dir)) != NULL) {
snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, iface_dir->d_name);
- path_buff[PATH_BUFF_LEN - 1] = '\0';
file_content = read_file(path_buff);
if (!file_content)
continue;
@@ -292,7 +291,6 @@ static int register_interfaces(struct globals *globals)
file_content = NULL;
snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, iface_dir->d_name);
- path_buff[PATH_BUFF_LEN - 1] = '\0';
file_content = read_file(path_buff);
if (!file_content)
continue;
@@ -328,7 +326,6 @@ static int parse_orig_list(struct globals *globals)
struct vis_list_entry *v_entry;
snprintf(path, sizeof(path), "/sys/kernel/debug/batman_adv/%s/originators", globals->interface);
- path[sizeof(path) - 1] = 0;
fbuf = read_file(path);
if (!fbuf)
return -1;
7 years, 10 months
[linux-merge]linux integration; annotated tag, v4.0-rc4, created. v4.0-rc4
by postmaster@open-mesh.org
The annotated tag, v4.0-rc4 has been created
at 327b326bcb2d2426d3727ba473d89c30a55b0dbb (tag)
tagging 06e5801b8cb3fc057d88cb4dc03c0b64b2744cda (commit)
replaces v4.0-rc3
tagged by Linus Torvalds
on Sun Mar 15 17:38:31 2015 -0700
- Shortlog ------------------------------------------------------------
Linux 4.0-rc4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAABAgAGBQJVBiYHAAoJEHm+PkMAQRiGcuMH/0WiXQeyyCV+L6XEKTibgp7D
HHZW43dVIfU2GNnlRzFXzD8sUMJNyCplTL5TDedHBhoiiB6IEN8PYlZsbfYg+4S4
ll3vkZUgCAGQHnzpbZnWD9fGD01loUv5yhw9VEsMzEWyjSjJzaj0G5J57ei4pW0L
zZ256E+rcdHgWHzT3K6n3zSPxlTpjMNY3BTUmH5eF/5RPWYJOLeF8DkecswOV005
JX7qDIPbzfatjR7UpzIf5BRRwsPe242xbDWFQZFUUqqOnvRqA5jKJiwXQsxhNjFG
oug07QaH3qbwvR0mPJoYhC/FSCzrhpwYopbISCqHWRXYMktBZwL0UC+vE1M7AtM=
=WynX
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------
--
linux integration
7 years, 10 months
[alfred] master: alfred: Fix typo transfered -> transferred (29af430)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 29af43005b1ab99b1df5ec285ea07ec2937aff75
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sat Mar 14 12:42:54 2015 +0100
alfred: Fix typo transfered -> transferred
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
29af43005b1ab99b1df5ec285ea07ec2937aff75
packet.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packet.h b/packet.h
index ceb6c79..5ecdf39 100644
--- a/packet.h
+++ b/packet.h
@@ -165,7 +165,7 @@ struct alfred_change_interface_v0 {
*
* The sequence number has a special meaning. Failure status packets use
* it to store the error code. Success status packets store the number of
- * transfered packets in it.
+ * transferred packets in it.
*
* Sent as unicast to the node requesting the data
*/
7 years, 10 months
[alfred] master: alfred: Fix alignment of multi-line statements (a3ee3d8)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit a3ee3d8c8e492283197e78f12e878088d39272cd
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sat Mar 14 12:42:55 2015 +0100
alfred: Fix alignment of multi-line statements
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
a3ee3d8c8e492283197e78f12e878088d39272cd
hash.h | 2 +-
send.c | 2 +-
server.c | 2 +-
unix_sock.c | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hash.h b/hash.h
index ee01c0f..6e027bb 100644
--- a/hash.h
+++ b/hash.h
@@ -57,7 +57,7 @@ void hash_init(struct hashtable_t *hash);
/* allocates and clears the hash */
struct hashtable_t *hash_new(int size, hashdata_compare_cb compare,
- hashdata_choose_cb choose);
+ hashdata_choose_cb choose);
/* remove bucket (this might be used in hash_iterate() if you already found
* the bucket you want to delete and don't need the overhead to find it again
diff --git a/send.c b/send.c
index 3228d5c..cc55489 100644
--- a/send.c
+++ b/send.c
@@ -120,7 +120,7 @@ int push_data(struct globals *globals, struct interface *interface,
status_end.tx.seqno = htons(seqno);
send_alfred_packet(interface, destination, &status_end,
- sizeof(status_end));
+ sizeof(status_end));
}
return 0;
diff --git a/server.c b/server.c
index ab6f4ec..83dfc9b 100644
--- a/server.c
+++ b/server.c
@@ -72,7 +72,7 @@ static int tx_compare(void *d1, void *d2)
if (memcmp(&txh1->server_addr, &txh2->server_addr,
sizeof(txh1->server_addr)) == 0 &&
- txh1->id == txh2->id)
+ txh1->id == txh2->id)
return 1;
else
return 0;
diff --git a/unix_sock.c b/unix_sock.c
index a3affdc..2c862d5 100644
--- a/unix_sock.c
+++ b/unix_sock.c
@@ -389,7 +389,7 @@ int unix_sock_read(struct globals *globals)
case ALFRED_MODESWITCH:
ret = unix_sock_modesw(globals,
(struct alfred_modeswitch_v0 *)packet,
- client_sock);
+ client_sock);
break;
case ALFRED_CHANGE_INTERFACE:
ret = unix_sock_change_iface(globals,
7 years, 10 months
[alfred] master: alfred: Remove spaces before tabs (0ea3683)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 0ea3683b7da033622b66f4780b1bdc4dc193e5ad
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sat Mar 14 12:42:51 2015 +0100
alfred: Remove spaces before tabs
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
0ea3683b7da033622b66f4780b1bdc4dc193e5ad
main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
index e9821be..7ad4625 100644
--- a/main.c
+++ b/main.c
@@ -149,8 +149,8 @@ static struct globals *alfred_init(int argc, char *argv[])
{"interface", required_argument, NULL, 'i'},
{"master", no_argument, NULL, 'm'},
{"help", no_argument, NULL, 'h'},
- {"req-version", required_argument, NULL, 'V'},
- {"modeswitch", required_argument, NULL, 'M'},
+ {"req-version", required_argument, NULL, 'V'},
+ {"modeswitch", required_argument, NULL, 'M'},
{"change-interface", required_argument, NULL, 'I'},
{"unix-path", required_argument, NULL, 'u'},
{"version", no_argument, NULL, 'v'},
7 years, 10 months
[alfred] master: alfred: Reduce number of lines with more than 80 chars (2800c13)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 2800c130936a3dbbb748532048cd99ab72670408
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sat Mar 14 12:42:48 2015 +0100
alfred: Reduce number of lines with more than 80 chars
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
2800c130936a3dbbb748532048cd99ab72670408
batadv_query.h | 3 ++-
client.c | 4 +++-
hash.c | 13 +++++++------
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/batadv_query.h b/batadv_query.h
index 6b938ea..8991ee9 100644
--- a/batadv_query.h
+++ b/batadv_query.h
@@ -24,7 +24,8 @@
#include <stdint.h>
#include <netinet/in.h>
-struct ether_addr *translate_mac(const char *mesh_iface, struct ether_addr *mac);
+struct ether_addr *translate_mac(const char *mesh_iface,
+ struct ether_addr *mac);
uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac);
int batadv_interface_check(const char *mesh_iface);
int mac_to_ipv6(const struct ether_addr *mac, struct in6_addr *addr);
diff --git a/client.c b/client.c
index 42dd4ad..f68a5b0 100644
--- a/client.c
+++ b/client.c
@@ -265,11 +265,13 @@ int alfred_client_change_interface(struct globals *globals)
struct alfred_change_interface_v0 *change_interface;
int ret, len;
char *input, *token, *saveptr;
+ size_t interface_len;
if (unix_sock_open_client(globals))
return -1;
- if (strlen(globals->change_interface) > sizeof(change_interface->ifaces)) {
+ interface_len = strlen(globals->change_interface);
+ if (interface_len > sizeof(change_interface->ifaces)) {
fprintf(stderr, "%s: interface name list too long, not changing\n",
__func__);
return 0;
diff --git a/hash.c b/hash.c
index 685842f..a53bb9c 100644
--- a/hash.c
+++ b/hash.c
@@ -292,12 +292,13 @@ void *hash_remove(struct hashtable_t *hash, void *data)
while (hash_it_t.bucket != NULL) {
if (hash->compare(hash_it_t.bucket->data, data)) {
- int bucket_same;
- bucket_same = (hash_it_t.bucket ==
- hash->table[hash_it_t.index]);
- hash_it_t.first_bucket = (bucket_same ?
- &hash->table[hash_it_t.index] :
- NULL);
+ struct element_t **first_bucket = NULL;
+
+ if (hash_it_t.bucket == hash->table[hash_it_t.index])
+ first_bucket = &hash->table[hash_it_t.index];
+
+ hash_it_t.first_bucket = first_bucket;
+
return hash_remove_bucket(hash, &hash_it_t);
}
7 years, 10 months
[alfred] master: alfred: Simplify comparison of pointer with NULL (2323dde)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 2323dded1e082bebf7db1475297a00277968b58e
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Sat Mar 14 12:42:56 2015 +0100
alfred: Simplify comparison of pointer with NULL
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Signed-off-by: Simon Wunderlich <sw(a)simonwunderlich.de>
>---------------------------------------------------------------
2323dded1e082bebf7db1475297a00277968b58e
hash.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/hash.c b/hash.c
index 20034d6..13372fa 100644
--- a/hash.c
+++ b/hash.c
@@ -46,9 +46,9 @@ void hash_delete(struct hashtable_t *hash, hashdata_free_cb free_cb)
for (i = 0; i < hash->size; i++) {
bucket = hash->table[i];
- while (bucket != NULL) {
+ while (bucket) {
- if (free_cb != NULL)
+ if (free_cb)
free_cb(bucket->data);
last_bucket = bucket;
@@ -73,7 +73,7 @@ static int hash_add_bucket(struct hashtable_t *hash, void *data,
index = hash->choose(data, hash->size);
bucket_it = hash->table[index];
- while (bucket_it != NULL) {
+ while (bucket_it) {
if (check_duplicate &&
hash->compare(bucket_it->data, data))
return -1;
@@ -87,7 +87,7 @@ static int hash_add_bucket(struct hashtable_t *hash, void *data,
bucket->next = NULL;
/* and link it */
- if (prev_bucket == NULL)
+ if (!prev_bucket)
hash->table[index] = bucket;
else
prev_bucket->next = bucket;
@@ -117,7 +117,7 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
{
struct hash_it_t *iter;
- if (iter_in == NULL) {
+ if (!iter_in) {
iter = debugMalloc(sizeof(struct hash_it_t), 301);
iter->index = -1;
iter->bucket = NULL;
@@ -128,15 +128,15 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
/* sanity checks first (if our bucket got deleted in the last
* iteration): */
- if (iter->bucket != NULL) {
- if (iter->first_bucket != NULL) {
+ if (iter->bucket) {
+ if (iter->first_bucket) {
/* we're on the first element and it got removed after
* the last iteration. */
if ((*iter->first_bucket) != iter->bucket) {
/* there are still other elements in the list */
- if ((*iter->first_bucket) != NULL) {
+ if (*iter->first_bucket) {
iter->prev_bucket = NULL;
iter->bucket = (*iter->first_bucket);
iter->first_bucket = &hash->table[iter->index];
@@ -146,7 +146,7 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
iter->bucket = NULL;
}
- } else if (iter->prev_bucket != NULL) {
+ } else if (iter->prev_bucket) {
/* we're not on the first element, and the bucket got
* removed after the last iteration. The last bucket's
@@ -160,8 +160,8 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
}
/* now as we are sane, select the next one if there is some */
- if (iter->bucket != NULL) {
- if (iter->bucket->next != NULL) {
+ if (iter->bucket) {
+ if (iter->bucket->next) {
iter->prev_bucket = iter->bucket;
iter->bucket = iter->bucket->next;
iter->first_bucket = NULL;
@@ -175,7 +175,7 @@ struct hash_it_t *hash_iterate(struct hashtable_t *hash,
/* go through the entries of the hash table */
while (iter->index < hash->size) {
- if ((hash->table[iter->index]) == NULL) {
+ if (!hash->table[iter->index]) {
iter->index++;
continue;
}
@@ -244,7 +244,7 @@ void *hash_find(struct hashtable_t *hash, void *keydata)
index = hash->choose(keydata , hash->size);
bucket = hash->table[index];
- while (bucket != NULL) {
+ while (bucket) {
if (hash->compare(bucket->data, keydata))
return bucket->data;
@@ -265,9 +265,9 @@ void *hash_remove_bucket(struct hashtable_t *hash, struct hash_it_t *hash_it_t)
/* save the pointer to the data */
data_save = hash_it_t->bucket->data;
- if (hash_it_t->prev_bucket != NULL)
+ if (hash_it_t->prev_bucket)
hash_it_t->prev_bucket->next = hash_it_t->bucket->next;
- else if (hash_it_t->first_bucket != NULL)
+ else if (hash_it_t->first_bucket)
(*hash_it_t->first_bucket) = hash_it_t->bucket->next;
debugFree(hash_it_t->bucket, 1306);
@@ -288,7 +288,7 @@ void *hash_remove(struct hashtable_t *hash, void *data)
hash_it_t.bucket = hash->table[hash_it_t.index];
hash_it_t.prev_bucket = NULL;
- while (hash_it_t.bucket != NULL) {
+ while (hash_it_t.bucket) {
if (hash->compare(hash_it_t.bucket->data, data)) {
struct element_t **first_bucket = NULL;
7 years, 10 months