changeset 1205:2b3f347dd225

Move sources/native-root to sources/root-filesystem (mostly to make tab completion work better when navigating the source).
author Rob Landley <rob@landley.net>
date Fri, 13 Aug 2010 16:34:07 -0500
parents 6ab5fbb82619
children 99c49806ea6d
files sources/native-root/bin/getent sources/native-root/etc/group sources/native-root/etc/mdev.conf sources/native-root/etc/passwd sources/native-root/etc/resolv.conf sources/native-root/sbin/init.sh sources/native-root/src/hello.cpp sources/native-root/src/thread-hello.c sources/native-root/src/thread-hello2.c sources/root-filesystem/bin/getent sources/root-filesystem/etc/group sources/root-filesystem/etc/mdev.conf sources/root-filesystem/etc/mtab sources/root-filesystem/etc/passwd sources/root-filesystem/etc/resolv.conf sources/root-filesystem/sbin/init.sh sources/root-filesystem/src/hello.cpp sources/root-filesystem/src/thread-hello.c sources/root-filesystem/src/thread-hello2.c
diffstat 19 files changed, 250 insertions(+), 249 deletions(-) [+]
line wrap: on
line diff
--- a/sources/native-root/bin/getent	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-#!/bin/sh
-
-# Copyright 2009 Rob Landley <rob@landley.net>, licensed under GPLv2.
-
-isnum()
-{
-  [ ! -z "$(echo $1 | grep '^[0-9]*$')" ]
-}
-
-nocomments()
-{
-  sed 's/\([^#]*\)#.*/\1/' /etc/$1
-}
-
-# The world's cheesiest getent implementation
-
-case "$1" in
-  passwd|group)
-    isnum "$2" &&
-      grep -m 1 "[^:]*:[^:]*:$2:" /etc/$1 ||
-      grep -m 1 "^$2:" /etc/$1
-    ;;
-
-  hosts|networks|protocols)
-    nocomments $1 | grep -m 1 -w "$2"
-    ;;
-
-  services)
-    nocomments $1 | (isnum "$2" && grep -m 1 "[ 	]$2/" || grep -m 1 -w "$2")
-    ;;
-esac
--- a/sources/native-root/etc/group	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-root:x:0:
-guest:x:1:
--- a/sources/native-root/etc/mdev.conf	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-null 0:0 777
-(zero|random|urandom) 0:0 666
--- a/sources/native-root/etc/passwd	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-root:x:0:0:root:/root:/bin/sh
-guest:x:1:1:root:/root:/bin/sh
--- a/sources/native-root/etc/resolv.conf	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-# This is the default for QEMU
-nameserver 10.0.2.3
--- a/sources/native-root/sbin/init.sh	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,97 +0,0 @@
-#!/bin/sh
-
-# Otherwise, building source packages wants things like /bin/bash and
-# running the results wants /lib/ld-uClibc.so.0, so set up some directories
-# and symlinks to let you easily compile source packages.
-
-export HOME=/home
-
-# Populate /dev
-mountpoint -q sys || mount -t sysfs sys sys
-mountpoint -q dev || mount -t tmpfs -o noatime dev dev
-mdev -s
-
-# Make sure /proc is there
-mountpoint -q proc || mount -t proc proc proc
-
-[ -z "$CPUS" ] && export CPUS=1
-export PS1='($HOST:$CPUS) \w \$ '
-
-# If we're running under qemu, do some more setup
-if [ $$ -eq 1 ]
-then
-
-  # Note that 10.0.2.2 forwards to 127.0.0.1 on the host.
-
-  # Setup networking for QEMU (needs /proc)
-  ifconfig eth0 10.0.2.15
-  route add default gw 10.0.2.2
-
-  # If we have no RTC, try rdate instead:
-  [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov
-
-  mount -t tmpfs /tmp /tmp
-
-  # If there's a /dev/hdb or /dev/sdb, mount it on home
-
-  [ -b /dev/hdb ] && HOMEDEV=/dev/hdb
-  [ -b /dev/sdb ] && HOMEDEV=/dev/sdb
-  if [ ! -z "$HOMEDEV" ]
-  then
-    mount -o noatime $HOMEDEV /home
-  else
-    # Only mount a tmpfs if / isn't writeable.
-    touch /.temp 2>/dev/null
-    [ $? -ne 0 ] && mount -t tmpfs /home /home || rm /.temp
-  fi
-  cd /home
-
-  [ -b /dev/hdc ] && MNTDEV=/dev/hdc
-  [ -b /dev/sdc ] && MNTDEV=/dev/sdc
-  if [ ! -z "$MNTDEV" ]
-  then
-    mount -o ro $MNTDEV /mnt
-  fi
-
-  CONSOLE="$(sed -n 's@.* console=\(/dev/\)*\([^ ]*\).*@\2@p' /proc/cmdline)"
-
-  if [ -z "$DISTCC_HOSTS" ]
-  then
-    echo "Not using distcc."
-  else
-    echo "Distcc acceleration enabled."
-  fi
-  echo Type exit when done.
-
-  HANDOFF=/bin/ash
-  if [ -e /mnt/init ]
-  then
-    X=xx
-    echo "Press any key for command line..."
-    read -t 3 -n 1 X
-    if [ "$X" == xx ]
-    then
-      echo "Running automated build."
-      HANDOFF=/mnt/init
-    fi
-  fi
-  exec /sbin/oneit -c /dev/"$CONSOLE" "$HANDOFF"
-
-# If we're not PID 1, it's probably a chroot.
-else
-  [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] &&
-    echo "nameserver 8.8.8.8" > /etc/resolv.conf
-
-  # If we have no RTC, try using ntp to set the clock
-  [ "$(date +%s)" -lt 10000000 ] && ntpd -nq -p north-america.pool.ntp.org
-
-  # Switch to a shell with command history.
-
-  echo Type exit when done.
-  /bin/ash
-  cd /
-  umount ./dev
-  umount ./sys
-  umount ./proc
-  sync
-fi
--- a/sources/native-root/src/hello.cpp	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-#include <iostream>
-using namespace std;
-
-int main()
-{
-    cout << "hello world" << endl;
-    return 0;
-}
--- a/sources/native-root/src/thread-hello.c	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-#define __REENTRANT
-#include <pthread.h>
-#include <stdio.h>
- 
-void *threadhello(void *unused)
-{
-  printf("Hello, world!\n");
-  return 0;
-}
- 
-int main() {
-  pthread_t thready;
-  pthread_create(&thready, NULL, &threadhello, NULL);
-  usleep(10);
-}
--- a/sources/native-root/src/thread-hello2.c	Fri Aug 13 15:41:03 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-// Threaded hello world program that uses mutex and event semaphores to pass
-// the string to print from one thread to another, and waits for the child
-// thread to return a result before exiting the program.
-
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-// Thread, semaphores, and mailbox
-struct thread_info {
-	pthread_t thread;
-	pthread_mutex_t wakeup_mutex;
-	pthread_cond_t wakeup_send, wakeup_receive;
-	unsigned len;
-	char *data;
-};
-
-// Create a new thread with associated resources.
-struct thread_info *newthread(void *(*func)(void *))
-{
-	struct thread_info *ti = malloc(sizeof(struct thread_info));
-	memset(ti, 0, sizeof(struct thread_info));
-
-	pthread_create(&(ti->thread), NULL, func, ti);
-
-	return ti;
-}
-
-// Send a block of data through mailbox.
-void thread_send(struct thread_info *ti, char *data, unsigned len)
-{
-	pthread_mutex_lock(&(ti->wakeup_mutex));
-	// If consumer hasn't consumed yet, wait for them to do so.
-	if (ti->len)
-		pthread_cond_wait(&(ti->wakeup_send), &(ti->wakeup_mutex));
-	ti->data = data;
-	ti->len = len;
-	pthread_cond_signal(&(ti->wakeup_receive));
-	pthread_mutex_unlock(&(ti->wakeup_mutex));
-}
-
-// Receive a block of data through mailbox.
-void thread_receive(struct thread_info *ti, char **data, unsigned *len)
-{
-	pthread_mutex_lock(&(ti->wakeup_mutex));
-	if (!ti->len)
-		pthread_cond_wait(&(ti->wakeup_receive), &(ti->wakeup_mutex));
-	*data = ti->data;
-	*len = ti->len;
-	// If sender is waiting to send us a second message, wake 'em up.
-	// Note that "if (ti->len)" be used as an unlocked/nonblocking test for
-	// pending data, although you still need call this function to read data.
-	ti->len = 0;
-	pthread_cond_signal(&(ti->wakeup_send));
-	pthread_mutex_unlock(&(ti->wakeup_mutex));
-}
-
-// Function for new thread to execute.
-void *hello_thread(void *thread_data)
-{
-	struct thread_info *ti = (struct thread_info *)thread_data;
-
-	for (;;) {
-		unsigned len;
-		char *data;
-
-		thread_receive(ti, &data, &len);
-		if (!data) break;
-		printf("%.*s", len, data);
-		free(data);
-	}
-
-	return 0;
-}
-
-int main(int argc, char *argv[])
-{
-	void *result;
-	char *data = strdup("Hello world!\n");
-	struct thread_info *ti = newthread(hello_thread);
-
-	// Send one line of text.
-	thread_send(ti, data, strlen(data));
-	// Signal thread to exit and wait for it to do so.
-	thread_send(ti, NULL, 1);
-	pthread_join(ti->thread, &result);
-
-	return (long)result;
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/bin/getent	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+# Copyright 2009 Rob Landley <rob@landley.net>, licensed under GPLv2.
+
+isnum()
+{
+  [ ! -z "$(echo $1 | grep '^[0-9]*$')" ]
+}
+
+nocomments()
+{
+  sed 's/\([^#]*\)#.*/\1/' /etc/$1
+}
+
+# The world's cheesiest getent implementation
+
+case "$1" in
+  passwd|group)
+    isnum "$2" &&
+      grep -m 1 "[^:]*:[^:]*:$2:" /etc/$1 ||
+      grep -m 1 "^$2:" /etc/$1
+    ;;
+
+  hosts|networks|protocols)
+    nocomments $1 | grep -m 1 -w "$2"
+    ;;
+
+  services)
+    nocomments $1 | (isnum "$2" && grep -m 1 "[ 	]$2/" || grep -m 1 -w "$2")
+    ;;
+esac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/etc/group	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,2 @@
+root:x:0:
+guest:x:1:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/etc/mdev.conf	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,2 @@
+null 0:0 777
+(zero|random|urandom) 0:0 666
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/etc/mtab	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,1 @@
+/proc/mounts
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/etc/passwd	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,2 @@
+root:x:0:0:root:/root:/bin/sh
+guest:x:1:1:root:/root:/bin/sh
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/etc/resolv.conf	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,2 @@
+# This is the default for QEMU
+nameserver 10.0.2.3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/sbin/init.sh	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,97 @@
+#!/bin/sh
+
+# Otherwise, building source packages wants things like /bin/bash and
+# running the results wants /lib/ld-uClibc.so.0, so set up some directories
+# and symlinks to let you easily compile source packages.
+
+export HOME=/home
+
+# Populate /dev
+mountpoint -q sys || mount -t sysfs sys sys
+mountpoint -q dev || mount -t tmpfs -o noatime dev dev
+mdev -s
+
+# Make sure /proc is there
+mountpoint -q proc || mount -t proc proc proc
+
+[ -z "$CPUS" ] && export CPUS=1
+export PS1='($HOST:$CPUS) \w \$ '
+
+# If we're running under qemu, do some more setup
+if [ $$ -eq 1 ]
+then
+
+  # Note that 10.0.2.2 forwards to 127.0.0.1 on the host.
+
+  # Setup networking for QEMU (needs /proc)
+  ifconfig eth0 10.0.2.15
+  route add default gw 10.0.2.2
+
+  # If we have no RTC, try rdate instead:
+  [ "$(date +%s)" -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov
+
+  mount -t tmpfs /tmp /tmp
+
+  # If there's a /dev/hdb or /dev/sdb, mount it on home
+
+  [ -b /dev/hdb ] && HOMEDEV=/dev/hdb
+  [ -b /dev/sdb ] && HOMEDEV=/dev/sdb
+  if [ ! -z "$HOMEDEV" ]
+  then
+    mount -o noatime $HOMEDEV /home
+  else
+    # Only mount a tmpfs if / isn't writeable.
+    touch /.temp 2>/dev/null
+    [ $? -ne 0 ] && mount -t tmpfs /home /home || rm /.temp
+  fi
+  cd /home
+
+  [ -b /dev/hdc ] && MNTDEV=/dev/hdc
+  [ -b /dev/sdc ] && MNTDEV=/dev/sdc
+  if [ ! -z "$MNTDEV" ]
+  then
+    mount -o ro $MNTDEV /mnt
+  fi
+
+  CONSOLE="$(sed -n 's@.* console=\(/dev/\)*\([^ ]*\).*@\2@p' /proc/cmdline)"
+
+  if [ -z "$DISTCC_HOSTS" ]
+  then
+    echo "Not using distcc."
+  else
+    echo "Distcc acceleration enabled."
+  fi
+  echo Type exit when done.
+
+  HANDOFF=/bin/ash
+  if [ -e /mnt/init ]
+  then
+    X=xx
+    echo "Press any key for command line..."
+    read -t 3 -n 1 X
+    if [ "$X" == xx ]
+    then
+      echo "Running automated build."
+      HANDOFF=/mnt/init
+    fi
+  fi
+  exec /sbin/oneit -c /dev/"$CONSOLE" "$HANDOFF"
+
+# If we're not PID 1, it's probably a chroot.
+else
+  [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] &&
+    echo "nameserver 8.8.8.8" > /etc/resolv.conf
+
+  # If we have no RTC, try using ntp to set the clock
+  [ "$(date +%s)" -lt 10000000 ] && ntpd -nq -p north-america.pool.ntp.org
+
+  # Switch to a shell with command history.
+
+  echo Type exit when done.
+  /bin/ash
+  cd /
+  umount ./dev
+  umount ./sys
+  umount ./proc
+  sync
+fi
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/src/hello.cpp	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,8 @@
+#include <iostream>
+using namespace std;
+
+int main()
+{
+    cout << "hello world" << endl;
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/src/thread-hello.c	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,15 @@
+#define __REENTRANT
+#include <pthread.h>
+#include <stdio.h>
+ 
+void *threadhello(void *unused)
+{
+  printf("Hello, world!\n");
+  return 0;
+}
+ 
+int main() {
+  pthread_t thready;
+  pthread_create(&thready, NULL, &threadhello, NULL);
+  usleep(10);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sources/root-filesystem/src/thread-hello2.c	Fri Aug 13 16:34:07 2010 -0500
@@ -0,0 +1,90 @@
+// Threaded hello world program that uses mutex and event semaphores to pass
+// the string to print from one thread to another, and waits for the child
+// thread to return a result before exiting the program.
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+// Thread, semaphores, and mailbox
+struct thread_info {
+	pthread_t thread;
+	pthread_mutex_t wakeup_mutex;
+	pthread_cond_t wakeup_send, wakeup_receive;
+	unsigned len;
+	char *data;
+};
+
+// Create a new thread with associated resources.
+struct thread_info *newthread(void *(*func)(void *))
+{
+	struct thread_info *ti = malloc(sizeof(struct thread_info));
+	memset(ti, 0, sizeof(struct thread_info));
+
+	pthread_create(&(ti->thread), NULL, func, ti);
+
+	return ti;
+}
+
+// Send a block of data through mailbox.
+void thread_send(struct thread_info *ti, char *data, unsigned len)
+{
+	pthread_mutex_lock(&(ti->wakeup_mutex));
+	// If consumer hasn't consumed yet, wait for them to do so.
+	if (ti->len)
+		pthread_cond_wait(&(ti->wakeup_send), &(ti->wakeup_mutex));
+	ti->data = data;
+	ti->len = len;
+	pthread_cond_signal(&(ti->wakeup_receive));
+	pthread_mutex_unlock(&(ti->wakeup_mutex));
+}
+
+// Receive a block of data through mailbox.
+void thread_receive(struct thread_info *ti, char **data, unsigned *len)
+{
+	pthread_mutex_lock(&(ti->wakeup_mutex));
+	if (!ti->len)
+		pthread_cond_wait(&(ti->wakeup_receive), &(ti->wakeup_mutex));
+	*data = ti->data;
+	*len = ti->len;
+	// If sender is waiting to send us a second message, wake 'em up.
+	// Note that "if (ti->len)" be used as an unlocked/nonblocking test for
+	// pending data, although you still need call this function to read data.
+	ti->len = 0;
+	pthread_cond_signal(&(ti->wakeup_send));
+	pthread_mutex_unlock(&(ti->wakeup_mutex));
+}
+
+// Function for new thread to execute.
+void *hello_thread(void *thread_data)
+{
+	struct thread_info *ti = (struct thread_info *)thread_data;
+
+	for (;;) {
+		unsigned len;
+		char *data;
+
+		thread_receive(ti, &data, &len);
+		if (!data) break;
+		printf("%.*s", len, data);
+		free(data);
+	}
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	void *result;
+	char *data = strdup("Hello world!\n");
+	struct thread_info *ti = newthread(hello_thread);
+
+	// Send one line of text.
+	thread_send(ti, data, strlen(data));
+	// Signal thread to exit and wait for it to do so.
+	thread_send(ti, NULL, 1);
+	pthread_join(ti->thread, &result);
+
+	return (long)result;
+}