Without that, functions like ipc_nv_data_md5_calculate won't
print anything as the ipc_client logging requires a valid
ipc_client.

Signed-off-by: Denis 'GNUtoo' Carikli <[email protected]>
---
 tools/nv_data-md5.c | 47 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/tools/nv_data-md5.c b/tools/nv_data-md5.c
index d998296..dde94a2 100644
--- a/tools/nv_data-md5.c
+++ b/tools/nv_data-md5.c
@@ -22,19 +22,47 @@
 #include <sys/types.h>
 
 #include <samsung-ipc.h>
+#include <string.h>
 
 void usage_print(void)
 {
     printf("Usage: nv_data-md5 [nv_data.bin]\n");
 }
 
+void log_callback(__attribute__((unused)) void *data,
+                 const char *message)
+{
+    char *buffer;
+    size_t length;
+    int i;
+
+    if (message == NULL)
+        return;
+
+    buffer = strdup(message);
+    length = strlen(message);
+
+    for (i = length; i > 0; i--) {
+        if (buffer[i] == '\n')
+            buffer[i] = '\0';
+        else if (buffer[i] != '\0')
+            break;
+    }
+
+    printf("[ipc] %s\n", buffer);
+
+    free(buffer);
+}
+
 int main(int argc, char *argv[])
 {
+    struct ipc_client *client = NULL;
     char *secret = NV_DATA_SECRET;
     size_t size = NV_DATA_SIZE;
     size_t chunk_size = NV_DATA_CHUNK_SIZE;
     char *md5_string = NULL;
     char *path;
+    int rc = 0;
 
     if (argc < 2) {
         usage_print();
@@ -43,8 +71,19 @@ int main(int argc, char *argv[])
 
     path = argv[1];
 
-    md5_string = ipc_nv_data_md5_calculate(NULL, path, secret, size,
-                                           chunk_size);
+    client = ipc_client_create(IPC_CLIENT_TYPE_DUMMY);
+    if (client == NULL) {
+        printf("Creating client failed\n");
+        goto error;
+    }
+
+    rc = ipc_client_log_callback_register(client, log_callback, NULL);
+    if (rc < 0) {
+        printf("Registering log callback failed: error %d\n", rc);
+        goto error;
+    }
+
+    md5_string = ipc_nv_data_md5_calculate(client, path, secret, size, 
chunk_size);
     if (md5_string == NULL) {
         fprintf(stderr, "Calculating nv_data backup md5 failed\n");
         return 1;
@@ -55,6 +94,10 @@ int main(int argc, char *argv[])
     free(md5_string);
 
     return 0;
+
+error:
+    if (client != NULL)
+        ipc_client_destroy(client);
 }
 
 // vim:ts=4:sw=4:expandtab
-- 
2.24.1

_______________________________________________
Replicant mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/replicant

Reply via email to