aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraxtloss <axtlos@getcryst.al>2024-07-08 12:54:00 +0200
committeraxtloss <axtlos@getcryst.al>2024-07-08 12:54:00 +0200
commita3377b0606c708efdc5656532676038c28a5c444 (patch)
tree8595e4a6d2c56d60ade81a92baf95f6ce668fe04 /src
downloadrunc-a3377b0606c708efdc5656532676038c28a5c444.tar.gz
runc-a3377b0606c708efdc5656532676038c28a5c444.tar.bz2
initial commit
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/config.c71
-rw-r--r--src/config.h7
-rw-r--r--src/main.c37
4 files changed, 118 insertions, 0 deletions
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;
+}