summaryrefslogtreecommitdiff
path: root/schulung_tools/ipc_shm/send.c
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2017-12-19 10:59:40 +0100
committerJohn Ogness <john.ogness@linutronix.de>2017-12-19 10:59:40 +0100
commit270520b4a2eac8725c8575c3180964289722e191 (patch)
treed9512cd96d0c52e14293c3f8bc19fd168ee14025 /schulung_tools/ipc_shm/send.c
parent27209bb802048f4803d9cd9a5c2f99d613986446 (diff)
schulung_tools: add various demos and tools
Different tools have been used by various trainers as demos. Put all these into master so they are available to all trainers. ipc_pipe: ipc demo using pipes ipc_shm: ipc demo using shared memory libduma: source and instructions for compiling libduma matrix: demo of good and bad cache access mtrace: patch and infos for using mtrace with ASLR rtex: demo of handling page faults Signed-off-by: John Ogness <john.ogness@linutronix.de>
Diffstat (limited to 'schulung_tools/ipc_shm/send.c')
-rw-r--r--schulung_tools/ipc_shm/send.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/schulung_tools/ipc_shm/send.c b/schulung_tools/ipc_shm/send.c
new file mode 100644
index 0000000..028610f
--- /dev/null
+++ b/schulung_tools/ipc_shm/send.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include "shm.h"
+
+int main(void)
+{
+ struct share_data *data;
+ int rv;
+
+ data = get_share();
+ if (!data)
+ return 1;
+
+ rv = pthread_mutex_lock(&data->m);
+ if (rv != 0) {
+ if (rv == EOWNERDEAD) {
+ printf("send (%d): recover mutex\n", getpid());
+ data->msg[0] = 0;
+ pthread_mutex_consistent(&data->m);
+ } else {
+ /* maybe rv == ENOTRECOVERABLE */
+ return 1;
+ }
+ }
+
+ printf("send (%d): type message and hit RETURN to send signal\n",
+ getpid());
+ fgets(data->msg, sizeof(data->msg), stdin);
+
+ /* set "sending" uprobe here */
+
+ pthread_cond_signal(&data->c);
+ pthread_mutex_unlock(&data->m);
+
+ sleep(1);
+
+ return 0;
+}