From a3377b0606c708efdc5656532676038c28a5c444 Mon Sep 17 00:00:00 2001 From: axtloss Date: Mon, 8 Jul 2024 12:54:00 +0200 Subject: initial commit --- src/Makefile.am | 3 +++ src/config.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/config.h | 7 ++++++ src/main.c | 37 ++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 src/Makefile.am create mode 100644 src/config.c create mode 100644 src/config.h create mode 100644 src/main.c (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..b9e91a4 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,3 @@ +bin_PROGRAMS = runc +runc_SOURCES = main.c config.c +AM_LDFLAGS = -L /usr/lib -lextlib diff --git a/src/config.c b/src/config.c new file mode 100644 index 0000000..b456c50 --- /dev/null +++ b/src/config.c @@ -0,0 +1,71 @@ +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include "config.h" + +struct compile_cmd_t **ccmds; +int ccmds_size = 0; +int parse_config(const char *fpath, const struct stat *sb, + int typeflag, struct FTW *ftwbuf) +{ + if (!S_ISREG (sb->st_mode)) + return 0; + + struct compile_cmd_t *ccmd = malloc (sizeof (struct compile_cmd_t)); + struct compile_cmd_t **ccmds_tmp = realloc (ccmds, sizeof (ccmds)+sizeof (struct compile_cmd_t)); + if (ccmds_tmp) + ccmds = ccmds_tmp; + + FILE *cfg = fopen (fpath, "r"); + + int filled = 0; + while (filled == 0) { + char *line = strdup (""); + int tmp_char; + while ((tmp_char = fgetc (cfg))) { + char *line_tmp = realloc (line, strlen (line) + 8); + if (line_tmp) line = line_tmp; + sprintf (line, "%s%c", line, tmp_char); + if (tmp_char == '\n' || tmp_char == '\0') + break; + } + printf ("%s", line); + free (line); + } + fclose (cfg); + ccmds_tmp[ccmds_size] = ccmd; + ccmds_size += 1; + return 0; +} + +void get_commands() { + // struct compile_cmd_t **ccmds; + ccmds = malloc (sizeof (struct compile_cmd_t)); + char *home = getenv ("HOME"); + if (!home) { + puts ("warn: HOME not found. Unable to read home configuration files."); + } + char **paths = malloc (sizeof (char*)*4); + paths[0] = strdup ("/etc/runc.d"); + paths[1] = strdup ("/usr/share/runc"); + if (home) { + paths[2] = malloc (strlen (home)+strlen ("/.local/share/runc")+1); + sprintf (paths[2], "%s/.local/share/runc", home); + } + for (int i = 0; i < 3; i++) { + if (!paths[i]) break; + int err = nftw (paths[i], parse_config, 10, FTW_DEPTH|FTW_MOUNT|FTW_PHYS); + free (paths[i]); + } + free (paths); + + for (int i = 0; i < ccmds_size; i++) { + puts (ccmds[i]->cmd); + free (ccmds[i]->cmd); + free (ccmds[i]); + } + free (ccmds); +} diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..f27b17f --- /dev/null +++ b/src/config.h @@ -0,0 +1,7 @@ +struct compile_cmd_t { + char *cmd; + char *args; + char *fileext; +}; + +void get_commands(); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..d714ebe --- /dev/null +++ b/src/main.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#define _XOPEN_SOURCE 500 +#include +#include "config.h" + +int main (int argc, char *argv[]) { + char *compiler = "gcc"; + char *tmplate = strdup ("/tmp/XXXXXX"); + if (!tmplate) + exit (1); + char *tmpdir = mkdtemp(tmplate); + if (!tmpdir) + exit (1); + char *cmd = malloc (strlen (compiler)+strlen(argv[argc-1])+strlen (" -o ")+strlen (tmpdir)+strlen ("/meow")+1); + char *excmd = malloc (strlen (tmplate)+strlen ("/meow")+1); + if (!cmd) + exit (1); + if (!excmd) + exit (1); + puts (tmpdir); + sprintf (cmd, "%s %s -o %s/meow", compiler, argv[argc-1], tmpdir); + system (cmd); + sprintf (excmd, "%s/meow", tmpdir); + system (excmd); + int rtrn = rrmdir (tmpdir); + if (rtrn != 0) + printf ("%d %d\n", rtrn, errno); + get_commands(); + free (tmpdir); + free (cmd); + free (excmd); + return 0; +} -- cgit v1.2.3