diff options
author | axtloss <axtlos@getcryst.al> | 2024-07-08 12:54:00 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2024-07-08 12:54:00 +0200 |
commit | a3377b0606c708efdc5656532676038c28a5c444 (patch) | |
tree | 8595e4a6d2c56d60ade81a92baf95f6ce668fe04 | |
download | runc-a3377b0606c708efdc5656532676038c28a5c444.tar.gz runc-a3377b0606c708efdc5656532676038c28a5c444.tar.bz2 |
initial commit
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/config.c | 71 | ||||
-rw-r--r-- | src/config.h | 7 | ||||
-rw-r--r-- | src/main.c | 37 |
6 files changed, 134 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af437a6 --- /dev/null +++ b/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = src diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..22a9db9 --- /dev/null +++ b/configure.ac @@ -0,0 +1,15 @@ +AC_INIT([runc], [1.0], [axtlos@disroot.org]) +AM_INIT_AUTOMAKE([-Wall -Werror foreign]) +AC_PROG_CC +AC_CHECK_HEADERS([ + extlib.h +]) +AC_FUNC_MALLOC +AC_FUNC_REALLOC +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T +AC_CONFIG_FILES([ + Makefile + src/Makefile +]) +AC_OUTPUT
\ No newline at end of file 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 <stdlib.h> +#include <extlib.h> +#include <ftw.h> +#include <stdio.h> +#include <string.h> +#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 <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#define _XOPEN_SOURCE 500 +#include <extlib.h> +#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; +} |