- cleaned up

This commit is contained in:
Sergey Bolshakov 2007-03-03 00:48:18 +03:00
parent be01ee5e40
commit 48d26b2d15
13 changed files with 90 additions and 157 deletions

View File

@ -163,7 +163,7 @@ include .depend
endif endif
gencpio: gen_init_cpio.c gencpio: gen_init_cpio.c
gcc -Wall -O2 $^ -o $@ $(CC) $(CFLAGS) -o $@ $^
install: $(TARGETS) install: $(TARGETS)
mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(BINSDIR) mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(BINSDIR)

View File

@ -38,7 +38,7 @@ endif
ifeq (ppc, $(ARCH)) ifeq (ppc, $(ARCH))
CFLAGS += -Os -pipe -Wall -fomit-frame-pointer CFLAGS += -Os -pipe -Wall -fomit-frame-pointer
else else
CFLAGS += -pipe -Wall -Wno-deprecated-declarations -D_BSD_SOURCE -D_GNU_SOURCE CFLAGS := -pipe -Wall -O2
endif endif
GLIBC_INCLUDES = GLIBC_INCLUDES =

2
dhcp.c
View File

@ -95,7 +95,7 @@ struct bootp_request {
char hwaddr[16]; char hwaddr[16];
char servername[64]; char servername[64];
char bootfile[128]; char bootfile[128];
char vendor[DHCP_VENDOR_LENGTH]; unsigned char vendor[DHCP_VENDOR_LENGTH];
} ; } ;
static const char vendor_cookie[] = { 99, 130, 83, 99, 255 }; static const char vendor_cookie[] = { 99, 130, 83, 99, 255 };

15
disk.c
View File

@ -69,15 +69,14 @@ static const char * detect_partition_type(char * dev)
struct partition_detection_anchor anchor0; struct partition_detection_anchor anchor0;
struct partition_detection_anchor anchor1; struct partition_detection_anchor anchor1;
struct partition_detection_anchor anchor2; struct partition_detection_anchor anchor2;
}; } partitions_signatures[] = {
struct partition_detection_info partitions_signatures[] = { { "Linux Swap", { 4086, "SWAP-SPACE" }, { 0, NULL }, { 0, NULL } },
{ "Linux Swap", { 4086, "SWAP-SPACE" }, { 0, NULL } }, { "Linux Swap", { 4086, "SWAPSPACE2" }, { 0, NULL }, { 0, NULL } },
{ "Linux Swap", { 4086, "SWAPSPACE2" }, { 0, NULL } }, { "Ext2", { 0x438, "\x53\xEF" }, { 0, NULL }, { 0, NULL } },
{ "Ext2", { 0x438, "\x53\xEF" }, { 0, NULL } }, { "ReiserFS", { 0x10034, "ReIsErFs" }, { 0, NULL }, { 0, NULL } },
{ "ReiserFS", { 0x10034, "ReIsErFs" }, { 0, NULL } }, { "ReiserFS", { 0x10034, "ReIsEr2Fs" }, { 0, NULL }, { 0, NULL } },
{ "ReiserFS", { 0x10034, "ReIsEr2Fs" }, { 0, NULL } },
{ "XFS", { 0, "XFSB" }, { 0x200, "XAGF" }, { 0x400, "XAGI" } }, { "XFS", { 0, "XFSB" }, { 0x200, "XAGF" }, { 0x400, "XAGI" } },
{ "JFS", { 0x8000, "JFS1" }, { 0, NULL } }, { "JFS", { 0x8000, "JFS1" }, { 0, NULL }, { 0, NULL } },
{ "NTFS", { 0x1FE, "\x55\xAA" }, { 0x3, "NTFS" }, { 0, NULL } }, { "NTFS", { 0x1FE, "\x55\xAA" }, { 0x3, "NTFS" }, { 0, NULL } },
{ "FAT32", { 0x1FE, "\x55\xAA" }, { 0x52, "FAT32" }, { 0, NULL } }, { "FAT32", { 0x1FE, "\x55\xAA" }, { 0x52, "FAT32" }, { 0, NULL } },
{ "FAT", { 0x1FE, "\x55\xAA" }, { 0x36, "FAT" }, { 0, NULL } }, { "FAT", { 0x1FE, "\x55\xAA" }, { 0x36, "FAT" }, { 0, NULL } },

50
init.c
View File

@ -54,7 +54,7 @@ char ** myenv = NULL;
int klog_pid; int klog_pid;
void fatal_error(char *msg) void fatal_error(const char *msg)
{ {
printf("FATAL ERROR IN INIT: %s : %s\n\nI can't recover from this, please reboot manually and send bugreport.\n", msg,strerror(errno)); printf("FATAL ERROR IN INIT: %s : %s\n\nI can't recover from this, please reboot manually and send bugreport.\n", msg,strerror(errno));
while (1); while (1);
@ -70,41 +70,13 @@ void print_warning(char *msg)
printf("W: %s\n", msg); printf("W: %s\n", msg);
} }
void print_int_init(int fd, int i)
{
char buf[10];
char * chptr = buf + 9;
int j = 0;
if (i < 0)
{
write(1, "-", 1);
i = -1 * i;
}
while (i)
{
*chptr-- = '0' + (i % 10);
j++;
i = i / 10;
}
write(fd, chptr + 1, j);
}
void print_str_init(int fd, char * string)
{
write(fd, string, strlen(string));
}
/* fork to: /* fork to:
* (1) watch /proc/kmsg and copy the stuff to /dev/tty4 * (1) watch /proc/kmsg and copy the stuff to /dev/tty4
* (2) listens to /dev/log and copy also this stuff (log from programs) * (2) listens to /dev/log and copy also this stuff (log from programs)
*/ */
void doklog() void doklog()
{ {
int in, out, i; int in, out, i, ii;
int log; int log;
char buf[1024]; char buf[1024];
@ -145,8 +117,8 @@ void doklog()
i = read(in, buf, sizeof(buf)); i = read(in, buf, sizeof(buf));
if (i > 0) { if (i > 0) {
if (out >= 0) if (out >= 0)
write(out, buf, i); ii = write(out, buf, i);
write(log, buf, i); ii = write(log, buf, i);
} }
} }
} }
@ -281,9 +253,8 @@ static int nuke(const char *what)
if ( err ) { if ( err ) {
errno = err; errno = err;
fatal_error(what); fatal_error(what);
} else {
return 0;
} }
return 0;
} }
struct filesystem struct filesystem
@ -413,9 +384,12 @@ int main(int argc, char **argv)
} }
char my_hostname[] = "localhost.localdomain"; char my_hostname[] = "localhost.localdomain";
sethostname(my_hostname, sizeof(my_hostname)); if (sethostname(my_hostname, sizeof(my_hostname)) < 0)
print_error("could not set hostname");
/* the default domainname (as of 2.0.35) is "(none)", which confuses glibc */ /* the default domainname (as of 2.0.35) is "(none)", which confuses glibc */
setdomainname("", 0); if (setdomainname("", 0) < 0)
print_error("could not set domainname");
doklog(); doklog();
@ -429,7 +403,9 @@ int main(int argc, char **argv)
printf("Running stage1...\n"); printf("Running stage1...\n");
/* create a pipe for env passing */ /* create a pipe for env passing */
pipe(fds); if (pipe(fds) < 0)
fatal_error("failed to create env pipe");
fcntl(fds[0], F_SETFD, 1); fcntl(fds[0], F_SETFD, 1);
fcntl(fds[1], F_SETFD, 0); fcntl(fds[1], F_SETFD, 0);

View File

@ -87,11 +87,6 @@ static void *grab_file(const char *filename, unsigned long *size)
return buffer; return buffer;
} }
static void release_file(void *data, unsigned long size)
{
free(data);
}
int insmod_call(char *pathname, char *params) int insmod_call(char *pathname, char *params)
{ {
void *file; void *file;
@ -105,7 +100,7 @@ int insmod_call(char *pathname, char *params)
} }
rc = init_module(file, len, params == NULL ? "" : params); rc = init_module(file, len, params == NULL ? "" : params);
release_file(file, len); free(file);
if (rc != 0) { if (rc != 0) {
log_message("init_module: '%s': %s", pathname, moderror(errno)); log_message("init_module: '%s': %s", pathname, moderror(errno));
return rc; return rc;
@ -130,7 +125,7 @@ static enum insmod_return insmod_archived_file(const char * mod_name, char * opt
return INSMOD_FAILED; return INSMOD_FAILED;
rc = init_module(file, len, options == NULL ? "" : options); rc = init_module(file, len, options == NULL ? "" : options);
release_file(file, len); free(file);
if (rc != 0) { if (rc != 0) {
log_message("init_module: '%s': %s", module_name, moderror(errno)); log_message("init_module: '%s': %s", module_name, moderror(errno));
return INSMOD_FAILED; return INSMOD_FAILED;
@ -233,33 +228,6 @@ void init_modules_insmoding(void)
} }
} }
static void add_modules_conf(char * str)
{
static char data[500] = "";
char * target = "/etc/modules.conf";
int fd;
if (strlen(data) + strlen(str) >= sizeof(data))
return;
strcat(data, str);
strcat(data, "\n");
fd = open(target, O_CREAT|O_WRONLY|O_TRUNC, 00660);
if (fd == -1) {
log_perror(str);
return;
}
if (write(fd, data, strlen(data) + 1) != strlen(data) + 1)
log_perror(str);
close(fd);
}
static int module_already_present(const char * name) static int module_already_present(const char * name)
{ {
FILE * f; FILE * f;
@ -307,7 +275,7 @@ enum insmod_return my_insmod(const char * mod_name, enum driver_type type, char
char alias[500]; char alias[500];
int i; int i;
#ifndef DISABLE_NETWORK #ifndef DISABLE_NETWORK
char ** net_devices = NULL; /* fucking compiler */ char ** net_devices = NULL;
#endif #endif
log_message("have to insmod %s", mod_name); log_message("have to insmod %s", mod_name);
@ -343,8 +311,6 @@ enum insmod_return my_insmod(const char * mod_name, enum driver_type type, char
goto already_present; goto already_present;
ptr++; ptr++;
} }
sprintf(alias, "alias %s %s", *new_net_devices, mod_name);
add_modules_conf(alias);
log_message("NET: %s", alias); log_message("NET: %s", alias);
net_discovered_interface(*new_net_devices); net_discovered_interface(*new_net_devices);
@ -380,8 +346,6 @@ static enum return_type insmod_with_options(char * mod, enum driver_type type)
return RETURN_ERROR; return RETURN_ERROR;
} }
add_modules_conf(options);
return RETURN_OK; return RETURN_OK;
} }

View File

@ -34,6 +34,7 @@
#include <newt.h> #include <newt.h>
#include "frontend.h" #include "frontend.h"
#include "tools.h"
void init_frontend(char * welcome_msg) void init_frontend(char * welcome_msg)
{ {

View File

@ -39,7 +39,7 @@
* Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com> * Wed Oct 1 23:55:28 1997: Dick Streefland <dick_streefland@tasking.com>
* Implemented the "bg", "fg" and "retry" mount options for NFS. * Implemented the "bg", "fg" and "retry" mount options for NFS.
* *
* 1999-02-22 Arkadiusz Miśkiewicz <misiek@pld.ORG.PL> * 1999-02-22 Arkadiusz Mi kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support * - added Native Language Support
* *
* Modified by Olaf Kirch and Trond Myklebust for new NFS code, * Modified by Olaf Kirch and Trond Myklebust for new NFS code,

View File

@ -139,7 +139,7 @@ char * get_net_intf_description(char * intf_name)
static struct pci_module_map * get_pci_ids() static struct pci_module_map * get_pci_ids()
{ {
static struct pci_module_map * pcidb = NULL; static struct pci_module_map * pcidb = NULL;
struct pci_module_map * last, *new; struct pci_module_map *new, *last = NULL;
char buf[50]; char buf[50];
int v, d; int v, d;
FILE *f; FILE *f;
@ -221,7 +221,7 @@ static void pci_probe(enum driver_type type)
} }
while (NULL != fgets(buf, sizeof(buf), f)) { while (NULL != fgets(buf, sizeof(buf), f)) {
int i, matched, dfn, vendor, device, class, subv, subid; int i, fd, matched, dfn, vendor, device, class, subv, subid;
struct pci_module_map * pcidb; struct pci_module_map * pcidb;
sscanf(buf, "%x %x", &dfn, &vendor); sscanf(buf, "%x %x", &dfn, &vendor);
@ -233,9 +233,9 @@ static void pci_probe(enum driver_type type)
log_message("gathering info for %s", devname); log_message("gathering info for %s", devname);
if ((i = open(devname, O_RDONLY)) != -1) { if ((fd = open(devname, O_RDONLY)) != -1) {
read(i, devdata, sizeof(devdata)); i = read(fd, devdata, sizeof(devdata));
close(i); close(fd);
} else continue; } else continue;
class = devdata[9] | (devdata[10] << 8) | (devdata[11] << 16); class = devdata[9] | (devdata[10] << 8) | (devdata[11] << 16);
@ -363,7 +363,6 @@ static void usb_probe(enum driver_type type)
FILE * f; FILE * f;
char buf[200]; char buf[200];
static struct usb_module_map * usb_ids = NULL;
switch (type) { switch (type) {
#ifdef ENABLE_USBNET #ifdef ENABLE_USBNET

View File

@ -1,11 +1,8 @@
# -*- rpm-spec -*-
# $Id$
%def_with shell %def_with shell
Name: propagator Name: propagator
Version: 20061123 Version: 20070301
Release: alt1.0.glibc.1 Release: alt0.1
Summary: 'Early userspace' set of binaries Summary: 'Early userspace' set of binaries
License: GPL License: GPL
@ -13,20 +10,17 @@ Group: System/Kernel and hardware
Source0: %name-%version.tar.bz2 Source0: %name-%version.tar.bz2
BuildPreReq: mar-glibc BuildRequires: mar >= 20070301-alt1 bzlib-devel-static libnewt-devel-static libslang-devel-static
# Automatically added by buildreq on Thu Feb 01 2007
BuildRequires: bzlib-devel-static libnewt-devel-static libslang-devel-static
%description %description
%name is a set of binaries useful in 'early userspace' environment, %name is a set of binaries useful in 'early userspace' environment,
including init and various helpers for hw probing and bootstrapping. including init and various helpers for hw probing and bootstrapping.
%prep %prep
%setup -qc %setup -c
%build %build
make %{?_with_shell:WITH_SHELL=t} make %{?_with_shell:WITH_SHELL=t} CFLAGS="$RPM_OPT_FLAGS"
%install %install
%make_install DESTDIR=%buildroot LIBDIR=%_libdir install %make_install DESTDIR=%buildroot LIBDIR=%_libdir install
@ -36,8 +30,10 @@ make %{?_with_shell:WITH_SHELL=t}
%_libdir/%name %_libdir/%name
%changelog %changelog
* Fri Feb 02 2007 Nick S. Grechukh <gns@altlinux.ru> 20061123-alt1.0.glibc.1 * Thu Mar 1 2007 Sergey Bolshakov <sbolshakov@altlinux.ru> 20070301-alt0.1
- accurate glibc patch, instead of published dirty hack - switch to glibc, thanks to gns@
- redo block device probing, based on sysfs
- cleaned up
* Thu Nov 23 2006 Sergey Bolshakov <sbolshakov@altlinux.ru> 20061123-alt1 * Thu Nov 23 2006 Sergey Bolshakov <sbolshakov@altlinux.ru> 20061123-alt1
- added conditional shell spawning - added conditional shell spawning

88
tools.c
View File

@ -318,74 +318,66 @@ int prepare_progress()
{ {
char readbuffer[4096]; char readbuffer[4096];
int size; int size;
if (splashfd > 0) return(0); if (splashfd > 0) return(0);
splashfd = open(PROCSPLASH,O_RDWR);
if (splashfd < 0) splashfd = open(PROCSPLASH,O_RDWR);
{ if (splashfd < 0) {
log_message("Error open /proc/splash\n"); log_message("Error open /proc/splash\n");
return(-1); return(-1);
} }
size = read(splashfd, readbuffer, sizeof(readbuffer)); size = read(splashfd, readbuffer, sizeof(readbuffer));
if ( strstr(readbuffer,"silent") && strstr(readbuffer,": on") ) if (strstr(readbuffer,"silent") && strstr(readbuffer,": on")) {
{ log_message("bootsplash detected and progress enabled");
log_message("bootsplash detected and progress enabled"); } else {
} close(splashfd);
else splashfd = -1;
{
close(splashfd);
splashfd = -1;
}
if (splashcount == 0 )
{
char * splash_param = get_param_valued("splashcount");
if (!splash_param)
{
splashcount = -1;
return;
}
if (sscanf(splash_param,"%d",&splashcount) != 1)
{
splashcount = -1;
return;
}
} }
return(0); if (splashcount == 0 ) {
char * splash_param = get_param_valued("splashcount");
if (!splash_param) {
splashcount = -1;
return(0);
}
if (sscanf(splash_param,"%d",&splashcount) != 1) {
splashcount = -1;
return(0);
}
}
return(0);
} }
void close_progress() void close_progress()
{ {
char * tmpcount; char s[16];
char * tmpstep;
if (splashfd < 0) if (splashfd < 0)
return; return;
close(splashfd); close(splashfd);
sprintf(tmpcount,"%i",splashcount); snprintf(s, sizeof(s), "%i", splashcount);
sprintf(tmpstep,"%i",splashstep); add_to_env("SPLASHCOUNT", s);
add_to_env("SPLASHCOUNT",tmpcount); snprintf(s, sizeof(s), "%i", splashstep);
add_to_env("SPLASHSTEP",tmpstep); add_to_env("SPLASHSTEP", s);
return; return;
} }
void set_splash(char * mode) int set_splash(char * mode)
{ {
if (splashfd < 0) if (splashfd < 0)
return; return 0;
write(splashfd,mode, strlen(mode)); return(write(splashfd, mode, strlen(mode)));
return;
} }
void update_splash() int update_splash()
{ {
int progress = 0; int progress = 0;
char data[32]; char data[32];
if (splashcount <= 0) if (splashcount <= 0)
return; return 0;
++splashstep; splashstep++;
progress = (65534 * splashstep ) / splashcount; progress = (65534 * splashstep ) / splashcount;
log_message("boostplash progress: %i",progress); log_message("boostplash progress: %i",progress);
sprintf(data,"show %i\n",progress); sprintf(data,"show %i\n",progress);
write(splashfd,data,strlen(data)); return write(splashfd,data,strlen(data));
return;
} }
char * get_ramdisk_realname(void) char * get_ramdisk_realname(void)
@ -403,9 +395,9 @@ char * get_ramdisk_realname(void)
return strdup(img_name); return strdup(img_name);
} }
char * get_ramdisk_path(char *mount_path) char * get_ramdisk_path(const char *mount_path)
{ {
char * img_name[500]; char img_name[500];
char * st2_path = get_ramdisk_realname(); char * st2_path = get_ramdisk_realname();
/* FIXME */ /* FIXME */
@ -480,17 +472,19 @@ void add_to_env(char * name, char * value)
my_env[env_size] = NULL; my_env[env_size] = NULL;
} }
void pass_env(int fd) int pass_env(int fd)
{ {
char ** ptr = my_env; char ** ptr = my_env;
char *s; char *s;
int i = 0;
while (ptr && *ptr) { while (ptr && *ptr) {
s = *ptr; s = *ptr;
while(*s++); while(*s++);
write(fd, *ptr, s - *ptr); i = write(fd, *ptr, s - *ptr);
ptr++; ptr++;
} }
return i;
} }
char ** list_directory(char * direct) char ** list_directory(char * direct)

View File

@ -38,11 +38,15 @@ void * memdup(void *src, size_t size);
void add_to_env(char * name, char * value); void add_to_env(char * name, char * value);
void handle_env(char ** env); void handle_env(char ** env);
char ** grab_env(void); char ** grab_env(void);
void pass_env(int); int pass_env(int);
char ** list_directory(char * direct); char ** list_directory(char * direct);
int string_array_length(char ** a); int string_array_length(char ** a);
int do_losetup(char * device, char * target); int do_losetup(char * device, char * target);
char * get_ramdisk_path(char *); char * get_ramdisk_path(const char *);
int set_splash(char *);
int update_splash(void);
int prepare_progress(void);
void close_progress(void);
struct param_elem struct param_elem
{ {

2
url.c
View File

@ -425,7 +425,7 @@ int http_download_file(char * hostname, char * remotename, int * size)
buf = alloca(strlen(remotename) + 20); buf = alloca(strlen(remotename) + 20);
sprintf(buf, "GET %s HTTP/1.0\r\n\r\n", remotename); sprintf(buf, "GET %s HTTP/1.0\r\n\r\n", remotename);
write(sock, buf, strlen(buf)); rc = write(sock, buf, strlen(buf));
/* This is fun; read the response a character at a time until we: /* This is fun; read the response a character at a time until we: