aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/BIN48
-rw-r--r--misc/ETC18
-rw-r--r--misc/HOME25
-rw-r--r--misc/MAN19
-rw-r--r--misc/child_block.c9
-rw-r--r--misc/dup2_inout.c13
-rw-r--r--misc/fmt_argv.c10
-rw-r--r--misc/initreq.c31
-rw-r--r--misc/opendevconsole.c12
-rw-r--r--misc/set_sigaction.c10
-rw-r--r--misc/sulogin.c9
-rw-r--r--misc/system_child_block.c9
-rw-r--r--misc/system_set_sigaction.c42
-rw-r--r--misc/try_helper.h29
-rw-r--r--misc/try_int.h25
-rw-r--r--misc/trypagesize.c5
-rw-r--r--misc/tryprocess.c132
-rw-r--r--misc/tryulong32.c6
18 files changed, 432 insertions, 0 deletions
diff --git a/misc/BIN b/misc/BIN
new file mode 100644
index 0000000..6abcaf0
--- /dev/null
+++ b/misc/BIN
@@ -0,0 +1,48 @@
+v:1:::::
+d:::755:::
+d:::755:/etc::
+d:::755:/etc/ninit::
+
+# d:::755:/etc/ninit/bin::
+# g:::755:/etc/ninit/bin/::
+# x:::::argv0::
+# x:::::env::
+# x:::::conditional-init::
+# x:::::sleeprun::
+# x:::::install-bin::
+# x:::::serdo::
+# x:::::ninit-huge::
+# x:::::ninit-mmap::
+# x:::::ninit-conf:scripts/conf:
+# x:::::ninit-scan:scripts/scan:
+
+g:::600:/etc/ninit/::
+x:::644::.sync:Version:
+x:::644::.nsvc_help:nsvc_help:
+p:::::in:
+p:::::out:
+
+d:::755:/bin::
+x:::755:/bin/:nsvc::
+
+d:::755:/sbin::
+g:::755:/sbin/::
+x:::::ninit-reload:reload:
+x:::::ninit-reboot:reboot:
+x:::::ninit-pidfile:pidfile:
+x:::::ninit-sysvinit:sysvinit:
+x:::::ninit-runlevel:runlevel:
+x:::::bootlog::
+x:::::pututmpid::
+x:::::nkillall::
+x:::::ninit-shutdown:shutdown:
+c:::::ninit-inittab:inittab:
+c:::::ninit-service:scripts/service:
+
+d:::755:/etc/ninit/sys::
+g:::755:/etc/ninit/sys/::
+x:::::run::
+x:::::run-wait:wait:
+x:::::update::
+x:::::remove::
+x:::::procfs::
diff --git a/misc/ETC b/misc/ETC
new file mode 100644
index 0000000..aa55bef
--- /dev/null
+++ b/misc/ETC
@@ -0,0 +1,18 @@
+d:::755:/etc::
+d:::755:/etc/ninit::
+
+g:::600:/etc/ninit/::
+x:::644::.sync:Version:
+x:::644::.nsvc_help:nsvc_help:
+
+v:1:::::
+p:::::in:
+p:::::out:
+
+d:::755:/etc/ninit/sys::
+g:::755:/etc/ninit/sys/::
+x:::::run::
+x:::::run-wait:wait:
+x:::::update::
+x:::::remove::
+x:::::procfs::
diff --git a/misc/HOME b/misc/HOME
new file mode 100644
index 0000000..91b9944
--- /dev/null
+++ b/misc/HOME
@@ -0,0 +1,25 @@
+v:1:::::
+d:::755:::
+
+g:::755:::
+d::::/sys::
+d::::/default::
+d::::/env::
+d::::/sleep::
+d::::/sh::
+d::::/S::
+
+g:::600:/::
+x:::644::.sync:Version:
+x:::644::.nsvc_help:nsvc_help:
+p:::::in:
+p:::::out:
+
+c:::755:/env/:env::
+
+g:::755:/sys/::
+x:::::run::
+c:::::run-wait:wait:
+c:::::update::
+c:::::remove::
+c:::::procfs::
diff --git a/misc/MAN b/misc/MAN
new file mode 100644
index 0000000..f91815d
--- /dev/null
+++ b/misc/MAN
@@ -0,0 +1,19 @@
+v:1:::::
+d:::755:::
+d:::755:/man8::
+
+g:::644:/man8/::
+x:::::ninit.8.gz::
+x:::::nsvc.8.gz::
+x:::::ninit-scan.8.gz:scan.8.gz:
+x:::::bootlog.8.gz::
+x:::::nkillall.8.gz::
+x:::::pututmpid.8.gz::
+x:::::ninit-shutdown.8.gz:shutdown.8.gz:
+x:::::ninit-runlevel.8.gz:runlevel.8.gz:
+x:::::ninit-sysvinit.8.gz:sysvinit.8.gz:
+x:::::ninit-pidfile.8.gz:pidfile.8.gz:
+x:::::ninit-inittab.8.gz:inittab.8.gz:
+x:::::ninit-service.8.gz:service.8.gz:
+x:::::ninit-reload.8.gz:reload.8.gz:
+x:::::ninit-reboot.8.gz:reboot.8.gz:
diff --git a/misc/child_block.c b/misc/child_block.c
new file mode 100644
index 0000000..284fb73
--- /dev/null
+++ b/misc/child_block.c
@@ -0,0 +1,9 @@
+#include <sys/types.h>
+#include <signal.h>
+
+void child_block(int type) /*EXTRACT_INCL*/{ /* SIG_BLOCK, SIG_UNBLOCK */
+ sigset_t mask;
+ sigemptyset(&mask);
+ sigaddset(&mask, SIGCHLD);
+ sigprocmask(type, &mask, 0);
+}
diff --git a/misc/dup2_inout.c b/misc/dup2_inout.c
new file mode 100644
index 0000000..13132d8
--- /dev/null
+++ b/misc/dup2_inout.c
@@ -0,0 +1,13 @@
+#include <unistd.h>
+#include <fcntl.h>
+
+void dup2_inout(char *file, int from, mode_t mode) /*EXTRACT_INCL*/ {
+ int to = open(file, mode);
+ if (to == from || to == -1) return;
+ while (1) {
+ dup2(to,from);
+ fcntl(from,F_SETFD,0);
+ if (from++ != 1) break;
+ }
+ close(to);
+}
diff --git a/misc/fmt_argv.c b/misc/fmt_argv.c
new file mode 100644
index 0000000..a61f8db
--- /dev/null
+++ b/misc/fmt_argv.c
@@ -0,0 +1,10 @@
+#include "../ninitfeatures.h"
+
+int fmt_argv(int fd, char **argv, const char *sep) /*EXTRACT_INCL*/ {
+ int len=0;
+ for (; argv[len]; len++) {
+ errmsg_puts(fd, argv[len]);
+ errmsg_puts(fd, (char *)sep);
+ }
+ return len;
+}
diff --git a/misc/initreq.c b/misc/initreq.c
new file mode 100644
index 0000000..c0160f0
--- /dev/null
+++ b/misc/initreq.c
@@ -0,0 +1,31 @@
+
+#include <stdio.h>
+#include <unistd.h>
+#include "../initreq.h"
+
+int main() {
+ struct init_request req;
+ while (1) {
+ if (read(0, &req, sizeof(req)) != (int)sizeof(req)) return 1;
+
+ printf("magic:\t%x\n" "cmd:\t%d\n" "runlevel:\t%d=%c\n"
+ "sleeptime:\t%d\n"
+ "reserved:\t%s\n"
+ "exec_name:\t%s\n"
+ "host:\t%s\n"
+ "term_type:\t%s\n"
+ "tty_id:\t%s\n"
+ "gen_id:\t%s\n"
+ "\n",
+ req.magic, req.cmd, req.runlevel, req.runlevel,
+ req.sleeptime,
+ req.i.bsd.reserved,
+ req.i.bsd.exec_name,
+ req.i.bsd.host,
+ req.i.bsd.term_type,
+ req.i.bsd.tty_id,
+ req.i.bsd.gen_id
+ );
+ }
+ return 0;
+}
diff --git a/misc/opendevconsole.c b/misc/opendevconsole.c
new file mode 100644
index 0000000..3f92223
--- /dev/null
+++ b/misc/opendevconsole.c
@@ -0,0 +1,12 @@
+#include <fcntl.h>
+#include <unistd.h>
+
+void opendevconsole() /*EXTRACT_INCL*/ {
+ int fd;
+ if ((fd=open("/dev/console",O_RDWR|O_NOCTTY))>=0) {
+ dup2(fd,0);
+ dup2(fd,1);
+ dup2(fd,2);
+ if (fd>2) close(fd);
+ }
+}
diff --git a/misc/set_sigaction.c b/misc/set_sigaction.c
new file mode 100644
index 0000000..2b429a6
--- /dev/null
+++ b/misc/set_sigaction.c
@@ -0,0 +1,10 @@
+#include <signal.h>
+extern void sighandler(int sig);
+
+void set_sigaction(int sig) /*EXTRACT_INCL*/{
+ struct sigaction sa;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_handler=sighandler;
+ sa.sa_flags=SA_RESTART | SA_NOCLDSTOP;
+ sigaction(sig, &sa, 0);
+}
diff --git a/misc/sulogin.c b/misc/sulogin.c
new file mode 100644
index 0000000..6f0aa26
--- /dev/null
+++ b/misc/sulogin.c
@@ -0,0 +1,9 @@
+#include <unistd.h>
+#include <stdlib.h>
+extern char **environ;
+
+void sulogin() /*EXTRACT_INCL*/ {
+ char *argv[2] = {"sulogin",0};
+ execve("/sbin/sulogin",argv,environ);
+ _exit(1);
+}
diff --git a/misc/system_child_block.c b/misc/system_child_block.c
new file mode 100644
index 0000000..7032f71
--- /dev/null
+++ b/misc/system_child_block.c
@@ -0,0 +1,9 @@
+#define SIGACTION_FUNCTIONS
+#include "../process_defs.h"
+extern int rt_sigprocmask();
+
+void system_child_block(int type) /*EXTRACT_INCL*/ {
+ /* SIG_BLOCK, SIG_UNBLOCK */
+ STATIC_SIGCHLD_MASK;
+ rt_sigprocmask(type,&sigchld_mask,0,sizeof(sigchld_mask));
+}
diff --git a/misc/system_set_sigaction.c b/misc/system_set_sigaction.c
new file mode 100644
index 0000000..04515c4
--- /dev/null
+++ b/misc/system_set_sigaction.c
@@ -0,0 +1,42 @@
+#define SIGACTION_FUNCTIONS
+#include "../process_defs.h"
+
+typedef void (*sighandler_t)(int);
+typedef struct { unsigned long sig[SIGSET_MASK_LEN_N]; } sigset_t;
+
+/* copy/paste from dietlibc! Felix, you are great! */
+struct sigaction {
+#if defined(__alpha__) || defined(__ia64__) || defined(__hppa__)
+ sighandler_t sa_handler;
+ unsigned long sa_flags;
+ sigset_t sa_mask;
+#elif defined(__mips__)
+ unsigned long sa_flags;
+ sighandler_t sa_handler;
+ sigset_t sa_mask;
+ void (*sa_restorer)(void);
+ int32_t sa_resv[1];
+#else /* arm, i386, ppc, s390, sparc, saprc64, x86_64 */
+ sighandler_t sa_handler;
+ unsigned long sa_flags;
+ void (*sa_restorer)(void);
+ sigset_t sa_mask;
+#endif
+};
+
+extern void sighandler(int sig);
+extern void __restore();
+extern void __restore_rt();
+extern int rt_sigaction();
+#include "../byte_defs.h"
+
+void system_set_sigaction(int sig) /*EXTRACT_INCL*/ {
+ struct sigaction sa;
+ byte_zero(&sa, sizeof(sa));
+ sa.sa_handler=sighandler;
+ sa.sa_flags=SA_FLAGS_number;
+#ifndef INIT_SKIP_SIGRETURN
+ sa.sa_restorer=&(SA_RESTORER_function);
+#endif
+ rt_sigaction(sig, &sa, 0, sizeof(sigset_t));
+}
diff --git a/misc/try_helper.h b/misc/try_helper.h
new file mode 100644
index 0000000..bdc7319
--- /dev/null
+++ b/misc/try_helper.h
@@ -0,0 +1,29 @@
+unsigned int s_len(const char * s) {
+ unsigned int len=0;
+ while (s[len]) ++len;
+ return len;
+}
+
+char *fmt_ul(unsigned long u) {
+ static char strnum[48];
+ char *hex = "0123456789abcdef";
+ char *s = strnum+44;
+ *s = 0;
+ do { *--s = hex[(u % 16)]; u /= 16; } while(u); /* handles u==0 */
+ *--s = 'x';
+ *--s = '0';
+ return s;
+}
+
+char *fmt_o(unsigned char c) {
+ static char x[8];
+ x[4] = 0;
+ x[3] = '0' + (c & 7); c >>= 3;
+ x[2] = '0' + (c & 7); c >>= 3;
+ x[1] = '0' + (c & 7);
+ x[0] = '\\';
+ return x;
+}
+
+void w(char *s) { write(1,s,s_len(s)); }
+void wn(unsigned long u) { w(fmt_ul(u)); }
diff --git a/misc/try_int.h2 b/misc/try_int.h2
new file mode 100644
index 0000000..c010eaf
--- /dev/null
+++ b/misc/try_int.h2
@@ -0,0 +1,5 @@
+#ifndef INT_DEFS_H
+#define INT_DEFS_H
+typedef unsigned Z uint32t;
+typedef Z int32t;
+#endif
diff --git a/misc/trypagesize.c b/misc/trypagesize.c
new file mode 100644
index 0000000..33c7cbb
--- /dev/null
+++ b/misc/trypagesize.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+int main() {
+ if (getpagesize() == 4096) return 0;
+ return 1;
+}
diff --git a/misc/tryprocess.c b/misc/tryprocess.c
new file mode 100644
index 0000000..821e670
--- /dev/null
+++ b/misc/tryprocess.c
@@ -0,0 +1,132 @@
+#include "../ninitfeatures.h"
+#include <unistd.h>
+#include <signal.h>
+#include "try_helper.h"
+
+#define ioctl libc_ioctl
+#include <termios.h>
+#undef ioctl
+#include <sys/ioctl.h>
+
+#define w_sn_(a,b) w(a); wn(b); w("\n")
+#define w_sp_(a,b,c) w(a); wn((void *)(&b) - (void *)(&c)); w("\n")
+#define w_sns(a,b,c) w(a); wn(b); w(c)
+#define w_ss_(a,b) w(a); w(b); w("\n")
+#define w_o(X) w(fmt_o((unsigned char)X))
+#define w_to(t,X) w(t); w_o(X)
+
+#include "../struct_root.h"
+INIT_ROOT_DEFINE(ch, char*);
+INIT_ROOT_DEFINE(ui, unsigned int);
+
+#define UL sizeof(unsigned long)
+#define MASK_LEN (_NSIG/(8 * UL))
+#define WORD(X) ((X-1)/(8*UL))
+#define MASK(X) (((unsigned long)1) << (X-1) % (8*UL))
+
+int main() {
+ int i,k;
+ struct sigaction sa;
+ unsigned long uu[256];
+ char *ss[4] = { "kbreq", "ctrlaltdel", "powerS", "levelU" };
+
+ w("#define NINIT_SERVICES_CODED\t\"");
+ for (k=4, i=0; i<4; i++) {
+ w_o(k);
+ k += 1 + s_len(ss[i]);
+ }
+ for (i=0; i<4; i++) {
+ w(ss[i]);
+ if (i<3) w("\\000");
+ }
+ w("\"\n");
+
+ if (SIGWINCH < 256 && SIGINT < 256 && SIGPWR < 256 && SIGHUP < 256) {
+ w("#define NINIT_SIGNAL_HANDLER_CODED\t\"");
+ w_o(SIGWINCH); w_o(SIGINT); w_o(SIGPWR); w_o(SIGHUP);
+ w("\"\n");
+ }
+
+ if (SIGTERM < 256 && SIGALRM < 256 && SIGSTOP < 256 &&
+ SIGCONT < 256 && SIGHUP < 256 && SIGINT < 256 && SIGKILL < 256) {
+ w("#define NSVC_SIGNAL_CODED\t\"");
+ w_to("t",SIGTERM); w_to("a",SIGALRM); w_to("p",SIGSTOP);
+ w_to("c",SIGCONT); w_to("h",SIGHUP); w_to("i",SIGINT);
+ w_to("k",SIGKILL);
+ w("\"\n");
+ }
+
+ w_sn_("#if 0\n\tdev_t\t", sizeof(dev_t));
+ w_sn_("\tgid_t\t", sizeof(gid_t));
+ w_sn_("\tuid_t\t", sizeof(uid_t));
+ w_sn_("\tmode_t\t", sizeof(mode_t));
+
+ w_sn_("#endif\n#define X_TIOCGPGRP\t", TIOCGPGRP);
+ w("\n#ifdef SIGACTION_FUNCTIONS\n\n");
+
+#ifndef SA_RESTORER
+#define SA_RESTORER 0x04000000
+#endif
+
+ w_sn_("#define SA_RESTART\t", SA_RESTART);
+ w_sn_("#define SA_NOCLDSTOP\t", SA_NOCLDSTOP);
+
+ uu[0] = SA_RESTART | SA_NOCLDSTOP | SA_RESTORER;
+#ifdef INIT_SKIP_SIGRETURN
+ w("#define INIT_SKIP_SIGRETURN\n");
+ uu[0] = SA_RESTART | SA_NOCLDSTOP;
+#endif
+ w_sn_("#define SA_FLAGS_number\t", uu[0]);
+
+#if defined(__i386__)
+ w("#define SA_RESTORER_function\t__restore");
+ if (uu[0] & SA_SIGINFO) w("_rt");
+#endif
+
+#if defined(__x86_64__)
+ w("#define SA_RESTORER_function\t__restore_rt");
+#endif
+ w("\n");
+
+ w("\n#if 0\n");
+ /* w_sn_("#define STAT_SIZE\t", sizeof(struct stat)); */
+ w_sn_("#define SIGATION_SIZE\t", sizeof(sa));
+ w_sn_("#define SIGSET_T_SIZE\t", sizeof(sa.sa_mask));
+ w_sn_("#define SIGSET_WORD_N\t", WORD(SIGCHLD));
+ w_sn_("#define SIGSET_MASK_N\t", MASK(SIGCHLD));
+
+ w_sp_("\tsa_handler offset\t", sa.sa_handler, sa);
+ w_sp_("\tsa_flags offset\t", sa.sa_flags, sa);
+ w_sp_("\tsa_restorer offest\t",sa.sa_restorer, sa);
+ w_sp_("\tsa_mask offset\t", sa.sa_mask, sa);
+ w("#endif\n\n");
+
+ for (i=0; i<256; i++) uu[i] = 0;
+ uu[WORD(SIGCHLD)] = MASK(SIGCHLD);
+ w_sn_("#define SIGSET_MASK_LEN_N\t", MASK_LEN);
+ w_sns("#define STATIC_SIGCHLD_MASK unsigned long sigchld_mask[",
+ MASK_LEN, "] = { ");
+
+ for (i=0;; ) {
+ wn(uu[i]);
+ if (++i == MASK_LEN) break;
+ w(", ");
+ }
+
+ w(" }\n"
+ "\n#else\n"
+ "#include \"struct_root.h\"\n");
+
+ if (sizeof(struct ch) > sizeof(struct ui)) {
+ w("#define INIT_NAME_IS_UINT\n");
+ w_sn_("#define PROCESS_SIZE ", sizeof(struct ui));
+ w("INIT_ROOT_DEFINE(process, uint32t) *root;\n");
+ } else {
+ w("#undef INIT_NAME_IS_UINT\n");
+ w_sn_("#define PROCESS_SIZE ", sizeof(struct ch));
+ w("INIT_ROOT_DEFINE(process, char*) *root;\n");
+ }
+
+ w("#endif\n");
+ return 0;
+}
diff --git a/misc/tryulong32.c b/misc/tryulong32.c
new file mode 100644
index 0000000..e0adc6d
--- /dev/null
+++ b/misc/tryulong32.c
@@ -0,0 +1,6 @@
+int main() {
+ unsigned long u=1,k=0;
+ for (; k<32; k++) u += u;
+ if (!u) return 0;
+ return 1;
+}