git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Usermode/GUI Terminal - Renamed folder
[tpg/acess2.git]
/
Usermode
/
Applications
/
init_src
/
main.c
diff --git
a/Usermode/Applications/init_src/main.c
b/Usermode/Applications/init_src/main.c
index
0d8713d
..
1a609ac
100644
(file)
--- a/
Usermode/Applications/init_src/main.c
+++ b/
Usermode/Applications/init_src/main.c
@@
-10,7
+10,7
@@
// === CONSTANTS ===
#define DEFAULT_SHELL "/Acess/SBin/login"
// === CONSTANTS ===
#define DEFAULT_SHELL "/Acess/SBin/login"
-#define INITTAB_FILE "/Acess/Conf
ig
/inittab"
+#define INITTAB_FILE "/Acess/Conf/inittab"
#define ARRAY_SIZE(x) ((sizeof(x))/(sizeof((x)[0])))
#define ARRAY_SIZE(x) ((sizeof(x))/(sizeof((x)[0])))
@@
-54,19
+54,23
@@
int main(int argc, char *argv[])
// No inittab file found, default to:
_SysDebug("inittab '%s' is invalid, falling back to one VT", gsInittabPath);
// No inittab file found, default to:
_SysDebug("inittab '%s' is invalid, falling back to one VT", gsInittabPath);
+ #if 1
for( ;; )
{
int pid = SpawnCommand(0, 1, 1, (char *[]){DEFAULT_SHELL, NULL});
for( ;; )
{
int pid = SpawnCommand(0, 1, 1, (char *[]){DEFAULT_SHELL, NULL});
+ // TODO: Detect errors
_SysWaitTID(pid, NULL);
}
_SysWaitTID(pid, NULL);
}
- // TODO: Detect errors
+ #else
+ return 41;
+ #endif
}
// TODO: Implement message watching
for(;;)
{
int pid, status;
}
// TODO: Implement message watching
for(;;)
{
int pid, status;
- pid = _SysWaitTID(
0
, &status);
+ pid = _SysWaitTID(
-1
, &status);
_SysDebug("PID %i died, looking for respawn entry", pid);
}
_SysDebug("PID %i died, looking for respawn entry", pid);
}
@@
-76,11
+80,13
@@
int main(int argc, char *argv[])
char *ReadQuotedString(FILE *FP)
{
char ch;
char *ReadQuotedString(FILE *FP)
{
char ch;
+
while( isblank(ch = fgetc(FP)) )
;
while( isblank(ch = fgetc(FP)) )
;
- if( ch == '\n' )
- return NULL;
+ if( ch == '\n' ) {
+ return NULL;
+ }
char *retstr = NULL;
int mode = 0;
char *retstr = NULL;
int mode = 0;
@@
-96,8
+102,10
@@
char *ReadQuotedString(FILE *FP)
}
else if( mode == 0 )
{
}
else if( mode == 0 )
{
- if( isspace(ch) )
+ if( isspace(ch) ) {
+ fseek(FP, -1, SEEK_CUR);
break;
break;
+ }
else if( ch == '\\' )
mode |= 4;
else if( ch == '"' )
else if( ch == '\\' )
mode |= 4;
else if( ch == '"' )
@@
-140,6
+148,7
@@
char *ReadQuotedString(FILE *FP)
space += 32;
void *tmp = realloc(retstr, space+1);
if( !tmp ) {
space += 32;
void *tmp = realloc(retstr, space+1);
if( !tmp ) {
+ _SysDebug("ReadQuotedString - realloc(%i) failure", space+1);
free(retstr);
return NULL;
}
free(retstr);
return NULL;
}
@@
-148,7
+157,8
@@
char *ReadQuotedString(FILE *FP)
retstr[pos++] = ch;
}
}
retstr[pos++] = ch;
}
}
- retstr[pos] = '\0';
+ if( retstr )
+ retstr[pos] = '\0';
return retstr;
}
return retstr;
}
@@
-160,13
+170,22
@@
char **ReadCommand(FILE *FP)
char *arg;
do {
arg = ReadQuotedString(FP);
char *arg;
do {
arg = ReadQuotedString(FP);
+ if(arg == NULL)
+ break;
if( pos == space - 1 ) {
if( pos == space - 1 ) {
+ _SysDebug("Too many arguments %i", pos);
ret[pos] = NULL;
FreeCommand(ret);
return NULL;
}
ret[pos++] = arg;
} while(arg != NULL);
ret[pos] = NULL;
FreeCommand(ret);
return NULL;
}
ret[pos++] = arg;
} while(arg != NULL);
+
+ if( pos == 0 )
+ {
+ free(ret);
+ return NULL;
+ }
ret[pos] = NULL;
return ret;
}
ret[pos] = NULL;
return ret;
}
@@
-184,6
+203,7
@@
void FreeCommand(char **Command)
int ProcessInittab(const char *Path)
{
int ProcessInittab(const char *Path)
{
+ int line_num = 0;
FILE *fp = fopen(Path, "r");
if( !fp )
FILE *fp = fopen(Path, "r");
if( !fp )
@@
-192,8
+212,14
@@
int ProcessInittab(const char *Path)
while(!feof(fp))
{
char cmdbuf[64+1];
while(!feof(fp))
{
char cmdbuf[64+1];
- if( fscanf(fp, "%64s%*[ \t]", &cmdbuf) != 1 )
+
+ line_num ++;
+
+ int rv;
+ if( (rv = fscanf(fp, "%64s%*[ \t]", cmdbuf)) != 1 ) {
+ _SysDebug("fscanf rv %i != exp 1", rv);
break;
break;
+ }
// Clear comments
if( cmdbuf[0] == '#' ) {
// Clear comments
if( cmdbuf[0] == '#' ) {
@@
-202,31
+228,36
@@
int ProcessInittab(const char *Path)
continue ;
}
if( cmdbuf[0] == '\0' ) {
continue ;
}
if( cmdbuf[0] == '\0' ) {
- if( fgetc(fp) != '\n' ) {
+ char ch = fgetc(fp);
+ if( ch != '\n' && ch != -1 ) {
fclose(fp);
fclose(fp);
+ _SysDebug("Unexpected char 0x%x, expecting EOL", ch);
return 2; // Unexpected character?
}
continue ;
}
return 2; // Unexpected character?
}
continue ;
}
-
+
// Check commands
if( strcmp(cmdbuf, "ktty") == 0 ) {
// ktty <ID> <command...>
// - Spins off a console on the specified kernel TTY
int id = 0;
// Check commands
if( strcmp(cmdbuf, "ktty") == 0 ) {
// ktty <ID> <command...>
// - Spins off a console on the specified kernel TTY
int id = 0;
- if( fscanf(fp, "%d ", &id) != 1 )
+ if( fscanf(fp, "%d ", &id) != 1 ) {
+ _SysDebug("init[ktty] - TTY ID read failed");
goto lineError;
goto lineError;
+ }
char **command = ReadCommand(fp);
char **command = ReadCommand(fp);
- if( !command )
+ if( !command ) {
+ _SysDebug("init[ktty] - Command read failure");
goto lineError;
goto lineError;
+ }
AddKTerminal(id, command);
AddKTerminal(id, command);
- free(command);
}
else if(strcmp(cmdbuf, "stty") == 0 ) {
// stty <devpath> [78][NOE][012][bB]<baud> <command...>
char path_seg[32+1];
char modespec[4+6+1];
}
else if(strcmp(cmdbuf, "stty") == 0 ) {
// stty <devpath> [78][NOE][012][bB]<baud> <command...>
char path_seg[32+1];
char modespec[4+6+1];
- if( fscanf(fp, "%32s %
6s ", &path_seg, &
modespec) != 2 ) {
+ if( fscanf(fp, "%32s %
10s ", path_seg,
modespec) != 2 ) {
goto lineError;
}
char **command = ReadCommand(fp);
goto lineError;
}
char **command = ReadCommand(fp);
@@
-239,8
+270,14
@@
int ProcessInittab(const char *Path)
// - Runs a daemon (respawning) that logs to the specified files
// - Will append a header whenever the daemon starts
char *stdout_path = ReadQuotedString(fp);
// - Runs a daemon (respawning) that logs to the specified files
// - Will append a header whenever the daemon starts
char *stdout_path = ReadQuotedString(fp);
+ if( !stdout_path )
+ goto lineError;
char *stderr_path = ReadQuotedString(fp);
char *stderr_path = ReadQuotedString(fp);
+ if( !stderr_path )
+ goto lineError;
char **command = ReadCommand(fp);
char **command = ReadCommand(fp);
+ if( !command )
+ goto lineError;
AddDaemon(stdout_path, stderr_path, command);
}
AddDaemon(stdout_path, stderr_path, command);
}
@@
-252,23
+289,33
@@
int ProcessInittab(const char *Path)
if(!command)
goto lineError;
if(!command)
goto lineError;
- int handles[] = {0, 1,
2
};
+ int handles[] = {0, 1,
1
};
int pid = _SysSpawn(command[0], (const char **)command, NULL, 3, handles, NULL);
int pid = _SysSpawn(command[0], (const char **)command, NULL, 3, handles, NULL);
- _SysWaitTID(pid, NULL);
+ int retstatus;
+ _SysWaitTID(pid, &retstatus);
+ _SysDebug("Command '%s' returned %i", command[0], retstatus);
FreeCommand(command);
}
else {
// Unknown command.
FreeCommand(command);
}
else {
// Unknown command.
+ _SysDebug("Unknown command '%s'", cmdbuf);
+ goto lineError;
}
}
+ fscanf(fp, " ");
continue;
lineError:
continue;
lineError:
+ _SysDebug("label lineError: goto'd - line %i, cmdbuf='%s'", line_num, cmdbuf);
while( !feof(fp) && fgetc(fp) != '\n' )
;
continue ;
}
fclose(fp);
while( !feof(fp) && fgetc(fp) != '\n' )
;
continue ;
}
fclose(fp);
+
+ if( gpInitPrograms == NULL )
+ return 2;
+
return 0;
}
return 0;
}
@@
-326,8
+373,9
@@
int AddSerialTerminal(const char *DevPathSegment, const char *ModeStr, char **Co
int baud;
// Parse mode string
int baud;
// Parse mode string
- if( sscanf(ModeStr, "%1[78]%1[NOE]%1[012]%*1[bB]%d", &dbit, &parity, &sbit, &baud) !=
5
) {
+ if( sscanf(ModeStr, "%1[78]%1[NOE]%1[012]%*1[bB]%d", &dbit, &parity, &sbit, &baud) !=
4
) {
// Oops?
// Oops?
+ _SysDebug("Serial mode string is invalid ('%s')", ModeStr);
return -1;
}
return -1;
}
@@
-370,7
+418,7
@@
int SpawnCommand(int c_stdin, int c_stdout, int c_stderr, char **ArgV)
_SysClose(c_stdin);
if( c_stdout != c_stdin )
_SysClose(c_stdout);
_SysClose(c_stdin);
if( c_stdout != c_stdin )
_SysClose(c_stdout);
- if( c_stderr != c_stdin && c_stderr != c_std
in
)
+ if( c_stderr != c_stdin && c_stderr != c_std
out
)
_SysClose(c_stderr);
return rv;
_SysClose(c_stderr);
return rv;
@@
-378,7
+426,7
@@
int SpawnCommand(int c_stdin, int c_stdout, int c_stderr, char **ArgV)
int SpawnKTerm(tInitProgram *Program)
{
int SpawnKTerm(tInitProgram *Program)
{
- const char fmt[] = "/Devices/
VTerm/
%i";
+ const char fmt[] = "/Devices/
pts/vt
%i";
char path[sizeof(fmt)];
snprintf(path, sizeof(path), fmt, Program->TypeInfo.KTerm.ID);
char path[sizeof(fmt)];
snprintf(path, sizeof(path), fmt, Program->TypeInfo.KTerm.ID);
@@
-394,6
+442,11
@@
int SpawnSTerm(tInitProgram *Program)
int in = _SysOpen(Program->TypeInfo.STerm.Path, OPENFLAG_READ);
int out = _SysOpen(Program->TypeInfo.STerm.Path, OPENFLAG_WRITE);
int in = _SysOpen(Program->TypeInfo.STerm.Path, OPENFLAG_READ);
int out = _SysOpen(Program->TypeInfo.STerm.Path, OPENFLAG_WRITE);
+ if(in == -1 || out == -1 ) {
+ _SysDebug("Unable to open serial port '%s'", Program->TypeInfo.STerm.Path);
+ return -1;
+ }
+
#if 0
if( _SysIOCtl(in, 0, NULL) != DRV_TYPE_SERIAL )
{
#if 0
if( _SysIOCtl(in, 0, NULL) != DRV_TYPE_SERIAL )
{
@@
-420,6
+473,13
@@
int SpawnDaemon(tInitProgram *Program)
return -2;
}
return -2;
}
+ // Log spawn header
+ {
+ char buffer[101];
+ size_t len = snprintf(buffer, 100, "[%i] init spawning '%s'\n", _SysTimestamp(), Program->Command);
+ _SysWrite(out, buffer, len);
+ }
+
return SpawnCommand(in, out, err, Program->Command);
}
return SpawnCommand(in, out, err, Program->Command);
}
UCC
git Repository :: git.ucc.asn.au