-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker.c
More file actions
84 lines (68 loc) · 2.35 KB
/
worker.c
File metadata and controls
84 lines (68 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/***
* blksync - synchronize chunks of data between files and/or block devices
*
* Copyright (C) 2011 Damien Churchill <damoxc@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <assert.h>
#include <errno.h>
#include <mqueue.h>
#include <stdio.h>
#include <stdlib.h>
#include "action.h"
#include "chunk.h"
#include "common.h"
#include "worker.h"
/**
* Hashing worker thread
*/
void *bs_hash_chunk(void *arg) {
Chunk chunk;
ssize_t msg_size;
params *p = (params *)arg;
Action action;
unsigned char hash[p->hash_length];
printf("Thread-%d starting life\n", p->id);
action = malloc(sizeof(struct bs_action_t));
while (1) {
// Don't sit in a while loop if we can't get message, die!
msg_size = mq_receive(p->r_queue, (char *)action, MSG_SIZE, NULL);
//printf("receiver msg_size: %ld\n", msg_size);
if (msg_size == -1 || action->type == END_THREAD) {
if (msg_size == -1)
perror("Unable to read from read-queue");
break;
}
chunk = (Chunk)action->data;
//printf("receiver chunk-%d: %p\n", chunk->number, chunk);
assert(chunk != NULL);
assert(chunk->data != NULL);
assert(p != NULL);
bs_sha1(hash, chunk->data, p->hash_length);
bs_print_hash((unsigned char *)chunk->hash, p->hash_length);
printf("\n");
bs_print_hash((unsigned char *)hash, p->hash_length);
printf("\n");
bs_destroy_chunk(chunk);
//printf("new_hash: %s\n", chunk->hash);
//if (memcmp(chunk->hash, new_hash, SHA1_LENGTH) != 0) {
// TODO: trigger write back to backup file
//}
}
free(action);
printf("Thread-%d ending life\n", p->id);
return NULL;
}