Skip to content

Commit

Permalink
Runtime initial
Browse files Browse the repository at this point in the history
  • Loading branch information
philberty committed May 27, 2014
1 parent a019c67 commit ab8b4cc
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
bin_PROGRAMS = test$(EXEEXT) log$(EXEEXT) watcher$(EXEEXT)
bin_PROGRAMS = \
proTest$(EXEEXT) \
logTest$(EXEEXT) \
wtail$(EXEEXT) \
watcher$(EXEEXT)
lib_LTLIBRARIES = libwatchy.la

pkgconfigdir = $(libdir)/pkgconfig
Expand All @@ -9,13 +13,17 @@ libwatchy_cindlude_HEADERS = watchy.h
libwatchy_la_LDFLAGS = -rpath '$(libdir)'
libwatchy_la_SOURCES = \
libwatchy.c \
runtime.c \
osdep-@[email protected]

watcher_SOURCES = watcher.c
watcher_LDADD = libwatchy.la

test_SOURCES = test.c
test_LDADD = libwatchy.la
wtail_SOURCES = wtail.c
wtail_LDADD = libwatchy.la

log_SOURCES = log.c
log_LDADD = libwatchy.la
proTest_SOURCES = test.c
proTest_LDADD = libwatchy.la

logTest_SOURCES = log.c
logTest_LDADD = libwatchy.la
29 changes: 29 additions & 0 deletions src/runtime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include "watchy.h"

static int pfd;
static bool init = false;

int watchy_writePacket (const struct watchy_data * data, const int fd)
{
return 0;
}

int watchy_cAttachRuntime (const char * fifo, const char * bind, const int port)
{
return;
}

void watchy_detachRuntime (void)
{
return;
}
3 changes: 3 additions & 0 deletions src/watchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
// get all the data no need to keep reading etc..
#define WTCY_PACKET_SIZE 256

// hardcoded /tmp
#define WTCY_DEFAULT_FIFO "/tmp/watchy.fifo"

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
49 changes: 49 additions & 0 deletions src/wtail.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>

int main (int argc char **argv)
{
FILE *ps_pipe;
FILE *grep_pipe;

int bytes_read;
int nbytes = 100;
char *my_string;

/* Open our two pipes */
ps_pipe = popen ("ps -A", "r");
grep_pipe = popen ("grep init", "w");

/* Check that pipes are non-null, therefore open */
if ((!ps_pipe) || (!grep_pipe))
{
fprintf (stderr,
"One or both pipes failed.\n");
return EXIT_FAILURE;
}

/* Read from ps_pipe until two newlines */
my_string = (char *) malloc (nbytes + 1);
bytes_read = getdelim (&my_string, &nbytes, "\n\n", ps_pipe);

/* Close ps_pipe, checking for errors */
if (pclose (ps_pipe) != 0)
{
fprintf (stderr,
"Could not run 'ps', or other error.\n");
}

/* Send output of 'ps -A' to 'grep init', with two newlines */
fprintf (grep_pipe, "%s\n\n", my_string);

/* Close grep_pipe, cehcking for errors */
if (pclose (grep_pipe) != 0)
{
fprintf (stderr,
"Could not run 'grep', or other error.\n");
}

/* Exit! */
return 0;
}

0 comments on commit ab8b4cc

Please sign in to comment.