update to cinit-0.3pre19
Signed-off-by: Nico Schottelius <nico@ikn.schottelius.org>
This commit is contained in:
parent
367a74c75e
commit
7c47ae1c48
1119 changed files with 101885 additions and 0 deletions
53
software/cinit/browse_source/cinit-0.3pre19/src/test/data1.c
Normal file
53
software/cinit/browse_source/cinit-0.3pre19/src/test/data1.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int a, b, e;
|
||||
char *c = "/etc/cinit/svc/...", *data;
|
||||
|
||||
int a2, b2;
|
||||
char *c2;
|
||||
|
||||
a2 = b2 = 0;
|
||||
|
||||
a = 1001;
|
||||
b = strlen(c);
|
||||
c2 = malloc(b + 1);
|
||||
if(!c2)
|
||||
return 40;
|
||||
|
||||
e = sizeof(a) + sizeof(b) + b;
|
||||
|
||||
printf("e=%d (b=%d)\n", e, b);
|
||||
|
||||
data = malloc(e);
|
||||
if(!data)
|
||||
return 20;
|
||||
|
||||
/*
|
||||
* in
|
||||
*/
|
||||
strcpy(data, (char *) &a);
|
||||
e = sizeof(a);
|
||||
strcpy(&data[e], (char *) &b);
|
||||
e += sizeof(b);
|
||||
strcpy(&data[e], c);
|
||||
|
||||
/*
|
||||
* out
|
||||
*/
|
||||
strncpy((char *) &a2, data, sizeof(a2));
|
||||
printf("a2=%d\n", a2);
|
||||
e = sizeof(a2);
|
||||
|
||||
strncpy((char *) &b2, &data[e], sizeof(b2));
|
||||
printf("b2=%d\n", b2);
|
||||
e += sizeof(b2);
|
||||
|
||||
strncpy(c2, &data[e], b2);
|
||||
printf("c2=%s\n", c2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
/*************
|
||||
*
|
||||
* A very small program to show that the child() of a fork()
|
||||
* proceess can / CANNOT exit before fork() returns in the parent
|
||||
*
|
||||
* Nico Schottelius, Copying: GPLv3, 20070925
|
||||
*
|
||||
* I run it this way:
|
||||
|
||||
* % ./fork-latency | grep "Unknown child exited" | sort | uniq | wc -l
|
||||
* => Number of children that exited before we recorded them! (should be 0)
|
||||
*
|
||||
* % ./fork-latency | grep "found" | sort | uniq | wc -l
|
||||
* => children, which exited after fork() returned.
|
||||
*
|
||||
* % ./fork-latency | grep "found" | wc -l
|
||||
* => should equal MAX (see sourcecode)
|
||||
*
|
||||
* % ./fork-latency | wc -l
|
||||
* => should also equal MAX (see sourcecode)
|
||||
*
|
||||
* Some interesting facts:
|
||||
*
|
||||
* - With MAX=5000 I get:
|
||||
*
|
||||
* [20:02] ikn:test% ./fork-latency | grep "found" | wc -l
|
||||
* 731705
|
||||
* [20:03] ikn:test% ./fork-latency | wc -l
|
||||
* 734683
|
||||
*
|
||||
* [20:04] ikn:test% ./fork-latency | sort | head -n 4
|
||||
* 1339) found
|
||||
* 1339) found
|
||||
* 1339) found
|
||||
* 1339) found
|
||||
*
|
||||
*
|
||||
* I'm wondering, why even with WNOHANG I get to check pids twice,
|
||||
* also because I'm clearing the pid, after I found it (list[o] = 0).
|
||||
*
|
||||
|
||||
This code is weired (using return intead of exit, see below):
|
||||
|
||||
[20:38] ikn:test% ./fork-latency > D
|
||||
[20:38] ikn:test% cat D
|
||||
MAX=2
|
||||
MAX=2
|
||||
[1] Forked 12264
|
||||
MAX=2
|
||||
[1] Forked 12264
|
||||
[0] Forked 12265
|
||||
(12264) found
|
||||
(12265) found
|
||||
[20:38] ikn:test%
|
||||
|
||||
|
||||
With _exit:
|
||||
|
||||
[21:17] ikn:test% ./fork-latency > E
|
||||
[21:17] ikn:test% cat E
|
||||
MAX=2
|
||||
[1] Forked 15388
|
||||
[0] Forked 15389
|
||||
(15388) found
|
||||
(15389) found
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <unistd.h> /* fork() */
|
||||
#include <signal.h> /* sigaction, sigemtpyset */
|
||||
#include <sys/wait.h> /* waitpid */
|
||||
#include <stdio.h> /* printf, NULL */
|
||||
|
||||
#define MAX 20000 /* number of forks */
|
||||
|
||||
pid_t list[MAX];
|
||||
int i;
|
||||
int got_sig;
|
||||
|
||||
void sig_child(int sig)
|
||||
{
|
||||
got_sig = 1;
|
||||
}
|
||||
|
||||
void reap_child()
|
||||
{
|
||||
int o;
|
||||
int found;
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
got_sig = 0;
|
||||
|
||||
/* WNOHANG is evil: it makes us call the loop MORE THAN ONCE
|
||||
* PER DEAD CHILD! -> registering a dead child via signal
|
||||
* handler makes WNOHANG obsolete
|
||||
*/
|
||||
//while((pid = waitpid(-1, &status, WNOHANG)) > 0) {
|
||||
while((pid = waitpid(-1, &status, 0)) > 0) {
|
||||
found = 0;
|
||||
// no need to search the whole list, use o = i instead
|
||||
// for(o = 0; o < MAX; o++) {
|
||||
for(o = i; o < MAX; o++) {
|
||||
if(list[o] == pid) {
|
||||
list[o] = 0; /* empty */
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(found) {
|
||||
printf("(%d) found\n", pid);
|
||||
} else {
|
||||
printf("(%d) Unknown child exited\n", pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
/* listen to SIGCHLD */
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = sig_child;
|
||||
sa.sa_flags = SA_NOCLDSTOP;
|
||||
sigaction(SIGCHLD, &sa, NULL);
|
||||
|
||||
i = MAX;
|
||||
|
||||
printf("MAX=%d\n", i);
|
||||
|
||||
for(i = MAX - 1; i >= 0; i--) {
|
||||
list[i] = fork();
|
||||
/* child exists immediately */
|
||||
if(list[i] == 0) _exit(0);
|
||||
|
||||
/* this causes a different behaviour */
|
||||
/* if(list[i] == 0) return 0; */
|
||||
|
||||
printf("[%d] Forked %d\n", i, list[i]);
|
||||
|
||||
/* parent code */
|
||||
if(got_sig) reap_child();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Forking 1
|
||||
Forking 1
|
||||
(11456) found
|
||||
Forking 0
|
||||
Forking 1
|
||||
(11456) found
|
||||
Forking 0
|
||||
(11457) found
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Forking 1 (0)
|
||||
Forking 1 (11799)
|
||||
Forking 0 (0)
|
||||
Forking 1 (11799)
|
||||
Forking 0 (11800)
|
||||
(11799) found
|
||||
(11800) found
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
[1] Forked 11905
|
||||
[1] Forked 11905
|
||||
[0] Forked 11906
|
||||
(11905) found
|
||||
(11906) found
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
MAX=2
|
||||
MAX=2
|
||||
[1] Forked 12264
|
||||
MAX=2
|
||||
[1] Forked 12264
|
||||
[0] Forked 12265
|
||||
(12264) found
|
||||
(12265) found
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
MAX=2
|
||||
[1] Forked 15388
|
||||
[0] Forked 15389
|
||||
(15388) found
|
||||
(15389) found
|
||||
40001
software/cinit/browse_source/cinit-0.3pre19/src/test/fork-latency.c.F
Normal file
40001
software/cinit/browse_source/cinit-0.3pre19/src/test/fork-latency.c.F
Normal file
File diff suppressed because it is too large
Load diff
40001
software/cinit/browse_source/cinit-0.3pre19/src/test/fork-latency.c.G
Normal file
40001
software/cinit/browse_source/cinit-0.3pre19/src/test/fork-latency.c.G
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,46 @@
|
|||
#include <string.h> /* memcpy() */
|
||||
#include <stdio.h>
|
||||
|
||||
struct cinit_answer {
|
||||
int options;
|
||||
char data[2045];
|
||||
};
|
||||
|
||||
int f1(struct cinit_answer *buf);
|
||||
int f2(struct cinit_answer *buf);
|
||||
|
||||
int f2(struct cinit_answer *buf)
|
||||
{
|
||||
struct cinit_answer msg;
|
||||
|
||||
printf("f2: %p\n", buf);
|
||||
|
||||
msg.options = 12;
|
||||
strcpy(msg.data, "stringit");
|
||||
|
||||
printf("addr= %p\n", memcpy(buf, &msg, sizeof(*buf)));
|
||||
|
||||
printf("ok\n");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int f1(struct cinit_answer *buf)
|
||||
{
|
||||
printf("f1: %p\n", buf);
|
||||
printf("ret=%d\n", f2(buf));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct cinit_answer test;
|
||||
|
||||
if(!f1(&test))
|
||||
return 1;
|
||||
|
||||
printf("s: %s d: %d\n", test.data, test.options);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char *strip_final_newline(char *test1);
|
||||
|
||||
int main()
|
||||
{
|
||||
// char *test1 = "zeile1\nzeile2\n";
|
||||
// char *test2 = "zeile1\nzeile2\nzeile3";
|
||||
char *test1;
|
||||
char *test2;
|
||||
|
||||
test1 = malloc(50);
|
||||
test2 = malloc(50);
|
||||
|
||||
strcpy(test1, "zeile1\nzeile2\n");
|
||||
strcpy(test2, "zeile1\nzeile2\nzeile3");
|
||||
|
||||
char *result;
|
||||
|
||||
result = strip_final_newline(test1);
|
||||
printf("A%sA\n", result);
|
||||
|
||||
result = strip_final_newline(test2);
|
||||
printf("B%sB\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
/***********************************************************************
|
||||
*
|
||||
* 2006 Nico Schottelius (nico-cinit at schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* test build_argv
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "build_argv.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
char *file = "./test_exec_link";
|
||||
struct ba_argv cargv;
|
||||
int tmp;
|
||||
|
||||
if((tmp = cinit_build_argv(file, &cargv)) != BA_OK) {
|
||||
if(tmp != BA_E_MEM) {
|
||||
perror("fehler:");
|
||||
exit(24);
|
||||
} else
|
||||
exit(23);
|
||||
}
|
||||
|
||||
printf("code: %s\n", cargv.argv[0]);
|
||||
execve((cargv.argv)[0], cargv.argv, cargv.envp);
|
||||
|
||||
perror("execve");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
/***********************************************************************
|
||||
*
|
||||
* 2006 Nico Schottelius (nico-cinit at schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* test build_argv
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "build_argv.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
char *file = "./test_exec";
|
||||
struct ba_argv cargv;
|
||||
int tmp;
|
||||
|
||||
if((tmp = cinit_build_argv(file, &cargv)) != BA_OK) {
|
||||
if(tmp != BA_E_MEM) {
|
||||
perror("fehler:");
|
||||
exit(24);
|
||||
} else
|
||||
exit(23);
|
||||
}
|
||||
|
||||
printf("code: %s\n", cargv.argv[0]);
|
||||
execve((cargv.argv)[0], cargv.argv, cargv.envp);
|
||||
|
||||
perror("execve");
|
||||
|
||||
return 1;
|
||||
}
|
||||
7
software/cinit/browse_source/cinit-0.3pre19/src/test/test_exec
Executable file
7
software/cinit/browse_source/cinit-0.3pre19/src/test/test_exec
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
# Nico Schottelius
|
||||
# Test-skript for cinit
|
||||
|
||||
echo '$0': "$0"
|
||||
echo '$@': "$@"
|
||||
echo 'cinit_is_great:' $cinit_is_great
|
||||
|
|
@ -0,0 +1 @@
|
|||
cinit_is_great=yes
|
||||
|
|
@ -0,0 +1 @@
|
|||
Let's see if we read the arguments....YES!
|
||||
|
|
@ -0,0 +1 @@
|
|||
test_exec
|
||||
|
|
@ -0,0 +1 @@
|
|||
test_exec.env
|
||||
|
|
@ -0,0 +1 @@
|
|||
test_exec.params
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
/***********************************************************************
|
||||
*
|
||||
* 2006 Nico Schottelius (nico-cinit at schottelius.org)
|
||||
*
|
||||
* part of cLinux/cinit
|
||||
*
|
||||
* test gen_svc_tree
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "build_argv.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
gen_svc_tree("/etc/cinit/svc/init");
|
||||
list_display_all();
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int openreadclose(char *filename, char **where);
|
||||
|
||||
int main()
|
||||
{
|
||||
char *data;
|
||||
char *file = "test_openreadclose.c";
|
||||
|
||||
openreadclose(file, &data);
|
||||
|
||||
printf("%s\n", data);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
22
software/cinit/browse_source/cinit-0.3pre19/src/test/tired.c
Normal file
22
software/cinit/browse_source/cinit-0.3pre19/src/test/tired.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct msgq_server_short {
|
||||
long mtype;
|
||||
int mu;
|
||||
};
|
||||
|
||||
main()
|
||||
{
|
||||
struct msgq_server_short t1, *t2;
|
||||
|
||||
t2 = &t1;
|
||||
|
||||
int a = sizeof(t1);
|
||||
int b = sizeof(t2);
|
||||
int c = sizeof(*t2);
|
||||
|
||||
printf("a=%d,b=%d,c=%d\n", a, b, c);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct test {
|
||||
char buf[2048];
|
||||
int cmd;
|
||||
};
|
||||
|
||||
struct badtest {
|
||||
char *buf;
|
||||
int cmd;
|
||||
};
|
||||
|
||||
#define PATH "/etc/cinit/svc/local-tuning/udev"
|
||||
|
||||
int main()
|
||||
{
|
||||
struct test cmd;
|
||||
struct badtest nocmd;
|
||||
int pfd[2];
|
||||
int tmp;
|
||||
|
||||
strcpy(cmd.buf, "/which/service/to/disable");
|
||||
cmd.cmd = 42;
|
||||
|
||||
if(pipe(pfd) == -1)
|
||||
return 1;
|
||||
nocmd.cmd = 42;
|
||||
nocmd.buf = malloc(strlen(PATH) + 1);
|
||||
strcpy(nocmd.buf, PATH);
|
||||
|
||||
if(fork() > 1) {
|
||||
tmp = write(pfd[1], &cmd, sizeof(cmd));
|
||||
printf("PA: tmp=%d\n", tmp);
|
||||
|
||||
tmp = write(pfd[1], &nocmd, sizeof(nocmd));
|
||||
printf("PA: tmp2=%d\n", tmp);
|
||||
} else {
|
||||
strcpy(cmd.buf, "");
|
||||
cmd.cmd = 0;
|
||||
|
||||
tmp = read(pfd[0], &cmd, sizeof(cmd));
|
||||
printf("CH: tmp = %d, cmd = %d, buf = %s\n", tmp, cmd.cmd, cmd.buf);
|
||||
|
||||
free(nocmd.buf);
|
||||
nocmd.cmd = 0;
|
||||
|
||||
tmp = read(pfd[0], &nocmd, sizeof(nocmd));
|
||||
printf("CH: tmp = %d, cmd = %d, buf = %s\n", tmp, nocmd.cmd, nocmd.buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue