382ef3783807560ba60f93c13be24471090ec7d6
Stefan Schuermans add copyright headers and l...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c   1) /**
libuptpl/src/write.c   2)  * UProcTrace: User-space Process Tracing
libuptpl/src/write.c   3)  * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
libuptpl/src/write.c   4)  * Copyleft: GNU LESSER GENERAL PUBLIC LICENSE version 3 (see LICENSE)
libuptpl/src/write.c   5)  */
libuptpl/src/write.c   6) 
Stefan Schuermans first incomplete begin_proc...

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c  7) #include "write.h"
liblwptpl/src/write.c  8) 
Stefan Schuermans implement proc_end event

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c  9) #include <fcntl.h>
Stefan Schuermans add header to events to sep...

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 10) #include <stdint.h>
Stefan Schuermans first incomplete begin_proc...

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 11) #include <stdlib.h>
Stefan Schuermans implement proc_end event

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 12) #include <string.h>
liblwptpl/src/write.c 13) #include <sys/file.h>
liblwptpl/src/write.c 14) #include <unistd.h>
Stefan Schuermans first incomplete begin_proc...

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 15) 
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  16) struct uptpl_event_header_s {
libuptpl/src/write.c  17)   uint8_t magic[4]; /**< u p t 0 */
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  18)   uint8_t size[4];  /**< size of payload in network byte oder */
Stefan Schuermans add header to events to sep...

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 19) } __attribute__((packed));
liblwptpl/src/write.c 20) 
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  21) void uptpl_write(void const *data, size_t size) {
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  22)   if (!data || !size || size > 0xFFFFFFFF) {
Stefan Schuermans implement proc_end event

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 23)     return;
liblwptpl/src/write.c 24)   }
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  25)   char const *filename = getenv("UPTPL_OUTPUT");
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  26)   if (!filename) {
Stefan Schuermans implement proc_end event

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 27)     return;
liblwptpl/src/write.c 28)   }
liblwptpl/src/write.c 29)   int fd = open(filename, O_WRONLY | O_APPEND);
liblwptpl/src/write.c 30)   if (fd == -1) {
liblwptpl/src/write.c 31)     return;
liblwptpl/src/write.c 32)   }
liblwptpl/src/write.c 33)   if (flock(fd, LOCK_EX) == -1) {
liblwptpl/src/write.c 34)     close(fd);
liblwptpl/src/write.c 35)     return;
liblwptpl/src/write.c 36)   }
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  37)   struct uptpl_event_header_s uptpl_event_header = {
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  38)       .magic = {'u', 'p', 't', '0'},
libuptpl/src/write.c  39)       .size = {
libuptpl/src/write.c  40)           (size >> 24) & 0xFF,
libuptpl/src/write.c  41)           (size >> 16) & 0xFF,
libuptpl/src/write.c  42)           (size >> 8) & 0xFF,
libuptpl/src/write.c  43)           size & 0xFF,
libuptpl/src/write.c  44)       }};
Stefan Schuermans hide ignoring return value...

Stefan Schuermans authored 4 years ago

libuptpl/src/write.c  45)   ssize_t written = write(fd, &uptpl_event_header, sizeof(uptpl_event_header));
libuptpl/src/write.c  46)   written += write(fd, data, size);
libuptpl/src/write.c  47)   (void)written; /* if writing failed, nobody there to receive the error */
Stefan Schuermans implement proc_end event

Stefan Schuermans authored 4 years ago

liblwptpl/src/write.c 48)   flock(fd, LOCK_UN);
liblwptpl/src/write.c 49)   close(fd);